commodity.vue
18.5 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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
<!-- 商品管理 -->
<template>
<d2-container class="commodity">
<div class="header"
slot="header">
<d2-search ref="showSearch"
class="show-search"
:searchForm="searchForm"
:formData="showFormData">
<!-- <p>
<el-input
size="small"
class="custom-input"
v-model="searchForm.goodsName"
placeholder="请输入商品名称"
suffix-icon="el-icon-search"
></el-input>
</p> -->
</d2-search>
<div class="up-btns">
<el-button :id="tableParams.btnId"
size="small"
type="primary">查询</el-button>
<el-button size="small"
@click="handleReset">重置</el-button>
</div>
</div>
<div class="d2-container-content">
<d2-table-header>
<span slot="left">
<auth-button category="Button"
style="{display: inline-block}"
:showBtnIds="['9030201']"></auth-button>
</span>
<auth-button category="Button"
style="{display: inline-block}"
:showBtnIds="['9030202']"></auth-button>
</d2-table-header>
<d2-table ref="commodityTable"
:hasNum="false"
:searchForm="searchForm"
:tableParams="tableParams"
:getListApi="getListApi"
:beforeSearchFn="beforeSearchFn">
<img slot="img"
slot-scope="scope"
class="pro-img"
:src="scope.scope.goodsInfo.thumbUrl" />
<div v-if="Object.keys(scope.scope).includes('upgradeGoodsList')"
slot="auth-button"
slot-scope="scope">
<el-button type="text"
size="mini"
style="margin-right: 10px;"
@click="handleCommodityDetail(scope.scope)">查看</el-button>
<!-- <auth-button :data="scope.scope"></auth-button> -->
<span style="margin-right: 10px;">
<auth-button :data="scope.scope"
:showBtnIds="['9030203']"></auth-button>
</span>
<span style="margin-right: 10px;"
v-show="showUpOrDownBT(scope.scope)">
<auth-button :data="scope.scope"
:showBtnIds="['9030205']"></auth-button>
</span>
<auth-button :data="scope.scope"
:showBtnIds="['9030206']"></auth-button>
</div>
<div v-else
slot="auth-button-other"
slot-scope="scope">
<auth-button :data="scope.scope"
:showBtnIds="['9030208']"></auth-button>
</div>
</d2-table>
</div>
<d2-dialog v-if="detailVisible"
:title="detailData ? detailData.goodsInfo.goodsName : ''"
:className="storeDetail"
:isVisible.sync="detailVisible"
:showClose="showClose"
:noCancel="true"
@closeDialog="handleDetailClose"
@confirmDialog="handleDetailClose">
<store-detail :detailData="detailData"></store-detail>
</d2-dialog>
<!-- 查看面板 -->
<drawer-detail v-if="drawerDetailVisible"
:drawerDetailVisible="drawerDetailVisible"
:commodityInfoId="commodityDetailInfoId"
@handleDrawerClose="handleDrawerClose"></drawer-detail>
</d2-container>
</template>
<script>
import { getList, exportBaseList, baseGoodsUpOrDown, baseGoodsDelete, baseGoodsUpOrDownForChild } from '@api/commodity'
import { getParkStore } from '@api/editCustomer'
import { BaseData, brandMerchantList } from '@/common/constants.js'
import { exportJsonToExcel } from '@/common/Export2Excel.js'
import { mapActions } from 'vuex'
import _ from 'lodash'
import storeDetail from './storeDetail'
import drawerDetail from './drawerDetail'
export default {
name: 'commodity',
data() {
return {
userInfo: this.$store.state.d2admin.user.info,
searchForm: {
goodsName: '',
goodsType: '',
status: '',
reviewStatus: '',
brandMerchantCode: ''
},
showFormData: [{
label: '分类',
name: 'goodsType',
type: 'select',
optionList: [],
optionId: 'goodsType',
optionLabel: 'goodsTypeName',
optionsName: 'productTypeList'
}, {
label: '商品名称',
name: 'goodsName',
type: 'input',
isClear: true,
keyFn: this.keyDowmGetList
},
// {
// label: '品牌商',
// name: 'brandMerchantCode',
// type: 'select',
// optionList: [],
// optionId: 'confId',
// optionLabel: 'confValue',
// optionsName: 'brandList'
// },
{
label: '产品状态',
name: 'status',
type: 'select',
optionList: [],
optionId: 'confId',
optionLabel: 'confValue',
optionsName: 'statusList'
}, {
label: '审核状态',
name: 'reviewStatus',
type: 'select',
optionList: [],
optionId: 'confId',
optionLabel: 'confValue',
optionsName: 'reviewStatusList'
}, {
label: '园区店',
name: 'yqMerchantId',
type: 'select',
optionList: [],
optionId: 'merchantId',
optionLabel: 'merchantName',
optionsName: 'parkServiceList'
}, {
label: '创建时间',
name: 'createTime',
type: 'datePicker',
isClear: true,
pickerOptions: 'rangePickerOptions'
}],
getListApi: getList,
// 表格参数
tableParams: {
needUnique: true,
mutiSelectUniqueKey: 'uniqueVal',
btnId: new Date().getTime() + parseInt(Math.random() * 1000),
listName: 'list',
tableOption: {
width: '170'
},
tableColumns: [{
label: '序号',
prop: 'index'
}, {
label: '商品ID',
prop: 'commodityCode',
width: '110',
formatter: (cellValue) => {
return cellValue.commodityCode || cellValue.goodsCode
}
}, {
label: '缩略图',
prop: 'img',
addHtml: 'img'
}, {
label: '商品名称',
parentProp: 'goodsInfo',
prop: 'goodsName',
width: '120'
}, {
label: '分类',
parentProp: 'goodsInfo',
prop: 'goodsTypeName',
width: '100'
},
// {
// label: '品牌商',
// parentProp: 'goodsInfo',
// prop: 'brandMerchantName'
// }, {
// label: '属性',
// prop: 'attribute'
// },
{
label: '绑定商品数(件)',
prop: 'upgradeGoodsNum',
width: '118px'
}, {
label: '分配门店数(家)',
prop: 'merchantNum',
width: '118px'
}, {
label: '园区店名称',
prop: 'yqMerchantName',
formatter: (cellValue) => {
return cellValue.hasOwnProperty('yqMerchantNames') ? cellValue.yqMerchantNames : ''
},
width: '170px'
}, {
label: '创建时间',
prop: 'createDateStr',
width: '155px'
}, {
label: '审核时间',
prop: 'examineDate',
width: '155px',
formatter: (cellValue) => {
return cellValue.hasOwnProperty('reviewInfoList') ? (cellValue.reviewInfoList ? cellValue.reviewInfoList[0].reviewDate : '') : cellValue.reviewDate ? cellValue.reviewDate : ''
}
}, {
label: '审核状态',
prop: 'reviewStatus',
width: '100px',
formatter: (cellValue) => {
return {
0: '审核中',
1: '审核通过',
2: '驳回'
}[cellValue.reviewStatus]
}
}, {
label: '状态',
prop: 'status',
width: '100px',
className: (cellValue) => {
return {
0: 'ashSpot',
1: 'greenSpot',
2: 'yellowSpot'
}[cellValue.status]
},
formatter: (cellValue) => {
return {
0: '待上架',
1: '在售',
2: '部分在售'
}[cellValue.status]
}
}
]
},
// 查看门店
detailVisible: false,
showClose: false,
// 商品详情
drawerDetailVisible: false,
// 基本数据
baseData: {
parkServiceList: [],
productTypeList: [],
brandList: [],
statusList: [{
confId: 0,
confValue: '待上架'
}, {
confId: 1,
confValue: '在售'
}, {
confId: 2,
confValue: '部分在售'
}],
reviewStatusList: [{
confId: 0,
confValue: '审核中'
}, {
confId: 1,
confValue: '审核通过'
}, {
confId: 2,
confValue: '驳回'
}]
}
}
},
components: {
storeDetail,
drawerDetail
},
mounted() {
const $store = this.$store.getters['d2admin/auth/curBtns']
console.log($store)
this.baseData.brandList = _.cloneDeep(brandMerchantList)
var allOpt = { confId: '', confValue: '全部' }
this.baseData.brandList.unshift(allOpt)
this.baseData.statusList.unshift(allOpt)
this.baseData.reviewStatusList.unshift(allOpt)
this.getBaseData()
if (this.userInfo.beSuper) {
getParkStore({}).then(res => {
res.forEach(item => {
item.merchantId = item.merchantNo
})
this.baseData.parkServiceList = res
this.getOptionsList()
})
}
},
methods: {
...mapActions({
get: 'd2admin/base/get',
close: 'd2admin/page/close'
}),
async getBaseData() {
this.baseData.productTypeList = _.cloneDeep(await this.get(BaseData.productType))
this.baseData.productTypeList.unshift({
goodsType: '',
goodsTypeName: '全部'
})
this.showFormData.forEach((item, index) => {
if (item.type === 'select') {
this.$set(this.showFormData[index], 'optionList', this.baseData[item.optionsName])
}
})
},
beforeSearchFn() {
return new Promise(resolve => {
if (this.searchForm.createTime) {
this.searchForm.startDate = new Date(this.searchForm.createTime[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
this.searchForm.endDate = new Date(this.searchForm.createTime[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
} else {
this.searchForm.startDate = ''
this.searchForm.endDate = ''
}
resolve()
})
},
keyDowmGetList() {
this.$refs.commodityTable.refreshTable()
},
getOptionsList() {
this.showFormData.forEach((item, index) => {
if (item.type === 'select') {
if (this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this.showFormData[index].optionLabel] !== '全部') {
const temp = {}
temp[this.showFormData[index].optionId] = ''
temp[this.showFormData[index].optionLabel] = '全部'
this.baseData[item.optionsName].unshift(temp)
}
this.$set(this.showFormData[index], 'optionList', this.baseData[item.optionsName])
}
})
},
handleReset() {
this.searchForm = {
goodsName: '',
goodsType: '',
status: '',
reviewStatus: '',
brandMerchantCode: ''
}
},
handleAdd(form) {
this.close({ tagName: '/editCommodity' })
this.$router.push({
name: 'editCommodity',
params: {
addOrEdit: 'add',
form: form
}
})
},
handleExport() {
const tHeader = ['序号', '商品ID', '商品名称', '分类', '绑定商品数(件)', '分配门店数(家)', '园区店名称', '创建时间', '审核时间', '审核状态', '状态']
const fieldVal = ['index', 'goodsCode', 'goodsName', 'goodsTypeName', 'upgradeGoodsNum', 'merchantNum', 'yqMerchantNames', 'createdDate', 'reviewDate', 'reviewStatus', 'status']
exportBaseList(this.searchForm).then(res => {
require.ensure([], () => {
const data = this.formatJson(fieldVal, res)
exportJsonToExcel(tHeader, data, '基础商品列表')
})
})
},
formatJson(filterVal, jsonData) {
return jsonData.map(v => filterVal.map(j => v[j]))
},
handleEdit(row) {
this.close({ tagName: '/editCommodity' })
this.$router.push({
name: 'editCommodity',
params: {
addOrEdit: 'edit',
row: row
}
})
},
handleUpOrDown(row) {
// !row.status
// ? baseGoodsUpOrDown({ baseGoodsId: row.id, shelfStatus: 1 }).then(res => {
// this.notice.okTips()
// this.$refs.commodityTable.refreshTable()
// })
// : this.$confirm('是否确认将包含升级商品在内的商品组合整体下架?', '提示', {
// confirmButtonText: '确定',
// cancelButtonText: '取消',
// type: 'warning'
// }).then(() => {
// baseGoodsUpOrDown({ baseGoodsId: row.id, shelfStatus: 0 }).then(res => {
// this.notice.okTips()
// this.$refs.commodityTable.refreshTable()
// })
// }).catch(err => {
// console.log(err)
// })
var html = ''
var shelfStatus = 0
if (row.status == '0') {
html = '上架'
shelfStatus = 1
} else if (row.status == '1') {
html = '下架'
} else {
return
}
this.$confirm(html + '所有升级商品需要进入审核', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
baseGoodsUpOrDown({ baseGoodsId: row.id, shelfStatus: shelfStatus }).then(res => {
this.notice.okTips()
this.$refs.commodityTable.refreshTable()
})
}).catch(err => {
console.log(err)
})
},
// 父商品上下架操作按钮显示
showUpOrDownBT(row) {
var flag = false
if (row.status == '0' || row.status == '1') { // 父商品状态为待上架或在售时显示按钮
flag = true
} else if (row.status == '2') { // 父商品状态为部分在售时不显示按钮
flag = false
}
// if (row.upgradeGoodsList.every(o => o.status == '0')) {//子商品状态全部为待上架时父商品显示上架操作
// row.parentStatus = '0'
// flag = true
// } else if (row.upgradeGoodsList.every(o => o.status == '1')) {//子商品状态全部为在售状态时父商品显示下架操作
// row.parentStatus = '1'
// flag = true
// }
// console.log(row);
return flag
},
// 子商品单独上下架
handleUpOrDownForChild(row) {
console.log(row)
if (row.reviewStatus || row.reviewStatus == '0') {
if (row.reviewStatus == '0') { // 审核状态(0 审核中,1:审核通过,2:驳回)
this.$confirm('审核中的商品不可执行此操作!', '提示', {
confirmButtonText: '确定',
showCancelButton: false,
type: 'warning'
}).then(() => {
})
} else {
if (row.status || row.status == '0') {
var html = ''
var shelfStatus = ''// 上下架状态(0:待上架,1:在售)
if (row.status == '0') {
html = '上架'
shelfStatus = '1'
} else if (row.status == '1') {
html = '下架'
shelfStatus = '0'
}
this.$confirm(html + '该商品需要进入审核', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
baseGoodsUpOrDownForChild({ upgradedGoodsId: row.id, shelfStatus: shelfStatus }).then(res => {
this.notice.okTips()
this.$refs.commodityTable.refreshTable()
})
}).catch(err => {
console.log(err)
})
}
}
}
},
handleDetail(row) {
this.detailData = _.cloneDeep(row)
this.detailVisible = true
},
handleDetailClose() {
this.detailVisible = false
},
handleDelete(row) {
var html = '需下架在售商品才可以删除!'
// if (row.status == '1') {
// html = '需下架该商品后才可删除!'
// } else if (row.status == '2') {
// html = '审核中的商品不可执行此操作!'
// }
row.status
? this.$confirm(html, '提示', {
confirmButtonText: '确定',
showCancelButton: false,
type: 'warning'
}).then(() => {
})
: this.$confirm('删除后不可恢复,是否删除?', '提示', {
confirmButtonText: '确定',
// showCancelButton: false,
type: 'warning'
}).then(() => {
baseGoodsDelete({ baseGoodsId: row.id }).then(res => {
this.notice.okTips()
this.$refs.commodityTable.refreshTable()
})
}).catch(err => {
console.log(err)
})
},
handleCommodityDetail(row) {
this.drawerDetailVisible = true
this.commodityDetailInfoId = row.id
},
handleDrawerClose(isExamineOp) {
this.drawerDetailVisible = false
if (isExamineOp) {
this.$refs.commodityTable.refreshTable()
}
}
}
}
</script>
<style>
.commodity {
position: relative;
}
.commodity .pro-img {
width: 80px;
height: 80px;
}
.commodity .custom-input {
display: inline-block;
width: 220px;
}
.commodity p {
margin: 0;
}
</style>