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' import { useDictStoreWithOut } from '@/store/modules/dict'
const props = defineProps<{
items?: any[]
disabled?: boolean
}>()
const message = useMessage() // const message = useMessage() //
const { t } = useI18n() // const { t } = useI18n() //
@ -81,6 +86,7 @@ const dictReady = ref(false)
/** 查询列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
ignoreSelectionChange.value = true
try { try {
const data = await MoldBrandApi.getMoldPage({ const data = await MoldBrandApi.getMoldPage({
pageNo: queryParams.pageNo, pageNo: queryParams.pageNo,
@ -94,6 +100,8 @@ const getList = async () => {
total.value = data.total total.value = data.total
} finally { } finally {
loading.value = false loading.value = false
await nextTick()
ignoreSelectionChange.value = false
} }
} }
@ -111,12 +119,36 @@ const resetQuery = () => {
const tableRef = ref() const tableRef = ref()
const selectedRows = ref<any[]>([]) const selectedRows = ref<any[]>([])
const ignoreSelectionChange = ref(false)
watch(list, async () => { watch(list, async () => {
await nextTick() await nextTick()
restoreSelection() 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 = () => { const restoreSelection = () => {
if (!tableRef.value || selectedRows.value.length === 0) return if (!tableRef.value || selectedRows.value.length === 0) return
tableRef.value.clearSelection?.() tableRef.value.clearSelection?.()
@ -129,7 +161,19 @@ const restoreSelection = () => {
} }
const handleSelectionChange = (rows: any[]) => { 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> => { const validate = async (): Promise<boolean> => {

Loading…
Cancel
Save