serviceAddUpdateLook.vue
20.5 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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
<template>
<div class="live-room">
<div class="topMsg">
<p class="pageTitle">基本信息</p>
<el-button type="primary" size="small" @click="goBack">返回</el-button>
</div>
<div class="live-room container">
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
<el-form-item size="small" label="服务名称" prop="couponName" style="width: 440px">
<el-input size="small" :disabled="disabledContent" v-model.trim="ruleForm.couponName" maxlength="20" placeholder="请输入服务名称,如“精洗轿车”"></el-input>
</el-form-item>
<el-form-item size="small" label="有效期" prop="effectiveType">
<div class="radioGroupWrap">
<el-radio-group v-model="ruleForm.effectiveType" :disabled="disabledContent">
<el-radio :label="3" class="itemBlock">无有效期</el-radio>
<!-- effectiveType:1, effectiveDays:5 -->
<el-radio :label="1">
领取后
<el-input
v-model="ruleForm.effectiveDays"
maxlength="4"
@input="
val => {
ruleForm.effectiveDays = val.replace(/[^\d]/g, '')
}
"
:disabled="disabledContent"
placeholder="请输入"
size="small"
style="width: 100px"
></el-input>
天内有效
</el-radio>
<!-- effectiveStartTime effectiveEndTime +具体时间 -->
<el-radio :label="2">
<el-date-picker :size="small" :disabled="disabledContent" style="width: 230px" v-model="ruleForm.daterange" type="daterange" value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions || {}"></el-date-picker>
</el-radio>
</el-radio-group>
</div>
</el-form-item>
<el-form-item size="small" label="使用限制" prop="customUseLimit">
<div class="radioGroupWrap">
<el-radio-group v-model="ruleForm.customUseLimit" :disabled="disabledContent">
<el-radio :label="0" class="itemBlock">不限制使用次数</el-radio>
<!-- useType:1 useAmount:6 -->
<el-radio :label="1">
有效期内可使用
<el-button @click="sub1" class="addsubBtn" :disabled="disabledContent">-</el-button>
<span class="numWrap">{{ ruleForm.limitTime1 }}</span>
<el-button @click="add1" class="addsubBtn" :disabled="disabledContent">+</el-button>
次
</el-radio>
<el-radio :label="2">
有效期内每
<el-input
v-model="ruleForm.limitDays"
maxlength="4"
@input="
val => {
ruleForm.limitDays = val.replace(/[^\d]/g, '')
}
"
:disabled="disabledContent"
placeholder="请输入"
size="small"
style="width: 100px"
></el-input>
天内可使用
<el-button @click.stop="sub2" class="addsubBtn" :disabled="disabledContent">-</el-button>
<span class="numWrap">{{ ruleForm.limitTime2 }}</span>
<el-button @click.stop="add2" class="addsubBtn" :disabled="disabledContent">+</el-button>
次
</el-radio>
</el-radio-group>
</div>
</el-form-item>
<el-form-item size="small" label="会员价" prop="vipPrice" style="width: 315px">
<el-input size="small" :disabled="disabledContent" maxlength="9" v-model="ruleForm.vipPrice" placeholder="请输入" @keyup.native="ruleForm.vipPrice = oninput(ruleForm.vipPrice)">
<!-- <template slot="append">元</template> -->
<span slot="suffix" class="suffix-label">元</span>
</el-input>
</el-form-item>
<el-form-item size="small" label="门店价" prop="shopPrice" style="width: 315px">
<el-input size="small" :disabled="disabledContent" maxlength="9" v-model="ruleForm.shopPrice" placeholder="请输入" @keyup.native="ruleForm.shopPrice = oninput(ruleForm.shopPrice)">
<!-- <template slot="append">元</template> -->
<span slot="suffix" class="suffix-label">元</span>
</el-input>
</el-form-item>
<el-form-item size="small" label="库存" prop="stock" style="width: 315px">
<el-input size="small" :disabled="title == '查看'" maxlength="6" v-model.number="ruleForm.stock" placeholder="请输入"></el-input>
</el-form-item>
<el-form-item size="small" label="使用说明" prop="useDescription" style="width: 670px">
<el-input size="small" :rows="6" :disabled="title == '查看'" type="textarea" v-model="ruleForm.useDescription" placeholder="请输入" maxlength="200" show-word-limit></el-input>
</el-form-item>
<!-- <el-form-item size="small">
<el-button type="primary" @click="submitForm('ruleForm')" size="small">创建</el-button>
<el-button type="primary" @click="resetForm('ruleForm')" size="small">重置</el-button>
</el-form-item> -->
</el-form>
<div class="serviceCard">
<div class="cardtop">
<img src="@/assets/serviceMemberCard.png" alt="" />
<span class="serviceName ellipsis-1" :title="ruleForm.couponName">{{ ruleForm.couponName || '-' }}</span>
<span class="effectiveRange">{{ limitText }}</span>
<span class="timeRange">{{ effectiveRangeText }}</span>
<div class="grayLine"></div>
<div class="desc">使用说明:</div>
<span class="detailDesc">{{ ruleForm.useDescription }}</span>
</div>
</div>
</div>
<div
class="footer-panel"
v-if="title !== '查看'"
:style="{
left: footerLeft + 'px',
width: footerWidth + 'px'
}"
>
<el-button type="primary" @click="submitForm('ruleForm')" size="medium">创建</el-button>
<el-button type="primary" @click="goBack" size="medium">取消</el-button>
</div>
<!-- :hasScroll="false" :noBtnOk="true" :noCancel="true" :noClose="false" -->
<glsx-dialog title="" top="30vh" :hasScroll="false" width="547px" btnCloseLabel="取消" :noClose="false" :noCancel="true" btnSize="small" :isVisible="isDialogVisible" :showClose="false" @closeDialog="handleClose" @confirmDialog="handleConfirm">
<div class="content-body">
当前有内容信息未保存,是否继续取消
</div>
</glsx-dialog>
</div>
</template>
<script>
import glsxDialog from '@/components/glsx-dialog'
import { createService, detailService, updateService } from '@/api/modules/service'
export default {
components: {
glsxDialog
},
data() {
var checkZero = (rule, value, callback) => {
setTimeout(() => {
if (value == 0) {
callback(new Error('请输入有效数字值'))
} else {
callback()
}
})
}
var checkStock = (rule, value, callback) => {
if (value <= 0) {
return callback(new Error('库存不能为空或负数'))
}
setTimeout(() => {
if (!Number.isInteger(value)) {
callback(new Error('请输入数字值'))
} else {
if (value < 0) {
callback(new Error('必须大于或等于0'))
} else {
callback()
}
}
}, 1000)
}
return {
isDialogVisible:false,
pickerOptions: {
disabledDate(time) {
return time.getTime() < Date.now()- 8.64e7// 如果没有后面的-8.64e7就是不可以选择今天的
}
},
ruleForm: {
couponName: '',
// region: '',
// date1: '',
// date2: '',
// delivery: false,
// type: [],
// resource: '',
effectiveType: 3, //有效期(默认无有效期)
effectiveDays: '',
customUseLimit: 0, //使用限制(默认不限制使用次数)
limitTime1: 1,
limitDays: '30',
limitTime2: 5,
vipPrice: '',
shopPrice: '',
stock: '',
useDescription: '',
daterange: []
},
copyRuleForm:{},
rules: {
couponName: [{ required: true, message: '请输入服务名称', trigger: 'blur' }],
// region: [{ required: true, message: '请选择活动区域', trigger: 'change' }],
// date1: [{ type: 'date', required: true, message: '请选择日期', trigger: 'change' }],
// date2: [{ type: 'date', required: true, message: '请选择时间', trigger: 'change' }],
// type: [{ type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }],
effectiveType: [{ required: true, message: '请选择有效期', trigger: 'change' }],
customUseLimit: [{ required: true, message: '请选择使用限制', trigger: 'change' }],
vipPrice: [
{ required: true, message: '请输入会员价', trigger: 'blur' },
{ validator: checkZero, trigger: 'blur' }
],
shopPrice: [
{ required: true, message: '请输入门店价', trigger: 'blur' },
{ validator: checkZero, trigger: 'blur' }
],
stock: [
{ required: true, message: '请输入库存', trigger: 'blur' },
{ validator: checkStock, trigger: 'blur' }
]
// useDescription: [{ required: true, message: '请填写活动形式', trigger: 'blur' }]
},
merchantId: '',
merchantName: '',
title: this.$route.query.title || ''
}
},
computed: {
disabledContent() {
if (this.title == '查看' || this.title == '编辑') {
return true
}
return false
},
limitText() {
if (this.ruleForm.customUseLimit == 0) {
return `不限制使用次数`
} else if (this.ruleForm.customUseLimit == 1) {
return `有效期内可使用${this.ruleForm.limitTime1}次`
} else if (this.ruleForm.customUseLimit == 2) {
return `有效期内每${this.ruleForm.limitDays}天内可使用${this.ruleForm.limitTime2}次`
}
return '不限制使用次数'
},
effectiveRangeText() {
if (this.ruleForm.effectiveType == 1) {
return `领取后${this.ruleForm.effectiveDays}天内有效`
} else if (this.ruleForm.effectiveType == 2) {
return `${this.ruleForm.daterange[0]}-${this.ruleForm.daterange[1]}`
}
return '无有效期'
}
// 有效期内可使用3次
},
created() {
this.copyRuleForm = JSON.parse(JSON.stringify(this.ruleForm))//深拷贝一份数据
if (window.__POWERED_BY_QIANKUN__) {
//运行在qiankun容器中
this.merchantId = this.$globalState.session.merchantId
this.merchantName = this.$globalState.session.merchantName
}
if (this.title == '编辑' || this.title == '查看') {
var breadcrumbTitle = this.title
// document.getElementsByClassName('el-breadcrumb__item')[3].innerText = `${breadcrumbTitle}服务`
// document.getElementById('tab-/membercenter/memberCenter/serviceAddUpdateLook').innerHTML = 'AAAAAAAA'
this.getPageDetail()
}
},
mounted() {
this.footerLeft = document.querySelector('.base-container-right').offsetLeft
this.footerWidth = document.documentElement.clientWidth - this.footerLeft
},
methods: {
getPageDetail() {
let params = {}
params.couponId = this.$route.query.couponId
detailService(params).then(res => {
this.ruleForm = res
this.ruleForm.customUseLimit = res.useType
if (res.effectiveType == 1) {
this.ruleForm.effectiveDays = res.effectiveDays
}
if (res.effectiveType == 2) {
this.ruleForm.daterange = [res.effectiveStartTime, res.effectiveEndTime]
}
// this.ruleForm.limitTime1 = ''
// this.ruleForm.limitTime2 = ''
// this.limitDays = ''
if (res.useType == 1) {
this.ruleForm.limitTime1 = res.useAmount
}
if (res.useType == 2) {
this.ruleForm.limitTime2 = res.useAmount
this.ruleForm.limitDays = res.useLimitDays
}
this.copyRuleForm = JSON.parse(JSON.stringify(this.ruleForm))//深拷贝一份数据
})
},
submitForm(formName) {
this.$refs[formName].validate(valid => {
if (valid) {
if (this.title == '编辑') {
this.updateService()
} else {
this.createService()
}
} else {
return false
}
})
},
//创建服务
createService() {
let params = {
effectiveDays: '',
useAmount: '',
useLimitDays: ''
}
params.couponName = this.ruleForm.couponName
//有效期
params.effectiveType = this.ruleForm.effectiveType
//使用限制
params.useType = this.ruleForm.customUseLimit
//有效期 effectiveType: 3 1 2
if (this.ruleForm.effectiveType == 1 && !parseInt(this.ruleForm.effectiveDays)) {
this.$message.error('请输入有效期')
return false
}
params.effectiveDays = this.ruleForm.effectiveDays
if (this.ruleForm.effectiveType == 2) {
if (!this.ruleForm.daterange) {
this.$message.error('请输入有效期')
return false
} else {
params.effectiveStartTime = this.ruleForm.daterange[0] + ' 00:00:00'
params.effectiveEndTime = this.ruleForm.daterange[1] + ' 23:59:59'
}
}
//使用限制
if (this.ruleForm.customUseLimit == 1) {
if (!parseInt(this.ruleForm.limitTime1)) {
this.$message.error('请输入有效期使用次数')
return false
} else {
params.useAmount = this.ruleForm.limitTime1
}
}
if (this.ruleForm.customUseLimit == 2) {
if (!parseInt(this.ruleForm.limitTime2) || !parseInt(this.ruleForm.limitDays)) {
this.$message.error('请输入有效期使用次数')
return false
} else {
params.useLimitDays = this.ruleForm.limitDays
params.useAmount = this.ruleForm.limitTime2
}
}
params.vipPrice = this.ruleForm.vipPrice
params.shopPrice = this.ruleForm.shopPrice
params.stock = this.ruleForm.stock
params.useDescription = this.ruleForm.useDescription
params.discountType = 7
params.merchantId = this.merchantId
params.merchantName = this.merchantName
createService(params).then(res => {
if (res.code == 0) {
this.$message.success('创建服务成功')
this.$router.push('/memberCenter/service')
} else {
this.$message({
type: 'error',
message: res.message
})
}
})
},
//更新服务
updateService() {
let param = {}
param.discountType = 7
param.merchantId = this.merchantId
param.merchantName = this.merchantName
param.couponId = this.$route.query.couponId
param.stock = this.ruleForm.stock
param.useDescription = this.ruleForm.useDescription
updateService(param).then(res => {
if (res.code == 0) {
this.$message.success('编辑服务成功')
this.$router.push('/memberCenter/service')
} else {
this.$message({
type: 'error',
message: res.message
})
}
})
},
goBack() {
if(JSON.stringify(this.ruleForm)==JSON.stringify(this.copyRuleForm)){
this.$router.push('/memberCenter/service')
}else{
// this.$message.error('是否保存信息')
this.isDialogVisible=true
}
},
handleClose(){
this.isDialogVisible=false
},
handleConfirm(){
this.$router.push('/memberCenter/service')
},
oninput(value) {
let str = value
let len1 = str.substr(0, 1)
let len2 = str.substr(1, 1) //如果第一位是0,第二位不是点,就用数字把点替换掉
if (str.length > 1 && len1 == 0 && len2 != '.') {
str = str.substr(1, 1)
} //第一位不能是.
if (len1 == '.') {
str = ''
}
if (len1 == '+') {
str = ''
}
if (len1 == '-') {
str = ''
} //限制只能输入一个小数点
if (Number(value) >= 999999999) {
return (str = 999999999)
}
if (str.indexOf('.') != -1) {
let str_ = str.substr(str.indexOf('.') + 1)
if (str_.indexOf('.') != -1) {
str = str.substr(0, str.indexOf('.') + str_.indexOf('.') + 1)
}
}
//正则替换
// (/[^\-\d.]/g, ''))"
str = str.replace(/[^\d.^]+/g, '') // 保留数字和小数点
str = str.replace(/^\D*([0-9]\d*\.?\d{0,2})?.*$/, '$1') // 小数点后只能输 2 位
return str
},
sub1() {
if (this.ruleForm.limitTime1 <= 0) {
return
}
this.ruleForm.limitTime1--
},
add1() {
this.ruleForm.limitTime1++
},
sub2() {
if (this.ruleForm.limitTime2 <= 0) {
return
}
this.ruleForm.limitTime2--
},
add2() {
this.ruleForm.limitTime2++
}
}
}
</script>
<style lang="scss" scoped>
.live-room {
.topMsg {
margin: 20px 0px 0;
padding: 0 20px;
background-color: #fff;
height: 56px;
border-bottom: 1px solid#DCDFE6;
display: flex;
justify-content: space-between;
align-items: center;
.pageTitle {
position: relative;
// margin-bottom: 20px;
// height: 20px;
font-size: 20px;
font-weight: 700;
color: #333333;
line-height: 20px;
letter-spacing: 1px;
}
}
.container {
margin: 0 0px 100px;
position: relative;
/deep/ .el-form-item__content {
.radioGroupWrap {
width: 550px;
height: 164px;
background-color: #f4f6fc;
padding-top: 10px;
padding-left: 20px;
}
}
.numWrap {
display: inline-block;
background-color: #fff;
min-width: 34px;
height: 22px;
text-align: center;
line-height: 22px;
margin: 0 2px;
}
.addsubBtn {
background-color: #fff;
color: #5850ff;
padding: 5px 9px;
}
.el-radio {
display: block;
&:not(:first-child) {
margin-top: 18px;
}
}
.itemBlock {
margin-top: 10px;
}
.serviceCard {
position: absolute;
padding: 10px;
box-sizing: border-box;
top: 136px;
right: 78px;
width: 343px;
min-height: 184px;
background: #ffffff;
box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.06);
border-radius: 4px;
border: 1px solid #e4e7ed;
span {
font-size: 12px;
font-weight: 400;
color: #999999;
}
.cardtop {
position: relative;
.serviceName {
position: absolute;
left: 88px;
top: 5px;
width: 230px;
font-size: 14px;
font-weight: 600;
color: #333333;
}
.effectiveRange {
position: absolute;
left: 88px;
top: 30px;
}
.timeRange {
position: absolute;
left: 88px;
top: 60px;
}
.grayLine {
position: absolute;
width: 100%;
left: 0;
top: 90px;
height: 1px;
opacity: 0.14;
background-color: #979797;
}
.desc {
margin-top: 20px;
margin-left: 88px;
color: #333;
}
.detailDesc {
display: inline-block;
margin-left: 88px;
margin-top: 10px;
width: 230px;
word-wrap: break-word;
}
}
}
}
.footer-panel {
display: flex;
align-items: center;
justify-content: center;
position: fixed;
width: 100%;
bottom: 0px;
height: 64px;
background: #ffffff;
z-index: 999;
box-shadow: 0px -1px 1px 0px rgba(88, 80, 255, 0.1);
}
/deep/ .el-dialog__header{
border: 0;
}
/deep/ .el-dialog__body{
border-bottom: 1px solid #e6e6e6;
padding: 20px 25px;
.content-body{
height: 136px;
line-height: 121px;
font-size: 18px;
text-align: center;
font-weight: 400;
color: #333333;
}
}
/deep/ .el-dialog__footer {
text-align: center;
padding-top: 15px;
padding-bottom: 15px;
}
}
</style>