index.vue
16.2 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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
<template>
<div class="equity-wrap">
<div class="find-wrap">
<GLCombiForm ref="showSearch" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
<div class="out_wrap">
<div class="choseRow flex_scb">
<div class="wrap">
<div class="choseItem" :class="{ active: currentIndex == index }" v-for="(item, index) in choseList" :key="index" @click="tabClick(index)">
{{ item }}
</div>
</div>
<div class="flex_sc">
<GLButton fn="新增商品" size="small" type="primary" @click="jump">新增商品</GLButton>
<template v-if="currentIndex == 1">
<GLButton fn="下架商品" plain size="small" @click="batchOperation(2)">批量下架</GLButton>
</template>
<template v-if="currentIndex > 1">
<GLButton fn="上架商品" plain size="small" @click="batchOperation(1)">批量上架</GLButton>
</template>
<template v-if="currentIndex == 2">
<GLButton fn="删除商品" size="small" @click="batchOperation(-1)">批量删除</GLButton>
</template>
</div>
</div>
</div>
<div class="table_box">
<GLTable ref="table" :pageConf="pageConf" :noDataImg="url" @setTableFinishFun="setTableFinishFun" :searchForm="searchForm" :tableParams="tableParams" :getListApi="getListApi">
<div class="flex_sc" slot="colorStatus" slot-scope="scope">
<div class="table_point" :style="{ background: colors[scope.scope.status] }"></div>
<span>{{ ['待上架', '上架', '下架'][scope.scope.status] }}</span>
</div>
<div slot="table-btns" slot-scope="scope">
<GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="3"></GLTableButton>
</div>
</GLTable>
</div>
<!-- <div class="pannel tableTopButton">
<el-button plain size="small" @click="toggleAll">全选</el-button>
<GLButton fn="上架商品" size="small" @click="batchOperation(1)">上架</GLButton>
<GLButton fn="下架商品" size="small" @click="batchOperation(2)">下架</GLButton>
<GLButton fn="删除商品" size="small" @click="batchOperation(-1)">删除</GLButton>
</div>
<div class="table_wrap">
<GLTable ref="table" :pageConf="pageConf" :noDataImg="url" @setTableFinishFun="setTableFinishFun" :searchForm="searchForm" :tableParams="tableParams" :getListApi="getListApi">
<div class="flex_sc" slot="colorStatus" slot-scope="scope">
<div class="table_point" :style="{ background: colors[scope.scope.status] }"></div>
<span>{{ ['待上架', '上架', '下架'][scope.scope.status] }}</span>
</div>
<div slot="table-btns" slot-scope="scope">
<GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="3"></GLTableButton>
</div>
</GLTable>
</div> -->
</div>
<GLDialog mode="mid" title="商品短链" :visible.sync="isVisible" :before-close="handleClose" :close-on-click-modal="false">
<div class="con-wrap flex_cc">
<div class="link flex_cc">{{ shortLink }}</div>
</div>
<div slot="footer">
<el-button size="small" @click="handleClose">取消</el-button>
<el-button size="small" type="primary" @click="copyLink">复制</el-button>
</div>
</GLDialog>
</div>
</template>
<script>
const cloneText = message => {
let input = document.createElement('input')
input.value = message
document.body.appendChild(input)
input.select()
input.setSelectionRange(0, input.value.length), document.execCommand('Copy')
document.body.removeChild(input)
}
import url from '@/assets/empty.png'
import { searchMixin } from '@/mixins'
export default {
name: '',
mixins: [searchMixin],
data() {
return {
url: url,
size: 'small',
pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
flag: false,
searchForm: {
brandName: '',
productName: '',
supplier: '',
productId: '',
status:'',
id: ''
},
searchFormData: [
{
label: '品牌名称',
name: 'brandName',
type: 'select',
optionList: [],
optionId: 'brandName',
optionLabel: 'brandName',
isClear: true
},
{
label: '商品名称',
name: 'productName',
type: 'input',
isClear: true
},
{
label: '提供方',
name: 'supplier',
type: 'select',
optionList: [
{
label: '海威',
value: 'HW'
}
],
optionId: 'value',
optionLabel: 'label',
isClear: true
},
{
label: '商品编码',
name: 'productId',
type: 'input',
isClear: true
},
// {
// label: '商品状态',
// name: 'status',
// type: 'select',
// optionList: [
// {
// label: '上架',
// value: '1'
// },
// {
// label: '下架',
// value: '2'
// },
// {
// label: '待上架',
// value: '0'
// }
// ],
// optionId: 'value',
// optionLabel: 'label',
// isClear: true
// },
{
label: '商品ID',
name: 'id',
type: 'input',
isClear: true
}
],
buttonList: [
{
type: 'GLButton',
name: row => {
return '编辑'
},
attrs: {
type: 'text',
fn: '编辑商品'
},
listeners: {
click: row => this.jump(row.scope)
}
},
{
type: 'GLButton',
name: row => {
return '复制'
},
attrs: {
type: 'text',
fn: '复制商品'
},
listeners: {
click: row => this.copy(row.scope)
}
},
{
type: 'el-button',
name: row => {
return '生成商品短链'
},
attrs: {
type: 'text',
disabled: row => {
return !row.scope.groupStatus || row.scope.status != 1
}
},
listeners: {
click: row => this.toCreateLine(row.scope)
}
}
],
supplierList: [
{
label: '海威',
value: 'HW'
}
],
statusList: [
{
label: '上架',
value: '1'
},
{
label: '下架',
value: '2'
},
{
label: '待上架',
value: '0'
}
],
getListApi: this.$apis.orderApi.getGoodsList,
tableParams: {
listName: 'list',
mutiSelectName: 'goodsIndex',
mutiSelectUniqueKey: 'id',
tableOption: false,
tableColumns: [
{
label: '提供方',
width: 150,
formatter: cell => {
return '海威'
}
},
{
label: '商品SKU',
minWidth:450,
formatter: cell => {
let str = cell.appearance == 1 ? `${cell.brandName || ''}${cell.productName || ''}` : `${cell.brandName || ''}${cell.productName || ''}${cell.denomination || ''}`
return str
}
},
{
label: '会员价/元',
width: 150,
align: 'right',
prop: 'salesPrice',
formatter(cell) {
return parseFloat(cell.salesPrice).toFixed(2)
}
},
{
prop: 'sales',
sortable: true,
label: '销量',
width: 110
// renderHeader: h => {
// return h('div', { class: 'table-header' }, [
// h('span', '销量'),
// h('table-tooltip', {
// props: { content: '该商品的历史总销量,订单发生退款、换货历史销量均不变' }
// })
// ])
// }
},
{
label: '库存',
width:110,
sortable: true,
formatter: cell => {
return cell.stock == -1 ? '无限制' : cell.stock
}
},
{
label: '商品状态',
addHtml: 'colorStatus'
// formatter: cell => {
// return ['待上架', '上架', '下架'][cell.status]
// }
},
{
label: '操作',
width: 170,
fixed: 'right',
addHtml: 'table-btns'
}
]
},
goodsBrandList: [],
selectStatus: false,
isVisible: false,
shortLink: null,
colors: ['#FDB757', '#2CCA74', '#999999'],
choseList: ['全部', '上架', '待上架', '下架'],
currentIndex: 0
}
},
mounted() {
this.getAllBrandList()
},
methods: {
tabClick(e) {
this.currentIndex = e
let status = ''
switch (e) {
case 1:
status = 1
break
case 2:
status = 0
break
case 3:
status = 2
break
default:
status = ''
break
}
this.searchForm.status = status
this.handleSearch()
},
handleClose() {
this.isVisible = !this.isVisible
},
copyLink() {
if (!this.shortLink) return
cloneText(this.shortLink)
this.$message.success('复制成功')
this.handleClose()
},
// 生成短链
toCreateLine(row) {
const { merchantId, sapCode } = this.$globalState.session
let base_info = `merchantId=${merchantId}`
if (sapCode) {
base_info = `${base_info}&storeCode=${sapCode}`
}
const href = window.location.host
const CHARGE_PATH =href.indexOf('cgacar') != -1 ? 'packageEquity/pages/commodity/chargeDetail/chargeDetail' : 'packageShopmall/packageEquity/pages/commodity/chargeDetail/chargeDetail'
const MINI_PATH =href.indexOf('cgacar') != -1 ? 'packageEquity/pages/commodity/detail/detail' : 'packageShopmall/packageEquity/pages/commodity/detail/detail'
const MINI_OPTIONS = {
supplier: row.supplier,
brandName: row.brandName
}
if (row.appearance == 2) {
MINI_OPTIONS.icon = row.icon
}
if (row.appearance == 1) {
MINI_OPTIONS.id = row.id
}
const ENV = this.$custom_env
let query = `param=${encodeURIComponent(JSON.stringify(MINI_OPTIONS))}&${base_info}&shortlink=1`
let para = {
path: row.appearance == 2 ? CHARGE_PATH : MINI_PATH,
query,
appId: ENV.environment == 'beta' ? 'wx9f91c1ec493eb425' : ENV.channel == 2 ? 'wxfe82b8d65d07808f' : 'wxe10067a63c1856ac',
envVersion: ENV.envVersion
}
this.$apis.orderApi.createShortLink(para).then(res => {
this.shortLink = res.data
this.isVisible = true
})
},
getAllBrandList() {
this.$apis.orderApi.getAllBrandList().then(res => {
// this.goodsBrandList = res.data || []
const item = this.searchFormData.find(item => item.name === 'brandName')
item.optionList = res.data
})
},
jump({ id, status }, copy) {
// let params = {}
// if (id) params.id = id
// if (status == 0) params.edit = true
// let target = ['嘀加权益卡管理平台', '运营平台', '权益', '商品管理', '*商品']
// if (window.$config.axios.environment) {
// target = ['权益卡管理平台', '运营平台', 'SCRM权益平台', '商品管理', '*商品详情']
// }
let query = {}
if (id) query.id = id
if (status == 0) {
query.edit = true
query.$title = encodeURI('编辑商品')
}
if (copy == true) {
query.edit = true
query.$title = encodeURI('编辑商品')
}
this.$router.push({ path: '/goods/addGoods', query })
},
copy({ id }) {
this.$apis.orderApi.getEquityGoodsById({ id }).then(({ code, data, message }) => {
if (code == 0) {
this.$apis.orderApi.createGoods(data).then(res => {
if (res.code == 0) {
this.$message({
message: '复制成功!',
type: 'success'
})
let [target] = this.$refs.table.data
let copy = true
console.log(target)
this.jump(target, copy)
} else {
this.$message.error(res.message)
}
})
} else {
this.$message.error(message)
}
})
},
toggleAll() {
let { goodsIndexMutiTable } = this.$refs.table.$refs
let { data } = goodsIndexMutiTable
this.selectStatus = !this.selectStatus
data.map(row => {
goodsIndexMutiTable.toggleRowSelection(row, this.selectStatus)
})
},
setTableFinishFun() {
//接收到的数据为空
if (!this.$refs.table.data.length) {
this.$refs.table.setTableHeightFun()
}
},
handleReset() {
this.flag = false
this.searchForm = {}
this.tabClick(this.currentIndex)
// this.handleSearch()
},
handleSearch() {
this.flag = false
this.$refs.table.refreshTable()
this.$nextTick(() => {
this.flag = true
})
},
// ['待上架', '上架', '下架'] //
batchOperation(status) {
let { goodsIndexMutiTable } = this.$refs.table.$refs
let { selection } = goodsIndexMutiTable
if (!selection.length) return
let ids = []
try {
selection.map(e => {
if (status == 1) {
if (e.status == 1) throw '仅能上架待上架和下架商品'
} else if (status == 2) {
if (e.status != 1) throw '仅能下架上架商品'
} else if (status == -1) {
if (e.status != 0) throw '仅能删除待上架商品'
}
ids.push(e.id)
})
} catch (error) {
this.$message.error(error)
return
}
let content = {
'-1': '是否批量删除',
1: '是否批量上架',
2: '是否批量下架'
}
this.$confirm(content[status], '提示', {
confirmButtonText: '是',
cancelButtonText: '否',
type: 'warning'
})
.then(() => {
let target = 'deleteGoods'
let params = { ids }
if (status != -1) {
target = 'goodsShelves'
params.status = status
}
this.$apis.orderApi[target](params).then(({ code, message }) => {
if (code == 0) {
this.$message({
message: '操作成功!',
type: 'success'
})
this.search()
} else {
this.$message.error(message)
}
})
})
.catch(() => {})
}
}
}
</script>
<style lang="scss" scoped>
.addGood {
margin-bottom: 16px;
}
.find-wrap {
background: #ffffff;
padding: 20px;
}
.out_wrap {
position: relative;
z-index: 100;
margin-bottom: -1px;
}
.choseRow {
display: flex;
.choseItem {
display: inline-block;
box-sizing: border-box;
padding: 0 20px;
height: 40px;
line-height: 40px;
cursor: pointer;
border: 1px solid #e5e5e5;
margin-right: 1px;
border-radius: 4px 4px 0 0;
background: #fafafa;
}
.active {
color: #5850ff;
background-color: white;
font-weight: 600;
border-bottom: none;
}
}
.table_box {
border: 1px solid #e5e5e5;
box-sizing: border-box;
padding: 16px 20px;
border-radius: 0 4px 4px 4px;
}
.con-wrap {
height: 191px;
.link {
width: 536px;
height: 62px;
background: #f9f9f9;
font-size: 14px;
font-weight: 400;
color: #666666;
}
}
.flex_cc {
display: flex;
align-items: center;
justify-content: center;
}
.el-button + .el-button {
margin-left: 8px;
}
</style>