plus.js
8.96 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
var t = getApp(),
a = t.request,
o = t.globalData.setting,
os = o,
i = require("../../../utils/util.js"),
ut = i,
s = require("../../../utils/common.js"),
w = require("../../../utils/wxParse/wxParse.js"),t_pay = require("../../../utils/pay2.js");
var regeneratorRuntime = require('../../../utils/runtime.js');
Page({
/**
* 页面的初始数据
*/
data: {
currentId: 0,
url: o.imghost,
screenWidth: 0,
screenheight: 0,
canvasHidden: true,
shareImgPath: null,
is_plusCard: "",//卡的列表
imagePath: "",
is_pulscardname: "",//plus会员的名字
is_card: 0,//用于判断是否是续费页和购买页面 0不是puls会员
content: "",//等级卡规则
is_card_rule: "",//等级卡规则判断用
is_show: 0, //页面要加载完才能显示
open_yq: 0, //显示打开邀请码的弹窗
by_index:null, //购买卡的下班
isyaoqingma:0, //是否邀请码
is_salesman:0, //是否营业员
inp_recommon: null, //输入的邀请码
inp_serviceman: null, //输入的营业员
is_fengxiang: 0, //是不是分享过来的
def_recommon: null, //分享人的手机号
def_serviceman: null, //分享人的营业员
fir_leader:0,
},
swiperChange: function (e) {
var currentId = e.detail.current;
this.setData({
currentId: currentId
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
var store_id=getApp().globalData.setting.stoid;
//获取用户设备信息,屏幕宽度
wx.getSystemInfo({
success: res => {
that.setData({screenWidth: res.screenWidth})
}
})
var fir_leader = options.scene;
that.setData({fir_leader:fir_leader})
if (fir_leader != null && fir_leader != undefined && fir_leader != "") {
var r_url="/api/weshop/plus/vip/mem/list?storeId=" + store_id + "&userId=" + fir_leader
getApp().request.get(r_url, {
success: function (res) {
var is_ok = 1;
if (res.data.code == -1) {
getApp().my_warnning("未找到分享会员", 0, that);
is_ok = 0;
that.back_user();
}
var user_information = res.data.data[0];
if (user_information['GradeCardID'] == null || user_information['GradeCardID'] == "" || user_information['GradeCardID'] == undefined) {
getApp().my_warnning("分享会员不是plus会员", 0, that);
is_ok = 0;
that.back_user();
}
//--获取当前的时间--
var now = ut.gettimestamp();
if (user_information['ExpiryDate']) {
var str = user_information['ExpiryDate'].replace(/-/g, '/');
var end = new Date(str);
end = Date.parse(end) / 1000;
if (end < now) {
getApp().my_warnning("分享plus会员已经过期", 0, that);
is_ok = 0;
that.back_user();
}
} else {
getApp().my_warnning("分享plus会员已经过期", 0, that);
is_ok = 0;
that.back_user();
}
if (is_ok == 1) {
that.setData({def_recommon: user_information.MobileTel, def_serviceman: user_information.StaffNo,is_fengxiang:1})
//--先判断会员状态--
var user_info=getApp().globalData.userInfo;
if(user_info==null || user_info.mobile==undefined || user_info.mobile=="" || user_info.mobile==null){
wx.navigateTo({ url: '/pages/getphone/getphone?first_leader='+fir_leader, })
return false;
}
}
}
});
}
//-----------商家配置信息----- 等级卡规则,是否又开邀请码,营业员------------
getApp().request.get("/api/weshop/storeconfig/get/" + store_id, {
success: function (res) {
var is_cardrule = res.data.data.cardrules;
var switch_list= res.data.data.switch_list;
var swi_arr=JSON.parse(switch_list);
w.wxParse("content", "html", is_cardrule, that, 6);
that.setData({
is_card_rule: is_cardrule,
isyaoqingma:parseInt(swi_arr.isyaoqingma),
is_salesman:parseInt(swi_arr.is_staffno)
});
}
});
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.getPlusCardType();
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
var goods_list = this.selectComponent("#goods_list"); //组件的id
goods_list.get_list();
},
//--- 获取卡类列表 ---
getPlusCardType: function (e) {
var storid = o.stoid;
var th = this;
getApp().request.promiseGet("/api/weshop/plus/vip/mem/bership/list?" + "storeId=" + storid, {}).then(res => {
var plusCard = res.data.data;
var arr = [1219, 2089, 3031];
var new_arr = new Array();
for (var i = 0; i < plusCard.length; i++) {
//plusCard[i].free=arr[i];
var item = {"fee": plusCard[i].CardFee, 'index': i}
new_arr.push(item);
}
//根據距離遠近排序,越近在前面,升序
new_arr.sort(function (a, b) {
if (a.fee < b.fee) {
return -1;
} else if (a.fee == b.fee) {
return 0;
} else {
return 1;
}
});
//---给数组添加立省多少钱---
for (i = 0; i < plusCard.length; i++) {
for (var j = 0; j < new_arr.length; j++) {
if (i == new_arr[j].index) {
plusCard[i].free = arr[j];
break;
}
}
}
th.setData({
is_plusCard: plusCard, is_show: 1
})
var goods_list = th.selectComponent("#goods_list"); //组件的id
goods_list.get_list();
})
},
//--开通会员---接受前端index,弹起窗口---
Opening: function (e) {
var th = this;
th.data.by_index = e.currentTarget.dataset.ind;
if (th.data.is_fengxiang) {
th.buy_card();
} else {
//--如果后台都没有勾邀请码,营业员,立即购买--
if (!th.data.isyaoqingma && !th.data.is_salesman) {th.buy_card(); return false;}
th.setData({open_yq: 1})
}
},
//--立即购买卡--
buy_card: async function () {
var th = this;
var is_card = 0;
//--商家是不是有等级卡功能,开通的人数是不是够用,开通是时间是不是到期--
await getApp().request.promiseGet("/api/weshop/plus/plus/card/register",
{data: {storeId: os.stoid}}).then(res => {
if (res.data.code == 0) is_card = 1;
})
if (is_card == 0) getApp().my_warnning("请联系商家升级plus功能", 0, th);
var item = th.data.is_plusCard[th.data.by_index];
var req = {};
req.cardId = item.CardId;
req.rechargeType = 3;
//如果不是你导购,也不是等级会员分享
if (th.data.is_fengxiang == 1) {
if (th.data.def_recommon) req.recommon = th.data.def_recommon
if (th.data.def_serviceman) req.serviceman = th.data.def_serviceman
} else {
//---后台要求要输入邀请码---
if (th.data.isyaoqingma) {
if (!th.data.inp_recommon) {
getApp().my_warnning("请输入邀请码", 0, th);
return false;
}
req.recommon = th.data.inp_recommon
}
//--后台要求要输入营业员--
if (th.data.is_salesman) {
if (!th.data.inp_serviceman) {
getApp().my_warnning("请输入营业员", 0, th);
return false;
}
req.serviceman = th.data.inp_serviceman
}
}
req.storeId = os.stoid;
req.userId = getApp().globalData.user_id;
//--如果有邀请码,和营业员的情况下--
if(req.recommon || req.serviceman ) {
var req_data = {storeId: os.stoid, userId: req.userId};
if(req.recommon) req_data.inviteCode=req.recommon;
if(req.serviceman) req_data.staffNo=req.serviceman;
getApp().request.get("/api/weshop/plus/vip/mem/referee/code/check", {
data:req_data,
success:function(res){
if(res.data.code==0) {
t_pay.pay(req, th.success, function () {
getApp().my_warnning("支付失败", 0, th);
});
}else{
getApp().my_warnning("支付失败", 0, th);
}
}
})
}else{
t_pay.pay(req, th.success, function () {
getApp().my_warnning("支付失败", 0, th);
});
}
},
//返回会员页面
OpeningClose: function() {
this.setData({open_yq:0});
},
//返回会员中心
back_user:function () {
setTimeout(function () {
wx.reLaunch({url:"/pages/user/index/index"});
},1000)
},
//--支付成功,跳转到等级卡续费页面--
success:function () {
var u_url="/pages/user/cardinfo/cardinfo";
wx.reLaunch({url:u_url})
},
//--绑定邀请码的输入--
b_input:function (e) {
var value=e.detail.value;
var name=e.currentTarget.dataset.name;
var ob={};
ob[name]=value
this.setData(ob);
}
})