Commit f4c2bd2c by chenwq

fix(select-muti-pro): 修复多选商品时已选商品丢失问题

修复在多选商品组件中,当商品列表更新时已选商品丢失的问题。修改了beforeSearchFn和setTableFinishFun方法,确保已选商品能够正确保留和恢复。同时优化了handleMutiSelectConfirm方法,避免重复添加已选商品。
1 parent d61d78a0
......@@ -128,12 +128,21 @@ export default {
methods: {
beforeSearchFn() {
return new Promise((resolve, reject) => {
var selectedData = this.$refs?.tableRef?.mutiSelectArr[this.tableParams.mutiSelectName] || []
let list = this.productList || []
this.selectedProList.forEach(item => {
if (!list?.map(k => k.id).includes(item.id) && !selectedData?.map(k => k.id).includes(item.id)) {
selectedData.push(item)
}
})
this.selectedProList = this.$common.utils.deepClone(selectedData)
this.searchForm = this.$common.utils.deepClone(this.goodsFormObj)
resolve()
})
},
setTableFinishFun() {
setTableFinishFun(list) {
this.productList = list
this.recoverySelected()
},
getOptionsList(formName, hasAll = true, refreshSigle) {
......@@ -177,12 +186,17 @@ export default {
if (this.selectedProList.length) {
this.selectedProList.forEach(row => {
const obj = this.productList.find(item => item.id == row.id)
this.$refs.tableRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].toggleRowSelection(row, true)
obj && this.$refs.tableRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].toggleRowSelection(obj, true)
})
}
},
handleMutiSelectConfirm() {
var selectedData = this.$refs.tableRef.mutiSelectArr[this.tableParams.mutiSelectName]
this.selectedProList.forEach(item => {
if (!this.productList.map(k => k.id).includes(item.id) && !selectedData.map(k => k.id).includes(item.id)) {
selectedData.push(item)
}
})
if (selectedData && selectedData.length > 100) {
this.$message({
message: '最多选择100件商品',
......@@ -191,6 +205,7 @@ export default {
})
return true
}
console.log(this.$common.utils.deepClone(selectedData), 'selectedData===')
this.$emit('handleMutiSelectConfirm', selectedData)
},
handleMutiSelectClose() {
......
......@@ -200,7 +200,7 @@ export default {
prop: 'goodsStock',
width: 150,
line: 1,
sortable: 'custom',
// sortable: 'custom',
formatter: cellValue => {
return cellValue.goodsStock != null ? cellValue.goodsStock : cellValue.minGoodsStock + '-' + cellValue.maxGoodsStock
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!