certificate.vue
7.53 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
<template>
<div class="certificate-wrap" v-loading="loading">
<div class="gl-form-page">
<el-form ref="configForm" label-width="154px" :model="addForm" :rules="addRules">
<div class="config-form-item el-form-item">
<label class="is-require">选择券:</label>
<el-button size="small" icon="el-icon-plus" @click="handleAdd">选择券</el-button>
</div>
</el-form>
</div>
<template v-if="tableData.length > 0">
<div class="merchant-wrap">
<el-table :data="tableData" border style="width: 100%" :height="tableData.length > 15 ? 600 : auto">
<el-table-column type="index" width="50"></el-table-column>
<el-table-column prop="couponName" label="券名称" width="200"></el-table-column>
<el-table-column prop="discountType" label="券类型" width="100">
<template slot-scope="scope">
<span>{{ numToCouponText[scope.row.discountType] }}</span>
</template>
</el-table-column>
<el-table-column prop="couponAnticipatedCost" label="预估成本/元"></el-table-column>
<el-table-column prop="effectiveType" label="有效期" width="100">
<template slot-scope="scope">
<span>{{ toLabelText(scope.row) }}</span>
</template>
</el-table-column>
<el-table-column prop="residueAmount" label="剩余库存" width="100"></el-table-column>
</el-table>
</div>
</template>
<select-gift-dialog v-if="isSelectGiftVisible" :isSelectGiftVisible="isSelectGiftVisible" :selectedGiftList="selectedGiftList" @handleGiftConfirm="handleGiftConfirm" @handleGiftClose="handleGiftClose"></select-gift-dialog>
</div>
</template>
<script>
import url from '@/assets/empty.png'
import selectGiftDialog from './selectGiftDialog.vue'
export default {
data() {
return {
url: url,
isSelectGiftVisible: false,
selectedGiftList: [],
loading: false,
searchForm: {
subMerchantId: '',
subMerchantName: '',
select: '1',
selectInput: ''
},
openSubscribeList: [],
tableData: [],
selectedList: [],
orderShow: ['service', 'cash', 'discount', 'exchange'],
numToCoupon: {
2: 'discount',
3: 'cash',
4: 'exchange',
7: 'service'
},
numToCouponText: {
2: '折扣券',
3: '代金券',
4: '兑换券',
7: '门店服务'
},
editForm: {
couponList: []
},
couponObj: {
// 折扣券
discount: {
label: '折扣券',
discountType: 2,
list: []
},
// 代金券
cash: {
label: '代金券',
discountType: 3,
list: []
},
// 兑换券
exchange: {
label: '兑换券',
discountType: 4,
list: []
},
// 会员服务
service: {
label: '会员服务',
discountType: 7,
list: []
}
}
}
},
components: {
selectGiftDialog
},
props: {
channelId: {
type: String,
default: ''
},
topicId: {
type: String,
default: ''
}
},
// components: {
// relateStoreDialog
// },
created() {
this.getCouponconfig()
},
methods: {
toLabelText(row) {
switch (row.effectiveType) {
case 3:
return '永久有效'
case 2:
return row.effectiveStartTime ? row.effectiveStartTime.split(' ')[0] + '-' + row.effectiveEndTime.split(' ')[0] : ''
case 1:
return row.effectiveDays + '天'
}
},
getCouponconfig() {
this.$apis.store.getCouponconfig({ topicId: this.topicId }).then(res => {
if (res.code == 0) {
res.data.coupons.forEach(item => {
item.couponAnticipatedCost = (item.couponAnticipatedCost / 100).toFixed(2)
})
this.tableData = res.data.coupons
}
})
},
handleAdd() {
// console.log(this.couponObj, '')
this.selectedGiftList = JSON.parse(JSON.stringify(this.couponObj))
this.handleGiftClose()
},
handleGiftClose() {
this.isSelectGiftVisible = !this.isSelectGiftVisible
},
handleGiftConfirm(selectedData, type) {
// console.log(selectedData, 'selectedData')
if (type != 'group') {
this.handleGiftClose()
}
this.couponObj = selectedData
this.recoveryTotalPrice()
this.recoveryGiftList()
this.getData()
},
getData() {
this.orderShow.forEach(item => {
if (this.couponObj[item].list&&this.couponObj[item].list.length) {
this.tableData = this.couponObj[item].list
}
})
},
// 计算预估成本
recoveryTotalPrice() {
this.totalEstimatedCost = 0
this.orderShow.forEach(item => {
this.couponObj[item].list.forEach(subItem => {
// 失效券不加入预估成本
if (subItem.status != '3') {
this.totalEstimatedCost = this.totalEstimatedCost + parseInt(subItem.couponAnticipatedCost || 0) * parseInt(subItem.couponAmount)
}
})
})
this.totalEstimatedCost = (this.totalEstimatedCost / 100).toFixed(2)
},
// 礼包
recoveryGiftList() {
this.editForm.couponList = []
this.orderShow.forEach(item => {
this.couponObj[item].list.forEach(k => {
this.editForm.couponList.push(k)
})
})
// this.hasCouponBlock()
},
// hasCouponBlock(isValidate = true) {
// var idx = this.editFormData.findIndex(item => item.name == 'couponListBlock')
// this.editFormData[idx].isHide = !this.editForm.couponList.length
// isValidate && this.$refs.editFormRef.$refs[this.editChildRef].validateField('couponList')
// },
handleSave() {
if (this.tableData.length == 0) {
this.$message({
message: '请选择商户',
type: 'error'
})
return
}
let couponIds = []
this.tableData.forEach(item => {
couponIds.push(item.id)
})
let params = {
topicId: this.topicId,
couponIds,
couponNames: this.tableData[0].couponName
}
this.$apis.store.configCoupons(params).then(res => {
if (res.code == 0) {
this.$router.go(-1)
}
this.$message({
message: res.code == '0' ? '配置成功' : res.message,
type: res.code == '0' ? 'success' : 'error'
})
})
},
handleCancel() {
this.$router.go(-1)
}
}
}
</script>
<style lang="scss" scoped>
.container {
.gl-form-page {
flex: 1;
padding: 20px;
.config-form-item {
display: flex;
margin-top: 20px;
/deep/.el-form-item__content {
width: 460px;
}
/deep/.el-input--prefix .el-input__inner {
line-height: 32px;
height: 32px;
}
}
/deep/.el-input__prefix {
line-height: 32px;
.el-input__icon {
line-height: 32px;
}
}
label {
font-size: 14px;
text-align: right;
color: #666;
width: 154px;
// margin-right: 12px;
height: 36px;
line-height: 36px;
img {
width: 14px;
height: 14px;
vertical-align: middle;
margin-left: 5px;
}
&.is-require {
&::before {
content: '*';
color: #f56c6c;
margin-right: 4px;
}
}
}
}
.merchant-wrap {
width: 700px;
margin-left: 194px;
margin-top: 10px;
}
}
</style>