row.id);
+ // 获取当前页所有行的ID
+ const currentPageAllIds = this.beforeSplitRows.map((row) => row.id);
+ // 更新选中映射
+ currentPageIds.forEach((id) => {
+ const record =
+ selection.find((row) => row.id === id) ||
+ this.beforeSplitRows.find((row) => row.id === id);
+ if (record) {
+ this.$set(this.beforeSplitSelectedMap, id, record);
+ }
+ });
+ currentPageAllIds.forEach((id) => {
+ if (!currentPageIds.includes(id)) {
+ if (this.beforeSplitSelectedIds.includes(id)) {
+ const index = this.beforeSplitSelectedIds.indexOf(id);
+ if (index > -1) {
+ this.beforeSplitSelectedIds.splice(index, 1);
+ }
+ }
+ if (this.beforeSplitSelectedMap[id]) {
+ this.$delete(this.beforeSplitSelectedMap, id);
+ }
+ }
+ });
+ currentPageIds.forEach((id) => {
+ if (!this.beforeSplitSelectedIds.includes(id)) {
+ this.beforeSplitSelectedIds.push(id);
+ }
+ if (!this.beforeSplitSelectedMap[id]) {
+ const record = this.beforeSplitRows.find((row) => row.id === id);
+ if (record) {
+ this.$set(this.beforeSplitSelectedMap, id, record);
+ }
+ }
+ });
+ },
+ syncBeforeSplitTableSelection() {
+ this.$nextTick(() => {
+ if (this.$refs.beforeSplitTable) {
+ this.syncingBeforeSplitSelection = true;
+ this.$refs.beforeSplitTable.clearSelection();
+ this.beforeSplitRows.forEach((row) => {
+ if (this.beforeSplitSelectedIds.includes(row.id)) {
+ this.$refs.beforeSplitTable.toggleRowSelection(row, true);
+ }
+ });
+ this.$nextTick(() => {
+ this.syncingBeforeSplitSelection = false;
+ });
+ }
+ });
+ },
handlePaidQueryChange() {
this.paidPage = 1;
this.getPaidList();
@@ -1246,6 +1659,55 @@ export default {
.filter(Boolean);
this.selectedPreviewRows = rows;
this.selectedPreviewSelection = rows.map((row) => row.id);
+ this.selectedPreviewSource = "pending";
+ this.selectedPreviewVisible = true;
+ this.$nextTick(() => {
+ if (this.$refs.previewTable) {
+ this.syncingPreviewSelection = true;
+ this.$refs.previewTable.clearSelection();
+ this.selectedPreviewRows.forEach((row) => {
+ if (this.selectedPreviewSelection.includes(row.id)) {
+ this.$refs.previewTable.toggleRowSelection(row, true);
+ }
+ });
+ this.$nextTick(() => {
+ this.syncingPreviewSelection = false;
+ });
+ }
+ });
+ },
+ openSelectedPreviewBeforeSplit() {
+ // 记录已存在的编辑值,便于重建时保留
+ const editedMap = {};
+ (this.selectedPreviewRows || []).forEach((r) => {
+ editedMap[r.id] = { applyNum: r.applyNum, money: r.money };
+ });
+
+ // 按当前已选的明细拆分前集合构建预览(始终以最新选择为准)
+ const rows = this.beforeSplitSelectedIds
+ .map((id) => {
+ if (!this.beforeSplitSelectedMap[id]) {
+ const record = this.beforeSplitRows.find((row) => row.id === id);
+ if (record) {
+ this.$set(this.beforeSplitSelectedMap, id, record);
+ }
+ }
+ const rec = this.beforeSplitSelectedMap[id];
+ if (!rec) return null;
+ // 合并保留之前在弹窗中编辑过的值
+ const edited = editedMap[id];
+ if (edited) {
+ if (edited.applyNum !== undefined && edited.applyNum !== null)
+ rec.applyNum = edited.applyNum;
+ if (edited.money !== undefined && edited.money !== null)
+ rec.money = edited.money;
+ }
+ return rec;
+ })
+ .filter(Boolean);
+ this.selectedPreviewRows = rows;
+ this.selectedPreviewSelection = rows.map((row) => row.id);
+ this.selectedPreviewSource = "beforeSplit";
this.selectedPreviewVisible = true;
this.$nextTick(() => {
if (this.$refs.previewTable) {
@@ -1298,18 +1760,31 @@ export default {
return;
}
- // 同步选择状态
+ // 同步选择状态(根据数据来源更新对应的选择状态)
const newIds = [...this.selectedPreviewSelection];
- this.pendingSelectedIds = newIds;
- const newMap = {};
- newIds.forEach((id) => {
- const record =
- this.selectedPreviewRows.find((row) => row.id === id) ||
- this.pendingSelectedMap[id] ||
- this.pendingRows.find((row) => row.id === id);
- if (record) newMap[id] = record;
- });
- this.pendingSelectedMap = { ...newMap };
+ if (this.selectedPreviewSource === "pending") {
+ this.pendingSelectedIds = newIds;
+ const newMap = {};
+ newIds.forEach((id) => {
+ const record =
+ this.selectedPreviewRows.find((row) => row.id === id) ||
+ this.pendingSelectedMap[id] ||
+ this.pendingRows.find((row) => row.id === id);
+ if (record) newMap[id] = record;
+ });
+ this.pendingSelectedMap = { ...newMap };
+ } else if (this.selectedPreviewSource === "beforeSplit") {
+ this.beforeSplitSelectedIds = newIds;
+ const newMap = {};
+ newIds.forEach((id) => {
+ const record =
+ this.selectedPreviewRows.find((row) => row.id === id) ||
+ this.beforeSplitSelectedMap[id] ||
+ this.beforeSplitRows.find((row) => row.id === id);
+ if (record) newMap[id] = record;
+ });
+ this.beforeSplitSelectedMap = { ...newMap };
+ }
// 组装并跳转
const titleParts = selectedRows.map(
@@ -1445,6 +1920,7 @@ export default {
const params = {
page: this.pendingPage,
page_size: this.pendingPageSize,
+ is_before: 0, // 待采购传 0
};
if (this.pendingQuery.creator_department_id) {
params.creator_department_id = this.pendingQuery.creator_department_id;
@@ -1498,6 +1974,63 @@ export default {
// 不再移除之前选择的项,保持跨查询选择
this.syncPendingTableSelection();
},
+ async getBeforeSplitList() {
+ const params = {
+ page: this.beforeSplitPage,
+ page_size: this.beforeSplitPageSize,
+ is_before: 1, // 明细拆分前传 1
+ };
+ if (this.beforeSplitQuery.creator_department_id) {
+ params.creator_department_id = this.beforeSplitQuery.creator_department_id;
+ }
+ if (this.beforeSplitQuery.created_by) {
+ params.created_by = this.beforeSplitQuery.created_by;
+ }
+ if (this.beforeSplitQuery.keywords) {
+ params.keywords = this.beforeSplitQuery.keywords;
+ }
+ if (this.beforeSplitQuery.chengbanren_id) {
+ params.chengbanren_id = this.beforeSplitQuery.chengbanren_id;
+ }
+ if (this.beforeSplitQuery.caigouneirong) {
+ params.caigouneirong = this.beforeSplitQuery.caigouneirong;
+ }
+ const res = await waitList(params);
+ this.beforeSplitTotal = res.total || 0;
+ // 映射数据到表格字段
+ this.beforeSplitRows = (res.data || []).map((item) => ({
+ ...item, // 保留原始数据,方便后续使用
+ checked: false,
+ applicant: item.yibancaigou?.flow?.creator?.name || "",
+ department: item.yibancaigou?.flow?.creator_department?.name || "",
+ flowTitle: item.yibancaigou?.flow?.title || "",
+ purchaseContent: item.yibancaigou?.caigouneirong || "",
+ purchaser:
+ item.yibancaigou?.flow?.logs && item.yibancaigou.flow.logs.length > 0
+ ? item.yibancaigou.flow.logs[0]?.user?.name || ""
+ : "",
+ isContractFlow: item.yibancaigou?.flow?.contract_flow ? "是" : "否",
+ paidNum: item.fund_log_wuzicaigou_items_sum_num || 0,
+ total: item.num || 0,
+ itemName: item.pinminghuofuwuxuqiu || "",
+ model: item.xinghao || "",
+ origin: item.chandi || "",
+ unit: item.danwei || "",
+ purpose: item.yongtu || "",
+ applyNum: null, // 本次报销数量,由用户输入
+ money: null, // 付款金额,由用户输入
+ shifouqingdan: item.shifouqingdan || "",
+ shifoubijia: item.shifoubijia || "",
+ shifoufahuo: item.shifoufahuo || "",
+ }));
+ this.beforeSplitRows.forEach((row) => {
+ if (this.beforeSplitSelectedIds.includes(row.id)) {
+ this.$set(this.beforeSplitSelectedMap, row.id, row);
+ }
+ });
+ // 不再移除之前选择的项,保持跨查询选择
+ this.syncBeforeSplitTableSelection();
+ },
async getPaidList() {
const params = {
page: this.paidPage,
@@ -1559,7 +2092,10 @@ export default {
// 重置分页参数
if (newTab === "pending") {
this.pendingPage = 1;
- this.pendingPageSize = 40;
+ this.pendingPageSize = 10;
+ } else if (newTab === "beforeSplit") {
+ this.beforeSplitPage = 1;
+ this.beforeSplitPageSize = 10;
} else if (newTab === "paid") {
this.paidPage = 1;
this.paidPageSize = 10;
@@ -1576,6 +2112,16 @@ export default {
};
this.pendingSelectedIds = [];
this.pendingSelectedMap = {};
+ } else if (newTab === "beforeSplit") {
+ this.beforeSplitQuery = {
+ creator_department_id: "",
+ created_by: "",
+ keywords: "",
+ chengbanren_id: "",
+ caigouneirong: "",
+ };
+ this.beforeSplitSelectedIds = [];
+ this.beforeSplitSelectedMap = {};
} else if (newTab === "paid") {
this.paidQuery = {
creator_department_id: "",
@@ -1593,6 +2139,9 @@ export default {
if (this.$refs.pendingTable) {
this.$refs.pendingTable.clearSelection();
}
+ if (this.$refs.beforeSplitTable) {
+ this.$refs.beforeSplitTable.clearSelection();
+ }
});
});
@@ -1602,6 +2151,9 @@ export default {
} else if (newTab === "pending") {
// 切换到待采购时也重新加载数据,确保状态正确
this.getWaitList();
+ } else if (newTab === "beforeSplit") {
+ // 切换到明细拆分前时重新加载数据
+ this.getBeforeSplitList();
}
},
// 关闭弹窗不清空已选择的数据