两个搜索选择的问题修复

This commit is contained in:
xiaofajia 2024-11-20 20:23:24 +08:00
parent b59d42636b
commit 45ef27e1da
2 changed files with 100 additions and 26 deletions

View File

@ -140,7 +140,7 @@
</el-form> </el-form>
<el-collapse> <el-collapse>
<el-collapse-item v-for="([key, value], index) in inItems" :title="key + `(${value.length})`"> <el-collapse-item v-for="([key, value], index) in inItems" :title="key + `(${value.length})`">
<el-table v-loading="inLoading" :ref="`tableRef_${index}`" :data="value" :stripe="true" <el-table v-loading="inLoading" :ref="`tableRef_${key}`" :data="value" :stripe="true"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
@selection-change="selectRow" @selection-change="selectRow"
@cell-mouse-enter="handleCellEnter" @cell-mouse-enter="handleCellEnter"
@ -227,7 +227,7 @@
</el-collapse-item> </el-collapse-item>
</el-collapse> </el-collapse>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button type="primary" :disabled="selectRows.length === 0" @click="doInWares">确定</el-button> <el-button type="primary" :disabled="allSelectRows.length === 0" @click="doInWares">确定</el-button>
<el-button @click="dialogVisible = false">取消</el-button> <el-button @click="dialogVisible = false">取消</el-button>
</div> </div>
</el-dialog> </el-dialog>
@ -338,7 +338,9 @@ export default {
children: "children" children: "children"
}, },
typeMap: null, typeMap: null,
selectRowIds: [] selectRowIds: [],
allSelectRows: [],
isRefresh: false,
} }
}, },
mounted() { mounted() {
@ -353,8 +355,9 @@ export default {
if (tableRef[0]) { if (tableRef[0]) {
tableRef[0].clearSelection(); // tableRef[0].clearSelection(); //
this.inItems.forEach(([key, value]) => { this.inItems.forEach(([key, value]) => {
const ids = this.allSelectRows.map(item => item.id)
value.forEach(item => { value.forEach(item => {
if (this.selectRowIds.includes(item.id)) { if (ids.includes(item.id)) {
tableRef[0].toggleRowSelection(item, true); tableRef[0].toggleRowSelection(item, true);
} }
}); });
@ -400,11 +403,13 @@ export default {
return JSON.parse(JSON.stringify(result)) return JSON.parse(JSON.stringify(result))
}, },
searchByQuery() { searchByQuery() {
this.isRefresh = true
this.getSoiList().then(() => { this.getSoiList().then(() => {
this.setSelectedRows() this.setSelectedRows()
}) })
}, },
resetByQuery() { resetByQuery() {
this.allSelectRows = []
this.inItemsQuery = null this.inItemsQuery = null
this.searchByQuery() this.searchByQuery()
}, },
@ -481,6 +486,8 @@ export default {
}, },
// //
async handleInWares(row) { async handleInWares(row) {
this.allSelectRows = []
this.inItemsQuery = null
await this.listServer() await this.listServer()
this.soId = row.id this.soId = row.id
this.inWaresFormData = { this.inWaresFormData = {
@ -510,16 +517,52 @@ export default {
this.inLoading = false this.inLoading = false
} }
}, },
selectRow(val) { selectRow(row) {
this.selectRows = val this.selectRows = row
if (val && val.length > 0) { this.selectRowIds = row.map(item => item.id)
this.selectRowIds = val.map(item => item.id) if (row && row.length > 0) {
// allSelectRows
this.allSelectRows = [...this.allSelectRows, ...row.filter(item => !this.allSelectRows.some(allRow => allRow.id === item.id))];
} else {
//
this.allSelectRows = this.allSelectRows.filter(item => !this.selectRowIds.includes(item.id));
} }
//
//
if (!this.isRefresh) {
//
// tableRef
const allRef = this.$refs
const newRef = Object.keys(allRef).filter(item => item.startsWith('tableRef_'))
newRef.forEach(tempRef => {
if (this.$refs[tempRef][0]) {
const ids = this.$refs[tempRef][0].data.map(item => item.id);
if (!row || row.length === 0) {
this.allSelectRows = this.allSelectRows.filter(item => !ids.includes(item.id))
} else {
//
const rowIds = row.map(item => item.id)
const exIds = ids.filter(id => !rowIds.includes(id))
this.allSelectRows = this.allSelectRows.filter(item => !exIds.includes(item.id))
}
}
})
}
this.isRefresh = false
//
this.allSelectRows = this.allSelectRows.reduce((acc, item) => {
const flag = acc.find(i => i.id === item.id)
if (!flag) {
return acc.concat([item])
} else {
return acc
}
}, [])
}, },
async doInWares() { async doInWares() {
try { try {
this.inWaresFormData.soiList = this.selectRows this.inWaresFormData.soiList = this.allSelectRows
this.inWaresFormData.waresList = this.selectRows.map(item => { this.inWaresFormData.waresList = this.allSelectRows.map(item => {
if (item.wares.ware){ if (item.wares.ware){
item.wares.warehouse = item.wares.ware.id item.wares.warehouse = item.wares.ware.id
} }

View File

@ -95,14 +95,14 @@
</el-table> </el-table>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button type="primary" v-if="type" @click="handlePass" <el-button type="primary" v-if="type" @click="handlePass"
:disabled="selections.length === 0 || selections.filter(item => !item.isStock).length !== 0"> :disabled="allSelectRows.length === 0 || allSelectRows.filter(item => !item.isStock).length !== 0">
通知领料 通知领料
</el-button> </el-button>
<el-button type="primary" v-else @click="handlePass" <el-button type="primary" v-else @click="handlePass"
:disabled="selections.length === 0 || selections.filter(item => !item.isStock).length !== 0"> :disabled="allSelectRows.length === 0 || allSelectRows.filter(item => !item.isStock).length !== 0">
通知退料 通知退料
</el-button> </el-button>
<el-button v-if="type" type="primary" @click="handleCreate" :disabled="selections.length === 0"> <el-button v-if="type" type="primary" @click="handleCreate" :disabled="allSelectRows.length === 0">
采购 采购
</el-button> </el-button>
</div> </div>
@ -307,6 +307,8 @@ export default {
children: "children" children: "children"
}, },
typeMap: null, typeMap: null,
allSelectRows: [],
isRefresh: false
} }
}, },
mounted() { mounted() {
@ -346,6 +348,7 @@ export default {
return JSON.parse(JSON.stringify(result)) return JSON.parse(JSON.stringify(result))
}, },
searchByQuery() { searchByQuery() {
this.isRefresh = true
const data = { const data = {
twId: this.twId, twId: this.twId,
query: this.query query: this.query
@ -357,14 +360,16 @@ export default {
setSelectedRows() { setSelectedRows() {
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.tableRef.clearSelection(); // this.$refs.tableRef.clearSelection(); //
const ids = this.allSelectRows.map(item => item.id)
this.items.forEach(row => { this.items.forEach(row => {
if (this.selectionIds.includes(row.id)) { if (ids.includes(row.id)) {
this.$refs.tableRef.toggleRowSelection(row, true); // this.$refs.tableRef.toggleRowSelection(row, true); //
} }
}); });
}); });
}, },
resetByQuery() { resetByQuery() {
this.allSelectRows = []
this.query = null this.query = null
this.searchByQuery() this.searchByQuery()
}, },
@ -383,7 +388,7 @@ export default {
soStatus: this.type ? "04" : "07", soStatus: this.type ? "04" : "07",
// purchaseType: "01" // purchaseType: "01"
} }
this.formData.repairSois = [...this.selections.map(item => { this.formData.repairSois = [...this.allSelectRows.map(item => {
return { return {
soiType: this.type ? '02' : "04", soiType: this.type ? '02' : "04",
goodsId: item.waresId, goodsId: item.waresId,
@ -391,7 +396,7 @@ export default {
} }
})] })]
if (this.type) { if (this.type) {
this.formData.items = [...this.selections.map(item => { this.formData.items = [...this.allSelectRows.map(item => {
return { return {
id: item.id, id: item.id,
} }
@ -414,7 +419,7 @@ export default {
const brandRes = await getCarBrand(this.carInfo.carBrand) const brandRes = await getCarBrand(this.carInfo.carBrand)
this.carInfo.carBrand = brandRes.data.brandName this.carInfo.carBrand = brandRes.data.brandName
} }
const ids = this.selections.map(item => item.id) const ids = this.allSelectRows.map(item => item.id)
const res = await getByIds(ids) const res = await getByIds(ids)
this.partList = Object.entries(res.data) this.partList = Object.entries(res.data)
const values = this.partList.map(([key, value]) => value) const values = this.partList.map(([key, value]) => value)
@ -449,6 +454,8 @@ export default {
this.handleQuery() this.handleQuery()
}, },
handleDispose(row) { handleDispose(row) {
this.allSelectRows = []
this.query = null
this.listServer() this.listServer()
this.formData = {} this.formData = {}
this.formData = { this.formData = {
@ -482,9 +489,33 @@ export default {
}, },
handleSelect(row) { handleSelect(row) {
this.selections = row this.selections = row
if (row && row.length > 0) {
this.selectionIds = row.map(item => item.id); this.selectionIds = row.map(item => item.id);
//
this.allSelectRows = [...this.allSelectRows, ...row]
//
//
if (!this.isRefresh){
//
const ids = this.$refs.tableRef.data.map(item => item.id);
if (!row || row.length === 0){
this.allSelectRows = this.allSelectRows.filter(item => !ids.includes(item.id))
}else {
//
const rowIds = row.map(item => item.id)
const exIds = ids.filter(id => !rowIds.includes(id))
this.allSelectRows = this.allSelectRows.filter(item => !exIds.includes(item.id))
} }
}
this.isRefresh = false
//
this.allSelectRows = this.allSelectRows.reduce((acc, item) => {
const flag = acc.find(i => i.id === item.id)
if (!flag){
return acc.concat([item])
}else {
return acc
}
}, [])
}, },
// //
getSummaries(param) { getSummaries(param) {
@ -591,12 +622,12 @@ export default {
// //
async handleSubmit() { async handleSubmit() {
try { try {
const isNull = this.validateNull(); // const isNull = this.validateNull();
if (!isNull) return; // if (!isNull) return;
const names = this.validateZero() // const names = this.validateZero()
if (names) { // if (names) {
await this.$modal.confirm("确认配件:" + names + "的采购价格为0吗") // await this.$modal.confirm("" + names + "0")
} // }
await this.createInit() await this.createInit()
await createRepairSo(this.formData) await createRepairSo(this.formData)
this.inStockDialog = false this.inStockDialog = false