myList.js
7.41 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
import config from '../../common/config';
import api from '../../common/api';
import event from '../../common/event';
import LimitModel from '../../models/limit/index';
import helper from '../../utils/helper';
import wx from '../../utils/wx';
import {Actionsheet} from '../../vendors/zanui/index';
import commonModel from '../../models/common';
import Yas from '../../common/yas';
let app = getApp();
let router = global.router;
let yas;
/**
* method=app.limitProduct.queryHelpInfo(助力信息)
method=app.limitProduct.addhelpUserInfo(添加助力信息)
method=app.drawline.getMyQueueList 获取我的排队列表
*/
Page(Object.assign({
/**
* 页面的初始数据
*/
data: {
actId: 0,
isEnd: 0,
userInfo: {}, // 用户信息
shareInfo: {
default_image: '',
product_name: '',
product_qrCode: '',
product_skn: '',
limitProductCode: ''
},
bgStyle: [ // 排队图片
'../../static/images/limit/queue_bg_1.png',
'../../static/images/limit/queue_bg_2.png',
'../../static/images/limit/queue_bg_3.png',
'../../static/images/limit/queue_bg_4.png',
'../../static/images/limit/queue_bg_5.png',
'../../static/images/limit/queue_bg_6.png',
'../../static/images/limit/queue_bg_7.png',
'../../static/images/limit/queue_bg_8.png'
],
vipImage: [ // 3种用户vip等级小图标
'',
'../../static/images/limit/level-1.png',
'../../static/images/limit/level-2.png',
'../../static/images/limit/level-3.png'
],
defaultAvatar: '../../static/images/icons/default-avatar.png',
api_status: 0, // 用于防止连续点击参加活动 0:没调用接口 1:正在调用接口
giftImage: '../../static/images/limit/gift.png',
hideInviteButton: 1, // 用户显示邀请按钮
queueList: [], // 排队列表
actionSheet: {
componentId: 'shareActionSheet',
show: false,
closeOnClickOverlay: true,
cancelText: '取消',
actions: [{
name: '邀请好友助力',
className: 'action-class',
loading: false,
openType: 'share'
}, {
name: '生成图片分享到朋友圈',
className: 'action-class',
loading: false,
}]
},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
console.log(options);
let actId = options.actId;
let isEnd = options.isEnd || 0;
let uid = app.getUid() || options.uid;
if (actId) {
this.setData({
actId: actId,
isEnd: parseInt(isEnd)
});
this.getQueueList(actId);
for (let i in options) {
options[i] = decodeURIComponent(options[i]);
}
this.setData({
shareInfo: Object.assign(this.data.shareInfo, options)
});
}
yas = new Yas();
yas.pageOpenReport();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function(options) {
console.log(options);
if (app.getUid()) {
this.setData({
hideInviteButton: 0
});
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function(res) {
let params = {
FROM: res.from,
SHARE_RESUIL: 0,
TITLE: decodeURIComponent(this.data.shareInfo.product_name),
DESC: '我在有货限定频道发现一个不错的商品赶快来看看吧!',
PATH: `/pages/product/detail/detail?limitProductCode=${this.data.limitProductCode}&originUid=${app.getUid()}&originUnionID=${app.getUnionID()}`, // eslint-disable-line
IMG: decodeURIComponent(this.data.shareInfo.default_image)
};
// 用户点击右上角分享
return {
title: params.TITLE, // 分享标题
desc: params.DESC, // 分享描述
path: params.PATH, // 分享路径
imageUrl: params.IMG,
success: function() {
params.SHARE_RESUIL = 1;
},
fail: function() {
params.SHARE_RESUIL = 2;
}
};
},
share: function() {
this.setData({
'actionSheet.show': true
});
},
handleZanActionsheetCancel() {
this.setData({
'actionSheet.show': false
});
},
// 当行动按钮中有一个被点击时触发
// index 代表被点击按钮在传入参数 actions 中的位置
handleZanActionsheetClick({index}) {
this.setData({
'actionSheet.show': false
});
let uid = this.data.originUid || this.data.uid;
if (index === 1) {
router.go('snapShare', this.data.shareInfo);
}
},
/**
* 邀请好友助力排队按钮
*/
inviteFriends: function(e) {
this.share();
},
/**
* 提交formId消息模板
*/
submitFormId: function(e) {
console.log('submitFormId:', {formId: e.detail.formId, uid: app.getUid() || 0, openId: app.getOpenID() || ''});
commonModel.addWechatFormId({
formId: e.detail.formId,
uid: app.getUid() || 0,
openId: app.getOpenID() || '',
miniapp_type: app.getMiniappType()
});
},
/**
* 获取排队列表
*/
getQueueList: function(actId, limit = 20) {
let that = this;
return LimitModel.getMyQueueList(actId, limit).then(res => {
console.log(res);
if (res.data && res.data.length > 0) {
let result = [];
let helpIndex = 0;
if (res.data[0].helpName && res.data[0].helpheadIco) {
result.push({
helpInfo: '好友"' + res.data[0].helpName + '"已为你助力',
background: helper.imgView(this.data.bgStyle[0], 340, 162, 1),
helpName: res.data[0].helpName,
helpheadIco: res.data[0].helpheadIco
});
helpIndex = 1;
}
res.data.forEach((item, index) => {
if (!item.headIco) {
item.headIco = that.data.defaultAvatar;
} else {
item.headIco = helper.image(item.headIco, 100, 100, 1);
}
item.nickName = item.nickName || '用户' + item.uid;
item.nickName = item.nickName.length > 12 ? item.nickName.substring(0, 12) + '...' : item.nickName;
item.queueTime = this.formatTimeText(item.queueTime);
item.vipLevel = item.vipLevel || 0;
item.vipImage = this.data.vipImage[item.vipLevel];
let bgStyle = this.data.bgStyle;
let bgIndex = (index + helpIndex) % bgStyle.length;
item.background = helper.imgView(bgStyle[bgIndex], 340, 162, 1);
result.push(item);
});
this.setData({
queueList: result
});
return Promise.resolve({code: 200, data: this.data.queueList});
} else {
return Promise.reject({code: 203, message: '获取失败'});
}
});
},
formatTimeText: function(time) {
let new_time;
if (time < 60) {
new_time = time + 'sec';
} else if (time >= 60 && time < 60 * 60) {
new_time = parseInt(time / 60, 10) + 'min';
} else if (time >= 60 * 60 && time < 60 * 60 * 24) {
new_time = parseInt(time / (60 * 60), 10) + 'hour';
} else if (time >= 60 * 60 * 24) {
new_time = parseInt(time / (60 * 60 * 24), 10) + 'day';
}
return new_time;
}
}, Actionsheet));