directional.js
5.18 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
Page({
data: {
IMGURL: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/hmd/',
IMGURKBASE: 'equity/version/1_0_0/',
show: false,
showPage: false,
// 背景图-映射值 1不送会员 2送会员
pageBg: {
1: {
max: 'wine_c_bg_icon',
mid: 'wine_bg_icon',
footer: 'direct_r_bg_icon',
int: 'direct_bg_icon_2_r',
modal: 'c_bag_r_icon'
},
2: {
max: 'direction_bg_icon',
mid: 'direct_vip_icon',
footer: 'direct_bg_icon_1',
int: 'direct_bg_icon_2',
modal: 'c_bag_g_icon'
}
},
giveMemberFlag: 2,
couponsList: []
},
onLoad(options) {
console.log(options)
if (options) {
let para = {
id: options.id
}
if (options.childId) {
para.childId = options.childId
this.childId = childId
}
if (options.staffUUID) {
const { staffUUID, staffName } = options
this.staff = {
staffUUID,
staffName
}
}
if (!para.id) return wx.p.wxApi.showToast('缺少参数ID')
this.getGiftsDetailData(para)
}
},
// 领取定向礼包
async toRecivedGifts() {
const { giftsData } = this.data
const mPattern = /^[1]([3-9])[0-9]{9}$/
const { merchantId } = wx.p.storage.get('merchant_info')
const userInfo = wx.p.storage.get('userInfo')
const receiveWay = giftsData.receiveWay
if (!this.userPhone&& receiveWay == 1) return wx.p.wxApi.showToast('请输入手机号码')
if (receiveWay == 1&&!this.userPhone.match(mPattern)) return wx.p.wxApi.showToast('请输入正确的手机号')
if (!this.userPhone&& receiveWay == 2) return wx.p.wxApi.showToast('请输入您车架号后6位领取')
if (receiveWay == 2&&this.userPhone.length < 6) return wx.p.wxApi.showToast('请输入您车架号后6位领取')
let para = {
directionalGiftId: giftsData.id,
nickName: userInfo.nickName,
nickUrl: userInfo.headImgUrl,
phone: userInfo.phone,
receiveCondition: this.userPhone || '',
merchantId: merchantId,
directionalGiftChildId: this.childId
}
if (this.staff) {
Object.assign(para, this.staff)
}
// 先判断登录
const loginStatus = await wx.p.router.intercept()
if (loginStatus) return
wx.p.wxApi.showLoading('领取中')
wx.p.api.couponsApi.giftsRecive(para).then(res => {
wx.hideLoading();
if (res) {
res.forEach(item => {
item.receiveStartTime = new Date(item.receiveStartTime).format('yyyy.MM.dd')
if (item.effectiveType == 1) {
item.receiveEndTime = new Date(item.receiveEndTime).format('yyyy.MM.dd hh:mm:ss')
} else {
item.receiveEndTime = new Date(item.receiveEndTime).format('yyyy.MM.dd')
}
// 这是为了适应详情跳转
item.couponId = item.id
item.id = item.userCouponId
})
this.toShowSuccess(res)
}
})
},
// 查询定向礼包详情
getGiftsDetailData(para) {
wx.p.wxApi.showLoading()
wx.p.api.couponsApi
.giftsDetail(para)
.then(res => {
wx.hideLoading()
this.setNaviTitle(res.name)
this.handlerPageShow(res)
})
},
// 处理页面展示内容
handlerPageShow(info) {
if (!info) return wx.p.wxApi.showToast(+JSON.stringify(info))
const { giveMemberFlag, giveMemberType } = info
let { pageBg } = this.data
// 送会员 giveMemberType 1 普通会员;2 银卡会员;3 金卡会员
if (giveMemberFlag == 2) {
const IMAGETYPE = {
1: 'direct_vip_icon',
2: 'direct_sliver_vip_icon',
3: 'direct_gold_vip_icon',
}
pageBg[2].mid = IMAGETYPE[giveMemberType]
}
this.setData({
showPage: true,
giveMemberFlag: giveMemberFlag || 1,
pageBg,
giftsData: info
})
},
toMineCoupons() {
wx.p.router.go('/packageMine/pages/coupon/index/index')
},
// 去使用
toUseGifts(e) {
let {
item
} = e.currentTarget.dataset
let temp = JSON.stringify(item)
let {
discountType,
useChannel,
id
} = item
if (discountType == 2 || discountType == 4) {
wx.p.router.go('/packageMall/pages/coupon/coupon', {
userCouponId: id,
useMemberType: item.useMemberType
})
return
}
/**线上商品代金券 */
if (discountType == 3 && useChannel == 1) {
if (item.useMemberType == 1) {
wx.p.wxApi.showToast('代金券已使用')
return
}
wx.p.router.go('/packageMine/pages/coupon/recommend/recommend', {
couponInfo: item
})
return
}
wx.p.router.go('/packageMine/pages/coupon/detail/detail', {
item
})
},
setNaviTitle(title) {
wx.setNavigationBarTitle({
title
})
},
intPhone(e) {
this.userPhone = e.detail.value
},
toShowSuccess(list) {
this.setData({
show: true,
couponsList: list
})
wx.setPageStyle({
style: {
overflow: 'hidden'
}
})
},
// 关闭弹框放开页面滚动
toCloseModal() {
this.setData({
show: false
})
wx.setPageStyle({
style: {
overflow: 'unset'
}
})
},
})