relateStoreTable.vue
5.19 KB
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
<!--
* @Author: 'wangzhihui' '1733904062@qq.com'
* @Date: 2024-06-12 15:21:09
* @LastEditors: 'wangzhihui' '1733904062@qq.com'
* @LastEditTime: 2026-04-08 17:13:53
* @FilePath: \dj-car-life-system\src\views\goods\grounding\components\relateStoreTable.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
<div class="store-table">
<el-table header-cell-class-name="header-cell-class-name"
style="width: 100%"
border
:data="isHide ? tableData : merchantGoodsRefList"
:header-row-style="headerRowStyle"
:span-method="isHide ? objectSpanMethod : null">
<el-table-column align="center"
label="序号"
width="60px">
<template #default="scope">
{{ getIndex(scope.$index) }}
</template>
</el-table-column>
<el-table-column align="center"
label="门店名称"
prop="merchantName" />
<el-table-column align="center"
label="门店商户号"
prop="merchantId" />
<el-table-column v-if="isHide"
align="center"
label="产品名称"
prop="upgradeGoodsName" />
<el-table-column align="center"
label="库存管控">
<template #default="scope">
<span v-if="isDetail">{{ scope.row.inventoryType == 1 ? '虚拟' : '实物' }}</span>
<el-select v-else
v-model="scope.row.inventoryType"
placeholder="请选择"
@change="handleInventoryChange(scope.row)">
<el-option label="实物" :value="2"></el-option>
<el-option label="虚拟" :value="1"></el-option>
</el-select>
</template>
</el-table-column>
<el-table-column v-if="!isDetail"
align="center"
label="操作"
width="90">
<template #default="scope">
<el-button type="text"
@click="handleDelete(scope.row)">
删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script>
export default {
name: "RelateProTable",
props: {
merchantGoodsRefList: {
type: Array,
default: () => {},
},
isDetail: {
type: Boolean,
default: false,
},
isHide: {
type: Boolean,
default: false,
},
},
data() {
return {
tableData: [],
};
},
watch: {
merchantGoodsRefList: {
handler(val) {
if (this.isHide) {
this.initData();
}
},
immediate: true,
},
},
mounted() {
},
methods: {
initData() {
const tableData = [];
(this.merchantGoodsRefList || []).forEach((pkg) => {
if (pkg.inventoryTypeRefList && pkg.inventoryTypeRefList.length > 0) {
pkg.inventoryTypeRefList.forEach((goods) => {
if (goods) {
tableData.push({
merchantId: pkg.merchantId,
merchantName: pkg.merchantName,
merchantGoodsId: goods.merchantGoodsId,
upgradeGoodsName: goods.upgradeGoodsName,
inventoryType: goods.inventoryType,
});
}
});
} else {
tableData.push({
merchantId: pkg.merchantId,
merchantName: pkg.merchantName,
merchantGoodsId: "",
upgradeGoodsName: "",
inventoryType: 2,
});
}
});
this.tableData = tableData;
this.getSpanArr(this.tableData);
},
getIndex(index) {
if (!this.isHide) {
return index + 1;
}
// 当有合并单元格时,计算当前行在 spanArr 中是第几个非0项,从而得出正确的顺序序号
let count = 0;
for (let i = 0; i <= index; i++) {
if (this.spanArr[i] > 0) {
count++;
}
}
return count;
},
getSpanArr(data) {
this.spanArr = [];
this.pos = 0;
for (let i = 0; i < data.length; i++) {
if (i === 0) {
this.spanArr.push(1);
this.pos = 0;
} else {
// 判断当前元素与上一个元素是否属于同一个套餐
if (data[i].merchantId === data[i - 1].merchantId) {
this.spanArr[this.pos] += 1;
this.spanArr.push(0);
} else {
this.spanArr.push(1);
this.pos = i;
}
}
}
},
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
// 合并序号(0)和套餐名称(1)列
if (columnIndex === 0 || columnIndex === 1 || columnIndex === 2 || columnIndex === 5) {
const _row = this.spanArr[rowIndex];
const _col = _row > 0 ? 1 : 0;
return {
rowspan: _row,
colspan: _col,
};
}
},
handleDelete(item) {
this.$emit("handleDelete", item);
},
handleInventoryChange(row) {
this.$emit("updateInventory", row);
},
headerRowStyle() {
return {
height: "40px",
background: "#F2F4F7",
};
},
},
};
</script>
<style lang="scss" scoped>
.store-table {
margin-top: 15px;
}
::v-deep .header-cell-class-name {
height: 30px;
background: #f2f4f7;
}
::v-deep .el-table th {
padding: 0;
}
::v-deep .el-table__body-wrapper tr td {
padding: 8px 0 !important;
}
</style>