// 自定义扩展业务代码
|
import gridBody from "./extend/OrderStockTake.vue";
|
// 引入杂收杂发平账弹窗组件
|
import gridHeader from "./extend/TakeStockSelect.vue";
|
import { ElMessageBox, ElLoading, ElMessage } from "element-plus";
|
|
let extension = {
|
components: {
|
// 查询界面扩展组件
|
gridHeader: gridHeader,
|
gridBody: gridBody, // 原有盘点弹窗组件
|
gridFooter: '',
|
modelHeader: '',
|
modelBody: '',
|
modelFooter: ''
|
},
|
tableAction: '', // 无需指定表名
|
buttons: { view: [], box: [], detail: [] }, // 扩展按钮
|
methods: {
|
onInit() {
|
// 原有盘点按钮逻辑保留
|
let OrderStockTakeBtn = this.buttons.find(x => x.value === 'OrderStockTake');
|
if (OrderStockTakeBtn) {
|
OrderStockTakeBtn.onClick = function () {
|
let rows = this.$refs.table.getSelected();
|
if (rows.length === 0) return this.$error("请选择一条盘点单据数据!");
|
if (rows.length > 1) return this.$error("只能选择一条盘点单据数据!");
|
|
const selectedReceiptNo = rows[0].orderNo;
|
if (!selectedReceiptNo) return this.$error("选中的单据缺少有效的单据号!");
|
this.$refs.gridBody.open(selectedReceiptNo);
|
};
|
}
|
|
// 监听原有弹窗事件(保留)
|
this.$nextTick(() => {
|
const stockTakeComp = this.$refs.gridBody;
|
if (stockTakeComp) {
|
stockTakeComp.$on('refresh', () => {
|
this.$refs.table.reload();
|
});
|
stockTakeComp.$on('box-returned', (boxNo) => {
|
this.$success(`料箱【${boxNo}】回库成功,表格将刷新!`);
|
this.$refs.table.reload();
|
});
|
}
|
|
});
|
|
// ========== 新增操作列:人工平账 + 杂收杂发平账 ==========
|
this.columns.push({
|
field: 'operation',
|
title: '操作',
|
width: 200,
|
fixed: 'right',
|
align: 'center',
|
formatter: (row) => {
|
return `
|
<span style="cursor: pointer;color: #2d8cf0;margin-right: 10px;" class="manual-reconciliation">
|
<i class="el-icon-check"></i>人工平账
|
</span>
|
<span style="cursor: pointer;color: #1989fa;" class="misc-reconciliation">
|
<i class="el-icon-edit"></i>杂收杂发平账
|
</span>
|
`;
|
},
|
click: (row, column, event) => {
|
const target = event.target;
|
// 区分点击的是人工平账还是杂收杂发平账
|
if (target.closest('.manual-reconciliation')) {
|
this.handleManualReconciliation(row); // 人工平账逻辑
|
} else if (target.closest('.misc-reconciliation')) {
|
this.handleMiscReconciliation(row); // 杂收杂发平账逻辑
|
}
|
}
|
});
|
},
|
|
// ========== 人工平账核心逻辑 ==========
|
handleManualReconciliation(row) {
|
// 弹出确认框
|
ElMessageBox.confirm(
|
'确认要执行人工平账操作吗?',
|
'操作确认',
|
{
|
confirmButtonText: '确认',
|
cancelButtonText: '取消',
|
type: 'warning'
|
}
|
).then(async () => {
|
// 添加遮罩层防止重复点击
|
const loading = ElLoading.service({
|
lock: true,
|
text: '处理中,请稍候...',
|
background: 'rgba(0, 0, 0, 0.7)'
|
});
|
|
try {
|
// 调用人工平账接口
|
const response = await this.http.get(`/api/TakeStockOrder/ManualReconciliation?id=${row.id}`);
|
if (response.status) {
|
ElMessage.success('人工平账操作成功!');
|
this.$refs.table.reload(); // 刷新表格
|
} else {
|
ElMessage.error(`操作失败:${response.message || '未知错误'}`);
|
}
|
} catch (error) {
|
} finally {
|
// 关闭遮罩层
|
loading.close();
|
}
|
}).catch(() => {
|
ElMessage.info('已取消人工平账操作');
|
});
|
},
|
|
// ========== 杂收杂发平账核心逻辑(修改后) ==========
|
handleMiscReconciliation(row) {
|
// 选中当前行
|
const table = this.$refs.table.$refs.table;
|
if (table) {
|
table.clearSelection();
|
table.toggleRowSelection(row, true);
|
}
|
|
// 调用接口获取杂收杂发平账数据
|
const fetchMiscData = async () => {
|
const loading = ElLoading.service({
|
lock: true,
|
text: '加载数据中...',
|
background: 'rgba(0, 0, 0, 0.7)'
|
});
|
|
try {
|
// 调用接口,传递row中的remark和id参数
|
const response = await this.http.get(`/api/TakeStockOrder/SelectOrder?remark=${row.remark || ''}&id=${row.id}`);
|
loading.close();
|
|
if (response.status) {
|
if (!Array.isArray(response.data) || response.data.length === 0) {
|
ElMessage.warning("未查询到相关数据");
|
// 打开空数据的弹窗
|
this.$refs.gridHeader.open(row, []);
|
return;
|
}
|
|
// 提取需要展示的字段
|
const displayData = response.data.map(item => ({
|
orderId: item.orderId || '',
|
materielCode: item.materielCode || '',
|
materielName: item.materielName || '',
|
batchNo: item.batchNo || '',
|
orderQuantity: item.orderQuantity || 0,
|
unit: item.unit || '',
|
supplyCode: item.supplyCode || '',
|
warehouseCode: item.warehouseCode || ''
|
}));
|
|
// 打开弹窗并传递处理后的数据
|
this.$refs.gridHeader.open(row, displayData);
|
} else {
|
ElMessage.error(`查询失败:${response.message || '未知错误'}`);
|
}
|
} catch (error) {
|
loading.close();
|
ElMessage.error(`网络异常:${error.message || '接口调用失败'}`);
|
}
|
};
|
|
// 执行数据查询并打开弹窗
|
fetchMiscData();
|
},
|
|
onInited() {
|
// 框架初始化完成后执行
|
},
|
searchBefore(param) {
|
// 查询前拦截
|
return true;
|
},
|
searchAfter(result) {
|
// 查询后数据处理
|
return true;
|
},
|
addBefore(formData) {
|
return true;
|
},
|
updateBefore(formData) {
|
return true;
|
},
|
rowClick({ row, column, event }) {
|
// 单击行选中当前行
|
this.$refs.table.$refs.table.toggleRowSelection(row);
|
},
|
modelOpenAfter(row) {
|
// 新建/编辑弹窗打开后处理
|
}
|
}
|
};
|
|
export default extension;
|