coupon.vue
13.6 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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<template>
<div class="addCoupon">
<!-- 新增优惠券 -->
<div class="addCouponBox" style="padding-right: 30px;">
<TitleWithCircle title="基本信息" style="margin-bottom: 20px;"/>
<div style="padding-bottom: 15px;padding-right: 30px;padding-left: 80px;font-weight: bold;">
所需金额:{{ changecouponfrom() }} 元
</div>
<el-form ref="ruleForm" class="formBox" :model="couponfrom" label-width="150px" :rules="couponRules">
<el-form-item label="优惠券名称" prop="couponName">
<el-input v-model="couponfrom.couponName" placeholder="请输入优惠券名称" onblur="value=value.replace(/(^\s*)|(\s*$)/g, '')" />
</el-form-item>
<el-form-item label="优惠券类型">
<el-radio v-model="couponfrom.couponType" label="1">满减券</el-radio>
<el-radio v-model="couponfrom.couponType" label="2">折扣券</el-radio>
</el-form-item>
<el-form-item v-if="couponfrom.couponType === '1'" class="inputW" label="优惠内容" prop="usageThreshold">
订单满 <el-input-number v-model="couponfrom.usageThreshold" :controls="false" :min="0" :precision="2" :step="0.01" /> 元 减 <el-input-number v-model="couponfrom.discountContent" :controls="false" :min="0" :precision="2" :step="0.01" /> 元
</el-form-item>
<el-form-item v-else class="inputW discount" label="优惠内容" prop="discountContent">
打 <el-input-number v-model="couponfrom.discountContent" :controls="false" :min="0" :max="9.9" :precision="1" :step="0.1" /> 折
<span v-if="couponfrom.couponType === '2'" style="margin-right: 10px;">
最高优惠金额
<el-input-number v-model="couponfrom.maxDiscountAmount" :controls="false" :min="0" :precision="2" :step="0.01" /> 元
</span>
<label>折数输入值要大于0 小于10,可保留一位小数</label>
</el-form-item>
<!-- <el-form-item v-if="couponfrom.couponType === '2'" class="inputW" label="最高优惠金额" prop="maxDiscountAmount">
<el-input-number v-model="couponfrom.maxDiscountAmount" :controls="false" :min="0" :precision="2" :step="0.01" /> 元
</el-form-item> -->
<el-form-item label="可用商品类别:">
<el-radio-group v-model="couponfrom.useCategory" @change="changeType">
<el-radio :label="1" >全部</el-radio>
<el-radio :label="2" >选择类别</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="选择商品类别:" v-if="couponfrom.useCategory === 2">
<el-select style="width: 100%;" multiple v-model="useCategory" placeholder="请选择" filterable @change="changeuseCategory">
<el-option
v-for="item in classList"
:key="item.classifyId"
:label="item.classifyName"
:value="item.classifyId"
/>
</el-select>
</el-form-item>
<el-form-item label="使用范围:">
<el-radio-group v-model="couponfrom.usedMerchants" >
<el-radio :label="1" >全平台</el-radio>
<!-- <el-radio :label="2" >自营</el-radio> -->
<el-radio :label="3" >部分商家</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="选择商家:" v-if="couponfrom.usedMerchants === 3">
<el-select
style="width: 100%;"
multiple
v-model="usedMerchants"
placeholder="请选择"
filterable
@change="changeusedMerchants"
>
<el-option
v-for="item in shopList"
:key="item.shopId"
:label="item.shopName"
:value="item.shopId"
/>
</el-select>
</el-form-item>
<div style="display: flex;">
<el-form-item label="是否开启积分兑换:">
<el-radio-group v-model="pointsRequired">
<el-radio :label="1" >是</el-radio>
<el-radio :label="0" >否</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item v-if="pointsRequired" label="所需积分:">
<el-input v-model="couponfrom.pointsRequired" type="number" style="width: 150px" /> 分
</el-form-item>
</div>
<el-form-item label="是否重复领用:">
<el-radio-group v-model="couponfrom.receiveAgain">
<el-radio :label="1" >是</el-radio>
<el-radio :label="0" >否</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item class="timeDataBox" label="用券时间" prop="startTime">
<el-date-picker
v-model="dateInfo"
type="datetimerange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="yyyy-MM-dd HH:mm:ss"
@change="changeDate"
/>
</el-form-item>
<el-form-item class="boxWidth" label="数量" prop="totalCoupons">
<el-input-number v-model="couponfrom.totalCoupons" :controls="false" :min="1" :max="changemax" :precision="0" :step="1" /> 张 <span >(最大:{{ changemax}} 张)</span>
<!-- <el-input v-model="couponfrom.totalCoupons" :controls="false" type="number" :min="1" oninput="value=value.replace(/[^\d]/g,'')" />张 <span v-if="coupoobj.symon && changecouponfrom()!=0">(最大:{{ (coupoobj.symon/changecouponfrom()).toFixed(0) }} 张)</span> -->
</el-form-item>
<el-form-item label="备注">
<el-input maxlength="200" show-word-limit rows="4" v-model="couponfrom.remark" placeholder="请输入备注" type="textarea" />
</el-form-item>
</el-form>
</div>
</div>
</template>
<script>
import { commdityClassGetAll } from '@/api/renovation';
import TitleWithCircle from '@/components/top/index';
import {
businessListGetAll,
} from '@/api/business'
export default {
components: {
TitleWithCircle
},
name: 'AddCoupon',
props: {
couponfrom: {
type: Object,
default: {},
},
coupoobj: {
type: Object,
default: {
symon:0
},
},
},
data() {
var moneyContentusageThreshold = (rule, value, callback) => {
if(!this.couponfrom.usageThreshold) {
return callback(new Error('请输入优惠门槛'));
}
if(!this.couponfrom.discountContent) {
return callback(new Error('请输入优惠内容'));
}
if(this.couponfrom.couponType == '1') {
if(Number(this.couponfrom.discountContent) >= Number(this.couponfrom.usageThreshold)) {
return callback(new Error('请满减金额大于优惠金额'));
}
}
callback();
}
var moneyContentdiscountContent = (rule, value, callback) => {
if(!this.couponfrom.discountContent) {
return callback(new Error('请输入优惠内容'));
}
if(!this.couponfrom.maxDiscountAmount) {
return callback(new Error('请输入最高优惠'));
}
callback();
}
return {
changemax:9999,
monys:0,
usedMerchants:null,
pointsRequired:0,
dateInfo: null,
isThreshold: true,
useCategory:null,
useCategory2:1,
classList:[],
shopList:[],
couponRules: {
couponName: [
{ required: true, message: '请输入优惠券名称', trigger: 'blur' }
],
usageThreshold: [ { validator: moneyContentusageThreshold, trigger: 'blur' }],
discountContent: [ { validator: moneyContentdiscountContent, trigger: 'blur' }],
startTime: [{required: true, message: '请选择时间', trigger: 'blur'}],
totalCoupons: [{ required: true, message: '请输入数量', trigger: 'blur' }]
},
}
},
watch: {
'couponfrom.discountContent'(val) {
this.setchangemax()
},
'couponfrom.usageThreshold'(val) {
this.setchangemax()
},
'couponfrom.maxDiscountAmount'(val) {
this.setchangemax()
},
'couponfrom.couponType'(val) {
this.couponfrom.maxDiscountAmount = 0
this.couponfrom.discountContent = 0
},
'couponfrom.useCategory'(val) {
if(val == '1') {
this.useCategory = null
} else {
}
},
'couponfrom.usedMerchants'(val) {
this.usedMerchants = null
},
pointsRequired(val) {
this.couponfrom.pointsRequired = 0
},
},
mounted() {
this.getAll()
},
methods: {
setchangemax(){
if(this.coupoobj.symon && this.changecouponfrom()!=0) {
this.changemax = Number(((Number(this.coupoobj.symon)/100)/this.changecouponfrom()).toFixed(0))
} else {
this.changemax = 999999
}
},
changeuseCategory(e){
this.$emit('changevalue','useCategorylist',e)
},
changeusedMerchants(e){
this.$emit('changevalue','usedMerchantslist',e)
},
changeDate(e){
console.error(e)
if(e && e.length>0) {
this.couponfrom.startTime = e[0]
this.couponfrom.endTime = e[1]
} else {
this.couponfrom.startTime = ''
this.couponfrom.endTime = ''
}
},
changecouponfrom() {
let num = 0
if(this.couponfrom.couponType == '1') {
num = (this.couponfrom.discountContent?Number(this.couponfrom.discountContent):0) * (this.couponfrom.totalCoupons?Number(this.couponfrom.totalCoupons):0)
} else if(this.couponfrom.couponType == '2') {
num = (this.couponfrom.maxDiscountAmount?Number(this.couponfrom.maxDiscountAmount):0) * (this.couponfrom.totalCoupons?Number(this.couponfrom.totalCoupons):0)
}
console.log(num)
return num
},
// 获取类别
async getAll () {
const res = await commdityClassGetAll({
page: 1,
pageSize: 100
})
this.classList = res.data.list
const res1 = await businessListGetAll ({
page: 1,
pageSize: 400
})
this.shopList = res1.data.list
},
changeThreshold(val) { // 输入框值改变
if (val) {
this.couponfrom.threshold = 0
}
},
changeType () {
}
}
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
@import url("../../styles/elDialog.scss");
.addCoupon {
background: #FFFFFF;
.dialog-footer {
// margin-left: 300px;
}
.formBox {
.flexBox {
display: flex;
}
.applyType {
span {
width: 100px;
height: 30px;
line-height: 30px;
background: #3F9B6A;
color: #FFFFFF;
text-align: center;
display: inline-block;
font-size: 14px;
margin-right: 30px;
border-radius: 4px;
cursor: pointer;
position: relative;
i {
position: absolute;
right: -10px;
top: -10px;
width: 25px;
height: 25px;
line-height: 25px;
background: #FFFFFF;
border-radius: 50%;
border: 1px solid #3F9B6A;
text-align: center;
color: #3F9B6A;
font-style: normal;
font-size: 12px;
}
}
}
}
.footBtnBox {
width: 100%;
display: flex;
justify-content: center;
margin-top: 50px;
}
.dateBox {
display: flex;
align-items: center;
.description {
width: 59px;
text-align: center;
display: block;
font-size: 14px;
color: #999999;
}
}
.discount label {
color: #cccccc;
font-weight: 500;
padding-left: 30px;
}
}
</style>
<style scoped>
.flexBox /deep/ .el-input {
width: 300px;
}
.inputW /deep/ .el-input, .el-input-number {
width: 100px;
/* margin: 0 8px; */
}
.inputW /deep/ .el-input .el-input__inner {
text-align: center;
}
.inputW /deep/ .el-form-item__error {
padding-left: 25px;
}
.inputW /deep/ .el-checkbox {
margin-left: 20px;
}
.inputW /deep/ .el-radio {
margin-left: 30px;
}
.boxWidth /deep/ .el-input {
width: 100px;
margin-right: 15px;
}
.boxWidth /deep/ .el-input .el-input__inner {
text-align: center;
}
.addCoupon /deep/ .el-button--primary {
background: #3F9B6A;
border-color: #3F9B6A;
}
.addCoupon /deep/ .el-dialog__header {
background-color: #3F9B6A;
}
.addCoupon /deep/ .el-dialog__headerbtn .el-dialog__close {
color: #FFFFFF;
}
.addCoupon .timeDataBox /deep/ .el-form-item__content {
display: flex;
align-items: center;
}
.addCoupon .timeDataBox /deep/ .el-form-item__label {}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
}
input[type="number"]{
-moz-appearance: textfield;
}
</style>