friend_assistance.js
5.74 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
var auth = require("../../../utils/auth.js"),
rq = require("../../../utils/request.js");
var e = getApp(),
app = e,
s = e.globalData.setting,
os = s,
app_d = e.globalData;
var regeneratorRuntime = require('../../../utils/runtime.js');
var ut = require("../../../utils/util.js");
Page({
/**
* 页面的初始数据
*/
data: {
iurl: s.imghost,
is_show: 0, //显示弹框
user: app_d.userInfo,
zl_act: null, //助力活动
tasking: 0, //助力任务ID
userId: 0, //任务用户的ID
s_num: 0, //分享的人数
taskId:0, //活动从表ID
helpId:0,
invalidTime:0, //任务失效时间戳
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
console.log('助力——————————————————————————————');
console.log(options);
var th = this;
var nav_b = th.selectComponent("#nav_b"); //组件的id
nav_b.set_name("助力", "/pages/user/assistance/assistance");
if (options.tasking) this.data.tasking = options.tasking;
if (options.userId) this.data.userId = options.userId;
//任务是不是为空
if (this.data.tasking == 0 || this.data.tasking == undefined) {
this.data.tasking = decodeURIComponent(options.scene);
}
},
// 跳转到助力首页,我也要参加
participate_activity: function() {
wx.navigateTo({
url: '/pages/user/assistance/assistance',
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
getApp().check_can_share();
//--先判断会员状态--
var user_info = getApp().globalData.userInfo;
if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
getApp().goto('/packageE/pages/togoin/togoin');
return false;
}
var th=this;
if (!th.data.user) th.setData({ user: getApp().globalData.userInfo});
if (this.data.tasking != null && this.data.tasking != 'undefined' && this.data.tasking != "" && this.data.tasking !=
0) {
getApp().request.promiseGet("/api/weshop/marketing/help/help/tasking/get", {
data: {
taskingId: th.data.tasking,
storeId: os.stoid
}
}).then(res => {
console.log('任务时间-------------------------');
console.log(res);
if (res.data.code == 0) {
th.data.userId = res.data.data.userId;
th.data.taskId = res.data.data.helpTaskId;
th.data.helpId=res.data.data.helpFormId;
// th.invalidTime = res.data.data.invalidTime
// th.setData({
// invalidTime:1662138310
// })
let openTime = res.data.data.openTime
th.getInvalidTime(openTime)
//获取活动的时间
return getApp().request.promiseGet("/api/weshop/marketing/help/help/act/get", {
data: {
helpId: res.data.data.helpFormId,
storeId: os.stoid
}
})
}
return ut.null_promise();
}).then(res => {
if (res.data.code == 0) {
th.setData({
zl_act: res.data.data
})
//获取活动的参与的人数
return getApp().request.promiseGet("/api/weshop/marketing/help/involve/help/act/people/count", {
data: {
helpId: res.data.data.id,
storeId: os.stoid,
taskId:th.data.taskId,
}
})
}
return ut.null_promise();
}).then(res => {
if (res && res.data && res.data.code == 0) {
th.setData({
s_num: res.data.data.countAll
});
}
})
}
},
getInvalidTime(openTime=0){
let th = this
rq.get("/api/weshop/marketing/giftbag/helpinfo/get", {
data: {
storeId: os.stoid,
// userId: user_id,
taskId: th.data.taskId,
helpId:th.data.helpId
},
success: function (res) {
console.log('获取失效时间------');
console.log(res);
if (res.data.code == 0) {
let validTime=res.data.data.validTime
let invalidTime =0
if (openTime && validTime > 0) {
invalidTime = openTime*1 + validTime*60*60
}
th.setData({
invalidTime
});
}
}
})
},
//点击开启礼盒
cklie_button: function() {
//判断任务是否失效
let invalidTime = this.data.invalidTime
let nowTime = parseInt((new Date().getTime())/1000)
if (invalidTime > 0) {
let disTime = invalidTime - nowTime
if (disTime <=0) {
getApp().showWarning("该任务已失效");
return
}
}
var th = this;
//--先判断会员状态--
var user_info = getApp().globalData.userInfo;
if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
wx.navigateTo({
url: '/packageE/pages/togoin/togoin',
})
return false;
}
var t_user_id = app_d.user_id;
var data = {
id: this.data.tasking,
storeId: os.stoid,
userId: this.data.userId,
zlUserId: t_user_id,
isWeappUser:1, //是不是小程序的入口,不需要判断
};
console.log(data);
getApp().request.json_post("/api/weshop/marketing/help/help/task/involve/insert",
data, //入参
function(res) { //成功
if (res.data.code == 0)
th.setData({
is_show: 1
});
else {
getApp().my_warnning(res.data.msg, 0, th)
}
},
function() { //失败
}
)
},
//点击关闭礼盒
clike_none: function() {
this.setData({is_show: 0});
getApp().goto("/pages/user/assistance/assistance_success?helpid="+this.data.helpId+"&taskId="+this.data.taskId);
},
//导航球
close: function() {
var th = this;
var nav_b = th.selectComponent("#nav_b"); //组件的id
nav_b.close_box();
nav_b.set_name("助力", "/pages/user/assistance/assistance");
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
getApp().globalData.no_clear=1;
},
})