ysy před 1 rokem
rodič
revize
e06cb8fa3c

+ 17 - 0
src/api/byProduct/index.js

@@ -32,3 +32,20 @@ export async function listDisposeBy(data) {
   }
   return Promise.reject(new Error(res.data.message));
 }
+
+
+
+// 新建副产品回收
+export async function disposeSave(data) {
+  const res = await request.post(`/mes/disposeorder/save`,data);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
+
+
+
+
+

+ 48 - 20
src/views/byProduct/components/addByProduct.vue

@@ -81,12 +81,12 @@
             >
           </div>
 
-          <div v-if="item.byProdList && item.byProdList.length > 0">
+          <div v-if="item.detailList && item.detailList.length > 0">
             <el-table
               :ref="`form222${idx}`"
               class="table_content"
               :max-height="300"
-              :data="item.byProdList"
+              :data="item.detailList"
               tooltip-effect="dark"
               style="width: 100%"
               stripe
@@ -113,10 +113,12 @@
               <el-table-column label="不合格品数量" prop="notFormedNum">
               </el-table-column>
 
-              <el-table-column label="回收" prop="quantity" width="160px">
-                <el-input v-model="row.quantity" disabled size="mini">
-                  <template slot="append">{{ row.unit }}</template>
-                </el-input>
+              <el-table-column label="回收" prop="quantity" width="180px">
+                <template slot-scope="{ $index, row }">
+                  <el-input v-model="row.quantity" disabled size="mini">
+                    <template slot="append">{{ row.unit }}</template>
+                  </el-input>
+                </template>
               </el-table-column>
 
               <el-table-column label="操作" fixed="right" width="100px">
@@ -149,7 +151,7 @@
 
 <script>
   import { getCode } from '@/api/produce/workOrder';
-  import { listDisposeBy } from '@/api/byProduct/index';
+  import { listDisposeBy, disposeSave } from '@/api/byProduct/index';
   import ProductModal from './ProductModal.vue';
   import produceOrder from '@/views/pick/pickApply/components/produceOrder.vue';
   export default {
@@ -172,7 +174,9 @@
 
         productWeight: null,
 
-        orderShow: false
+        orderShow: false,
+
+        newWeightList: []
       };
     },
 
@@ -189,7 +193,19 @@
         this.productForm.code = await getCode('dispose_code');
       },
 
-      save() {},
+      save() {
+        let param = {
+          detailList: this.materialList[0].detailList,
+          ...this.productForm,
+          categoryId: this.materialList[0].id,
+          quantity: this.productWeight
+        };
+        console.log(param);
+
+        disposeSave(param).then((res) => {
+          this.$emit('close', true);
+        });
+      },
 
       categorySelect() {
         this.$refs.productRefs.open({}, '选择物料', '1', null);
@@ -221,27 +237,39 @@
           workOrderIds: ids
         };
         listDisposeBy(param).then((res) => {
-          console.log(res);
-          let _arr = []
-          
-          let _totalWeight = 0;
+          this.newWeightList = res;
+          this.WeightListFN();
 
-          res.materialList.forEach(item => {
-            _totalWeight += Number(item.formedNum || 0 ) +  Number(item.notFormedNum || 0 );
-          });
+          this.$forceUpdate();
+        });
 
+        this.orderShow = false;
+      },
 
+      WeightListFN() {
+        let _totalNum = 0;
+        let _oneWeight = 0;
+        let _arr = [];
 
-          this.$set(this.materialList[0], 'byProdList', res);
+        // 使用reduce方法求和
+        _totalNum = this.newWeightList.reduce((acc, item) => {
+          return acc + item.formedNum + item.notFormedNum;
+        }, 0);
 
-          this.$forceUpdate();
+        _oneWeight = this.productWeight / _totalNum;
+
+        this.newWeightList.forEach((item) => {
+          _arr.push({
+            ...item,
+            quantity: (item.formedNum + item.notFormedNum) * _oneWeight
+          });
         });
 
-        this.orderShow = false;
+        this.$set(this.materialList[0], 'detailList', _arr);
       },
 
       removeItem(idx, index) {
-        this.materialList[idx].byProdList.splice(index, 1);
+        this.materialList[idx].detailList.splice(index, 1);
       }
     }
   };