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
<template>
<div class="app-container">
<el-card class="box-card">
<div class="clearfix">
<span class="left-text">商品分组</span>
<el-button
type="primary"
size="mini"
icon="el-icon-plus"
style="float: right"
@click="handleAdd()"
>新增</el-button
>
</div>
<!-- 分组表格 -->
<el-table :data="tableData" :height="tableHeight" style="width: 100%">
<el-table-column prop="id" label="分组ID" width="180">
</el-table-column>
<el-table-column prop="name" label="分组名称" width="180">
</el-table-column>
<el-table-column prop="goods_num" label="商品数量"> </el-table-column>
<el-table-column prop="created_time" label="创建时间">
<template slot-scope="scope">
<div>
{{ timeFormatter(scope.row.created_time) }}
</div>
</template>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<div v-if="!scope.row.seller_id == 0">
<el-button
size="mini"
type="text"
@click="handleUpdate(scope.row)"
>编辑
</el-button>
<el-button
size="mini"
type="text"
@click="handleDelete(scope.row)"
style="color: red"
>删除
</el-button>
</div>
<div v-if="scope.row.seller_id == 0">--</div>
<!-- <el-divider direction="vertical"></el-divider> -->
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<!-- <div class="footer_pagination">
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[20, 40, 60, 80, 100]"
:page-size="pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
>
</el-pagination>
</div> -->
</el-card>
<!-- 新增或修改弹窗 -->
<el-dialog
:title="title"
:visible.sync="dialogVisible"
:append-to-body="true"
:destroy-on-close="true"
:close-on-click-modal="false"
center
@close="clearPayform"
width="40%"
>
<div style="width: 100%; margin: 50px auto 200px">
<el-form
:model="formInline"
ref="formInline"
:rules="formInlines"
label-width="150px"
size="mini"
>
<el-form-item label="分组名称:" prop="name">
<el-input
v-model="formInline.name"
style="width: 80%"
placeholder="请输入商品分组名称"
></el-input>
</el-form-item>
</el-form>
</div>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false" size="mini">取 消</el-button>
<el-button
type="primary"
size="mini"
@click="closeDialogVisible('formInline')"
>确 定</el-button
>
</span>
</el-dialog>
<!-- 删除弹窗 -->
<el-dialog
title="提示"
:visible.sync="dialogDelete"
center
:close-on-click-modal="false"
width="30%"
>
<div style="text-align: center; margin: 0 auto">
<p>
确定要删除该分组吗?删除后,该分组的商品将分配到系统默认分组里面。商品的相关设置及状态保持不变。
</p>
</div>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogDelete = false" size="mini">取 消</el-button>
<el-button type="primary" size="mini" @click="closeDialogDelete()"
>确 定</el-button
>
</span>
</el-dialog>
</div>
</template>
<script>
import {
groupList,
addGroup,
updateGroup,
GroupInfo,
deleteGroup,
} from "@/api/module/settings";
import { dateFormat } from "@/utils";
export default {
name: "commodityGroup",
data() {
return {
fullHeight: 0,
tableHeight: 0,
code: 0,
tableData: [],
//新增和修改提示框分组名称
formInline: {
name: "",
},
//表单验证
formInlines: {
name: [
{ required: true, message: "分组名称不能为空", trigger: "blur" },
],
},
title: "",
//新增修改提示框
dialogVisible: false,
//删除提示框
dialogDelete: false,
};
},
created() {
this.$nextTick(() => {
this.fullHeight =
document.getElementsByClassName("box-card")[0].clientHeight;
});
this.getGroupList();
},
watch: {
fullHeight(val) {
let formHeight =
document.getElementsByClassName("clearfix")[0].clientHeight;
this.tableHeight = val - formHeight - 100;
},
},
methods: {
//新增分组
handleAdd() {
this.dialogVisible = true;
this.title = "新增分组";
},
//删除分组
handleDelete(val) {
this.code = val.id;
this.dialogDelete = true;
},
//编辑分组
handleUpdate(val) {
this.title = "编辑分组";
this.code = val.id;
let obj = {
id: val.id,
};
GroupInfo(obj).then((res) => {
if (res.code == 1) {
this.formInline.name = res.data.name;
this.dialogVisible = true;
}
});
},
//新增或修改弹框确定回调
closeDialogVisible(formInline) {
this.$refs[formInline].validate((valid) => {
if (valid) {
let obj = {
name: this.formInline.name,
};
if (this.title == "新增分组") {
addGroup(obj).then((res) => {
if (res.code == 1) {
this.$message({
type: "success",
message: "添加成功",
});
this.getGroupList();
} else if (res.code == 0) {
this.$message({
type: "error",
message: res.message,
});
}
});
}
if (this.title == "编辑分组") {
obj["id"] = this.code;
updateGroup(obj).then((res) => {
if (res.code == 1) {
this.$message({
type: "success",
message: "编辑成功",
});
this.getGroupList();
} else {
this.$message({
message: res.message,
type: "error",
});
}
});
}
this.dialogVisible = false;
}
});
},
//删除提示框
closeDialogDelete() {
let obj = {
id: this.code,
};
deleteGroup(obj).then((res) => {
if (res.code == 1) {
this.$message({
type: "success",
message: "删除成功",
});
this.getGroupList();
} else {
this.$message({
message: res.message,
type: "error",
});
}
});
this.dialogDelete = false;
},
/** 一般时间 格式化 */
timeFormatter(time) {
if (time) {
return dateFormat(time * 1000, "Y-m-d H:i:s");
} else {
return "--";
}
},
getGroupList() {
groupList().then((res) => {
if (res.code == 1) {
this.tableData = res.data.list;
} else {
this.$message({
message: res.message,
type: "error",
});
}
});
},
clearPayform() {
this.formInline.name = "";
},
},
};
</script>
<style lang="scss" scoped type="text/stylus">
.app-container {
overflow: auto;
}
.clearfix {
margin: 10px 0 15px 0;
}
.left-text {
font-size: 16px;
font-family: Microsoft YaHei;
font-weight: bold;
color: #333333;
line-height: 28px;
}
/* 分页 */
.footer_pagination {
text-align: center;
margin-top: 15px;
}
</style>