|
@@ -57,11 +57,11 @@
|
|
|
<el-button @click="search()">查询</el-button>
|
|
<el-button @click="search()">查询</el-button>
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
</el-form>
|
|
</el-form>
|
|
|
- <el-table border :data="whMaterialRecords" @selection-change="itemSelectionChangeHandle">
|
|
|
|
|
|
|
+ <el-table border :data="whMaterialRecords" @selection-change="itemSelectionChangeHandle" ref="addTable">
|
|
|
<el-table-column type="selection"></el-table-column>
|
|
<el-table-column type="selection"></el-table-column>
|
|
|
<el-table-column label="序号" type="index" width="50" align="center">
|
|
<el-table-column label="序号" type="index" width="50" align="center">
|
|
|
</el-table-column>
|
|
</el-table-column>
|
|
|
- <el-table-column prop="orderName" header-align="center" align="center" min-width="100"
|
|
|
|
|
|
|
+ <el-table-column prop="materialName" header-align="center" align="center" min-width="100"
|
|
|
:show-tooltip-when-overflow="true" label="名称">
|
|
:show-tooltip-when-overflow="true" label="名称">
|
|
|
</el-table-column>
|
|
</el-table-column>
|
|
|
<el-table-column prop="mapNumber" header-align="center" align="center" min-width="100"
|
|
<el-table-column prop="mapNumber" header-align="center" align="center" min-width="100"
|
|
@@ -207,9 +207,27 @@ export default {
|
|
|
}).then(({ data }) => {
|
|
}).then(({ data }) => {
|
|
|
if (data && data.code === '200') {
|
|
if (data && data.code === '200') {
|
|
|
this.whMaterialRecords = data.data.records
|
|
this.whMaterialRecords = data.data.records
|
|
|
|
|
+ // 先全部置零
|
|
|
this.whMaterialRecords.forEach(item => {
|
|
this.whMaterialRecords.forEach(item => {
|
|
|
item.cnt2 = 0;
|
|
item.cnt2 = 0;
|
|
|
});
|
|
});
|
|
|
|
|
+ // 回显已选项的发货数量
|
|
|
|
|
+ this.whMaterialRecords.forEach(item => {
|
|
|
|
|
+ const selected = this.dataForm.list.find(sel => sel.materialId === item.materialId)
|
|
|
|
|
+ if (selected) {
|
|
|
|
|
+ item.cnt2 = selected.deliverCnt
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ // 自动勾选已选项
|
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
|
+ if (this.$refs.addTable) {
|
|
|
|
|
+ this.whMaterialRecords.forEach(row => {
|
|
|
|
|
+ if (this.dataForm.list.some(sel => sel.materialId === row.materialId)) {
|
|
|
|
|
+ this.$refs.addTable.toggleRowSelection(row, true)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
} else {
|
|
} else {
|
|
|
this.$message.error(data.msg)
|
|
this.$message.error(data.msg)
|
|
|
}
|
|
}
|
|
@@ -219,22 +237,36 @@ export default {
|
|
|
itemSelectionChangeHandle(val) {
|
|
itemSelectionChangeHandle(val) {
|
|
|
this.selectedItems = val
|
|
this.selectedItems = val
|
|
|
},
|
|
},
|
|
|
|
|
+ // 提交新增发货数据
|
|
|
addItemSubmit() {
|
|
addItemSubmit() {
|
|
|
// 判断是否有选择数据
|
|
// 判断是否有选择数据
|
|
|
if (this.selectedItems.length === 0) {
|
|
if (this.selectedItems.length === 0) {
|
|
|
this.$message.error("请勾选数据")
|
|
this.$message.error("请勾选数据")
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- for (let index = 0; index < this.selectedItems.length; index++) {
|
|
|
|
|
- const element = this.selectedItems[index];
|
|
|
|
|
|
|
+ for (let i = 0; i < this.selectedItems.length; i++) {
|
|
|
|
|
+ const element = this.selectedItems[i];
|
|
|
|
|
+ // 在 whMaterialRecords 中查找当前元素的序号(index,从0开始)
|
|
|
|
|
+ const rowIndex = this.whMaterialRecords.findIndex(item => item.materialId === element.materialId);
|
|
|
if (element.cnt2 <= 0) {
|
|
if (element.cnt2 <= 0) {
|
|
|
- this.$message.error("第" + (index + 1) + "条发货数量不能小于等于0")
|
|
|
|
|
|
|
+ this.$message.error("第" + (rowIndex + 1) + "条发货数量不能小于等于0")
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let data = this.selectedItems.map(item => {
|
|
|
|
|
|
|
+ // 先复制原有的list
|
|
|
|
|
+ let list = [...this.dataForm.list]
|
|
|
|
|
+
|
|
|
|
|
+ // 用materialId为key,合并新旧数据,新数据覆盖旧数据
|
|
|
|
|
+ let map = {}
|
|
|
|
|
+ // 先放入旧数据
|
|
|
|
|
+ list.forEach(item => {
|
|
|
|
|
+ if (item.materialId) {
|
|
|
|
|
+ map[item.materialId] = item
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ // 再放入新数据(覆盖旧的)
|
|
|
|
|
+ this.selectedItems.forEach(item => {
|
|
|
let temp = {
|
|
let temp = {
|
|
|
productName: item.materialName,
|
|
productName: item.materialName,
|
|
|
productNumber: '',
|
|
productNumber: '',
|
|
@@ -250,10 +282,11 @@ export default {
|
|
|
}
|
|
}
|
|
|
temp.amount = temp.deliverCnt * temp.price
|
|
temp.amount = temp.deliverCnt * temp.price
|
|
|
temp.contractId = this.dataForm.contractId
|
|
temp.contractId = this.dataForm.contractId
|
|
|
- return temp
|
|
|
|
|
|
|
+ map[item.materialId] = temp
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- this.dataForm.list = data
|
|
|
|
|
|
|
+ // 生成最终list
|
|
|
|
|
+ this.dataForm.list = Object.values(map)
|
|
|
|
|
|
|
|
this.addItemVisible = false
|
|
this.addItemVisible = false
|
|
|
}
|
|
}
|