headerVip.js
8.33 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
import componentsMixin from "../../../../../mixins/componentsMixin";
import { defaultMerchantId } from "../../../../../api/environment";
import { equityApi, ssoApi } from "../../../../../api/api";
Component({
behaviors: [componentsMixin],
properties:{
freshVIP:{
type:Boolean,
observer:function(v){
if(v){
this.toCheckMember()
}
}
}
},
data: {
memberType: 1,
vipInfo: null,
showAuth: false
},
methods: {
toLookPackage(e) {
const { item } = e.currentTarget.dataset
if (!item.buyStatus) {
this.toOpenPage(0, item, true)
return
}
let temp = JSON.stringify(item)
wx.navigateTo({
url: "/packageEquity/pages/vipPackage/vipPackage?item=" + temp,
});
},
authSuccess(e) {
let {
data
} = e.detail
/**调取后端接口储存用户头像昵称 */
if (data) {
ssoApi.authUserInfo({
...data
}).then(({
code
}) => {
if (code == '0') {
getApp().login().then(({
data
}) => {
wx.$util.setStorageSync("srcm_shopmall_user_info",data);
this.setData({
userInfo: data
})
})
}
})
}
},
showAuthModal() {
this.setData({
showAuth: true
})
},
toCheckPackage(e) {
const { index, item } = e.currentTarget.dataset
if (item.buyStatus) {
this.toLookPackage(e)
return
}
this.toOpenPage(index, item, true)
},
toNotePage() {
wx.navigateTo({
url: "/packageEquity/pages/note/note",
});
},
toOpenPage(index, item, flag) {
let str = `?memberType=${this.data.memberType}` + `&index=${flag?index:null}` + `&item=${flag?JSON.stringify(item):null}`
wx.navigateTo({
url: "/packageEquity/pages/open/open" + str
});
},
// 检测是否已经登录
checkLogin() {
const sessionId = wx.$util.getSessionId();
let flag = true;
if (!sessionId) {
flag = false;
this.setData({
showLogin: true,
});
}
return flag; //fasle 未登录 true已登录
},
// 获取门店会员卡信息
getMemberCardData() {
const merchantId = wx.$util.getStorageSync("srcm_shopmall_merchant_id");
let newMerchantId = merchantId || defaultMerchantId;
let para = {
merchantId: newMerchantId,
};
equityApi.memberCard(para).then((res) => {
wx.$util.setStorageSync('vip_card_info', res)
this.setData({
memberInfo: res,
});
});
},
// 获取用户/门店信息
getUserinfo() {
let userInfo = wx.$util.getStorageSync("srcm_shopmall_user_info");
const merchantId = wx.$util.getStorageSync("srcm_shopmall_merchant_id");
this.setData({
userInfo,
merchantId
});
},
// 获取用户会员信息
toCheckMember() {
const isLogin = this.checkLogin()
wx.removeStorageSync('equity_info')
if (!isLogin) {
this.matchVipLevel(false, this.data.packageLen);
return
}
equityApi.checkOpenMember().then((res) => {
let flag = false;
let homeName = ''
if (res.data && res.data.validitDate) {
res.data.time = new Date(res.data.validitDate).format("yyyy/MM/dd");
}
if (res.code == 0 && res.data) {
flag = true;
}
if (res.data) {
// cardType:权益卡类型 0:体验卡 1:金卡 2:黑卡
// this.data.buyStatus = res.data.packageList && res.data.packageList.length ? true : false
const {cardType,packageList,goldCardClassName,cardClassName,memberName,activeType} = res.data
this.data.buyStatus = cardType ==2
const packageName = packageList.length?packageList[0].packageName:''
homeName = cardType==2?packageName:cardType==1?goldCardClassName:cardClassName
homeName = activeType==0&&flag?goldCardClassName:homeName
}
this.matchVipLevel(flag, this.data.packageLen);
wx.$util.setStorageSync('equity_info', res.data)
wx.setStorageSync('isVIP', flag)
this.setData({
vipInfo: res.data,
homeName
});
});
},
// 新版本---根据会员身份匹配对应的值
matchVipLevel(isOpen, len) {
let havePackage = this.data.buyStatus;
let obj = this.vipRule(isOpen, len, havePackage)
this.setData(obj);
},
// 会员定义规则
vipRule(isOpen, len, havePackage) {
let showMore = len > 1
// 没有开通会员&没有套餐列表
const type1 = !isOpen && !len
// 有开通会员&没有套餐列表
const type2 = isOpen && !len
// 没有开通会员&有套餐列表
const type3 = !isOpen && len
// 有开通会员&有套餐列表&没有购买过套餐
const type4 = isOpen && !havePackage
// 有开通会员&有套餐列表&有购买套餐
const type6 = isOpen && havePackage
const arr = [type1, type2, type3, type4, type6]
let tempIndex = 1
arr.forEach((item, index) => {
if (item) {
tempIndex = index + 1
}
})
tempIndex = tempIndex==5?6:tempIndex
const obj = {
showMore,
memberType: tempIndex
}
return obj
},
// 05版本---获取会员套餐列表
toGetPackage() {
let { userInfo, merchantId } = this.data
let newMerchantId = merchantId || defaultMerchantId;
let para = {
merchantId: newMerchantId,
pageNum: 1,
pageSize: 100,
state: 1
}
if (userInfo) {
para.accountId = userInfo.accountId
}
equityApi.equityPacks(para).then((res) => {
if (res.list.length == 1) {
let str = ''
res.list[0].list.forEach((item, index) => {
str = str + item.couponName + `${index==res.list[0].list.length-1?'':'+'}`
})
res.list[0].desc = str
}
this.data.canShow = true
wx.$util.setStorageSync('packageList', res.list)
this.setData({
packageList: res.list || [],
packageLen: res.list.length || 0,
}, () => {
this.toCheckMember()
});
})
},
componentHttp(){
this.getUserinfo()
this.getMemberCardData();
this.toGetPackage();
}
},
lifetimes:{
attached(){
this.componentHttp()
// 添加订阅者EQUITY
wx.$eventbus.on('EQUITY',()=>{
this.componentHttp()
})
}
}
// pageLifetimes: {
// show: function() {
// if (!this.data.canShow) {
// return
// }
// this.getUserinfo()
// this.getMemberCardData();
// this.toGetPackage();
// }
// }
});