647556386
2026-01-08 e7dac9ecb16aa627f0603beec9930c75ee6aa3f7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// 自定义扩展业务代码
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;