goodsMixin.js
5.33 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
export default {
data() {
return {
currentIndex:0,
goodsCategoryId: '',
inputValue: '',
tagInputValue: '',
inputVisible: false,
tags: [],
goodsTableData: [],
goodsTableParams: {
// rowStyle: ({ row, rowIndex }) => {
// return row.status == 0 ? {opacity:0.5} : ''
// },
tableColumns: [{
label: '权益名称',
prop: 'equityName',
minWidth: '200',
},
{
label: '权益描述',
prop: 'equityDesc',
minWidth: '200',
},
{
// label: '权益图标\n(80*80,支持JPG、PNG、GIF)',
minWidth: '200',
prop:'goodsImage',
addHtml: 'goodsImage',
renderHeader: h => {
return h('div', { class: 'table-header specHeader' }, [
h('span', '权益图标'),
h('table-tooltip', {
props: { content: '80*80,支持JPG、PNG、GIF' }
})
])
},
},
{
label: '品牌名称',
prop: 'brandName',
minWidth: '200',
},
{
label: '产品提供方',
// prop: 'supplier',
minWidth: '200',
formatter: (cell) => {
return '海威'
},
},
{
label: '首页展示',
prop: 'mainPageFlag',
minWidth: '200',
addHtml: 'mainPageFlag'
},
{
label: '操作',
width: 155,
fixed: 'right',
addHtml: 'auth-button'
}
]
},
showMoreTags:false,
moreTags:[]
}
},
mounted() {
},
methods: {
/**获取商品分类列表 */
getCategoryList() {
this.$apis.goodsEquityManageApi.getCategoryList().then(({ data }) => {
let { goodsCategoryId } = this
let { list } = data
let id = ''
if (goodsCategoryId) {
list.map(e => {
e.active = false
if (e.id == goodsCategoryId) {
e.active = true
id = goodsCategoryId
}
})
} else {
list[0].active = true
id = list[0].id
}
this.tags = list || []
this.getGoodsList(id)
this.goodsCategoryId = id
// if(this.tags.length>5){
// this.moreTags = this.tags.slice(5)
// this.tags = this.tags.slice(0,5)
// this.showMoreTags = true
// }
})
},
/**商品权益列表 */
getGoodsList(goodsCategoryId, callBack) {
this.$apis.goodsEquityManageApi.getGoodsList({ goodsCategoryId,pageSize: this.$refs.goodsTable.page.pageSize, pageNum: this.$refs.goodsTable.page.pageNum }).then(({ data }) => {
if (!callBack) {
this.goodsTableData = data.list || []
this.tableTotal = data.total
} else {
return callBack(data.list)
}
})
},
/**切换分类 */
changeGoodsCategory({ id, index }) {
this.tags.map(e => e.active = false)
this.tags[index].active = true
this.getGoodsList(id)
this.goodsCategoryId = id
this.currentIndex = index
// if(this.tags.length>5){
// this.moreTags = this.tags.slice(5)
// this.tags = this.tags.slice(0,5)
// this.showMoreTags = true
// }
if(this.$refs.mydrown){
this.$refs.mydrown.hide()
}
},
showInput(index, val) {
this.inputValue = val
this.$refs[`tag-input-${index}`][0].$el.classList.add('input-tag-show')
this.$refs[`tag-input-${index}`][0].$refs.input.focus()
},
changeTagName({ id, index }) {
let goodsCategory = this.inputValue
if (!goodsCategory) {
this.$refs[`tag-input-${index}`][0].$el.classList.remove('input-tag-show')
return
}
this.$apis.goodsEquityManageApi.categoryUpdate({ id, goodsCategory }).then(({ code, message }) => {
if (code == 0) {
this.getCategoryList()
} else {
this.$message.error(message)
}
this.$refs[`tag-input-${index}`][0].$el.classList.remove('input-tag-show')
})
},
/**删除分类 */
categoryDelete(id) {
this.getGoodsList(id, res => {
if (res.length) {
this.$message.error('请先删除该分类下的商品权益')
} else {
this.$apis.goodsEquityManageApi.categoryDelete({ id }).then(_res => {
if (_res.code == 0) {
this.getCategoryList()
this.changeGoodsCategory({id:this.tags[0].id,index:0})
} else {
this.$message.error(_res.message)
}
})
}
})
},
showAddInput() {
this.inputVisible = true;
this.$nextTick(_ => {
this.$refs.saveTagInput.$refs.input.focus()
})
},
handleInputConfirm() {
let inputValue = this.tagInputValue
if (inputValue) {
this.$apis.goodsEquityManageApi.createCategory({ goodsCategory: inputValue }).then(({ code, message }) => {
if (code == 0) {
this.getCategoryList()
} else {
this.$message.error(message)
}
})
}
this.inputVisible = false
this.tagInputValue = ''
}
}
}