diff --git a/src/api/repair/stockOperate/stockOperate.js b/src/api/repair/stockOperate/stockOperate.js index a7781d4..97e1553 100644 --- a/src/api/repair/stockOperate/stockOperate.js +++ b/src/api/repair/stockOperate/stockOperate.js @@ -14,7 +14,7 @@ export function createRepairSo(data){ // 分页 export function getRepairSoPage(params){ return request({ - url: preUrl + "/page", + url: preUrl + "/page-with-items", method: "get", params }) diff --git a/src/views/repair/stockOperate/Components/SoIndex.vue b/src/views/repair/stockOperate/Components/SoIndex.vue index 6e735e8..b108ebd 100644 --- a/src/views/repair/stockOperate/Components/SoIndex.vue +++ b/src/views/repair/stockOperate/Components/SoIndex.vue @@ -80,18 +80,26 @@
采购总金额: - ¥{{ purchaseAmount.toFixed(2) }} + ¥{{ (purchase && purchase.purchaseAmount ? purchase.purchaseAmount : 0).toFixed(2) }} +
+
+ 采购数量: + {{ (purchase && purchase.purchaseCount ? purchase.purchaseCount : 0).toFixed(2) }}
- - + + - + + + - + + + + + + + + + + + + + + + @@ -362,7 +396,10 @@ export default { list: [], loading: false, total: 0, - purchaseAmount: 0, + purchase: { + purchaseAmount: 0, + purchaseCount: 0 + }, dialogVisible: false, inItems: [], inItemsQuery: null, @@ -404,7 +441,12 @@ export default { return row.id }, inSoiList: [], - inLoading3: false + inLoading3: false, + expandedList: [], + // 需要合并的属性 + mergeProps: ['_index', 'soNo', 'itemCount', 'totalPrice', 'userName', 'supplierName', 'soTime', 'licenseNumber', 'createTime', 'corpName', 'soStatus', 'remark'], + // 项目相关的属性,不需要合并 + itemProps: ['itemGoodsName', 'itemGoodsCount', 'itemGoodsPrice', 'houseName'], } }, mounted() { @@ -510,30 +552,145 @@ export default { this.inItemsQuery = null this.searchByQuery() }, + // 处理数据并展开items数组 + processDataForMergeCells(data) { + const result = []; + let index = 0; + + data.forEach((item, idx) => { + const items = item.items || []; + + if (items.length > 0) { + items.forEach((subItem, subIdx) => { + const newItem = { + ...item, + _index: idx, // 保存原始索引 + _rowKey: `${item.id}_${subIdx}`, // 唯一标识 + _isFirstItem: subIdx === 0, + itemGoodsName: subItem.wares?.name || '-', + itemGoodsCount: subItem.goodsCount || '-', + itemGoodsPrice: subItem.goodsPrice || '-', + houseName: subItem.houseName || '-' + }; + result.push(newItem); + }); + } else { + // 没有items的情况 + const newItem = { + ...item, + _index: idx, + _rowKey: `${item.id}_0`, + _isFirstItem: true, + itemGoodsName: '-', + itemGoodsCount: '-', + itemGoodsPrice: '-', + houseName: '-' + }; + result.push(newItem); + } + }); + + return result; + }, + + // 合并单元格方法 + mergeCells({row, column, rowIndex, columnIndex}) { + // 如果是项目相关列,不合并 + if (this.itemProps.includes(column.property)) { + return { rowspan: 1, colspan: 1 }; + } + + // 如果是操作列,只在首行显示 + if (column.property === undefined && column.label === '操作') { + if (row._isFirstItem) { + const mainId = row.id; + let count = 0; + + // 计算相同id的行数 + for (let i = rowIndex; i < this.expandedList.length; i++) { + if (this.expandedList[i].id === mainId) { + count++; + } else { + break; + } + } + + return { rowspan: count, colspan: 1 }; + } else { + return { rowspan: 0, colspan: 0 }; + } + } + + // 合并其他公用数据列 + if (this.mergeProps.includes(column.property) || (column.property === undefined && column.label === '序号')) { + const mainId = row.id; + + // 只在每个主记录的第一行进行计算 + if (row._isFirstItem) { + let count = 0; + + // 计算相同id的行数 + for (let i = rowIndex; i < this.expandedList.length; i++) { + if (this.expandedList[i].id === mainId) { + count++; + } else { + break; + } + } + + return { rowspan: count, colspan: 1 }; + } else { + return { rowspan: 0, colspan: 0 }; + } + } + + return { rowspan: 1, colspan: 1 }; + }, + // 分页 async pageSo() { - this.queryParams.soType = null - this.queryParams.purchaseType = null + this.queryParams.soType = null; + this.queryParams.purchaseType = null; if (this.soByType && this.goodsYes) { - this.queryParams.soType = "03" - this.queryParams.purchaseType = "02" + this.queryParams.soType = "03"; + this.queryParams.purchaseType = "02"; } else if (this.soByType && !this.goodsYes) { - this.queryParams.soType = "01" - this.queryParams.purchaseType = "01" + this.queryParams.soType = "01"; + this.queryParams.purchaseType = "01"; } else if (!this.soByType && !this.isBack) { - this.queryParams.soType = "02" + this.queryParams.soType = "02"; } else if (this.isBack) { - this.queryParams.soType = '04' + this.queryParams.soType = '04'; } try { - this.loading = true - const res = await getRepairSoPage(this.queryParams) - this.list = res.data.records - this.total = res.data.total - const purchaseRes = await purchase(this.queryParams) - this.purchaseAmount = purchaseRes.data + this.loading = true; + const res = await getRepairSoPage(this.queryParams); + this.list = res.data.records; + this.total = res.data.total; + // 处理数据,展开items数组并准备合并单元格 + this.expandedList = this.processDataForMergeCells(this.list); + const purchaseRes = await purchase(this.queryParams); + // 增强代码健壮性,确保purchase数据存在 + if (purchaseRes && purchaseRes.data) { + this.purchase = { + purchaseAmount: purchaseRes.data.purchaseAmount || 0, + purchaseCount: purchaseRes.data.purchaseCount || 0 + }; + } else { + this.purchase = { + purchaseAmount: 0, + purchaseCount: 0 + }; + } + } catch (error) { + // 错误处理,确保页面不会因接口异常而无法显示 + console.error('获取采购数据失败:', error); + this.purchase = { + purchaseAmount: 0, + purchaseCount: 0 + }; } finally { - this.loading = false + this.loading = false; } }, // 搜索按钮 @@ -796,9 +953,12 @@ export default { .amount-card { margin-bottom: 20px; + display: flex; + flex-wrap: wrap; .amount-info { display: flex; align-items: center; + margin-right: 30px; .amount-label { font-size: 14px; color: #606266; diff --git a/src/views/repair/stockOperate/Components/SoReturn.vue b/src/views/repair/stockOperate/Components/SoReturn.vue index 274ee9c..04a517f 100644 --- a/src/views/repair/stockOperate/Components/SoReturn.vue +++ b/src/views/repair/stockOperate/Components/SoReturn.vue @@ -35,6 +35,17 @@ + + +
+ 退货总金额: + ¥{{ (purchase && purchase.purchaseAmount ? purchase.purchaseAmount : 0).toFixed(2) }} +
+
+ 退货数量: + {{ (purchase && purchase.purchaseCount ? purchase.purchaseCount : 0).toFixed(2) }} +
+
@@ -43,8 +54,8 @@ - - + @@ -181,7 +192,7 @@ -