index.vue
14.1 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
<!-- 商品管理-集团 -->
<template>
<div class="marketing pro-group">
<div class="m-b-20">
<GLButton :size="size" type="primary" fn="新建商品" class="el-icon-plus" @click="handleEdit(1)">新建商品</GLButton>
</div>
<div class="container">
<GLCombiForm ref="showSearch" :rowNumber="1" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
<!-- 表格区域 开始 -->
<GLTable ref="proGroupRef" class="table-img" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
<div slot="goodsImage" class="table-image" slot-scope="scope">
<el-popover placement="top" width="160" trigger="hover" popper-class="table-popover-block">
<img class="table-popover-img" :src="scope.scope.goodsImage" />
<img class="img-60 pointer" slot="reference" :src="scope.scope.goodsImage" />
</el-popover>
</div>
<div class="table-btns" slot="auth-button" slot-scope="scope">
<GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
</div>
</GLTable>
<!-- 表格区域 end -->
</div>
<!-- 下架 -->
<GLDialog title="下架" mode="small" :visible.sync="isDownVisible" @onOk="handleDownConfirm" @onCancel="handleDownClose">
<el-form class="small-content" ref="downRef" label-width="100px" :rules="downRules" :model="downForm">
<el-form-item label="下架备注" prop="offReason">
<el-input :size="size" v-model="downForm.offReason" placeholder="请输入下架备注" maxlength="30"></el-input>
</el-form-item>
</el-form>
</GLDialog>
<!-- 分享 -->
<share-dialog :isShareVisible="isShareVisible" :shareForm="shareForm" @handleShareClose="handleShareClose"></share-dialog>
</div>
</template>
<script>
import * as dayjs from 'dayjs'
import shareDialog from './components/shareDialog'
import url from '@/assets/empty.png'
export default {
name: 'productGroup',
data() {
return {
size: 'small',
url: url,
// 下架
isDownVisible: false,
downForm: {
id: '',
offReason: '',
goodsStatus: 0
},
downRules: {
offReason: [{ required: true, message: '请输入下架备注', trigger: 'change' }]
},
// 分享
isShareVisible: false,
shareForm: {},
// 表格
searchForm: {
goodsName: '',
createDate: [],
goodsStatus: ''
},
tableSearchForm: {},
// 搜索
searchFormData: [
{
label: '商品名称',
name: 'goodsName',
type: 'input',
maxlength: 20
},
{
label: '创建日期',
name: 'createDate',
type: 'datePicker',
isClear: true,
pickerOptions: 'beforeRangePickerOptions'
},
{
label: '商品状态',
name: 'goodsStatus',
type: 'select',
optionList: [],
optionId: 'confId',
optionLabel: 'confName',
optionsName: 'goodsStatusList'
}
],
// 表格按钮
tableButtonList: [
{
type: 'el-button',
name: row => {
return row.goodsStatus ? '下架' : '上架'
},
attrs: {
type: 'text'
},
listeners: {
click: this.handleUpOrDown
}
},
{
type: 'GLButton',
name: '编辑',
attrs: {
type: 'text',
fn: '编辑'
},
condition: row => {
return !row.goodsStatus
},
listeners: {
click: row => this.handleEdit(2, row)
}
},
{
type: 'GLButton',
name: '查看',
attrs: {
type: 'text',
fn: '查看'
},
condition: row => {
return row.goodsStatus
},
listeners: {
click: row => this.handleEdit(3, row)
}
},
{
type: 'el-button',
name: '置顶',
attrs: {
type: 'text'
},
listeners: {
click: this.handleTop
}
},
{
type: 'GLButton',
name: '删除',
attrs: {
type: 'text',
fn: '删除'
},
condition: row => {
return !row.goodsStatus
},
listeners: {
click: this.del
}
},
{
type: 'el-button',
name: '分享',
attrs: {
type: 'text'
},
listeners: {
click: this.handleShare
}
}
],
// 表格
getListApi: this.$apis.proManage.getListApi,
tableParams: {
listName: 'list',
tableOption: true,
tableColumns: [
{
label: '商品名称',
prop: 'goodsName',
width: 220,
line: 2
},
{
label: '缩略图',
prop: 'goodsImage',
addHtml: 'goodsImage'
},
{
label: '浏览量(次)',
name: 'goodsStatistics',
width: '180',
formatter: cellValue => {
return cellValue.goodsStatistics ? cellValue.goodsStatistics.viewAmount || '0' : '0'
}
},
{
label: '销量',
name: 'goodsStatistics',
formatter: cellValue => {
return cellValue.goodsStatistics ? cellValue.goodsStatistics.saleAmount || '0' : '0'
}
},
{
label: '零售价(元)',
name: 'retailPrice',
width: '180',
formatter: cellValue => {
return cellValue.retailPrice
}
},
{
label: '库存',
name: 'goodsStock',
formatter: cellValue => {
return cellValue.goodsStock || '0'
}
},
{
label: '创建日期',
prop: 'createdDate',
width: '180',
formatter: cellValue => {
return dayjs(cellValue.createdDate).format('YYYY-MM-DD HH:mm:ss')
}
},
{
label: '商品状态',
name: 'goodsStatus',
formatter: cellValue => {
return this.baseData.goodsStatusList.find(item => item.confId == cellValue.goodsStatus).confName
}
}
]
},
pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
baseData: {
goodsStatusList: [
{
confId: '0',
confName: '已下架'
},
{
confId: '1',
confName: '已上架'
}
]
}
}
},
components: {
shareDialog
},
mounted() {
this.getOptionsList('searchFormData')
},
methods: {
getParams() {
var params = JSON.parse(JSON.stringify(this.searchForm))
if (this.searchForm.createDate.length) {
params.startTime = new Date(this.searchForm.createDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
params.endTime = new Date(this.searchForm.createDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
}
delete params.createDate
return params
},
beforeSearchFn() {
return new Promise(resolve => {
this.tableSearchForm = this.getParams()
delete this.tableSearchForm.createDate
resolve()
})
},
secondConfirm(title, txt, apiModule, apiName, apiParams, fn) {
this.$confirm(txt, title, {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
callback: action => {
if (action == 'confirm') {
this.$apis[apiModule][apiName](apiParams).then(res => {
this.$message({
message: res.code == '0' ? '操作成功' : res.message,
type: res.code == '0' ? 'success' : 'error'
})
if (res.code == '0') {
fn && fn()
this.handleSearch()
}
})
}
}
})
},
// addOrEdit:1-新增;2-编辑;3-查看
// groupOrStore:1-集团;2-门店
handleEdit(addOrEdit, row) {
// addOrEdit == 1 ? this.$router.push('/productGroup/editProduct/' + addOrEdit + '/' + 1) : this.$router.push('/productGroup/editProduct/' + addOrEdit + '/' + 1 + '/' + row.id)
var titleObj = {
1: '新建商品',
2: '编辑商品',
3: '查看商品'
}
var params = {
addOrEdit: addOrEdit,
groupOrStore: 1,
$title: encodeURI(titleObj[addOrEdit])
}
addOrEdit != 1 && (params.id = row.id)
this.$router.push({
path: '/productGroup/editProduct',
query: params
})
},
handleUpOrDown(row) {
if (row.goodsStatus) {
this.downForm.id = row.id
this.dwonVisibleChange()
return true
}
this.secondConfirm('上架', '是否确认上架该商品?', 'proManage', 'updateStatusProApi', { id: row.id, goodsStatus: 1 })
},
dwonVisibleChange() {
this.$refs.downRef && this.$refs.downRef.clearValidate()
this.isDownVisible = !this.isDownVisible
},
handleDownClose() {
this.dwonVisibleChange()
this.downForm = {
id: '',
offReason: '',
goodsStatus: 0
}
},
handleDownConfirm() {
this.$refs.downRef.validate(valid => {
if (valid) {
this.$apis.proManage.updateStatusProApi(this.downForm).then(res => {
this.$message({
message: res.code == '0' ? '操作成功' : res.message,
type: res.code == '0' ? 'success' : 'error'
})
if (res.code == '0') {
this.handleDownClose()
this.handleSearch()
}
})
}
})
},
// 置顶
handleTop(row) {
this.secondConfirm('置顶', '是否确认置顶该商品?', 'proManage', 'topProApi', { id: row.id })
},
// 删除
del(row) {
this.secondConfirm('删除', '确定删除此商品?', 'proManage', 'deleteGoodsApi', { id: row.id })
},
handleShare(row) {
this.$apis.proManage.getProShareApi({ id: row.id }).then(res => {
this.shareForm = res
this.handleShareClose()
})
},
handleShareClose() {
this.isShareVisible = !this.isShareVisible
},
getOptionsList(formName, hasAll = true, refreshSigle) {
if (refreshSigle) {
var item = this[formName].find(k => k.name == refreshSigle)
var index = this[formName].findIndex(k => k.name == refreshSigle)
this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
const temp = {}
temp[this[formName][index].optionId] = ''
temp[this[formName][index].optionLabel] = '全部'
this[formName][index].optionList.unshift(temp)
}
} else {
this[formName].forEach((item, index) => {
if (item.type === 'select' && this.baseData[item.optionsName].length) {
this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
const temp = {}
temp[this[formName][index].optionId] = ''
temp[this[formName][index].optionLabel] = '全部'
this[formName][index].optionList.unshift(temp)
}
}
})
}
},
setTableFinishFun() {
//接收到的数据为空
if (!this.$refs.proGroupRef.data.length) {
this.$refs.proGroupRef.setTableHeightFun()
} else {
this.$refs.proGroupRef.tableHeightValues = ''
this.$refs.proGroupRef.data.forEach(item => {
item.saleAmount = item.goodsStatistics.saleAmount
if (item.specificationDetailList.length > 1) {
let retailPriceList = JSON.parse(JSON.stringify(item.specificationDetailList))
retailPriceList.sort((a, b) => {
return a.retailPrice - b.retailPrice
})
let stockeList = JSON.parse(JSON.stringify(item.specificationDetailList))
stockeList.sort((a, b) => {
return a.stock - b.stock
})
let minRatilPrice = retailPriceList[0].retailPrice / 100
let maxRatilPrice = retailPriceList[retailPriceList.length - 1].retailPrice / 100
let minStock = stockeList[0].stock
let maxStock = stockeList[stockeList.length - 1].stock
item.retailPrice = minRatilPrice == maxRatilPrice ? minRatilPrice.toFixed(2) : minRatilPrice.toFixed(2) + '-' + maxRatilPrice.toFixed(2)
item.minRatilPrice = minRatilPrice.toFixed(2)
item.goodsStock = minStock == maxStock ? minStock : minStock + '-' + maxStock
} else if (item.specificationDetailList.length == 1) {
item.retailPrice = (item.specificationDetailList[0].retailPrice / 100).toFixed(2)
item.minRatilPrice = item.retailPrice
item.goodsStock = item.specificationDetailList[0].stock
} else {
item.retailPrice = (item.retailPrice / 100).toFixed(2)
item.minRatilPrice = item.retailPrice
}
})
}
},
handleSearch() {
this.$refs.proGroupRef.refreshTable()
},
handleReset() {
this.searchForm = {
goodsName: '',
createDate: [],
goodsStatus: ''
}
this.handleSearch()
}
}
}
</script>
<style scoped></style>