Преглед изворни кода

物料统计bug、表单bug

lucw пре 7 месеци
родитељ
комит
d16c290df1

+ 48 - 10
src/views/batchRecord/components/editModal.vue

@@ -191,6 +191,9 @@
                   value-format="yyyy-MM-dd HH:mm:ss"
                   placeholder="选择日期"
                   style="width: 100%"
+                  :picker-options="{
+                    disabledDate: (time) => time.getTime() > Date.now()
+                  }"
                   @change="computedDuration"
                 >
                 </el-date-picker>
@@ -209,6 +212,9 @@
                   value-format="yyyy-MM-dd HH:mm:ss"
                   placeholder="选择日期"
                   style="width: 100%"
+                  :picker-options="{
+                    disabledDate: (time) => time.getTime() > Date.now()
+                  }"
                   @change="computedDuration"
                 >
                 </el-date-picker>
@@ -508,6 +514,7 @@
           :pickDetails.sync="form.pickDetails"
           :outputDetails.sync="form.outputDetails"
           :preOutputDetails="preOutputDetails"
+          :sumOutputDetails="sumOutputDetails"
           :workOrderId="form.workOrderId"
           :ruleId="form.ruleId"
           :produceTaskId="form.produceTaskId"
@@ -516,9 +523,9 @@
           :bomCategoryId="workOrderInfo.bomCategoryId"
           :outputType="form.outputType"
           :categoryId="workOrderInfo.categoryId"
+          :record-id="form.id"
           @refresh="getListByWorkOrderId"
         ></material>
-
         <header-title
           v-if="form.itemType == 2"
           title="检查项目"
@@ -985,9 +992,13 @@
             {
               validator: (rule, value, callback) => {
                 if (!value) return callback();
-                const now = new Date();
-                const start = new Date(value);
-                callback();
+                const start = new Date(value).getTime();
+                const now = Date.now();
+                if (start > now) {
+                  callback(new Error('开始时间不能超过当前时间'));
+                } else {
+                  callback();
+                }
               },
               trigger: 'blur'
             }
@@ -1002,10 +1013,13 @@
             {
               validator: (rule, value, callback) => {
                 if (!value) return callback();
-                const start = new Date(this.form.checkStartTime);
-                const finish = new Date(value);
+                const start = new Date(this.form.checkStartTime).getTime();
+                const finish = new Date(value).getTime();
+                const now = Date.now();
                 if (finish <= start) {
                   callback(new Error('结束时间必须大于开始时间'));
+                } else if (finish > now) {
+                  callback(new Error('结束时间不能超过当前时间'));
                 } else {
                   callback();
                 }
@@ -1050,6 +1064,7 @@
         teamList: [],
         teamAllList: [],
         preOutputDetails: [],
+        sumOutputDetails: [],
         outputTypeList: [
           { label: '原材料', value: 1 },
           { label: '在制品', value: 2 },
@@ -1072,9 +1087,12 @@
             return '产前准备';
           case 2:
             return '过程监测';
-
-          default:
+          case 3:
             return '产后检查';
+          case 4:
+            return '生产统计';
+          default:
+            return '';
         }
       },
       // 规则详情表头
@@ -1487,7 +1505,11 @@
           }
         }
 
-        if (this.$refs.statisticsRef && type != 'cache' && type != 'submit-reset') {
+        if (
+          this.$refs.statisticsRef &&
+          type != 'cache' &&
+          type != 'submit-reset'
+        ) {
           // 验证统计项目
           const valid = this.$refs.statisticsRef.validateStatisticsFilled();
           if (!valid) {
@@ -1622,7 +1644,21 @@
         });
 
         console.log('materialObject 物料信息', materialObject);
-        this.form.outputDetails = materialObject.outputDetails;
+        this.form.outputDetails = materialObject.outputDetails.map((i) => {
+          i.reportQuantityCopy = i.reportQuantity;
+
+          const sumItem = materialObject.sumOutputDetails.find(
+            (i) => i.categoryId === i.categoryId
+          );
+
+          if (sumItem) {
+            i.reportQuantity = sumItem.reportQuantity;
+          } else {
+            i.reportQuantity = i.reportQuantity || 0;
+          }
+
+          return i;
+        });
         const pickDetails = materialObject.pickDetails.map((i) => {
           // 物料清单中如果存在则 selected 设置为 true
           const any = this.form.outputDetails.find(
@@ -1644,6 +1680,8 @@
           (i) => i.outputType != 1
         );
 
+        this.sumOutputDetails = materialObject.sumOutputDetails;
+
         this.form.pickDetails = [
           ...preOutputDetails.filter((i) => i.outputType == 1),
           ...pickDetails

+ 34 - 2
src/views/batchRecord/components/statistics.vue

@@ -97,6 +97,12 @@
           ></el-input>
         </div>
       </template>
+
+      <template v-slot:operation="{ row }">
+        <el-button type="text" size="small" @click="deleteRow(row)"
+          >删除</el-button
+        >
+      </template>
     </ele-pro-table>
     <div
       v-if="
@@ -313,6 +319,7 @@
     getAllRoutingTaskList,
     getPickAndFeed
   } from '@/api/producetaskrecordrulesrecord/index';
+  import fix from 'highlight.js/lib/languages/fix';
 
   export default {
     props: {
@@ -403,6 +410,14 @@
             columnKey: 'index',
             align: 'center'
           });
+
+          cList.push({
+            width: 70,
+            label: '操作',
+            slot: 'operation',
+            fixed: 'right'
+          });
+
           return cList;
         } else {
           return [];
@@ -783,7 +798,9 @@
               if (value !== '' && typeof value === 'number') {
                 const dec = value.toString().split('.')[1];
                 if (dec && dec.length > 4) {
-                  value = Number(value.toFixed(4));
+                  const intPart = Math.trunc(value);
+                  const truncated = dec.slice(0, 4);
+                  value = Number(intPart + '.' + truncated);
                 }
               }
 
@@ -986,7 +1003,11 @@
               sums[targetIndex] = '';
             } else {
               const dec = result.toString().split('.')[1];
-              if (dec && dec.length > 4) result = Number(result.toFixed(4));
+              if (dec && dec.length > 4) {
+                const intPart = Math.trunc(result);
+                const truncated = dec.slice(0, 4);
+                result = Number(intPart + '.' + truncated);
+              }
               sums[targetIndex] = result;
             }
           } catch (e) {
@@ -1009,6 +1030,17 @@
         });
 
         this.localDetails[0].statisticsValue.push(row);
+      },
+      deleteRow(row) {
+        // 最后一条不允许删除
+        if (this.localDetails[0].statisticsValue.length <= 1) {
+          this.$message.warning('至少保留一条统计数据');
+          return;
+        }
+        const index = this.localDetails[0].statisticsValue.indexOf(row);
+        this.localDetails[0].statisticsValue.splice(index, 1);
+        // 通知父组件数据变更
+        this.emitChange();
       }
     }
   };

+ 180 - 62
src/views/produce/components/prenatalExamination/material.vue

@@ -45,7 +45,7 @@
           controls-position="right"
           :min="0"
           :max="reportQuantitymax(row)"
-          @change="$emit('update:outputDetails', localOutputDetails)"
+          @change="reportQuantityChange(row)"
         ></el-input-number>
       </template>
       <template v-slot:qualifiedQuantity="{ row }">
@@ -65,7 +65,7 @@
           controls-position="right"
           :min="0"
           :max="noQualifiedQuantityMax(row)"
-          @change="$emit('update:outputDetails', localOutputDetails)"
+          @change="noQualifiedQuantityChange(row)"
         ></el-input-number>
       </template>
       <template v-slot:msg="{ row }">
@@ -110,6 +110,10 @@
         type: Array,
         default: () => []
       },
+      sumOutputDetails: {
+        type: Array,
+        default: () => []
+      },
       // 工单id
       workOrderId: {
         type: [String, Number],
@@ -149,6 +153,11 @@
       categoryId: {
         type: [String, Number],
         required: false
+      },
+      // recordId 是否保存过数据
+      recordId: {
+        type: [String, Number],
+        default: ''
       }
     },
     watch: {
@@ -201,7 +210,7 @@
             this.getCategoryAndLevelByCategoryId();
           } else {
             // 3 BOM标准产出
-            this.getMaterialQuotaInfo();
+            this.setMaterialQuotaInfo();
           }
         }
       },
@@ -292,13 +301,40 @@
             prop: '',
             minWidth: 120,
             formatter: (row) => {
-              // 取值产出清单
-              const outputItem = this.localOutputDetails.find(
-                (item) => item.categoryId === row.categoryId
-              );
-              return (
-                (outputItem ? outputItem.reportQuantity : 0) + (row.unit || '')
-              );
+              // 产出为物料
+              if (this.outputType == 1) {
+                // 取值产出清单
+                const outputItem = this.localOutputDetails.find(
+                  (item) => item.categoryId === row.categoryId
+                );
+                return (
+                  (outputItem ? outputItem.reportQuantity : 0) +
+                  (row.unit || '')
+                );
+              } else {
+                // 产出为在制品 或 BOM标准产出
+                // 查询基数
+                if (!this.materialQuotaInfo) {
+                  return '0' + (row.unit || '');
+                }
+                const materialItem = this.materialQuotaInfo.materialQuota.find(
+                  (item) => item.id === row.categoryId
+                );
+                if (!materialItem) {
+                  return '0' + (row.unit || '');
+                }
+                // 需要的物料数量比例
+                let count =
+                  materialItem.count / this.materialQuotaInfo.baseCount;
+                // 产出清单的报工数量 当次报工+累计报工
+                const outputItem = this.localOutputDetails[0];
+                if (!outputItem) {
+                  return '0' + (row.unit || '');
+                }
+                // 当次消耗
+                let needQuantity = outputItem.reportQuantity * count;
+                return needQuantity + (row.unit || '');
+              }
             }
           },
           {
@@ -306,15 +342,60 @@
             prop: '',
             minWidth: 120,
             formatter: (row) => {
-              const outputItem = this.localOutputDetails.find(
-                (item) => item.categoryId === row.categoryId
-              );
-              if (!outputItem) {
-                return '0' + (row.unit || '');
+              if (this.outputType == 1) {
+                const outputItem = this.localOutputDetails.find(
+                  (item) => item.categoryId === row.categoryId
+                );
+                if (!outputItem) {
+                  return '0' + (row.unit || '');
+                }
+                if (this.recordId) {
+                  let count =
+                    outputItem.sumReportQuantity +
+                    outputItem.reportQuantity -
+                    outputItem.reportQuantityCopy;
+                  return count + (row.unit || '');
+                } else {
+                  let count =
+                    outputItem.sumReportQuantity + outputItem.reportQuantity;
+                  return count + (row.unit || '');
+                }
+              } else {
+                // 产出为在制品 或 BOM标准产出
+                // 查询基数
+                if (!this.materialQuotaInfo) {
+                  return '0' + (row.unit || '');
+                }
+                const materialItem = this.materialQuotaInfo.materialQuota.find(
+                  (item) => item.id === row.categoryId
+                );
+                if (!materialItem) {
+                  return '0' + (row.unit || '');
+                }
+                // 需要的物料数量比例
+                let count =
+                  materialItem.count / this.materialQuotaInfo.baseCount;
+                // 产出清单的报工数量 当次报工+累计报工
+                const outputItem = this.localOutputDetails[0];
+                if (!outputItem) {
+                  return '0' + (row.unit || '');
+                }
+                if (this.recordId) {
+                  // 累计消耗
+                  let needQuantity =
+                    (outputItem.sumReportQuantity +
+                      outputItem.reportQuantity -
+                      outputItem.reportQuantityCopy) *
+                    count;
+                  return needQuantity + (row.unit || '');
+                } else {
+                  // 累计消耗
+                  let needQuantity =
+                    (outputItem.sumReportQuantity + outputItem.reportQuantity) *
+                    count;
+                  return needQuantity + (row.unit || '');
+                }
               }
-              let count =
-                outputItem.sumReportQuantity + outputItem.reportQuantity;
-              return count + (row.unit || '');
             }
           }
         ];
@@ -434,7 +515,11 @@
         ]
       };
     },
-    mounted() {},
+    mounted() {
+      if (this.bomCategoryId && this.produceTaskId) {
+        this.getMaterialQuotaInfo();
+      }
+    },
     methods: {
       // 选择物料
       openMaterialModal() {
@@ -461,9 +546,20 @@
             // 存在则替换数量
             this.localPickDetails[index].quantity = newItem.quantity;
           } else {
+            const sumItem = this.sumOutputDetails.find(
+              (i) => i.categoryId === i.categoryId
+            );
+
+            let reportQuantity = newItem.reportQuantity || 0;
+
+            if (sumItem) {
+              reportQuantity = sumItem.reportQuantity;
+            }
+
             // 不存在则添加
             this.localPickDetails.push({
               ...newItem,
+              reportQuantity,
               ruleId: this.ruleId,
               bomCategoryId: this.bomCategoryId,
               produceTaskId: this.produceTaskId,
@@ -476,6 +572,43 @@
 
         this.$emit('update:pickDetails', this.localPickDetails);
       },
+      setMaterialQuotaInfo() {
+        console.log('this.materialQuotaInfo', this.materialQuotaInfo);
+        if (this.materialQuotaInfo && this.materialQuotaInfo.standardOutput) {
+          const sumItem = this.sumOutputDetails.find(
+            (i) =>
+              i.categoryId === this.materialQuotaInfo.standardOutput.categoryId
+          );
+
+          let reportQuantity = 0;
+
+          if (sumItem) {
+            reportQuantity = sumItem.reportQuantity;
+          }
+
+          // 赋值产出
+          this.localOutputDetails = [
+            {
+              ...this.materialQuotaInfo.standardOutput,
+              id: null,
+              reportQuantity,
+              qualifiedQuantity: 0,
+              noQualifiedQuantity: 0,
+              msg: '',
+              sumReportQuantity: 0,
+              sumQualifiedQuantity: 0,
+              sumNoQualifiedQuantity: 0,
+              ruleId: this.ruleId,
+              outputType: this.outputType,
+              produceTaskId: this.produceTaskId,
+              produceTaskInstanceId: this.produceTaskInstanceId,
+              produceTaskName: this.produceTaskName,
+              workOrderId: this.workOrderId
+            }
+          ];
+          this.$emit('update:outputDetails', this.localOutputDetails);
+        }
+      },
       // 获取bom的产出清单
       async getMaterialQuotaInfo() {
         if (this.bomCategoryId && this.produceTaskId) {
@@ -485,32 +618,6 @@
           );
           console.log('this.materialQuotaInfo', data);
           this.materialQuotaInfo = data;
-          //
-          if (data && data.standardOutput) {
-            // 赋值产出
-            this.localOutputDetails = [
-              {
-                ...data.standardOutput,
-                id: null,
-                reportQuantity: 0,
-                qualifiedQuantity: 0,
-                noQualifiedQuantity: 0,
-                msg: '',
-                sumReportQuantity: 0,
-                sumQualifiedQuantity: 0,
-                sumNoQualifiedQuantity: 0,
-                ruleId: this.ruleId,
-                outputType: this.outputType,
-                produceTaskId: this.produceTaskId,
-                produceTaskInstanceId: this.produceTaskInstanceId,
-                produceTaskName: this.produceTaskName,
-                workOrderId: this.workOrderId
-              }
-            ];
-            this.$emit('update:outputDetails', this.localOutputDetails);
-          }
-
-          console.log('this.localOutputDetails', this.localOutputDetails);
         }
       },
       // qualifiedQuantityMax 最大合格数量
@@ -518,7 +625,7 @@
         return row.reportQuantity;
       },
       noQualifiedQuantityMax(row) {
-        return row.reportQuantity - row.qualifiedQuantity;
+        return row.reportQuantity;
       },
       selectedChange(row) {
         console.log('row', row);
@@ -568,11 +675,21 @@
       async getCategoryAndLevelByCategoryId() {
         const data = await getCategoryAndLevelByCategoryId(this.categoryId);
         if (data) {
+          const sumItem = this.sumOutputDetails.find(
+            (i) => i.categoryId == data.categoryId
+          );
+
+          let reportQuantity = 0;
+
+          if (sumItem) {
+            reportQuantity = sumItem.reportQuantity;
+          }
+
           this.localOutputDetails = [
             {
               ...data,
               id: null,
-              reportQuantity: 0,
+              reportQuantity,
               qualifiedQuantity: 0,
               noQualifiedQuantity: 0,
               msg: '',
@@ -591,11 +708,6 @@
 
         this.$emit('update:outputDetails', this.localOutputDetails);
 
-        const bomInfo = await getMaterialQuotaInfo(
-          this.bomCategoryId,
-          this.produceTaskId
-        );
-        this.materialQuotaInfo = bomInfo;
         console.log('this.localOutputDetails', this.localOutputDetails);
         console.log('this.materialQuotaInfo', this.materialQuotaInfo);
       },
@@ -673,18 +785,11 @@
           let val = true;
 
           if (!this.materialQuotaInfo) {
-            this.materialQuotaInfo = await getMaterialQuotaInfo(
-              this.bomCategoryId,
-              this.produceTaskId
-            );
+            await this.getMaterialQuotaInfo();
           }
 
           // 没有配置产出清单 、没有原材料 不检查
-          if (
-            !this.materialQuotaInfo ||
-            !this.materialQuotaInfo.standardOutput ||
-            this.localPickDetails.length == 0
-          ) {
+          if (!this.materialQuotaInfo || this.localPickDetails.length == 0) {
             return true;
           }
 
@@ -769,18 +874,31 @@
 
         return true;
       },
+      // 当次报工修改
+      reportQuantityChange(row) {
+        // 同步当前合格数量 和 不合格数量为0
+        // 默认全部合格
+        row.qualifiedQuantity = row.reportQuantity;
+        row.noQualifiedQuantity = 0;
+        this.$emit('update:outputDetails', this.localOutputDetails);
+      },
       // qualifiedQuantityChange 当次合格数量变化 计算 noQualifiedQuantity不合格数量
       qualifiedQuantityChange(row) {
         row.noQualifiedQuantity = row.reportQuantity - row.qualifiedQuantity;
         this.$emit('update:outputDetails', this.localOutputDetails);
       },
+      // 不合格数量变化
+      noQualifiedQuantityChange(row) {
+        row.qualifiedQuantity = row.reportQuantity - row.noQualifiedQuantity;
+        this.$emit('update:outputDetails', this.localOutputDetails);
+      },
       localOutputDetailsRefresh() {
         if (this.outputType == 1) {
           this.$emit('refresh', 'output');
         } else if (this.outputType == 2) {
           this.getCategoryAndLevelByCategoryId();
         } else {
-          this.getMaterialQuotaInfo();
+          this.setMaterialQuotaInfo();
         }
       }
     }

+ 1 - 1
src/views/produce/components/prenatalExamination/materialModal.vue

@@ -137,7 +137,7 @@
             label: '关键词:',
             value: 'keyword',
             type: 'input',
-            placeholder: '物料编码、物料名称、批次号'
+            placeholder: '物料编码、物料名称'
           }
         ];
       }

+ 44 - 7
src/views/produce/components/prenatalExamination/releaseRulesDialog.vue

@@ -87,6 +87,9 @@
               value-format="yyyy-MM-dd HH:mm:ss"
               placeholder="选择日期"
               style="width: 100%"
+              :picker-options="{
+                disabledDate: (time) => time.getTime() > Date.now()
+              }"
               @change="computedDuration"
             >
             </el-date-picker>
@@ -101,6 +104,9 @@
               value-format="yyyy-MM-dd HH:mm:ss"
               placeholder="选择日期"
               style="width: 100%"
+              :picker-options="{
+                disabledDate: (time) => time.getTime() > Date.now()
+              }"
               @change="computedDuration"
             >
             </el-date-picker>
@@ -236,6 +242,7 @@
       :pickDetails.sync="addForm.pickDetails"
       :outputDetails.sync="addForm.outputDetails"
       :preOutputDetails="preOutputDetails"
+      :sumOutputDetails="sumOutputDetails"
       :workOrderId="addForm.workOrderId"
       :ruleId="addForm.ruleId"
       :produceTaskId="addForm.produceTaskId"
@@ -244,6 +251,7 @@
       :bomCategoryId="workOrderInfo.bomCategoryId"
       :outputType="addForm.outputType"
       :categoryId="workOrderInfo.categoryId"
+      :record-id="productionInfo.recordId"
       @refresh="getListByWorkOrderId"
     ></material>
 
@@ -561,9 +569,13 @@
             {
               validator: (rule, value, callback) => {
                 if (!value) return callback();
-                const now = new Date();
-                const start = new Date(value);
-                callback();
+                const start = new Date(value).getTime();
+                const now = Date.now();
+                if (start > now) {
+                  callback(new Error('开始时间不能超过当前时间'));
+                } else {
+                  callback();
+                }
               },
               trigger: 'blur'
             }
@@ -578,10 +590,13 @@
             {
               validator: (rule, value, callback) => {
                 if (!value) return callback();
-                const start = new Date(this.addForm.checkStartTime);
-                const finish = new Date(value);
+                const start = new Date(this.addForm.checkStartTime).getTime();
+                const finish = new Date(value).getTime();
+                const now = Date.now();
                 if (finish <= start) {
                   callback(new Error('结束时间必须大于开始时间'));
+                } else if (finish > now) {
+                  callback(new Error('结束时间不能超过当前时间'));
                 } else {
                   callback();
                 }
@@ -631,6 +646,8 @@
         workshopAreaList: [],
         // 上到工序的 产出明细
         preOutputDetails: [],
+        // 汇总产出明细
+        sumOutputDetails: [],
         outputTypeList: [
           { label: '原材料', value: 1 },
           { label: '在制品', value: 2 },
@@ -866,7 +883,21 @@
 
         console.log('materialList 物料信息', materialObject);
 
-        this.addForm.outputDetails = materialObject.outputDetails;
+        this.addForm.outputDetails = materialObject.outputDetails.map((i) => {
+          i.reportQuantityCopy = i.reportQuantity;
+
+          const sumItem = materialObject.sumOutputDetails.find(
+            (i) => i.categoryId === i.categoryId
+          );
+
+          if (sumItem) {
+            i.reportQuantity = sumItem.reportQuantity;
+          } else {
+            i.reportQuantity = i.reportQuantity || 0;
+          }
+
+          return i;
+        });
         const pickDetails = materialObject.pickDetails.map((i) => {
           // 物料清单中如果存在则 selected 设置为 true
           const any = this.addForm.outputDetails.find(
@@ -888,6 +919,8 @@
           (i) => i.outputType != 1
         );
 
+        this.sumOutputDetails = materialObject.sumOutputDetails;
+
         this.addForm.pickDetails = [
           ...preOutputDetails.filter((i) => i.outputType == 1),
           ...pickDetails
@@ -1016,7 +1049,11 @@
             }
           }
 
-          if (this.$refs.statisticsRef && type != 'cache' && type != 'submit-reset') {
+          if (
+            this.$refs.statisticsRef &&
+            type != 'cache' &&
+            type != 'submit-reset'
+          ) {
             // 验证统计项目
             const valid = this.$refs.statisticsRef.validateStatisticsFilled();
             if (!valid) {

+ 2 - 2
vue.config.js

@@ -37,8 +37,8 @@ module.exports = {
         // target: 'http://192.168.1.251:18086',
         // target: 'http://192.168.1.251:18086',
         // target: 'http://192.168.1.125:18086',
-        // target: 'http://192.168.1.116:18086', // 赵沙金
-        target: 'http://192.168.1.251:18086', // 开发环境
+        target: 'http://192.168.1.116:18086', // 赵沙金
+        // target: 'http://192.168.1.251:18086', // 开发环境
         // target: 'http://192.168.1.103:18086',192.168.1.116
         // target: 'http://192.168.1.144:18086',
         // target: 'http://192.168.1.30:18086',