Эх сурвалжийг харах

质检方案选择物品列表数据清除

hezhanp 8 сар өмнө
parent
commit
a7297f93db

+ 307 - 306
src/views/inspectionTemplate/AddorUpdate.vue

@@ -135,8 +135,8 @@
           tool-class="ele-toolbar-form"
           row-key="qualityLevelId"
           @selection-change="selectionChange"
-              @columns-change="handleColumnChange"
-              :cache-key="cacheKeyUrl"
+          @columns-change="handleColumnChange"
+          :cache-key="cacheKeyUrl"
         >
           <template v-slot:toolbar>
             <el-button @click="handAdd(1)" size="mini" type="primary"
@@ -255,7 +255,7 @@
       </el-row>
     </el-form>
     <span slot="footer" class="dialog-footer">
-      <el-button @click="visible = false">取消</el-button>
+      <el-button @click="handleClose()">取消</el-button>
       <el-button type="primary" @click="dataFormSubmit()">保存</el-button>
     </span>
     <termPop ref="termRef" @selectChange="selectChange"></termPop>
@@ -273,331 +273,332 @@
 </template>
 
 <script>
-  import termPop from '@/views/inspectionTemplate/inspectionClassify/index.vue';
-  import EquipmentDialog from '@/views/unqualifiedProduct/unqualifiedList/components/EquipmentDialog.vue';
-  import { getByCode } from '@/api/system/dictionary-data';
+import termPop from '@/views/inspectionTemplate/inspectionClassify/index.vue';
+import EquipmentDialog from '@/views/unqualifiedProduct/unqualifiedList/components/EquipmentDialog.vue';
+import { getByCode } from '@/api/system/dictionary-data';
 import tabMixins from '@/mixins/tableColumnsMixin';
 
-  import {
-    save,
-    update,
-    getById,
-    templatecategoryPage
-  } from '@/api/inspectionTemplate';
-  import { getCode } from '@/api/login';
-  export default {
-    components: { termPop, EquipmentDialog },
-    mixins:[tabMixins],
-      data() {
-      return {
+import {
+  save,
+  update,
+  getById,
+  templatecategoryPage
+} from '@/api/inspectionTemplate';
+import { getCode } from '@/api/login';
+export default {
+  components: { termPop, EquipmentDialog },
+  mixins: [tabMixins],
+  data() {
+    return {
       cacheKeyUrl: 'qms-c2e9664a-inspectionTemplate-AddorUpdate',
       columnsVersion: 1,
-        visible: false,
-        dataForm: {
-          id: 0,
-          type: null,
-          qualitySchemeTemplateName: '',
-          qualitySchemeTemplateCode: '',
-          inspectionItemVOList: [],
-          status: 1,
-          templateRemark: '',
-          sampleProportion: '',
-          sampleProportionUnit: '%',
-          validityPeriod: '',
-          validityPeriodUnit: ''
+      visible: false,
+      dataForm: {
+        id: 0,
+        type: null,
+        qualitySchemeTemplateName: '',
+        qualitySchemeTemplateCode: '',
+        inspectionItemVOList: [],
+        status: 1,
+        templateRemark: '',
+        sampleProportion: '',
+        sampleProportionUnit: '%',
+        validityPeriod: '',
+        validityPeriodUnit: ''
+      },
+      columns: [
+        {
+          width: 45,
+          type: 'selection',
+          columnKey: 'selection',
+          align: 'center',
+          reserveSelection: true
+        },
+        {
+          columnKey: 'index',
+          label: '序号',
+          type: 'index',
+          width: 55,
+          align: 'center',
+          showOverflowTooltip: true,
+          fixed: 'left'
+        },
+        {
+          label: '排序',
+          width: 100,
+          align: 'center',
+          slot: 'sort',
+          prop: 'sort',
+          fixed: 'left'
+        },
+        {
+          prop: 'categoryLevelClassName',
+          label: '质检类型',
+          align: 'center',
+          minWidth: 150
+        },
+        {
+          prop: 'inspectionCode',
+          label: '编码',
+          showOverflowTooltip: true,
+          align: 'center',
+          minWidth: 150
+        },
+        {
+          prop: 'inspectionName',
+          slot: 'inspectionName',
+          label: '名称',
+          showOverflowTooltip: true,
+          align: 'center',
+          minWidth: 150
+        },
+        {
+          prop: 'defaultValue',
+          slot: 'defaultValue',
+          label: '工艺参数',
+          align: 'center',
+          minWidth: 400,
+          columnKey: 'defaultValue'
         },
-        columns: [
-          {
-            width: 45,
-            type: 'selection',
-            columnKey: 'selection',
-            align: 'center',
-            reserveSelection: true
-          },
-          {
-            columnKey: 'index',
-            label: '序号',
-            type: 'index',
-            width: 55,
-            align: 'center',
-            showOverflowTooltip: true,
-            fixed: 'left'
-          },
-          {
-            label: '排序',
-            width: 100,
-            align: 'center',
-            slot: 'sort',
-            prop: 'sort',
-            fixed: 'left'
-          },
-          {
-            prop: 'categoryLevelClassName',
-            label: '质检类型',
-            align: 'center',
-            minWidth: 150
-          },
-          {
-            prop: 'inspectionCode',
-            label: '编码',
-            showOverflowTooltip: true,
-            align: 'center',
-            minWidth: 150
-          },
-          {
-            prop: 'inspectionName',
-            slot: 'inspectionName',
-            label: '名称',
-            showOverflowTooltip: true,
-            align: 'center',
-            minWidth: 150
-          },
-          {
-            prop: 'defaultValue',
-            slot: 'defaultValue',
-            label: '工艺参数',
-            align: 'center',
-            minWidth: 400,
-            columnKey: 'defaultValue'
-          },
 
-          {
-            columnKey: 'action',
-            label: '操作',
-            width: 80,
-            align: 'center',
-            resizable: false,
-            slot: 'action',
-            fixed: 'right'
-          }
+        {
+          columnKey: 'action',
+          label: '操作',
+          width: 80,
+          align: 'center',
+          resizable: false,
+          slot: 'action',
+          fixed: 'right'
+        }
+      ],
+      categoryColumns: [
+        {
+          width: 45,
+          type: 'selection',
+          columnKey: 'selection',
+          align: 'center',
+          reserveSelection: true
+        },
+        {
+          columnKey: 'index',
+          label: '序号',
+          type: 'index',
+          width: 55,
+          align: 'center',
+          showOverflowTooltip: true,
+          fixed: 'left'
+        },
+        {
+          prop: 'categoryLevelPath',
+          label: '分类',
+          align: 'center',
+          minWidth: 150
+        },
+        {
+          prop: 'code',
+          label: '编码',
+          showOverflowTooltip: true,
+          align: 'center',
+          minWidth: 150
+        },
+        {
+          prop: 'name',
+          label: '名称',
+          showOverflowTooltip: true,
+          align: 'center',
+          minWidth: 150
+        },
+        {
+          prop: 'specification',
+          label: '规格',
+          align: 'center',
+          minWidth: 150
+        },
+        {
+          prop: 'modelType',
+          label: '型号',
+          align: 'center',
+          minWidth: 150
+        },
+        {
+          prop: 'brandNum',
+          label: '牌号',
+          align: 'center',
+          minWidth: 150
+        },
+        {
+          columnKey: 'action',
+          label: '操作',
+          width: 80,
+          align: 'center',
+          resizable: false,
+          slot: 'action',
+          fixed: 'right'
+        }
+      ],
+      dataRule: {
+        type: [{ required: true, message: '请选择类型', trigger: 'blur' }],
+        qualitySchemeTemplateName: [
+          { required: true, message: '请输入质检方案名称', trigger: 'blur' }
         ],
-        categoryColumns: [
-          {
-            width: 45,
-            type: 'selection',
-            columnKey: 'selection',
-            align: 'center',
-            reserveSelection: true
-          },
-          {
-            columnKey: 'index',
-            label: '序号',
-            type: 'index',
-            width: 55,
-            align: 'center',
-            showOverflowTooltip: true,
-            fixed: 'left'
-          },
-          {
-            prop: 'categoryLevelPath',
-            label: '分类',
-            align: 'center',
-            minWidth: 150
-          },
+        status: [
           {
-            prop: 'code',
-            label: '编码',
-            showOverflowTooltip: true,
-            align: 'center',
-            minWidth: 150
-          },
-          {
-            prop: 'name',
-            label: '名称',
-            showOverflowTooltip: true,
-            align: 'center',
-            minWidth: 150
-          },
-          {
-            prop: 'specification',
-            label: '规格',
-            align: 'center',
-            minWidth: 150
-          },
-          {
-            prop: 'modelType',
-            label: '型号',
-            align: 'center',
-            minWidth: 150
-          },
-          {
-            prop: 'brandNum',
-            label: '牌号',
-            align: 'center',
-            minWidth: 150
-          },
-          {
-            columnKey: 'action',
-            label: '操作',
-            width: 80,
-            align: 'center',
-            resizable: false,
-            slot: 'action',
-            fixed: 'right'
+            required: true,
+            message: '请选择状态',
+            trigger: 'blur'
           }
-        ],
-        dataRule: {
-          type: [{ required: true, message: '请选择类型', trigger: 'blur' }],
-          qualitySchemeTemplateName: [
-            { required: true, message: '请输入质检方案名称', trigger: 'blur' }
-          ],
-          status: [
-            {
-              required: true,
-              message: '请选择状态',
-              trigger: 'blur'
-            }
-          ]
-        },
-        list: [],
-        templateCategoryList: [],
-        typeList: []
-      };
-    },
-    methods: {
-      async getTnspectionPlanType() {
-        let res = await getByCode('inspection_plan_type');
-        if (res?.code == 0) {
-          let list = res.data.map((item) => {
-            let key = Object.keys(item)[0];
-            return { value: key, label: item[key] };
-          });
-          this.typeList = list;
-        }
+        ]
       },
-      handAdd(type) {
-        if (type == 1) {
-          this.$refs.termRef.open(this.list);
-        }
-        if (type == 2) {
-          this.$refs.equipmentRefs.open();
-        }
-      },
-      handleClose() {
-        this.visible = false;
-      },
-      selectionChange(selection) {
-        console.log(selection, 'selection');
-      },
-      selectChange(list) {
-        this.list = list.map(item=>{
-          item['sort']=item['sort']||0
-          return item
+      list: [],
+      templateCategoryList: [],
+      typeList: []
+    };
+  },
+  methods: {
+    async getTnspectionPlanType() {
+      let res = await getByCode('inspection_plan_type');
+      if (res?.code == 0) {
+        let list = res.data.map((item) => {
+          let key = Object.keys(item)[0];
+          return { value: key, label: item[key] };
         });
-      },
-      handDel(index, type) {
-        if (type == 1) {
-          this.list.splice(index, 1);
-        }
-        if (type == 2) {
-          this.templateCategoryList.splice(index, 1);
+        this.typeList = list;
+      }
+    },
+    handAdd(type) {
+      if (type == 1) {
+        this.$refs.termRef.open(this.list);
+      }
+      if (type == 2) {
+        this.$refs.equipmentRefs.open();
+      }
+    },
+    handleClose() {
+      this.visible = false;
+      this.templateCategoryList = [];
+    },
+    selectionChange(selection) {
+      console.log(selection, 'selection');
+    },
+    selectChange(list) {
+      this.list = list.map((item) => {
+        item['sort'] = item['sort'] || 0;
+        return item;
+      });
+    },
+    handDel(index, type) {
+      if (type == 1) {
+        this.list.splice(index, 1);
+      }
+      if (type == 2) {
+        this.templateCategoryList.splice(index, 1);
+      }
+    },
+    confirmChoose(list) {
+      let categoryList = list.map((item) => {
+        item['name'] = item.name;
+        item['categoryId'] = item.id;
+        item['id'] = '';
+        return item;
+      });
+      this.templateCategoryList.push(...categoryList);
+    },
+    init(id) {
+      this.getTnspectionPlanType();
+      this.dataForm.id = id || 0;
+      this.visible = true;
+      this.$nextTick(async () => {
+        this.$refs['dataForm'].resetFields();
+        if (this.dataForm.id) {
+          getById(this.dataForm.id).then(({ data }) => {
+            this.dataForm = data;
+            let itemVOList = [];
+            if (data.inspectionItemVOList.length > 0) {
+              itemVOList = data.inspectionItemVOList.map((item) => {
+                item.inspectionItemId = this.dataForm.id;
+                // item.push({
+                //   inspectionItemId: this.dataForm.id
+                // });
+                return item;
+              });
+            }
+            // this.list = data.inspectionItemVOList;
+            this.list = itemVOList;
+            console.log(this.list);
+          });
+          templatecategoryPage({
+            templateId: this.dataForm.id,
+            size: -1
+          }).then((data) => {
+            console.log(data, 'data');
+            this.templateCategoryList = data.list;
+          });
+          // this.templateCategoryList=data.templateCategoryList||[];
+        } else {
+          const code = await getCode('template_code');
+          this.dataForm.qualitySchemeTemplateCode = code;
+          this.list = [];
         }
-      },
-      confirmChoose(list) {
-        let categoryList = list.map((item) => {
-          item['name'] = item.name;
-          item['categoryId'] = item.id;
-          item['id'] = '';
-          return item;
-        });
-        this.templateCategoryList.push(...categoryList);
-      },
-      init(id) {
-        this.getTnspectionPlanType();
-        this.dataForm.id = id || 0;
-        this.visible = true;
-        this.$nextTick(async () => {
-          this.$refs['dataForm'].resetFields();
+      });
+    },
+    // 表单提交
+    dataFormSubmit() {
+      this.$refs['dataForm'].validate((valid) => {
+        if (valid) {
+          if (!this.dataForm.id) {
+            delete this.dataForm.id;
+          }
+          const saveOrUpdate = this.dataForm.id ? update : save;
           if (this.dataForm.id) {
-            getById(this.dataForm.id).then(({ data }) => {
-              this.dataForm = data;
-              let itemVOList = [];
-              if (data.inspectionItemVOList.length > 0) {
-                itemVOList = data.inspectionItemVOList.map((item) => {
-                  item.inspectionItemId = this.dataForm.id;
-                  // item.push({
-                  //   inspectionItemId: this.dataForm.id
-                  // });
-                  return item;
-                });
+            this.dataForm.inspectionItemVOList = this.list.map((item) => {
+              if (!item.inspectionItemId) {
+                item.inspectionItemId = this.dataForm.id;
+                item.id = '';
               }
-              // this.list = data.inspectionItemVOList;
-              this.list = itemVOList;
-              console.log(this.list);
-            });
-            templatecategoryPage({
-              templateId: this.dataForm.id,
-              size: -1
-            }).then((data) => {
-              console.log(data, 'data');
-              this.templateCategoryList = data.list;
+              return item;
             });
-            // this.templateCategoryList=data.templateCategoryList||[];
           } else {
-            const code = await getCode('template_code');
-            this.dataForm.qualitySchemeTemplateCode = code;
-            this.list = [];
+            this.dataForm.inspectionItemVOList = this.list.map((item) => {
+              item.id = '';
+              return item;
+            });
           }
-        });
-      },
-      // 表单提交
-      dataFormSubmit() {
-        this.$refs['dataForm'].validate((valid) => {
-          if (valid) {
-            if (!this.dataForm.id) {
-              delete this.dataForm.id;
-            }
-            const saveOrUpdate = this.dataForm.id ? update : save;
-            if (this.dataForm.id) {
-              this.dataForm.inspectionItemVOList = this.list.map((item) => {
-                if (!item.inspectionItemId) {
-                  item.inspectionItemId = this.dataForm.id;
-                  item.id = '';
-                }
-                return item;
-              });
-            } else {
-              this.dataForm.inspectionItemVOList = this.list.map((item) => {
-                item.id = '';
-                return item;
-              });
-            }
 
-            this.dataForm.templateCategoryList = this.templateCategoryList;
+          this.dataForm.templateCategoryList = this.templateCategoryList;
 
-            saveOrUpdate(this.dataForm)
-              .then((msg) => {
-                this.loading = false;
-                this.$refs['dataForm'].resetFields();
-                // this.dataForm = {};
-                const info = this.dataForm.id ? '修改成功' : '新增成功';
-                this.$message.success(info);
-                this.visible = false;
-                // this.updateVisible(false);
-                this.$emit('refreshDataList');
-              })
-              .catch((e) => {
-                this.loading = false;
-              });
-          }
-        });
-      }
-    },
-    watch: {
-      'dataForm.type': {
-        handler(val) {
-          if (val == 2) {
-            this.templateCategoryList = [];
-          }
+          saveOrUpdate(this.dataForm)
+            .then((msg) => {
+              this.loading = false;
+              this.$refs['dataForm'].resetFields();
+              // this.dataForm = {};
+              const info = this.dataForm.id ? '修改成功' : '新增成功';
+              this.$message.success(info);
+              this.visible = false;
+              // this.updateVisible(false);
+              this.$emit('refreshDataList');
+            })
+            .catch((e) => {
+              this.loading = false;
+            });
+        }
+      });
+    }
+  },
+  watch: {
+    'dataForm.type': {
+      handler(val) {
+        if (val == 2) {
+          this.templateCategoryList = [];
         }
       }
     }
-  };
+  }
+};
 </script>
 <style lang="scss" scoped>
-  .title {
-    font-weight: bold;
-    padding-bottom: 20px;
-    padding-top: 20px;
-  }
+.title {
+  font-weight: bold;
+  padding-bottom: 20px;
+  padding-top: 20px;
+}
 </style>