selectDefineProductDialog.vue
10.6 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<template>
<baseDialog :dialog-config="selectDialogConfig"
:is-show.sync="visible"
@handleClick="handleConfirm">
<div v-if="selectDialogConfig.type == 1">
<el-row class="tableCon">
<div class="tableBox">
<div class="tableTop">商品</div>
<div class="tableContent">
<div class="searchBox">
<el-input v-model.trim="upgradeGoodsName" placeholder="搜索商品名称" size="small" clearable style="width: 200px;"></el-input>
<el-select v-model="brandMerchantCodeList" placeholder="请选择品牌方" multiple filterable collapse-tags clearable>
<el-option v-for="(item, index) in brandMerchantCodeSelectList" :key="index" :label="item.relatedPartyName" :value="item.id"></el-option>
</el-select>
<el-button type="primary" size="small" @click="handleSearch" >搜索</el-button>
</div>
<el-table
ref="seletingTable"
:data="listData"
height="364px"
class="table"
border
@select="handleChange"
@select-all="handleAll">
<el-table-column type="selection" width="55" align="center" :selectable="selectableFn" />
<el-table-column prop="upgradeGoodsName" label="商品名称" align="center">
</el-table-column>
</el-table>
<el-pagination
small
background
@current-change="handleCurrentChange"
:current-page.sync="currentPage"
:page-size="pageSize"
layout="total, prev, pager, next"
:total="total" />
</div>
</div>
<div class="tableBox">
<div class="tableTop">
<div>
<span>已选商品</span>
<span>{{ selectedData.length ? `(${selectedData.length}个)` : '' }}</span>
</div>
<el-button type="text" @click="clearSelect">清空</el-button>
</div>
<div class="tableContent">
<el-table
class="tableBox table"
:data="selectedData"
border
height="420px">
<el-table-column prop="upgradeGoodsName" label="商品名称" width="420px" align="center">
<template slot-scope="scope">
<span>{{ scope.row.upgradeGoodsName }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" width="55px">
<template slot-scope="scope">
<el-button
@click="handleDelete(scope.row)"
type="text">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
</el-row>
</div>
<div v-else>
<el-row class="tableCon">
<div class="tableBox">
<div class="tableTop">圈定产品</div>
<div class="tableContent">
<el-table
ref="seletingTable"
:data="listData"
height="424px"
class="table"
border
@select="handleChange"
@select-all="handleAll">
<el-table-column type="selection" width="55" align="center" :selectable="selectableFn" />
<el-table-column prop="productName" label="产品名称" align="center">
</el-table-column>
</el-table>
</div>
</div>
<div class="tableBox">
<div class="tableTop">
<div>
<span>已选圈定产品</span>
<span>{{ selectedData.length ? `(${selectedData.length}个)` : '' }}</span>
</div>
<el-button type="text" @click="clearSelect">清空</el-button>
</div>
<div class="tableContent">
<el-table
class="tableBox table"
:data="selectedData"
border
height="424px">
<el-table-column prop="productName" label="产品名称" align="center">
</el-table-column>
<el-table-column label="操作" align="center" width="50px">
<template slot-scope="scope">
<el-button
@click="handleDelete(scope.row)"
type="text">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
</el-row>
</div>
</baseDialog>
</template>
<script>
import { getUpgradeProductList } from '@api/productManage'
import { getBrandSupplyMerchant } from '@api/product'
import { deepClone } from '@/common/util'
export default {
name: 'SelectDefineProductDialog',
data() {
return {
selectedData: [],
listData: [],
// 分页
total: 0,
currentPage: 1,
pageSize: 20,
upgradeGoodsName: '',
brandMerchantCodeList: [],
brandMerchantCodeSelectList: []
}
},
computed: {
visible: {
get() {
return this.selectDialogConfig.selectDialogVisible
},
set() {
this.$emit('selectDialogClose')
}
}
},
props: {
selectDialogConfig: {
type: Object,
default: () => {}
}
},
mounted() {
if (this.selectDialogConfig.type == 1) {
// 获取sku商品列表数据
this.getSkuGoodsList()
// 获取品牌方数据
this.getBrandDataList()
} else {
this.listData = deepClone(this.selectDialogConfig.listData)
this.$nextTick(() => {
this.recoverySelection()
})
}
this.selectedData = deepClone(this.selectDialogConfig.selectData)
},
methods: {
getBrandDataList() {
getBrandSupplyMerchant({
partitionFlag: 1
}).then(res => {
this.brandMerchantCodeSelectList = res
})
},
getSkuGoodsList() {
let params = {
currentPage: this.currentPage,
pageSize: this.pageSize,
upgradeGoodsName: this.upgradeGoodsName,
brandMerchantCodeList: this.brandMerchantCodeList
}
getUpgradeProductList(params).then(res => {
res?.list?.forEach(val => {
val.customerId = val.id // 自定义的id用于唯一值判断
let specificationTypeSequenceArr = val.specificationTypeSequence?.split(';~;')
let specificationValueSequenceArr = val?.specificationData?.split(';~;')
const suffixMapping = {
1: '年',
2: '(km/万)',
3: '万'
}
if (specificationTypeSequenceArr?.length) {
specificationValueSequenceArr?.forEach((v, index) => {
const suffix = suffixMapping[specificationTypeSequenceArr[index]]
if (suffix) {
specificationValueSequenceArr[index] = `${v}${suffix}`
}
})
val.listShowSpecificationData = specificationValueSequenceArr?.join('/')
}
val.itemId = val.id // 后端需要的skuID
val.upgradeGoodsName = val.listShowSpecificationData ? `${val.upgradeGoodsName} ${val.listShowSpecificationData}` : val.upgradeGoodsName
})
this.total = res.total
this.listData = res?.list || []
this.$nextTick(() => {
this.recoverySelection()
})
})
},
recoverySelection() {
var exitIds = this.selectedData.map((item) => item.customerId)
this.listData.forEach((item) => {
exitIds.includes(item.customerId) &&
this.$refs.seletingTable.toggleRowSelection(item, true)
})
},
// sku搜索
handleSearch() {
this.currentPage = 1
this.getSkuGoodsList()
},
// 翻页
handleCurrentChange(val) {
this.currentPage = val
this.getSkuGoodsList()
},
selectableFn(row) {
var isSelect = true
if (this.selectDialogConfig?.otherSelectData?.filter(val => val.customerId == row.customerId)?.length) {
isSelect = false
}
return isSelect
},
// 选择
handleChange(selection, row) {
var addOrDelete = !!selection.find(
(item) => item.customerId === row.customerId
)
addOrDelete
? this.selectedData.push(row)
: (this.selectedData = this.selectedData.filter(
(item) => item.customerId !== row.customerId
))
},
// 全选
handleAll(selection) {
this.listData.forEach((item) => {
var isExit = this.selectedData.findIndex(
(subItem) => subItem.customerId === item.customerId
)
var selectFlag = selection?.some(subItem => subItem.customerId == item.customerId)
if (selection.length && isExit === -1 && selectFlag) {
this.selectedData.push(item)
} else if (!selection.length && isExit !== -1 && !selectFlag) {
this.selectedData.splice(isExit, 1)
}
})
},
handleDelete(row) {
this.selectedData = this.selectedData.filter(
(item) => item.customerId !== row.customerId
)
const obj = this.listData.find((v) => v.customerId == row.customerId)
this.$refs.seletingTable.toggleRowSelection(obj)
},
// 清除选中项
clearSelect() {
this.selectedData = []
this.$refs.seletingTable.clearSelection()
},
// 确定提交
handleConfirm() {
const message = this.selectDialogConfig.type == 1 ? '请选择商品' : '请选择圈定产品'
if (!this.selectedData?.length) return this.$message.warning(message)
// 商品最多支持选择99个
const maxMessage = `最多支持选择99个${this.selectDialogConfig.type == 1 ? '商品' : '圈定产品'}`
if (this.selectedData?.length > 99) return this.$message.warning(maxMessage)
let eventType = this.selectDialogConfig.type == 1 ? 'addSku' : 'addProductToPackage'
this.$emit(eventType, this.selectedData, this.selectDialogConfig.index)
}
}
}
</script>
<style lang="scss" scoped>
.tableCon {
margin-top: 20px;
display: flex;
.tableBox {
flex: 1;
margin-right: 12px;
border: 1px solid #e5e5e5;
.tableTop{
display: flex;
align-items: center;
justify-content: space-between;
height: 48px;
font-size: 16px;
color: #333333;
font-weight: 600;
background: #f5f5f5;
padding: 0 16px;
}
.tableContent{
padding: 16px;
.searchBox{
margin-bottom: 20px;
display: flex;
align-items: center;
justify-content: space-between;
}
}
}
.tableBox:last-child{
margin: 0;
}
::v-deep .el-table__header-wrapper th{
background: #F2F4F7 !important;
}
}
</style>