Просмотр исходного кода

优化质检项表单校验逻辑并统一数据源引用

yusheng 5 месяцев назад
Родитель
Сommit
9a03792735
2 измененных файлов с 138 добавлено и 70 удалено
  1. 124 67
      src/views/inspectionTemplate/AddorUpdate.vue
  2. 14 3
      src/views/inspectionWork/index.vue

+ 124 - 67
src/views/inspectionTemplate/AddorUpdate.vue

@@ -167,7 +167,7 @@
         <ele-pro-table
           ref="table"
           :columns="columns"
-          :datasource="list"
+          :datasource="dataForm.inspectionItemVOList"
           height="400px"
           full-height="calc(100vh - 76px)"
           tool-class="ele-toolbar-form"
@@ -206,8 +206,20 @@
             {{ getDictValue('质检标准类型', row.qualityStandardType) }}
           </template>
 
-          <template v-slot:inspectionName="{ row }">
-            <div> <el-input v-model="row.inspectionName"></el-input></div>
+          <template v-slot:inspectionName="{ row, $index }">
+            <div>
+              <el-form-item
+                label-width="0"
+                :rules="{
+                  required: true,
+                  message: ' ',
+                  trigger: 'change'
+                }"
+                :prop="'inspectionItemVOList.' + $index + '.inspectionName'"
+              >
+                <el-input v-model="row.inspectionName"></el-input>
+              </el-form-item>
+            </div>
           </template>
           <template v-slot:sort="{ row }">
             <el-input
@@ -217,44 +229,67 @@
               placeholder="输入排序"
             ></el-input>
           </template>
-          <template v-slot:defaultValue="{ row }">
-            <div style="width: 100%; display: flex">
-              <DictSelection
-                style="width: 85px"
-                clearable
-                dictName="数学字符"
-                v-model="row.symbol"
-              ></DictSelection>
-              <div v-if="row.textType == 3">
-                <el-input v-model="row.minValue" style="width: 80px"></el-input
-                >-
-                <el-input v-model="row.maxValue" style="width: 80px">
-                </el-input>
-              </div>
+          <template v-slot:defaultValue="{ row, $index }">
+            <el-form-item
+              label-width="0"
+              :rules="{
+                required: true,
+                message: ' ',
+                trigger: 'change'
+              }"
+              :prop="'inspectionItemVOList.' + $index + '.defaultValue'"
+            >
+              <div style="width: 100%; display: flex">
+                <DictSelection
+                  style="width: 85px"
+                  clearable
+                  dictName="数学字符"
+                  v-model="row.symbol"
+                ></DictSelection>
+                <div v-if="row.textType == 3">
+                  <el-input
+                    v-model="row.minValue"
+                    style="width: 80px"
+                  ></el-input
+                  >-
+                  <el-input v-model="row.maxValue" style="width: 80px">
+                  </el-input>
+                </div>
 
-              <div v-else style="width: 100%">
-                <el-input v-model="row.defaultValue"></el-input>
-              </div>
+                <div v-else style="width: 100%">
+                  <el-input v-model="row.defaultValue"></el-input>
+                </div>
 
-              <DictSelection
-                dictName="工艺参数单位"
-                clearable
-                filterable
-                v-model="row.unitName"
-                style="width: 100px"
-              >
-              </DictSelection>
-            </div>
+                <DictSelection
+                  dictName="工艺参数单位"
+                  clearable
+                  filterable
+                  v-model="row.unitName"
+                  style="width: 100px"
+                >
+                </DictSelection>
+              </div>
+            </el-form-item>
           </template>
-          <template v-slot:executionMethod="{ row }">
-            <el-select
-              v-model="row.executionMethod"
-              style="width: 100%"
-              @change="handleExecutionMethodChange(row)"
+          <template v-slot:executionMethod="{ row, $index }">
+            <el-form-item
+              label-width="0"
+              :rules="{
+                required: true,
+                message: ' ',
+                trigger: 'change'
+              }"
+              :prop="'inspectionItemVOList.' + $index + '.executionMethod'"
             >
-              <el-option :value="1" label="常规检验"></el-option>
-              <el-option :value="2" label="实验"></el-option>
-            </el-select>
+              <el-select
+                v-model="row.executionMethod"
+                style="width: 100%"
+                @change="handleExecutionMethodChange(row)"
+              >
+                <el-option :value="1" label="常规检验"></el-option>
+                <el-option :value="2" label="实验"></el-option>
+              </el-select>
+            </el-form-item>
           </template>
           <template v-slot:procedureName="{ row, $index }">
             <el-input
@@ -303,6 +338,9 @@
               </template>
             </el-popconfirm>
           </template>
+          <template v-slot:isRequired="{ column }">
+            <span class="is-required">{{ column.label }}</span>
+          </template>
         </ele-pro-table>
       </el-row>
       <el-row>
@@ -479,6 +517,7 @@
             prop: 'inspectionName',
             slot: 'inspectionName',
             label: '名称',
+            headerSlot:'isRequired',
             showOverflowTooltip: true,
             align: 'center',
             minWidth: 150
@@ -486,6 +525,7 @@
           {
             prop: 'defaultValue',
             slot: 'defaultValue',
+            headerSlot:'isRequired',
             label: '工艺参数',
             align: 'center',
             minWidth: 400,
@@ -494,6 +534,7 @@
           {
             prop: 'executionMethod',
             slot: 'executionMethod',
+            headerSlot:'isRequired',
             label: '执行方式',
             showOverflowTooltip: true,
             align: 'center',
@@ -592,7 +633,11 @@
           }
         ],
         dataRule: {
-          type: [{ required: true, message: '请选择类型', trigger: 'blur' },{ required: true, message: '请选择类型', trigger: 'change' }],
+          type: [
+            { required: true, message: '请选择类型', trigger: 'blur' },
+            { required: true, message: '请选择类型', trigger: 'change' }
+          ],
+
           qualitySchemeTemplateName: [
             { required: true, message: '请输入质检方案名称', trigger: 'blur' }
           ],
@@ -615,7 +660,7 @@
         if (this.type == 'view') {
           return;
         }
-        if (this.list[index].executionMethod != 2) {
+        if (this.dataForm.inspectionItemVOList[index].executionMethod != 2) {
           return;
         }
         this.releaseRulesType = type;
@@ -630,26 +675,34 @@
       releaseRulesSuccess(data) {
         if (this.releaseRulesType == 5) {
           this.$set(
-            this.list[this.currentIndex].procedureJson,
+            this.dataForm.inspectionItemVOList[this.currentIndex].procedureJson,
             'tempJson',
             data.tempJson.tempJson
           );
-          this.$set(this.list[this.currentIndex], 'procedureName', data.name);
+          this.$set(
+            this.dataForm.inspectionItemVOList[this.currentIndex],
+            'procedureName',
+            data.name
+          );
         }
 
         if (this.releaseRulesType == 7) {
           this.$set(
-            this.list[this.currentIndex].recordJson,
+            this.dataForm.inspectionItemVOList[this.currentIndex].recordJson,
             'tempJson',
             data.tempJson.tempJson
           );
-          this.$set(this.list[this.currentIndex], 'recordName', data.name);
+          this.$set(
+            this.dataForm.inspectionItemVOList[this.currentIndex],
+            'recordName',
+            data.name
+          );
         }
       },
       experimentationSave(tempJson) {
         if (this.releaseRulesType == 5) {
           this.$set(
-            this.list[this.currentIndex].procedureJson,
+            this.dataForm.inspectionItemVOList[this.currentIndex].procedureJson,
             'tempJson',
             tempJson
           );
@@ -657,7 +710,7 @@
 
         if (this.releaseRulesType == 7) {
           this.$set(
-            this.list[this.currentIndex].recordJson,
+            this.dataForm.inspectionItemVOList[this.currentIndex].recordJson,
             'tempJson',
             tempJson
           );
@@ -675,12 +728,13 @@
       },
       //失去焦点自动排序
       handleSortBlur() {
-        this.list = this.list.map((item) => ({
-          ...item,
-          sort: item.sort === '' || item.sort == null ? 0 : Number(item.sort)
-        }));
+        this.dataForm.inspectionItemVOList =
+          this.dataForm.inspectionItemVOList.map((item) => ({
+            ...item,
+            sort: item.sort === '' || item.sort == null ? 0 : Number(item.sort)
+          }));
 
-        this.list.sort((a, b) => a.sort - b.sort);
+        this.dataForm.inspectionItemVOList.sort((a, b) => a.sort - b.sort);
       },
       handleTaskinstance() {
         this.taskinstanceDialogFlag = true;
@@ -691,7 +745,7 @@
 
       handAdd(type) {
         if (type == 1) {
-          this.$refs.termRef.open(this.list);
+          this.$refs.termRef.open(this.dataForm.inspectionItemVOList);
         }
         if (type == 2) {
           this.$refs.equipmentRefs.open();
@@ -705,16 +759,17 @@
         console.log(selection, 'selection');
       },
       selectChange(list) {
-        this.list = list.map((item) => {
+        this.dataForm.inspectionItemVOList = list.map((item) => {
           item['sort'] = item['sort'] || 0;
           item['procedureJson'] = {};
           item['recordJson'] = {};
+          item['executionMethod'] = 1;
           return item;
         });
       },
       handDel(index, type) {
         if (type == 1) {
-          this.list.splice(index, 1);
+          this.dataForm.inspectionItemVOList.splice(index, 1);
         }
         if (type == 2) {
           this.templateCategoryList.splice(index, 1);
@@ -751,7 +806,7 @@
                 });
               }
               // this.list = data.inspectionItemVOList;
-              this.list = itemVOList;
+              this.dataForm.inspectionItemVOList = itemVOList;
               console.log(this.list);
             });
             templatecategoryPage({
@@ -765,7 +820,7 @@
           } else {
             const code = await getCode('template_code');
             this.dataForm.qualitySchemeTemplateCode = code;
-            this.list = [];
+            this.dataForm.inspectionItemVOList = [];
           }
         });
       },
@@ -787,18 +842,20 @@
               ? 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;
-              });
+              this.dataForm.inspectionItemVOList =
+                this.dataForm.inspectionItemVOList.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.inspectionItemVOList =
+                this.dataForm.inspectionItemVOList.map((item) => {
+                  item.id = '';
+                  return item;
+                });
             }
 
             this.dataForm.templateCategoryList = this.templateCategoryList;
@@ -813,7 +870,7 @@
                 this.visible = false;
 
                 this.templateCategoryList = []; // 必加:清空物品列表
-                this.list = []; // 可选:若需清空质检项列表,可添加这行
+                this.dataForm.inspectionItemVOList = []; // 可选:若需清空质检项列表,可添加这行
                 // this.updateVisible(false);
                 this.$emit('refreshDataList');
               })

+ 14 - 3
src/views/inspectionWork/index.vue

@@ -418,7 +418,6 @@
             width: 120,
             showOverflowTooltip: true,
             formatter: (row) => {
-      
               return row.executeUserName || '';
             }
           },
@@ -811,7 +810,11 @@
         });
       },
       //质检项派单
-      qualityInspectionSend(row, type) {
+      async qualityInspectionSend(row, type) {
+        const code = await verificationQualityInspector(row.id);
+        if (code == '-1') {
+          return;
+        }
         this.$refs.inspectionProjectTaskSendRef.open(row, type);
       },
       async datasource({ page, where, limit }) {
@@ -902,6 +905,10 @@
         this.addOpen = false;
       },
       async close(row) {
+        const code = await verificationQualityInspector(row.id);
+        if (code == '-1') {
+          return;
+        }
         await closeWork(row);
         this.done();
       },
@@ -925,7 +932,11 @@
           this.qualityMode = list;
         }
       },
-      openTransfer(id) {
+      async openTransfer(id) {
+        const code = await verificationQualityInspector(id);
+        if (code == '-1') {
+          return;
+        }
         this.transferVisible = true;
         this.transferId = id;
       },