index.vue
8.89 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
<!-- 商品分组 -->
<template>
<div style="padding: 0 10px;background-color:#f7f7f7;">
<div class="tab_show" v-if="commidyVisible==false && isVisible==false">
<!-- 搜索 -->
<div class="formSearch">
<el-form :inline="true" :model="formInline" class="demo-form-inline">
<el-form-item label="分组名称">
<el-input v-model="formInline.search" placeholder="请输入分组名称" />
</el-form-item>
</el-form>
<div>
<el-button style="background-color: #3F9B6A;color: #fff" @click="search">查询</el-button>
<el-button style="background-color: #3F9B6A;color: #fff" @click="addNewGroup">新增分组</el-button>
</div>
</div>
<!-- 表格 -->
<div class="tableBox">
<el-table
ref="multipleTable"
:data="tableData"
:header-cell-style="{fontSize: '14px',color:'#0009',fontWeight: 'normal',backgroundColor:'#F2F3F5'}"
tooltip-effect="dark"
>
<el-table-column label="分组名称" width="300">
<template slot-scope="scope">{{ scope.row.groupName }}</template>
</el-table-column>
<el-table-column label="分组描述" width="300">
<template slot-scope="scope">{{ scope.row.groupDescribe }}</template>
</el-table-column>
<el-table-column label="商品数量" width="150">
<template slot-scope="scope">{{ scope.row.number }}</template>
</el-table-column>
<el-table-column prop="updateTime" label="修改时间" width="220" />
<el-table-column label="操作" show-overflow-tooltip fixed="right">
<template slot-scope="scope">
<div class="btnList">
<div class="tableBtn greens" @click="edit(scope.row)">
编辑
</div>
<div class="tableBtn greens" @click="del(scope.row)">
删除
</div>
</div>
</template>
</el-table-column>
</el-table>
<div class="fenye">
<el-pagination
:current-page="formInline.page"
:page-sizes="[10, 20, 50, 100]"
:page-size="10"
background
layout="prev, pager, next,total"
:total="total"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
</div>
</div>
<!-- 新建分组弹框 -->
<div
v-if="isVisible"
>
<el-form :model="sizeForm">
<el-form-item label="分组封面" prop="fileLength" />
<div class="upload-wrap">
<el-upload
ref="upload"
:headers="headers"
:action="action"
:on-success="handleImageSuccess"
list-type="picture-card"
:limit="1"
:file-list="imgList"
>
<i class="el-icon-plus" />
</el-upload>
</div>
<el-form-item label="分组名称">
<el-input v-model="params.groupName" maxlength="20" />
</el-form-item>
<el-form-item size="large" class="btn-wrap">
<el-button type="primary" @click="onSubmit">确定</el-button>
<el-button @click="isVisible = false">取消</el-button>
</el-form-item>
</el-form>
</div>
<div
v-if="commidyVisible"
>
<CommGroup
:group-id="shopGroupId"
@cancel="commidyVisible = false"
@reload="search"
/>
</div>
</div>
</template>
<script>
import CommGroup from '@/views/commodity/commodityList/commodityGroup.vue'
import {
commodityListGetAll,
commodityListDelete,
commodityListUpdate,
commodityListAdd
} from '@/api/commodity'
import { getBtnList, getToken } from '@/utils/auth'
import { uploadUrl } from '@/utils/request'
export default {
components: {
CommGroup
},
data() {
// 这里存放数据
return {
btnList: '',
activeName: 'first',
formInline: {
search: '',
page: 1,
pageSize: 10,
},
params: {
groupImage: '',
groupName: '',
},
total: 1,
tableData: [],
isVisible: false,
type: 'add',
sizeForm: {},
imgList: [],
commidyVisible: false,
shopGroupId: 0,
action: uploadUrl,
headers: {
'Authorization-business': getToken()
},
}
},
// 监听属性 类似于data概念
computed: {
title() {
return this.type === 'add' ? '新建分组' : '查看分组'
}
},
// 监控data中的数据变化
watch: {},
// 生命周期 - 创建完成(可以访问当前this实例)
created() {},
// 生命周期 - 挂载完成(可以访问DOM元素)
mounted() {
this.getAll(this.formInline)
this.btnList = getBtnList()
},
// 方法集合
methods: {
btnClick(id) {
console.log(id)
if (id.permissionName === '新增分组') {
this.add()
}
},
handleSizeChange(val) {
this.formInline.pageSize = val
this.getAll(this.formInline)
},
handleCurrentChange(val) {
this.formInline.page = val
this.getAll(this.formInline)
},
handleImageSuccess(response) {
const url = response.data.url
this.params.groupImage = url
},
// 查询
search() {
this.total = 1
this.formInline.page = 1
this.getAll(this.formInline)
},
// 新建分组
add() {
this.type = 'add'
this.isVisible = true
this.params = {
groupImage: '',
groupName: ''
}
this.$refs.upload.clearFiles()
},
// 编辑分组
edit(row) {
this.commidyVisible = true
this.shopGroupId = row.shopGroupId
},
async onSubmit() {
if (this.type === 'add') {
this.addGroup()
} else {
this.updateGroup()
}
},
async addGroup() {
if (this.params.groupName === '') {
this.$message.error('请输入分组名称')
return
}
const res = await commodityListAdd(this.params)
if (res.code === '') {
this.isVisible = false
this.$message({
message: '新增成功',
type: 'success'
})
this.getAll(this.formInline)
}
},
async updateGroup() {
const res = await commodityListUpdate(this.params)
if (res.code === '') {
this.isVisible = false
this.$message({
message: '修改成功',
type: 'success'
})
this.getAll(this.formInline)
}
},
// 删除分组
del(row) {
this.$confirm('选中数据将被永久删除, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
commodityListDelete({ shopGroupId: row.shopGroupId }).then(res => {
if (res.code === '') {
this.$message({
type: 'success',
message: '删除成功!'
})
this.getAll(this.formInline)
}
})
})
.catch(() => {})
},
// 初始化查询所有数据
async getAll(formInline) {
const res = await commodityListGetAll(formInline)
this.total = res.data.total
this.tableData = res.data.list
},
// 1.4
// 新增分组
addNewGroup() {
this.shopGroupId = 0
this.commidyVisible = true
}
}
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
@import url("../../../styles/elDialog.scss");
.tab_show {
padding: 0 20px 20px 20px;
background-color:#fff;
}
.fenye {
margin-top: 20px;
display: flex;
justify-content: flex-end;
position: relative;
}
::v-deep .el-pagination__total {
position: absolute;
left: 10px;
}
.formSearch {
display: flex;
width: 100%;
font-size: 14px;
justify-content: space-between;
}
.group-dialog {
.btn-wrap {
text-align: center;
}
.upload-wrap {
width: 100%;
display: flex;
align-items: flex-end;
.image-wrap {
width: 120px;
height: 120px;
line-height: 120px;
margin-right: 15px;
margin-bottom: 15px;
text-align: center;
border: 1px dashed #d9d9d9;
img {
width: 100%;
height: 100%;
}
}
}
}
::v-deep .bian_css{
margin:auto;
max-height:840px;
overflow-y: auto;
.el-dialog__body {
padding: 0px;
background-color: #fff;
}
.el-dialog__header {
background-color: #fff;
padding:10px 20px 10px 20px;
border-bottom: 1px solid #EFEFEF;
}
.el-dialog__title {
font-size: 14px;
color: #000000e6;
}
.el-date-table td.available:hover{
background-color:#3F9B6A;
}
.el-date-table td.start-date span{
background-color:#3F9B6A;
}
}
</style>