station.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <div>
  3. <div class="query mg-b-8">
  4. <div class="query-items">
  5. <div class="query-item">
  6. <div class="lable">故障名称:</div>
  7. <div class="search-input">
  8. <el-input
  9. v-model="search"
  10. size="small"
  11. placeholder="输入报警分类"
  12. @input="filterFault"
  13. />
  14. </div>
  15. </div>
  16. </div>
  17. <div class="query-actions" style="margin-left: 50px">
  18. <button class="btn green" @click="insertItem()">新增</button>
  19. </div>
  20. </div>
  21. <div class="df-table">
  22. <el-table :data="tableData" class="custom-table" height="85vh">
  23. <el-table-column type="index" label="序号" align="center" width="50" />
  24. <el-table-column prop="name" align="center" label="报警类别" />
  25. <el-table-column prop="code" align="center" label="故障编码" />
  26. <el-table-column prop="time" align="center" label="创建时间" />
  27. <el-table-column align="center" label="操作">
  28. <template v-slot="scope">
  29. <el-button type="text" @click="editItem(scope)">编辑</el-button>
  30. <el-button type="text" @click="delItem(scope)" disabled>删除</el-button>
  31. </template>
  32. </el-table-column>
  33. </el-table>
  34. <el-dialog
  35. :title="dialogTitle"
  36. v-model="dialogShow"
  37. width="50%"
  38. top="15vh"
  39. custom-class="modal"
  40. :close-on-click-modal="true"
  41. >
  42. <el-form
  43. ref="ruleFormRef"
  44. :model="ruleForm"
  45. :rules="rules"
  46. label-width="120px"
  47. size="default"
  48. >
  49. <el-form-item :label="`${ruleForm['name--name--']}:`" prop="name">
  50. <el-input
  51. v-model="ruleForm.name"
  52. :placeholder="`请输入${ruleForm['name--name--']}`"
  53. type="input"
  54. />
  55. </el-form-item>
  56. <el-form-item :label="`${ruleForm['code--name--']}:`" prop="code">
  57. <el-input
  58. v-model="ruleForm.code"
  59. :placeholder="`请输入${ruleForm['code--name--']}`"
  60. type="input"
  61. :disabled="codedisabled"
  62. />
  63. </el-form-item>
  64. <el-form-item
  65. :label="`${ruleForm['remark--name--']}:`"
  66. prop="remark"
  67. >
  68. <el-input
  69. v-model="ruleForm.remark"
  70. :placeholder="`请输入${ruleForm['remark--name--']}`"
  71. type="input"
  72. />
  73. </el-form-item>
  74. </el-form>
  75. <template #footer>
  76. <span class="dialog-footer">
  77. <el-button type="info" size="medium" @click="cancel"
  78. >取消</el-button
  79. >
  80. <el-button
  81. type="success"
  82. size="medium"
  83. @click="submit('ruleFormRef')"
  84. >提交</el-button
  85. >
  86. </span>
  87. </template>
  88. </el-dialog>
  89. </div>
  90. </div>
  91. </template>
  92. <script>
  93. import { ElMessageBox } from "element-plus";
  94. export default {
  95. data() {
  96. return {
  97. sourceTableData: [],
  98. tableData: [],
  99. dialogTitle: "",
  100. dialogShow: false,
  101. codedisabled: false,
  102. ruleForm: {
  103. name: "",
  104. "name--name--": "报警类别",
  105. code: "",
  106. "code--name--": "编码",
  107. remark: "",
  108. "remark--name--": "备注",
  109. },
  110. rules: {
  111. name: [
  112. {
  113. required: true,
  114. message: "不可为空",
  115. trigger: "blur",
  116. },
  117. ],
  118. code: [
  119. {
  120. required: true,
  121. message: "不可为空",
  122. trigger: "blur",
  123. },
  124. ],
  125. },
  126. };
  127. },
  128. created() {
  129. this.getStationType();
  130. this.renderRules();
  131. },
  132. methods: {
  133. // 获取所有故障类型
  134. getStationType() {
  135. const that = this;
  136. this.API.requestData({
  137. subUrl: "station/all",
  138. success(res) {
  139. that.tableData = res.data;
  140. },
  141. });
  142. },
  143. // 取消新增或编辑
  144. cancel() {
  145. this.dialogShow = false;
  146. },
  147. //新增
  148. insertItem() {
  149. this.resetForm();
  150. this.dialogShow = true;
  151. this.dialogTitle = "新增";
  152. this.codedisabled = false;
  153. },
  154. // 编辑某一条
  155. editItem({ row }) {
  156. for (let key in row) {
  157. if (key !== "time") {
  158. this.ruleForm[key] = row[key];
  159. }
  160. }
  161. this.dialogShow = true;
  162. this.dialogTitle = "编辑";
  163. this.codedisabled = true;
  164. },
  165. // 删除某一条
  166. delItem({ row }) {
  167. const that = this;
  168. ElMessageBox.alert(`确定删除${row.name}?此操作不可逆!`, "", {
  169. showCancelButton: true,
  170. showConfirmButton: true,
  171. confirmButtonText: "确定",
  172. cancelButtonText: "我再想想",
  173. callback(action) {
  174. if (action === "confirm") {
  175. that.API.requestData({
  176. subUrl: "know/fault/type/delete",
  177. data: {
  178. id: row.id,
  179. },
  180. success() {
  181. that.BASE.showMsg({
  182. type: "success",
  183. msg: `删除成功`,
  184. });
  185. that.dialogShow = false;
  186. },
  187. });
  188. }
  189. },
  190. });
  191. },
  192. // 提交编辑或者新增数据
  193. submit(formName = "") {
  194. const that = this;
  195. that.$refs[formName].validate((valid) => {
  196. if (valid) {
  197. let data = {};
  198. for (let key in that.ruleForm) {
  199. if (key.indexOf("--name--") === -1) {
  200. data[key] = that.ruleForm[key];
  201. }
  202. }
  203. data.time = new Date().formatDate("yyyy-MM-dd hh:mm:ss");
  204. data.category = 'GZ';
  205. that.API.request({
  206. method: 'POST',
  207. subUrl: "know/fault/type/insert",
  208. data,
  209. success() {
  210. that.BASE.showMsg({
  211. type: "success",
  212. msg: `${data.id ? "编辑" : "新增"}成功`,
  213. });
  214. that.dialogShow = false;
  215. that.getStationType();
  216. },
  217. });
  218. } else {
  219. return false;
  220. }
  221. });
  222. },
  223. // 渲染 rules 中文描述
  224. renderRules() {
  225. for (let key in this.rules) {
  226. this.rules[key].forEach((ele) => {
  227. ele.message = `${this.ruleForm[key + "--name--"]}` + ele.message;
  228. });
  229. }
  230. },
  231. // 重置表单并且重置表单效验
  232. resetForm() {
  233. this.dialogTitle = "";
  234. this.ruleForm.id && delete this.ruleForm.id;
  235. for (let key in this.ruleForm) {
  236. if (key.indexOf("--name--") === -1) {
  237. this.ruleForm[key] = "";
  238. }
  239. }
  240. },
  241. },
  242. };
  243. </script>
  244. <style lang="less" scpoed>
  245. .el-form {
  246. margin-left: 50px;
  247. }
  248. .el-form .el-form-item {
  249. margin-top: 40px;
  250. width: 80%;
  251. display: flex;
  252. justify-items: center;
  253. }
  254. </style>