소스 검색

记录规则功能修改

lucw 8 달 전
부모
커밋
83f59fe249
1개의 변경된 파일229개의 추가작업 그리고 104개의 파일을 삭제
  1. 229 104
      src/views/rulesManagement/releaseRules/components/permitAdd.vue

+ 229 - 104
src/views/rulesManagement/releaseRules/components/permitAdd.vue

@@ -139,8 +139,20 @@
           </el-form-item>
         </el-col>
       </el-row>
-      <el-row style="margin-bottom: 10px">
-        <el-col v-if="formData.reportWorkType == 2" :span="8">
+      <el-row
+        v-if="
+          formData.reportWorkType != 0 &&
+          formData.produceTaskConfigBatchSavePo.produceTaskId
+        "
+        style="margin-bottom: 10px"
+      >
+        <el-col
+          v-if="
+            formData.reportWorkType == 2 &&
+            formData.produceTaskConfigBatchSavePo.produceTaskId
+          "
+          :span="8"
+        >
           <el-form-item
             label="关联产品方式"
             required
@@ -163,7 +175,7 @@
         </el-col>
 
         <el-col v-if="formData.relateProductMethod == 1" :span="8">
-          <el-form-item label="关联产品分类" required>
+          <el-form-item label="关联产品分类" required prop="categoryLevels">
             <ele-tree-select
               multiple
               clearable
@@ -679,19 +691,17 @@
         reportWorkType: '1',
         // 关联产品方式,0-不关联,1-关联分类,2-关联产品
         relateProductMethod: 0,
-        // 关联 ids {categoryLevelId || productId} 根据关联类型来
-        products: [],
         // 关联分类
         categoryLevels: [],
         // 关联产品
         categories: [],
         // 执行方式
         isExecuteMethod: 0,
-        produceTaskConfigs: null,
+        produceTaskConfigs: [],
         // 关联工序
         produceTaskConfigBatchSavePo: {
           addPOs: [],
-          deletedIds: null,
+          deletedIds: [],
           produceTaskId: '',
           produceTaskName: '',
           updatePOs: []
@@ -741,6 +751,14 @@
           reportWorkType: [
             { required: true, message: '请选择模块分类', trigger: 'change' },
             { required: true, message: '请选择模块分类', trigger: 'blur' }
+          ],
+          categoryLevels: [
+            {
+              required: true,
+              message: '请选择关联产品分类',
+              trigger: 'change'
+            },
+            { required: true, message: '请选择关联产品分类', trigger: 'blur' }
           ]
         },
         recordSheet: [], // 记录表
@@ -797,15 +815,34 @@
         try {
           const data = await recordrulesGetById(id);
 
-          if (data.categoryLevels) {
-            data.categoryLevels = data.categoryLevels.map((i) => i.id);
+          if (data.relateProductMethod == 1) {
+            data.categoryLevels = data.produceTaskConfigs
+              .map((i) => i.categoryLevelId)
+              .filter((i) => i != null);
           } else {
             data.categoryLevels = [];
           }
 
+          if (data.relateProductMethod == 2) {
+            // 产品
+            data.categories = data.produceTaskConfigs.map((i) => {
+              return {
+                id: i.productId,
+                code: i.productCode,
+                name: i.productName,
+                brandNum: i.brandNum,
+                modelType: i.modelType,
+                measuringUnit: i.measuringUnit,
+                packingUnit: i.packingUnit
+              };
+            });
+          } else {
+            data.categories = [];
+          }
+
           data.produceTaskConfigBatchSavePo = {
             addPOs: [],
-            deletedIds: null,
+            deletedIds: [],
             produceTaskId: data.produceTaskConfigs[0]?.produceTaskId,
             produceTaskName: data.produceTaskConfigs[0]?.produceTaskName,
             updatePOs: []
@@ -824,7 +861,7 @@
           this.$util.assignObject(this.formData, data);
 
           this.$nextTick(() => {
-            this.$refs.cycleMultipleRef.setRecordRulesCycleList(
+            this.$refs.cycleMultipleRef?.setRecordRulesCycleList(
               this.formData.recordRulesCycleList
             );
           });
@@ -882,27 +919,34 @@
             return this.$message.warning('至少条件一条规则项');
           }
 
-          try {
-            if (this.formData.isExecuteMethod) {
-              // 判断 formData.executeMethodList中的item 是否在details中有一条executeMethodTitle的数据
+          if (this.formData.isExecuteMethod) {
+            // 判断 formData.executeMethodList中的item 是否在details中有一条executeMethodTitle的数据
 
-              if (this.formData.executeMethodList.length == 0) {
-                return this.$message.warning(`请添加执行方式`);
-              }
+            if (this.formData.executeMethodList.length == 0) {
+              return this.$message.warning(`请添加执行方式`);
+            }
 
-              for (const item of this.formData.executeMethodList) {
-                const exists = this.formData.details.some(
-                  (detail) => detail.executeMethodTitle === item
+            for (const item of this.formData.executeMethodList) {
+              const exists = this.formData.details.some(
+                (detail) => detail.executeMethodTitle === item
+              );
+              if (!exists) {
+                this.$message.warning(
+                  `请为执行方式 "${item}" 添加至少一条规则项`
                 );
-                if (!exists) {
-                  this.$message.warning(
-                    `请为执行方式 "${item}" 添加至少一条规则项`
-                  );
-                  return false;
-                }
+                return false;
               }
             }
+          }
+
+          if (this.formData.relateProductMethod == 2) {
+            // 关联分类
+            if (this.formData.categories.length == 0) {
+              return this.$message.warning('请选择关联产品');
+            }
+          }
 
+          try {
             this.btnLoading = true;
 
             const body = this.formatBody();
@@ -938,42 +982,34 @@
             return this.$message.warning('至少条件一条规则项');
           }
 
-          // 判断关联工序
-          if (this.formData.reportWorkType == '2') {
-            if (
-              this.formData.produceTaskConfigs &&
-              this.formData.produceTaskConfigs[0] &&
-              this.formData.produceTaskConfigs[0].isUsing &&
-              this.formData.produceTaskConfigs[0].produceTaskId !=
-                this.formData.produceTaskConfigBatchSavePo.produceTaskId
-            ) {
-              return this.$message.warning(
-                '当前规则关联的工序有执行中的记录,不能更改!'
-              );
-            }
-          }
+          if (this.formData.isExecuteMethod) {
+            // 判断 formData.executeMethodList中的item 是否在details中有一条executeMethodTitle的数据
 
-          try {
-            if (this.formData.isExecuteMethod) {
-              // 判断 formData.executeMethodList中的item 是否在details中有一条executeMethodTitle的数据
-
-              if (this.formData.executeMethodList.length == 0) {
-                return this.$message.warning(`请添加执行方式`);
-              }
+            if (this.formData.executeMethodList.length == 0) {
+              return this.$message.warning(`请添加执行方式`);
+            }
 
-              for (const item of this.formData.executeMethodList) {
-                const exists = this.formData.details.some(
-                  (detail) => detail.executeMethodTitle === item
+            for (const item of this.formData.executeMethodList) {
+              const exists = this.formData.details.some(
+                (detail) => detail.executeMethodTitle === item
+              );
+              if (!exists) {
+                this.$message.warning(
+                  `请为执行方式 "${item}" 添加至少一条规则项`
                 );
-                if (!exists) {
-                  this.$message.warning(
-                    `请为执行方式 "${item}" 添加至少一条规则项`
-                  );
-                  return false;
-                }
+                return false;
               }
             }
+          }
+
+          if (this.formData.relateProductMethod == 2) {
+            // 关联分类
+            if (this.formData.categories.length == 0) {
+              return this.$message.warning('请选择关联产品');
+            }
+          }
 
+          try {
             this.btnLoading = true;
 
             const body = this.formatBody();
@@ -1017,22 +1053,6 @@
             .map((i, index) => {
               return { ...i, sortNum: index + 1 };
             });
-        // 处理关联产品 关联分类
-        if (this.formData.relateProductMethod == 1) {
-          this.formData.products = this.formData.categoryLevels.map((i) => {
-            return {
-              categoryLevelId: i
-            };
-          });
-        } else if (this.formData.relateProductMethod == 2) {
-          this.formData.products = this.formData.categories.map((i) => {
-            return {
-              productId: i.id
-            };
-          });
-        } else {
-          this.formData.products = [];
-        }
 
         const body = { ...this.formData };
 
@@ -1046,37 +1066,122 @@
           'yyyy-MM-dd HH:mm:ss'
         );
 
-        if (this.type == 'edit' && body.produceTaskConfigs[0]?.id) {
+        if (this.type == 'edit') {
           if (body.produceTaskConfigBatchSavePo.produceTaskId) {
             // 修改工序
-            body.produceTaskConfigBatchSavePo.updatePOs.push({
-              id: body.produceTaskConfigs[0]?.id,
-              executeMethod: 2,
-              itemType: 2,
-              produceTaskId: body.produceTaskConfigBatchSavePo.produceTaskId,
-              produceTaskName:
-                body.produceTaskConfigBatchSavePo.produceTaskName,
-              reportWorkType: this.formData.reportWorkType
-            });
+
+            if (body.relateProductMethod == 1) {
+              debugger;
+              // 分类
+              body.categoryLevels.forEach((categoryId) => {
+                // 判断是否已经存在
+                const exist = body.produceTaskConfigs.find(
+                  (i) => i.categoryLevelId == categoryId
+                );
+
+                if (!exist) {
+                  body.produceTaskConfigBatchSavePo.addPOs.push({
+                    executeMethod: 2,
+                    itemType: 1,
+                    produceTaskId:
+                      body.produceTaskConfigBatchSavePo.produceTaskId,
+                    produceTaskName:
+                      body.produceTaskConfigBatchSavePo.produceTaskName,
+                    categoryLevelId: categoryId,
+                    reportWorkType: this.formData.reportWorkType
+                  });
+                }
+              });
+
+              // 删除取消的分类
+              body.produceTaskConfigs.forEach((config) => {
+                if (
+                  !body.categoryLevels.includes(config.categoryLevelId) &&
+                  config.id
+                ) {
+                  body.produceTaskConfigBatchSavePo.deletedIds.push(config.id);
+                }
+              });
+            }
+
+            if (body.relateProductMethod == 2) {
+              // 产品
+              body.categories.forEach((product) => {
+                // 判断是否已经存在
+                const exist = body.produceTaskConfigs.find(
+                  (i) => i.productId == product.id
+                );
+                if (!exist) {
+                  body.produceTaskConfigBatchSavePo.addPOs.push({
+                    executeMethod: 2,
+                    itemType: 2,
+                    produceTaskId:
+                      body.produceTaskConfigBatchSavePo.produceTaskId,
+                    produceTaskName:
+                      body.produceTaskConfigBatchSavePo.produceTaskName,
+                    productCode: product.code,
+                    productId: product.id || product.productId,
+                    productName: product.name || product.productName,
+                    reportWorkType: this.formData.reportWorkType
+                  });
+                }
+              });
+
+              // 删除取消的产品
+              body.produceTaskConfigs.forEach((config) => {
+                const exist = body.categories.find((product) => {
+                  return product.id == config.productId;
+                });
+
+                if (!exist && config.id) {
+                  body.produceTaskConfigBatchSavePo.deletedIds.push(config.id);
+                }
+              });
+            }
           } else {
-            // 删除工序
-            body.produceTaskConfigBatchSavePo.deletedIds = [
-              this.formData.produceTaskConfigs[0].id
-            ];
+            // 删除工序 全删
+            body.produceTaskConfigBatchSavePo.deletedIds =
+              this.formData.produceTaskConfigs.map((i) => i.id);
           }
-
-          body.produceTaskConfigBatchSavePo.addPOs = [];
         } else {
           // 新增工序
-          if (body.produceTaskConfigBatchSavePo.produceTaskId) {
-            body.produceTaskConfigBatchSavePo.addPOs.push({
-              executeMethod: 2,
-              itemType: 2,
-              produceTaskId: body.produceTaskConfigBatchSavePo.produceTaskId,
-              produceTaskName:
-                body.produceTaskConfigBatchSavePo.produceTaskName,
-              reportWorkType: this.formData.reportWorkType
-            });
+          if (
+            body.reportWorkType != 0 &&
+            body.produceTaskConfigBatchSavePo.produceTaskId
+          ) {
+            if (body.relateProductMethod == 1) {
+              // 分类
+              body.categoryLevels.forEach((categoryId) => {
+                body.produceTaskConfigBatchSavePo.addPOs.push({
+                  executeMethod: 2,
+                  itemType: 1,
+                  produceTaskId:
+                    body.produceTaskConfigBatchSavePo.produceTaskId,
+                  produceTaskName:
+                    body.produceTaskConfigBatchSavePo.produceTaskName,
+                  categoryLevelId: categoryId,
+                  reportWorkType: this.formData.reportWorkType
+                });
+              });
+            }
+
+            if (body.relateProductMethod == 2) {
+              // 产品
+              body.categories.forEach((product) => {
+                body.produceTaskConfigBatchSavePo.addPOs.push({
+                  executeMethod: 2,
+                  itemType: 2,
+                  produceTaskId:
+                    body.produceTaskConfigBatchSavePo.produceTaskId,
+                  produceTaskName:
+                    body.produceTaskConfigBatchSavePo.produceTaskName,
+                  productCode: product.code,
+                  productId: product.id || product.productId,
+                  productName: product.name || product.productName,
+                  reportWorkType: this.formData.reportWorkType
+                });
+              });
+            }
           }
 
           body.produceTaskConfigBatchSavePo.updatePOs = [];
@@ -1092,11 +1197,11 @@
         }
 
         // 启用日期大于等于今天
-        const today = new Date();
-        today.setHours(0, 0, 0, 0); // 设置为当天的开始时间
-        if (new Date(startDate) < today) {
-          return callback(new Error('启用日期必须大于等于当前日期'));
-        }
+        // const today = new Date();
+        // today.setHours(0, 0, 0, 0); // 设置为当天的开始时间
+        // if (new Date(startDate) < today) {
+        //   return callback(new Error('启用日期必须大于等于当前日期'));
+        // }
 
         callback();
       },
@@ -1234,11 +1339,19 @@
       },
       // 关联产品
       relateProductSelect() {
-        this.$refs.ProductModalCorrelationRef.open(this.formData.categories);
+        this.$refs.ProductModalCorrelationRef.open();
       },
       changeRelateProduct(array) {
         console.log('this.formData.categories ', array);
-        this.formData.categories = array;
+
+        const productList = array.filter(
+          (i) => !this.formData.categories.some((cat) => cat.id === i.id)
+        );
+
+        this.formData.categories = [
+          ...this.formData.categories,
+          ...productList
+        ];
       },
       /// 获取产品分类
       async getProductCategory() {
@@ -1248,6 +1361,15 @@
       },
       // 选择工序
       openProduceTaskDialog() {
+        if (this.formData.produceTaskConfigs) {
+          // 其中包含 isUsing 为 true 则不能修改
+          const some = this.formData.produceTaskConfigs.some((i) => i.isUsing);
+          if (some) {
+            return this.$message.warning(
+              '当前规则关联的工序有执行中的记录,不能更改!'
+            );
+          }
+        }
         this.$refs.processModalRef.open();
       },
       // 工序
@@ -1314,6 +1436,9 @@
         }
         this.formData.produceTaskConfigBatchSavePo.produceTaskId = '';
         this.formData.produceTaskConfigBatchSavePo.produceTaskName = '';
+        this.formData.relateProductMethod = 0;
+        this.formData.categoryLevels = [];
+        this.formData.categories = [];
       }
     }
   };