两个搜索选择的问题修复
This commit is contained in:
parent
b59d42636b
commit
45ef27e1da
@ -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
|
||||
}
|
||||
|
@ -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.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
|
||||
|
Loading…
Reference in New Issue
Block a user