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
<template>
<div class="classificationOfDishes">
<a-button style="margin-bottom: 20px" type="primary" @click="showModal(1)">添加分类</a-button>
<a-table :columns="columns" :dataSource="dataSource" rowKey="productCategoryId" :pagination="pagination">
<span slot="productCategoryName"></span>
<span slot="sort"></span>
<span slot="isDisplay" slot-scope="isDisplay">
<a-badge v-if="isDisplay === 'DISPLAY'" status="success" text="已显示" />
<a-badge v-else-if="isDisplay === 'HIDDEN'" status="error" text="已隐藏" />
</span>
<span slot="action" slot-scope="text, record, index">
<a style="margin-right: 8px" href="javascript:;" @click="showModal(2, record)">修改</a>
<a href="javascript:;" @click="showConfirm(record, index)">{{record.isDisplay === 'DISPLAY' ? '隐藏' : '显示'}}</a>
</span>
</a-table>
<a-modal
title="增加分类"
:visible="visible"
@ok="saveProductCategory"
:confirmLoading="confirmLoading"
@cancel="handleCancel"
>
<div class="item">
<label>分类名称:</label><a-input v-model="productCategoryName" placeholder="请输入分类名称"/>
</div>
<div class="item">
<label>排序值:</label><a-input v-model="sort" placeholder="排序值为正整数"/>
</div>
</a-modal>
</div>
</template>
<script>
import { $http } from './../../../api/axios.js'
export default {
name: 'classificationOfDishes',
data () {
return {
columns: [{
title: '菜品类别',
dataIndex: 'productCategoryName'
}, {
title: '排序值',
dataIndex: 'sort'
}, {
title: '状态',
dataIndex: 'isDisplay',
scopedSlots: { customRender: 'isDisplay' }
}, {
title: '操作',
key: 'action',
scopedSlots: { customRender: 'action' }
}],
productCategoryName: '',
sort: '',
dataSource: [],
visible: false,
modelType: 1,
modelSource: '',
confirmLoading: false,
pagination: {
current: 1,
defaultCurrent: 1,
defaultPageSize: 1000,
hideOnSinglePage: true,
total: 0
}
}
},
created: function () {
this.getProductCategoryList()
},
methods: {
getProductCategoryList () {
$http.post(`/mingpay/v1/isv/product/list_product_category`).then((res) => {
if (res.data.resultCode === 0) {
this.dataSource = res.data.data
}
})
},
changeItem () {
this.confirmLoading = true
let updateProductCategoryData = {
productCategoryId: this.modelSource.productCategoryId,
productCategoryName: this.productCategoryName,
sort: this.sort
}
$http.post(`/mingpay/v1/isv/product/update_product_category`, updateProductCategoryData).then((res) => {
if (res.data.resultCode === 0) {
this.visible = false
this.confirmLoading = false
this.sort = ''
this.productCategoryName = ''
this.getProductCategoryList()
this.$message.success('操作成功')
} else {
this.$message.error('操作失败')
}
}).catch(() => {
this.$message.error('操作失败')
this.confirmLoading = false
})
},
showConfirm (record, index) {
let that = this
let title
let content
if (record.isDisplay === 'DISPLAY') {
title = '确认要隐藏该菜品分类吗?'
content = '隐藏后该分类下的所有菜品设备端都不可见'
} else {
title = '确认显示该分类吗?'
content = '显示后该分类下菜品可正常使用'
}
this.$confirm({
title: title,
content: content,
onOk () {
that.changeData(record, index)
},
onCancel () {}
})
},
changeData (record, index) {
let saveProductCategoryData = {
productCategoryId: this.categoryName,
sort: this.sort
}
if (record.isDisplay === 'DISPLAY') {
saveProductCategoryData = {
productCategoryId: record.productCategoryId,
isDisplay: 'HIDDEN'
}
} else {
saveProductCategoryData = {
productCategoryId: record.productCategoryId,
isDisplay: 'DISPLAY'
}
}
$http.post(`/mingpay/v1/isv/product/update_product_category_status`, saveProductCategoryData).then((res) => {
if (res.data.resultCode === 0) {
this.sort = ''
this.productCategoryName = ''
this.getProductCategoryList()
this.$message.success('操作成功')
} else {
this.$message.error('操作失败')
}
}).catch(() => {
this.$message.error('操作失败')
this.confirmLoading = false
})
},
showModal (type, data) {
this.modelSource = data
this.modelType = type
this.visible = true
if (type === 2) {
this.productCategoryName = data.productCategoryName
this.sort = data.sort
}
},
// 创建菜单
saveProductCategory () {
let that = this
let reg = '^[0-9]*$'
if (!/^[0-9]*$/.test(this.sort)) {
this.$message.error('排序值为正整数')
return false
}
if (this.productCategoryName === '') {
this.$message.error('分类名称不能为空')
} else if (this.sort === '') {
this.$message.error('排序值不能为空')
} else {
if (this.modelType === 2) {
this.changeItem()
return
}
this.confirmLoading = true
let saveProductCategoryData = {
productCategoryName: this.productCategoryName,
sort: parseInt(this.sort)
}
$http.post(`/mingpay/v1/isv/product/save_product_category`, saveProductCategoryData).then((res) => {
if (res.data.resultCode === 0) {
this.visible = false
this.confirmLoading = false
this.sort = ''
this.productCategoryName = ''
this.getProductCategoryList()
this.$message.success('操作成功')
} else {
this.$message.error('操作失败')
}
}).catch(() => {
this.$message.error('操作失败')
this.confirmLoading = false
})
}
},
handleCancel (e) {
this.visible = false
this.sort = ''
this.productCategoryName = ''
}
}
}
</script>
<style lang="less" scoped>
.item{
width: 100%;
display: flex;
align-items: center;
justify-content: center;
margin: 10px;
}
.item>label{
width: 75px;
text-align: right;
margin-right: 8px;
}
.item>input{
width: 220px;
}
</style>