labels.js
8.57 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
var e = getApp(),
a = e.globalData.setting,
os = a,
t = e.request,
d = e.globalData;
Page({
/**
* 页面的初始数据
*/
data: {
url: a.url, //接口网址
interest_lables: [], //兴趣标签
check_label: [], //用户选中的标签集合
user_label_val: "", //奖励多少
user_label_type: "", //奖励类型(1积分,1成长值)
is_modify: 0, //判断是第一次填写还是修改(0填写,1修改)
},
//点击选择兴趣标签把值放到已选中
click_label: function(e) {
var th = this;
var index = e.currentTarget.dataset.index; //选择兴趣标签的下标
var labels = th.data.interest_lables; //兴趣标签数组
var check_label = th.data.check_label; //已选中的数组
var labels_cid = th.data.interest_lables[index].check; //当前标签是否选中
var labels_check = 'interest_lables[' + index + '].check'; //用于点击标签把点击状态赋值进去
if (labels_cid) {
labels_cid = 0;
for (var i = 0; i < check_label.length; i++) {
if (labels[index].id == check_label[i].id) {
check_label.splice(i, 1);
}
}
th.setData({
[labels_check]: labels_cid,
check_label: check_label
})
} else {
if (check_label.length>9){
getApp().my_warnning("最多可选10个哦",0,th);
}else{
var check_new = {
lable: labels[index]
};
labels_cid = 1;
check_label.push(labels[index]);
}
th.setData({
[labels_check]: labels_cid,
check_label: check_label
})
}
},
//获取配置信息
get_config: function() {
var th = this;
getApp().getConfig2(function(ee) {
var sms_conf = ee.switch_list;
sms_conf = JSON.parse(sms_conf);
var getuser_label_type=1;
var getuser_label_val = 0;
if (sms_conf.user_label_type!=undefined)
{
getuser_label_type = parseInt(sms_conf.user_label_type)+1;
}
if (sms_conf.user_label_val != undefined) {
getuser_label_val = sms_conf.user_label_val;
}
th.setData({
user_label_val: getuser_label_val,
user_label_type: getuser_label_type
})
})
},
//页面跳转
goto: function(e) {
var th = this;
wx.navigateBack({ //返回
delta: 1
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
var th = this;
var pages = getCurrentPages();
var prevPage = pages[pages.length - 2]; //上一个页面
//直接调用上一个页面的setData()方法,把数据存到上一个页面中去
prevPage.setData({
is_zy: 1
})
th.query_nolabels();
th.get_config();
},
//获取标签集合
query_nolabels: function() {
var th = this;
var url = "/api/weshop/marketing/holiday/vip/interest/label/page";
var interest_lables = th.data.interest_lables; //兴趣标签集合
getApp().request.promiseGet(url, {
data: {
storeId: a.stoid,
pageSize:50,
page:1
}
}).then(res => {
if (res.data.code == 0) {
th.setData({
interest_lables: res.data.data.pageData
})
th.query_checklabels();
} else {
getApp().my_warnning("系统繁忙,请稍后再试", 0, th);
return false;
}
})
},
//查找会员选择的兴趣标签
query_checklabels: function() {
var th = this;
var url = "/api/weshop/marketing/holiday/vip/interest/label/get";
var interest_lables = th.data.interest_lables; //兴趣标签
getApp().request.promiseGet(url, {
data: {
userId: d.user_id,
storeId: a.stoid
}
}).then(res => {
if (res.data.code == 0) {
var data = res.data.data;
var arr = [];
var VipLabelId = []; //通过id标签找到已选择的标签
var dateList = data.VipLabelId.split(",");
for (var i in dateList) {
VipLabelId = VipLabelId.concat(dateList[i]);
}
if (VipLabelId.length > 0) {
for (var i = 0; i < interest_lables.length; i++) {
for (var ii = 0; ii < VipLabelId.length; ii++) {
if (interest_lables[i].id == VipLabelId[ii]) {
interest_lables[i].check = 1;
arr.push(interest_lables[i]);
}
}
}
}
//如何有之前有选择兴趣标签的话,再进来的话就是修改
if (data.VipLabelId != "") {
th.setData({
is_modify: 1
})
}
th.setData({
check_label: arr,
interest_lables: interest_lables
})
} else {
getApp().my_warnning("系统繁忙,请稍后再试", 0, th);
return false;
}
})
},
//更新会员兴趣标签
update_label: function() {
var th = this;
var is_modify = th.data.is_modify; //是否是修改
var check_label = th.data.check_label; //用户选择
var remark = "领取";
if (is_modify) {
user_label_type = 0;
remark = "修改";
}
if (check_label.length < 1) {
getApp().my_warnning("完成兴趣标签才能" + remark + "哦~", 0, th);
} else {
var user_label_val = th.data.user_label_val; //选择标签奖励多少
var user_label_type = th.data.user_label_type; //赠送类型
var url = "/api/weshop/marketing/holiday/vip/interest/label/update"; //更新标签接口地址
var nav_url = "/pages/user/userinfo/userinfo"; //领取成功之后跳转页面
var vipLabel = ""; //选择的标签名称
var vipLabelId = ""; //选择的标签id
var arr = [];
for (var i = 0; i < check_label.length; i++) {
if (i < check_label.length - 1) {
vipLabelId += check_label[i].id + ",";
vipLabel += check_label[i].LabelName + ",";
arr.push(check_label[i].LabelName);
} else {
vipLabelId += check_label[i].id;
vipLabel += check_label[i].LabelName;
arr.push(check_label[i].LabelName);
}
}
var my_confirm = th.selectComponent("#my_confirm"); //组件的id
remark = "标签赠送";
if (is_modify) {
my_confirm.open(
"确定修改标签?",
"取消",
"确定",
function() {
my_confirm.open_cancel(0);
},
function() {
my_confirm.open_cancel(0);
getApp().request.put(url, {
data: {
"storeId": a.stoid,
"userId": d.user_id,
"vipLabel": vipLabel,
"vipLabelId": vipLabelId,
"type": user_label_type,
"remark": remark,
"value": user_label_val,
"fromType": "REWARD"
},
success: function(res) {
if (res.data.code == 0) {
getApp().my_warnning("修改成功", 1, th);
setTimeout(function() {
var pages = getCurrentPages();
var prevPage = pages[pages.length - 2]; //上一个页面
//直接调用上一个页面的setData()方法,把数据存到上一个页面中去
prevPage.setData({
check_label: arr
})
th.goto();
}, 2000);
} else {
getApp().my_warnning("系统繁忙,请稍后再试", 0, th);
}
}
})
}
)
} else {
getApp().request.put(url, {
data: {
"storeId": a.stoid,
"userId": d.user_id,
"vipLabel": vipLabel,
"vipLabelId": vipLabelId,
"type": user_label_type,
"remark": remark,
"value": user_label_val,
"fromType": "REWARD"
},
success: function(res) {
if (res.data.code == 0) {
getApp().my_warnning("领取成功", 1, th);
setTimeout(function() {
var pages = getCurrentPages();
var prevPage = pages[pages.length - 2]; //上一个页面
//直接调用上一个页面的setData()方法,把数据存到上一个页面中去
prevPage.setData({
check_label: arr
})
th.goto();
}, 2000);
} else {
getApp().my_warnning("系统繁忙,请稍后再试", 0, th);
}
}
})
}
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
}
})