create.vue
11.3 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
<template>
<div class="gift-layout">
<template v-if="flag">
<div class="box">
<div class="item">
<div class="label">礼包名称</div>
<div class="value">
<van-field
v-model="obj.name"
:disabled="disabledList.includes('name')"
input-align="right"
maxlength="15"
placeholder="请输入礼包名称"
@input="input"
/>
</div>
</div>
<div class="item">
<div class="label">
备注名称
<span>(仅内部可见)</span>
</div>
<div class="value">
<van-field
v-model="obj.remarkName"
input-align="right"
:disabled="disabledList.includes('remark')"
maxlength="30"
placeholder="可按车主姓名+手机号形式备注"
@input="input"
/>
</div>
</div>
</div>
<div class="box">
<div class="item">
<div class="label">礼包明细</div>
<div class="value">预估成本:<span>¥{{centsToyuan(total)}}</span></div>
</div>
<template v-if="obj.couponList && obj.couponList.length">
<div class="detail-box">
<template v-for="(i,index) in obj.couponListView">
<div
class="detail"
:key="index"
>
<!-- status 优惠券状态(1:未生效,2:生效中,3:已失效) -->
<!-- 优惠券类型 1:满减券,2:折扣券,3:代金券,4:兑换券 5:购车代金券 6:商品折扣券,7:门店服务 -->
<span class="detail-title text-center">{{discountEnum[i.discountType]}}</span>
<template v-for="(e,ind) in i.list">
<div
:class="['detail-item',{'coupon-disabled':e.status != 2 && obj.receivedFlag != 2}]"
:key="ind"
>
<div class="name flex">
{{e.couponName}}
<template v-if="e.status != 2 && obj.receivedFlag != 2">
<div class="name-tips text-center">{{{1:'未生效',3:'已失效'}[e.status]}}</div>
</template>
</div>
<div class="num flex">
数量:x{{e.couponAmount}}
<div class="price">¥{{centsToyuan(e.couponAnticipatedCost * e.couponAmount)}}</div>
</div>
<div class="del sprite-icon icon-gift-del" v-if="!disabledList.includes('add')" @click="delCoupon(e)"></div>
</div>
</template>
</div>
</template>
</div>
</template>
<div v-if="!disabledList.includes('add')" :class="['add-box text-center',{'add-line':obj.couponList.length}]">
<div
class="add-btn text-center"
@click="showGiftModal"
>
<div class="sprite-icon icon-gift-add"></div>
</div>
</div>
</div>
<div v-if="obj.receiveRule!=3" class="box readonly-box radio-box">
<div class="title">领取条件</div>
<template v-for="(i,index) in receiveWayObj">
<div
class="radio-item"
:key="index"
>
<div
class="radio-name flex"
@click="changeRadio(index)"
>
<div :class="['radio',{'radio-active':obj.receiveWay == i.value}]"></div>
{{i.name}}
</div>
<template v-if="obj.receiveWay == i.value">
<div class="radio-input">
<van-field
v-model="obj[i.key]"
:type="i.type || 'text'"
:maxlength="i.maxlength"
:placeholder="i.placeholder"
@input="input(i,$event)"
/>
</div>
</template>
</div>
</template>
</div>
<div class="box readonly-box textarea">
<div class="title">赠送原因</div>
<div class="textarea-box">
<van-field
v-model="obj.giveReason"
type="textarea"
placeholder="请说明赠送礼包的原因(非必填)"
maxlength="50"
@input="input"
/>
</div>
</div>
<div
:class="['btn text-center x-center create',{'disabled-btn':disabled}]"
@click="submit"
>{{id?'确定':'创建'}}</div>
</template>
<gift-modal
ref="GiftModal"
:selectedList="obj.couponList"
@confirm="couponConfirm"
/>
</div>
</template>
<script type='text/ecmascript-6'>
import GiftModal from './GiftModal.vue'
import { giftApi, wxConfig} from '@/api'
import { discountTypeMixin } from '@/mixins'
import { setApproveParam } from '@/mixins/giftMixin'
export default {
name: '',
components: { GiftModal },
mixins: [discountTypeMixin],
data () {
return {
flag: false,
disabled: true,
disabledList:[],
obj: {
receiveWay: 1,
couponList: []
},
receiveWayObj: [
{ name: '指定手机号', type: 'tel', placeholder: '客户需输入指定的手机号,才能成功领取礼包', maxlength: 11, key: 'phone', value: 1 },
{ name: '指定车架号后6位', placeholder: '客户需输入指定的车架号,才能成功领取礼包', maxlength: 6, key: 'vin', value: 2 },
],
total: 0,
id: '',
test: ''
}
},
mounted () {
let { id,perfectFlag } = this.getQuery()
if (id) {
this.getDetail(id)
this.id = id
}
else this.flag = true
wxConfig.init(['thirdPartyOpenPage','onHistoryBack'])
},
methods: {
input (i, e) {
if (i && i.key == 'vin') this.obj[i.key] = e.replace(/[^0-9a-zA-Z]/g, '')
this.checkData()
},
setCouponData (res) {
let total = 0
let discountTypeList = Array.from(new Set([...res.couponList.map(e => e.discountType)]))
res.couponList.map(e => {
if (e.status == 2) total += Number(e.couponAnticipatedCost) * e.couponAmount
})
res.couponListView = discountTypeList.map(i => {
let list = []
res.couponList.map(e => {
if (i == e.discountType) list.push(e)
})
return {
discountType: i,
list
}
})
this.total = total
return res
},
getDetail () {
let { id,pageIdx, childId,perfectFlag } = this.getQuery()
let API = pageIdx==1? giftApi.getUserGiftDetail : pageIdx==2 ? giftApi.getApproveGiftDetail : giftApi.getGiftDetail
let pramas = {id,childId}
API(pramas).then(res => {
this.hideLoading()
if(res.receiveRule==2 || (res.receiveRule==3 && res.stock>1)){
this.disabledList=['name','remark','add']
}
res = this.setCouponData(res)
this.flag = true
if (res.receiveWay == 1) res.phone = res.receiveDetails
else res.vin = res.receiveDetails
this.obj = res
this.checkData()
})
},
changeRadio (index) {
this.obj.receiveWay = index == 0 ? 1 : 2
this.checkData()
},
showGiftModal () {
this.$refs.GiftModal.toggle()
},
couponConfirm ({ chooseItems }) {
this.obj.couponList = JSON.parse(JSON.stringify(chooseItems))
this.obj = this.setCouponData(this.obj)
this.checkData()
},
checkData () {
let { obj } = this
let target = ['name', 'remarkName', 'couponList', 'phone', 'vin']
try {
target.map(key => {
if (key == 'phone' || key == 'vin') {
if(obj.receiveRule!=3){
if (obj.receiveWay == 1) {
if (!obj.phone) throw key
} else {
if (!obj.vin) throw key
}
}
} else {
if (!obj[key]) throw key
if (Array.isArray(obj[key])) {
if (!obj[key].length) throw key
}
}
})
} catch (error) {
this.disabled = true
return
}
this.disabled = false
},
delCoupon (e) {
let { obj: { couponList } } = this
let index = null
couponList.map((i, ind) => {
if (i.discountType == e.discountType && i.couponId == e.couponId) index = ind
})
couponList.splice(index, 1)
this.obj.couponList = couponList
this.obj = this.setCouponData(this.obj)
this.checkData()
},
submit () {
const phoneRex = /^[1]([3-9])[0-9]{9}$/
let { obj, disabled, id } = this
if (disabled) return
if(obj.receiveRule!=3){
if (obj.receiveWay == 1) {
if (!phoneRex.test(obj.phone)) {
this.showToast('请输入正确的手机号')
return
}
} else {
if (obj.vin.length < 6) {
this.showToast('请输入车架号的后6位')
return
}
}
}
try {
obj.couponList.map(e => {
if (e.status != 2) throw false
})
} catch (error) {
this.showToast('礼包有失效券')
return
}
let couponCreateRequests = []
obj.couponList.map(e => {
couponCreateRequests.push({
couponId: e.couponId,
couponAmount: e.couponAmount,
couponAnticipatedCost: e.couponAnticipatedCost
})
})
let params = {
name: obj.name,
remarkName: obj.remarkName,
receiveWay: obj.receiveWay,
giveReason: obj.giveReason,
couponCreateRequests,
stock:1,
receiveDetailList: obj.receiveWay == 1 ? obj.phone : obj.vin
}
if (id){
params.id = id
params.approveFlag = obj.approveFlag
params.receiveRule = obj.receiveRule
params.stock = obj.stock
params.staffCreateRequests = obj.staffList
params.childId = obj.childId
}
params.requestSource = 2
let { perfectFlag,pageIdx } = this.getQuery()
if(id && perfectFlag==2){
params = {
id,
receiveWay:obj.receiveWay,
receiveDetail: obj.receiveWay == 1 ? obj.phone : obj.vin,
giveReason: obj.giveReason,
}
}
this.showLoading('提交中...')
const API =(id && perfectFlag==2) ? giftApi.createPerfectGift : giftApi.createOrupdataGift
API(params).then(res => {
this.hideLoading()
if(res.approveFlag == 2){
wxConfig.thirdPartyOpenPage(setApproveParam(res))
.then((resp) => {
setTimeout(()=>{
let { pageIdx} = this.getQuery()
let childId = pageIdx ==3 ? res.directionalGiftChildId : this.obj.childId ? this.obj.childId: ''
this.$router.replace({ name: 'gift.detail', query: {id:res.directionalGiftId,approveStatus:999,childId}})
},500)
})
}else{
// if(pageIdx==2){this.$route.query.approveStatus = 999}
this.$route.params.giftToast = `${id ? '修改' : '创建'}成功`
this.$router.back()
}
})
}
}
}
</script>
<style scoped lang='scss'>
@import '@/assets/css/gift-detail.scss';
.item {
.van-field {
padding: 0;
}
}
.add-line {
border-top: 1px solid rgba(195, 195, 195, 0.3);
}
</style>