两个搜索选择的问题修复

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-collapse>
<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"
@selection-change="selectRow"
@cell-mouse-enter="handleCellEnter"
@ -227,7 +227,7 @@
</el-collapse-item>
</el-collapse>
<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>
</div>
</el-dialog>
@ -338,7 +338,9 @@ export default {
children: "children"
},
typeMap: null,
selectRowIds: []
selectRowIds: [],
allSelectRows: [],
isRefresh: false,
}
},
mounted() {
@ -350,11 +352,12 @@ export default {
Object.keys(this.$refs).forEach(key => {
if (key.startsWith('tableRef_')) {
const tableRef = this.$refs[key];
if (tableRef[0]){
if (tableRef[0]) {
tableRef[0].clearSelection(); //
this.inItems.forEach(([key, value]) => {
const ids = this.allSelectRows.map(item => item.id)
value.forEach(item => {
if (this.selectRowIds.includes(item.id)) {
if (ids.includes(item.id)) {
tableRef[0].toggleRowSelection(item, true);
}
});
@ -400,11 +403,13 @@ export default {
return JSON.parse(JSON.stringify(result))
},
searchByQuery() {
this.isRefresh = true
this.getSoiList().then(() => {
this.setSelectedRows()
})
},
resetByQuery() {
this.allSelectRows = []
this.inItemsQuery = null
this.searchByQuery()
},
@ -481,6 +486,8 @@ export default {
},
//
async handleInWares(row) {
this.allSelectRows = []
this.inItemsQuery = null
await this.listServer()
this.soId = row.id
this.inWaresFormData = {
@ -510,16 +517,52 @@ export default {
this.inLoading = false
}
},
selectRow(val) {
this.selectRows = val
if (val && val.length > 0) {
this.selectRowIds = val.map(item => item.id)
selectRow(row) {
this.selectRows = row
this.selectRowIds = row.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() {
try {
this.inWaresFormData.soiList = this.selectRows
this.inWaresFormData.waresList = this.selectRows.map(item => {
this.inWaresFormData.soiList = this.allSelectRows
this.inWaresFormData.waresList = this.allSelectRows.map(item => {
if (item.wares.ware){
item.wares.warehouse = item.wares.ware.id
}

View File

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