assistance.js
6.52 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
var t = getApp(),
a = t.request,
o = t.globalData.setting,
os = o,
i = require("../../../utils/util.js"),
ut = i,
s = require("../../../utils/common.js");
var regeneratorRuntime = require('../../../utils/runtime.js');
var oo = t.globalData.setting,
os = oo,
ut = require("../../../utils/util.js");
Page({
/**
* 页面的初始数据
*/
data: {
url: os.url, //接口网址
iurl: os.imghost, //图片前缀网址
switch_head: 0, //0:我的任务,1:活动说明
zl_act: null, //助力活动
zl_user_list: [], //任务列表
is_load: 0, //是否已经加载
cur_page: 1, //页码
page_num: 5, //每页多少个
is_show_more: 0, //是否加载更多
help_id: "", //助力活动的id
timer: "", //任务列表的定时器
s_num: "", //多少人已经领取任务
page: 1, //我的任务的当前页
imageUrl:'',
btn_color:'',
bg_color:'',
font_color:'',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
var th = this;
var nav_b = th.selectComponent("#nav_b"); //组件的id
nav_b.set_name("助力", "/pages/user/assistance/assistance");
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
//--先判断会员状态--
var user_info = getApp().globalData.userInfo;
if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
getApp().goto('/pages/togoin/togoin');
return false;
}
var th = this;
// 助力活动
this.assistance();
},
print() {
var user_id = getApp().globalData.user_id;
var store_id = os.stoid;
getApp().request.promiseGet("/api/weshop/marketing/help/act/judge", {
data: {
storeId: store_id,
userId: user_id
}
}).then(res => {
console.log('res', res);
});
},
// 助力活动
assistance() {
var th = this;
var user_id = getApp().globalData.user_id;
var store_id = os.stoid;
getApp().request.promiseGet("/api/weshop/marketing/help/act/judge", {
isShowLoading: true,
data: {
storeId: store_id,
userId: user_id
}
}).then(res => {
if (res.data.code == 0) {
var help_data = res.data.data;
help_data.remark = help_data.remark.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block"');
th.setData({
zl_act: help_data,
help_id: help_data.id,
btn_color: help_data.btn_color,
bg_color: help_data.bg_color,
font_color: help_data.font_color,
imageUrl: help_data.imageUrl,
});
if (th.data.help_id != "" && th.data.help_id != null) {
//我的任务
th.get_list();
}
return getApp().request.promiseGet("/api/weshop/marketing/help/involve/help/act/people/count", {
isShowLoading: true,
data: {
helpId: help_data.id,
storeId: store_id
}
})
}else
getApp().my_warnning("暂无此活动或您不符合商家设置的会员参与对象,无法参与!", 0, th);
return ut.null_promise();
}).then(res => {
if ( res && res.data &&res.data.code == 0)
th.setData({
s_num: res.data.data.countAll
})
})
},
//--点击获取用户任务列表--会员的任务列表
get_list: function() {
var th = this;
var page = th.data.page;
if(page==1)th.data.zl_user_list=[];
var help_id = this.data.help_id;
var r=Math.random()*100;
t.request.get("/api/weshop/marketing/help/help/user/page", {
isShowLoading: true,
data: {
userId: getApp().globalData.user_id,
storeId: os.stoid,
helpId: help_id,
page: page,
pageSize: 5,
r:r,
},
success: function(res) {
clearTimeout(th.data.timer);
if (!th.data.is_load)
th.setData({
is_load: 1
})
if (res.data.code == 0) {
var list = th.data.zl_user_list;
//连接数组
list = list.concat(res.data.data.pageData);
th.setData({
zl_user_list: list,
is_load: 1,
});
if (res.data.data.total <= 5) {
th.setData({
is_show_more: 1
})
} else {
var page = th.data.page + 1;
th.setData({
is_show_more: 0,
page: page
})
}
} else {
//getApp().my_warnning(res.data.msg, 0, th);
th.setData({
is_show_more: 1,
page: page
})
}
}
})
},
//-----跳转到领取礼包的页面------
go_task: function() {
var th = this;
var help_id = th.data.help_id;
if (!help_id){
getApp().my_warnning("暂无此活动或您不符合商家设置的会员参与对象,无法参与!", 0, th);
return false;
}
getApp().goto("/pages/user/assistance/task_assistance?help_id=" + help_id);
},
switch_head: function(e) {
var th = this;
var index = e.currentTarget.dataset.index; //获取当前选择的是任务还是活动说明
var switch_head = th.data.switch_head; //0任务,1活动说明
if (index != switch_head) {
th.setData({
switch_head: index
})
}
},
//关闭导航
close: function() {
var th = this;
var nav_b = th.selectComponent("#nav_b"); //组件的id
nav_b.close_box();
},
// 领取礼包
get_libao: function(e) {
var help_id = e.currentTarget.dataset.help_id;//活动id
var taskId = e.currentTarget.dataset.taskid;//任务id
var id = e.currentTarget.dataset.id;//用于跳到礼包详情一键全部领取用的任务id
getApp().goto("/pages/user/assistance/giftpacklist?help_id=" + help_id + "&is_libao=" + 1 + "&taskId=" + taskId+"&id="+id);
},
//查看礼包id
select_libao: function(e) {
var orderSn = e.currentTarget.dataset.ordersn; //订单号
getApp().goto("/pages/user/assistance/giftpacklist?orderSn=" + orderSn);
},
//---查看任务---
go_to_task:function (e) {
var help_id = this.data.help_id;
var taskid=e.currentTarget.dataset.taskid;
getApp().goto("/pages/user/assistance/task_assistance?help_id=" + help_id+"&taskid="+taskid);
},
onShareAppMessage(res) {
if (res.from === 'button') {
// 来自页面内转发按钮
console.log(res.target)
}
return {
// title: '自定义转发标题',
}
},
onShareTimeline() {
return {
title: '好友助力-' + getApp().globalData.config.store_name,
}
},
})