style:模具入库-新增-入库模具清单多选框

main
黄伟杰 1 month ago
parent a7fd5ea264
commit 426e7da4c1

@ -58,6 +58,11 @@ import { MoldBrandApi, MoldVO } from '@/api/erp/mold'
import { useDictStoreWithOut } from '@/store/modules/dict'
const props = defineProps<{
items?: any[]
disabled?: boolean
}>()
const message = useMessage() //
const { t } = useI18n() //
@ -81,6 +86,7 @@ const dictReady = ref(false)
/** 查询列表 */
const getList = async () => {
loading.value = true
ignoreSelectionChange.value = true
try {
const data = await MoldBrandApi.getMoldPage({
pageNo: queryParams.pageNo,
@ -94,6 +100,8 @@ const getList = async () => {
total.value = data.total
} finally {
loading.value = false
await nextTick()
ignoreSelectionChange.value = false
}
}
@ -111,12 +119,36 @@ const resetQuery = () => {
const tableRef = ref()
const selectedRows = ref<any[]>([])
const ignoreSelectionChange = ref(false)
watch(list, async () => {
await nextTick()
restoreSelection()
})
watch(
() => props.items,
async (val) => {
if (!val || !Array.isArray(val) || val.length === 0) {
selectedRows.value = []
await nextTick()
restoreSelection()
return
}
const ids = (val as any[])
.map((item) => item.productId ?? item.id)
.filter((id) => id !== undefined && id !== null)
const uniqIds = Array.from(new Set(ids))
selectedRows.value = uniqIds.map((id) => ({ id }))
await nextTick()
restoreSelection()
},
{ immediate: true, deep: true }
)
const restoreSelection = () => {
if (!tableRef.value || selectedRows.value.length === 0) return
tableRef.value.clearSelection?.()
@ -129,7 +161,19 @@ const restoreSelection = () => {
}
const handleSelectionChange = (rows: any[]) => {
selectedRows.value = rows
if (ignoreSelectionChange.value) return
const currentPageIds = list.value.map((row) => row.id)
const currentSelectedIdSet = new Set(rows.map((row) => row.id))
selectedRows.value = selectedRows.value.filter(
(row) => !currentPageIds.includes(row.id) || currentSelectedIdSet.has(row.id)
)
rows.forEach((row) => {
if (!selectedRows.value.some((r) => r.id === row.id)) {
selectedRows.value.push(row)
}
})
}
const validate = async (): Promise<boolean> => {

Loading…
Cancel
Save