whj 1 year ago
parent
commit
7e632d55b7
1 changed files with 53 additions and 20 deletions
  1. 53 20
      src/views/sb/modelbom/modules/Detail.vue

+ 53 - 20
src/views/sb/modelbom/modules/Detail.vue

@@ -149,8 +149,8 @@ export default {
           dataIndex: 'zjm'
         }, */
         {
-          title: '数量',
-          dataIndex: 'num'
+          title: '库存',
+          dataIndex: 'inventory'
         },
         {
           title: '操作',
@@ -180,6 +180,7 @@ export default {
       this.visible = true
       this.model = record
       this.modalTitle = '详情'
+      const that = this
       selectSpareInfoListByModelId({ id: record.id }).then(res => {
         getSpareStore({
           spareVOS: res.data.map(item => {
@@ -191,15 +192,38 @@ export default {
           sbId: record.id
         }).then(response => {
           console.log(response)
+          that.data = res.data.map(item => {
+            console.log(item)
+
+            item.inventory = response.data.find(spare => spare.no === item.no) ? response.data.find(spare => spare.no === item.no).num : null
+            console.log(item)
+            return item
+          })
         })
-        this.data = res.data
-        console.log(this.data)
       })
     },
     handleOk () {
+      const that = this
       this.visibleOther = true
       selectSpareInfoListByModelId({ id: this.model.id }).then(res => {
-        this.data = res.data
+        getSpareStore({
+          spareVOS: res.data.map(item => {
+            return {
+              oldOrNew: item.oldOrNew,
+              beiJianCode: item.no
+            }
+          }),
+          sbId: this.model.id
+        }).then(response => {
+          console.log(response)
+          that.data = res.data.map(item => {
+            console.log(item)
+
+            item.inventory = response.data.find(spare => spare.no === item.no) ? response.data.find(spare => spare.no === item.no).num : null
+            console.log(item)
+            return item
+          })
+        })
       })
     },
     handleAddSpareInfo () {
@@ -212,21 +236,30 @@ export default {
     handleSpareSelected (record, keys, rows) {
       const addData = []
       console.log(record, keys, rows)
-      // getSpareStore({
-      //   spareVOS:{
-      //     oldOrNew:
-      //   }
-      // })
-      for (let i = 0; i < rows.length; i++) {
-        addData.push({ sbId: this.model.id, modelId: this.model.id, spareId: rows[i].id, spareName: rows[i].name, num: 1, period: 500, periodType: 6 })
-      }
-      addSbModelBomBatch(addData)
-        .then((response) => {
-          this.$message.info('批量添加成功')
-          this.handleOk()
-        }).catch(() => {
-          this.confirmLoading = false
-        })
+      const that = this
+
+      getSpareStore({
+        spareVOS: rows.data.map(item => {
+          return {
+            oldOrNew: item.oldOrNew,
+            beiJianCode: item.no
+          }
+        }),
+        sbId: that.model.id
+      }).then(response => {
+        console.log(response)
+        for (let i = 0; i < rows.length; i++) {
+          addData.push({ sbId: that.model.id, modelId: that.model.id, spareId: rows[i].id, spareName: rows[i].name, num: 1, period: 500, periodType: 6, inventory: response.data.find(spare => spare.no === rows[i].no) ? response.data.find(spare => spare.no === rows[i].no).num : null })
+        }
+        console.log(addData)
+        addSbModelBomBatch(addData)
+          .then((response) => {
+            that.$message.info('批量添加成功')
+            that.handleOk()
+          }).catch(() => {
+            that.confirmLoading = false
+          })
+      })
     },
     handleSpareStoreSelect () {
       this.$refs.spareStoreSelectModal.base()