张保健 4 years ago
parent
commit
3f056695b1
1 changed files with 137 additions and 139 deletions
  1. 137 139
      src/xt_pages/data/components/tableson.vue

+ 137 - 139
src/xt_pages/data/components/tableson.vue View File

77
           <el-col :span="12">
77
           <el-col :span="12">
78
             <el-form-item label="排序" prop="order">
78
             <el-form-item label="排序" prop="order">
79
               <el-input
79
               <el-input
80
-                type="age"
81
-                v-model="temp.order"
80
+                type="number" 
81
+                v-model.number="temp.order"
82
                 placeholder="请输入排序值,数值越大,排序越靠前"
82
                 placeholder="请输入排序值,数值越大,排序越靠前"
83
               ></el-input>
83
               ></el-input>
84
             </el-form-item>
84
             </el-form-item>
136
   fetchPv,
136
   fetchPv,
137
   createArticle,
137
   createArticle,
138
   updateArticle
138
   updateArticle
139
-} from "@/api/article";
140
-import waves from "@/directive/waves"; // 水波纹指令
141
-import { parseTime } from "@/utils";
142
-import store from "@/store";
143
-import bus from "@/assets/eventBus";
139
+} from '@/api/article'
140
+import waves from '@/directive/waves' // 水波纹指令
141
+import { parseTime } from '@/utils'
142
+import store from '@/store'
143
+import bus from '@/assets/eventBus'
144
 import {
144
 import {
145
   createConfig,
145
   createConfig,
146
   createChildConfig,
146
   createChildConfig,
147
   updateChildConfig,
147
   updateChildConfig,
148
   deleteChildConfig
148
   deleteChildConfig
149
-} from "@/api/data";
149
+} from '@/api/data'
150
 
150
 
151
 const calendarTypeOptions = [
151
 const calendarTypeOptions = [
152
-  { key: "CN", display_name: "China" },
153
-  { key: "US", display_name: "USA" },
154
-  { key: "JP", display_name: "Japan" },
155
-  { key: "EU", display_name: "Eurozone" }
156
-];
152
+  { key: 'CN', display_name: 'China' },
153
+  { key: 'US', display_name: 'USA' },
154
+  { key: 'JP', display_name: 'Japan' },
155
+  { key: 'EU', display_name: 'Eurozone' }
156
+]
157
 
157
 
158
 // arr to obj ,such as { CN : "China", US : "USA" }
158
 // arr to obj ,such as { CN : "China", US : "USA" }
159
 const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
159
 const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
160
-  acc[cur.key] = cur.display_name;
161
-  return acc;
162
-}, {});
160
+  acc[cur.key] = cur.display_name
161
+  return acc
162
+}, {})
163
 
163
 
164
 export default {
164
 export default {
165
-  name: "tableson",
165
+  name: 'tableson',
166
   directives: {
166
   directives: {
167
     waves
167
     waves
168
   },
168
   },
169
   props: {
169
   props: {
170
     type: {
170
     type: {
171
       type: String,
171
       type: String,
172
-      default: "patient"
172
+      default: 'patient'
173
     }
173
     }
174
   },
174
   },
175
   data() {
175
   data() {
184
         importance: undefined,
184
         importance: undefined,
185
         title: undefined,
185
         title: undefined,
186
         type: this.type,
186
         type: this.type,
187
-        sort: "+id"
187
+        sort: '+id'
188
       },
188
       },
189
       importanceOptions: [1, 2, 3],
189
       importanceOptions: [1, 2, 3],
190
       calendarTypeOptions,
190
       calendarTypeOptions,
191
       sortOptions: [
191
       sortOptions: [
192
-        { label: "ID Ascending", key: "+id" },
193
-        { label: "ID Descending", key: "-id" }
192
+        { label: 'ID Ascending', key: '+id' },
193
+        { label: 'ID Descending', key: '-id' }
194
       ],
194
       ],
195
-      statusOptions: ["published", "draft", "deleted"],
195
+      statusOptions: ['published', 'draft', 'deleted'],
196
       showReviewer: false,
196
       showReviewer: false,
197
       temp: {
197
       temp: {
198
         id: undefined,
198
         id: undefined,
199
         parent_id: 0,
199
         parent_id: 0,
200
         module: this.type,
200
         module: this.type,
201
         org_id: 0,
201
         org_id: 0,
202
-        name: "",
202
+        name: '',
203
         field_name: undefined,
203
         field_name: undefined,
204
-        value: "",
205
-        remark: ""
204
+        value: '',
205
+        remark: ''
206
       },
206
       },
207
       dialogFormVisible: false,
207
       dialogFormVisible: false,
208
-      dialogStatus: "",
208
+      dialogStatus: '',
209
       textMap: {
209
       textMap: {
210
-        update: "编辑",
211
-        create: "新增"
210
+        update: '编辑',
211
+        create: '新增'
212
       },
212
       },
213
       dialogPvVisible: false,
213
       dialogPvVisible: false,
214
       pvData: [],
214
       pvData: [],
215
       rules: {
215
       rules: {
216
-        name: [{ required: true, message: "请输入名称", trigger: "blur" }],
217
-        order: [
218
-          { type: "number", message: "排序必须为数字值", trigger: "blur" }
219
-        ]
216
+        name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
217
+        order: [{ type: 'number', message: '排序必须为数字11', trigger: 'blur' }]
220
         // timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
218
         // timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
221
         // title: [{ required: true, message: 'title is required', trigger: 'blur' }]
219
         // title: [{ required: true, message: 'title is required', trigger: 'blur' }]
222
       },
220
       },
223
       downloadLoading: false,
221
       downloadLoading: false,
224
       parentConfig: undefined,
222
       parentConfig: undefined,
225
       addState: true
223
       addState: true
226
-    };
224
+    }
227
   },
225
   },
228
   computed: {
226
   computed: {
229
     list: function() {
227
     list: function() {
230
       if (this.parentConfig != undefined) {
228
       if (this.parentConfig != undefined) {
231
-        this.addState = false;
232
-        const list = store.getters.configlist[this.parentConfig.module];
229
+        this.addState = false
230
+        const list = store.getters.configlist[this.parentConfig.module]
233
         for (var i = 0; i < list.length; i++) {
231
         for (var i = 0; i < list.length; i++) {
234
           if (list[i].id === this.parentConfig.id) {
232
           if (list[i].id === this.parentConfig.id) {
235
-            return list[i]["childs"];
236
-            break;
233
+            return list[i]['childs']
234
+            break
237
           }
235
           }
238
         }
236
         }
239
         // return store.getters.configlist[this.parentConfig.module][this.parentConfig.index ]["childs"];
237
         // return store.getters.configlist[this.parentConfig.module][this.parentConfig.index ]["childs"];
243
   filters: {
241
   filters: {
244
     statusFilter(status) {
242
     statusFilter(status) {
245
       const statusMap = {
243
       const statusMap = {
246
-        published: "success",
247
-        draft: "info",
248
-        deleted: "danger"
249
-      };
250
-      return statusMap[status];
244
+        published: 'success',
245
+        draft: 'info',
246
+        deleted: 'danger'
247
+      }
248
+      return statusMap[status]
251
     },
249
     },
252
     typeFilter(type) {
250
     typeFilter(type) {
253
-      return calendarTypeKeyValue[type];
251
+      return calendarTypeKeyValue[type]
254
     }
252
     }
255
   },
253
   },
256
   created() {
254
   created() {
257
     // this.getList()
255
     // this.getList()
258
   },
256
   },
259
   mounted() {
257
   mounted() {
260
-    var _this = this;
261
-    bus.$on("parentChangeId", function(parentData) {
262
-      _this.parentConfig = parentData;
258
+    var _this = this
259
+    bus.$on('parentChangeId', function(parentData) {
260
+      _this.parentConfig = parentData
263
       // _this.list = parentData.childs
261
       // _this.list = parentData.childs
264
       _this.temp = {
262
       _this.temp = {
265
         id: undefined,
263
         id: undefined,
266
         parent_id: parentData.id,
264
         parent_id: parentData.id,
267
         module: parentData.module,
265
         module: parentData.module,
268
         org_id: parentData.org_id,
266
         org_id: parentData.org_id,
269
-        name: "",
267
+        name: '',
270
         field_name: undefined,
268
         field_name: undefined,
271
-        value: "",
272
-        remark: ""
273
-      };
274
-    });
269
+        value: '',
270
+        remark: ''
271
+      }
272
+    })
275
   },
273
   },
276
   methods: {
274
   methods: {
277
     handleRowChange(currentRow, oldCurrentRow) {
275
     handleRowChange(currentRow, oldCurrentRow) {
278
-      this.currentId = currentRow.id;
276
+      this.currentId = currentRow.id
279
     },
277
     },
280
 
278
 
281
     handleFilter() {
279
     handleFilter() {
282
-      this.listQuery.page = 1;
283
-      this.getList();
280
+      this.listQuery.page = 1
281
+      this.getList()
284
     },
282
     },
285
     handleSizeChange(val) {
283
     handleSizeChange(val) {
286
-      this.listQuery.limit = val;
287
-      this.getList();
284
+      this.listQuery.limit = val
285
+      this.getList()
288
     },
286
     },
289
     handleCurrentChange(val) {
287
     handleCurrentChange(val) {
290
-      this.listQuery.page = val;
291
-      this.getList();
288
+      this.listQuery.page = val
289
+      this.getList()
292
     },
290
     },
293
     handleModifyStatus(row, status) {
291
     handleModifyStatus(row, status) {
294
-      this.temp = Object.assign({}, row); // copy obj
295
-      this.$confirm("此操作将永久删除该配置项, 是否继续?", "提示", {
296
-        confirmButtonText: "确 定",
297
-        cancelButtonText: "取 消",
298
-        type: "warning"
292
+      this.temp = Object.assign({}, row) // copy obj
293
+      this.$confirm('此操作将永久删除该配置项, 是否继续?', '提示', {
294
+        confirmButtonText: '确 定',
295
+        cancelButtonText: '取 消',
296
+        type: 'warning'
299
       })
297
       })
300
         .then(() => {
298
         .then(() => {
301
-          const tempData = Object.assign({}, this.temp);
299
+          const tempData = Object.assign({}, this.temp)
302
           deleteChildConfig(tempData).then(response => {
300
           deleteChildConfig(tempData).then(response => {
303
             if (!response.data) {
301
             if (!response.data) {
304
               // 由于mockjs 不支持自定义状态码只能这样hack
302
               // 由于mockjs 不支持自定义状态码只能这样hack
305
-              reject("error");
303
+              reject('error')
306
             }
304
             }
307
             if (response.data.state === 0) {
305
             if (response.data.state === 0) {
308
-              this.$message.error(response.data.msg);
306
+              this.$message.error(response.data.msg)
309
             }
307
             }
310
 
308
 
311
-            const result = response.data.data.dataconfig;
309
+            const result = response.data.data.dataconfig
312
             store
310
             store
313
-              .dispatch("updateChildConfigList", [tempData, "delete"])
311
+              .dispatch('updateChildConfigList', [tempData, 'delete'])
314
               .then(() => {
312
               .then(() => {
315
-                next();
316
-              });
317
-          });
313
+                next()
314
+              })
315
+          })
318
 
316
 
319
           this.$message({
317
           this.$message({
320
-            type: "success",
321
-            message: "删除成功!"
322
-          });
318
+            type: 'success',
319
+            message: '删除成功!'
320
+          })
323
         })
321
         })
324
         .catch(() => {
322
         .catch(() => {
325
           this.$message({
323
           this.$message({
326
-            type: "info",
327
-            message: "已取消删除"
328
-          });
329
-        });
324
+            type: 'info',
325
+            message: '已取消删除'
326
+          })
327
+        })
330
     },
328
     },
331
     resetTemp() {
329
     resetTemp() {
332
       this.temp = {
330
       this.temp = {
334
         parent_id: this.parentConfig.id,
332
         parent_id: this.parentConfig.id,
335
         module: this.parentConfig.module,
333
         module: this.parentConfig.module,
336
         org_id: this.parentConfig.org_id,
334
         org_id: this.parentConfig.org_id,
337
-        name: "",
335
+        name: '',
338
         field_name: undefined,
336
         field_name: undefined,
339
-        value: "",
340
-        remark: ""
341
-      };
337
+        value: '',
338
+        remark: ''
339
+      }
342
     },
340
     },
343
     handleCreate() {
341
     handleCreate() {
344
-      this.resetTemp();
345
-      this.dialogStatus = "create";
346
-      this.dialogFormVisible = true;
342
+      this.resetTemp()
343
+      this.dialogStatus = 'create'
344
+      this.dialogFormVisible = true
347
       this.$nextTick(() => {
345
       this.$nextTick(() => {
348
-        this.$refs["dataForm"].clearValidate();
349
-      });
346
+        this.$refs['dataForm'].clearValidate()
347
+      })
350
     },
348
     },
351
     createData() {
349
     createData() {
352
-      this.$refs["dataForm"].validate(valid => {
350
+      this.$refs['dataForm'].validate(valid => {
353
         if (valid) {
351
         if (valid) {
354
           createChildConfig(this.temp).then(response => {
352
           createChildConfig(this.temp).then(response => {
355
             if (!response.data) {
353
             if (!response.data) {
356
               // 由于mockjs 不支持自定义状态码只能这样hack
354
               // 由于mockjs 不支持自定义状态码只能这样hack
357
-              reject("error");
355
+              reject('error')
358
             }
356
             }
359
             if (response.data.state === 0) {
357
             if (response.data.state === 0) {
360
-              this.$message.error(response.data.msg);
358
+              this.$message.error(response.data.msg)
361
             }
359
             }
362
-            const result = response.data.data.dataconfig;
360
+            const result = response.data.data.dataconfig
363
 
361
 
364
             // this.list.unshift(tempval)
362
             // this.list.unshift(tempval)
365
             // 更新store
363
             // 更新store
366
             store
364
             store
367
-              .dispatch("updateChildConfigList", [result, "create"])
368
-              .then(() => {});
365
+              .dispatch('updateChildConfigList', [result, 'create'])
366
+              .then(() => {})
369
 
367
 
370
-            this.dialogFormVisible = false;
371
-            this.$message.success("创建成功");
372
-          });
368
+            this.dialogFormVisible = false
369
+            this.$message.success('创建成功')
370
+          })
373
         }
371
         }
374
-      });
372
+      })
375
     },
373
     },
376
     handleUpdate(row) {
374
     handleUpdate(row) {
377
-      this.temp = Object.assign({}, row); // copy obj
378
-      this.dialogStatus = "update";
379
-      this.dialogFormVisible = true;
375
+      this.temp = Object.assign({}, row) // copy obj
376
+      this.dialogStatus = 'update'
377
+      this.dialogFormVisible = true
380
       this.$nextTick(() => {
378
       this.$nextTick(() => {
381
-        this.$refs["dataForm"].clearValidate();
382
-      });
379
+        this.$refs['dataForm'].clearValidate()
380
+      })
383
     },
381
     },
384
     updateData() {
382
     updateData() {
385
-      this.$refs["dataForm"].validate(valid => {
383
+      this.$refs['dataForm'].validate(valid => {
386
         if (valid) {
384
         if (valid) {
387
-          const tempData = Object.assign({}, this.temp);
388
-          console.log("tempData", tempData);
385
+          const tempData = Object.assign({}, this.temp)
386
+          console.log('tempData', tempData)
389
           updateChildConfig(tempData).then(response => {
387
           updateChildConfig(tempData).then(response => {
390
             if (!response.data) {
388
             if (!response.data) {
391
               // 由于mockjs 不支持自定义状态码只能这样hack
389
               // 由于mockjs 不支持自定义状态码只能这样hack
392
-              reject("error");
390
+              reject('error')
393
             }
391
             }
394
             if (response.data.state === 0) {
392
             if (response.data.state === 0) {
395
-              this.$message.error(response.data.msg);
393
+              this.$message.error(response.data.msg)
396
             }
394
             }
397
 
395
 
398
-            const result = response.data.data.dataconfig;
396
+            const result = response.data.data.dataconfig
399
             store
397
             store
400
-              .dispatch("updateChildConfigList", [result, "update"])
401
-              .then(() => {});
398
+              .dispatch('updateChildConfigList', [result, 'update'])
399
+              .then(() => {})
402
 
400
 
403
-            this.dialogFormVisible = false;
401
+            this.dialogFormVisible = false
404
 
402
 
405
-            this.$message.success("更新成功");
406
-          });
403
+            this.$message.success('更新成功')
404
+          })
407
         }
405
         }
408
-      });
406
+      })
409
     },
407
     },
410
     handleDelete(row) {
408
     handleDelete(row) {
411
-      this.$message.success("删除成功");
412
-      const index = this.list.indexOf(row);
413
-      this.list.splice(index, 1);
409
+      this.$message.success('删除成功')
410
+      const index = this.list.indexOf(row)
411
+      this.list.splice(index, 1)
414
     },
412
     },
415
     handleFetchPv(pv) {
413
     handleFetchPv(pv) {
416
       fetchPv(pv).then(response => {
414
       fetchPv(pv).then(response => {
417
-        this.pvData = response.data.pvData;
418
-        this.dialogPvVisible = true;
419
-      });
415
+        this.pvData = response.data.pvData
416
+        this.dialogPvVisible = true
417
+      })
420
     },
418
     },
421
     handleDownload() {
419
     handleDownload() {
422
-      this.downloadLoading = true;
423
-      import("@/vendor/Export2Excel").then(excel => {
424
-        const tHeader = ["timestamp", "title", "type", "importance", "status"];
420
+      this.downloadLoading = true
421
+      import('@/vendor/Export2Excel').then(excel => {
422
+        const tHeader = ['timestamp', 'title', 'type', 'importance', 'status']
425
         const filterVal = [
423
         const filterVal = [
426
-          "timestamp",
427
-          "title",
428
-          "type",
429
-          "importance",
430
-          "status"
431
-        ];
432
-        const data = this.formatJson(filterVal, this.list);
424
+          'timestamp',
425
+          'title',
426
+          'type',
427
+          'importance',
428
+          'status'
429
+        ]
430
+        const data = this.formatJson(filterVal, this.list)
433
         excel.export_json_to_excel({
431
         excel.export_json_to_excel({
434
           header: tHeader,
432
           header: tHeader,
435
           data,
433
           data,
436
-          filename: "table-list"
437
-        });
438
-        this.downloadLoading = false;
439
-      });
434
+          filename: 'table-list'
435
+        })
436
+        this.downloadLoading = false
437
+      })
440
     },
438
     },
441
     formatJson(filterVal, jsonData) {
439
     formatJson(filterVal, jsonData) {
442
       return jsonData.map(v =>
440
       return jsonData.map(v =>
443
         filterVal.map(j => {
441
         filterVal.map(j => {
444
-          if (j === "timestamp") {
445
-            return parseTime(v[j]);
442
+          if (j === 'timestamp') {
443
+            return parseTime(v[j])
446
           } else {
444
           } else {
447
-            return v[j];
445
+            return v[j]
448
           }
446
           }
449
         })
447
         })
450
-      );
448
+      )
451
     }
449
     }
452
   }
450
   }
453
-};
451
+}
454
 </script>
452
 </script>
455
 
453
 
456
 <style rel="stylesheet/css" lang="scss" scoped></style>
454
 <style rel="stylesheet/css" lang="scss" scoped></style>