detail.js
13.2 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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
// pages/activity/detail/detail.js
const app = getApp();
var t = null;
Page({
/**
* 页面的初始数据
*/
data: {
current_swiper:0,
slide: [],
peopleList: [],
num:1,
actEndTimeList: [],
is_zan:false,
display:false,
content:'',
is_ask:false,
is_reply:false,
placeholder:'输入您的留言'
},
//查看我的订单
goMyRelease() {
wx.redirectTo({url:'/pages/order/order-detail/order-detail?id=' + this.data.order_id})
},
//完成按钮
goBack() {
wx.redirectTo({url:'/pages/spell-list/spell-list?current=' + 0})
},
// 问一问
ask(e) {
console.log('前问一问-display', this.data.display);
this.setData({
display: !this.data.display,
is_ask:true,is_reply:false,
content:'' ,
placeholder:'输入您的留言',
});
console.log('后问一问-display', this.data.display);
// wx.navigateTo({
// url: '/pages/comment/comment?activity_id=' + this.data.detail_id
// + '&common_id=' + 0
// })
// console.log('问',e.detail.value);
// this.setData({focus:true})
},
//输入评论内容
inputComment(e) {
this.setData({ content: e.detail.value });
},
//发送评论/回复
clickComment() {
this.setData({ display: false });
if(this.data.content === '' ) {
wx.showToast({title:'请输入内容',icon:'none'})
}else {
let url = '/portal/Active/common';
let params = {
token:wx.getStorageSync('token'),
activeId:this.data.detail_id,
commonId: this.data.is_ask?0:this.data.commet_id,
content:this.data.content,
};
app.post(url,params,{}).then((res)=>{
console.log('提交评论',res);
if(+res.code === 1) {
wx.showToast({title:this.data.is_ask?'留言成功':'回复成功',icon:'none',});
this.getDetail();
}
})
}
},
//评论input失去焦点
blur() {
this.setData({ display: false });
},
//点击键盘上的完成
confirm() {
this.setData({ display: false });
this.clickComment();
},
//回复
reply(e) {
const id = e.currentTarget.dataset.id;
this.setData({
display: !this.data.display,
is_ask:false,is_reply:true,
commet_id:id,content:'' ,
placeholder:'输入您的回复'
});
// wx.navigateTo({
// url: '/pages/comment/comment?is_reply=' + true
// + '&activity_id=' + this.data.detail_id + '&common_id=' + id
// })
},
//收藏/取消收藏
collect() {
console.log('收藏');
let self = this;
let url = '/portal/Active/collection';
let url_del = '/portal/Active/delCollection';
let header = {
"XX-Token": wx.getStorageSync('token')
};
let params = {
token: wx.getStorageSync('token'),
activeId: self.data.detail_id,
};
if(self.data.is_collect) {
app.post(url_del, params, header).then((res) => {
console.log('取消收藏',res);
if(+res.code === 1) {
wx.showToast({title:res.message,icon:'none'});
self.setData({
is_collect: 0
});
}
})
}else {
app.post(url, params, header).then((res) => {
console.log('收藏',res);
if(+res.code === 1) {
wx.showToast({title:res.message,icon:'none'});
self.setData({
is_collect: 1
});
}
})
}
},
//点赞
clickZan(e) {
let self = this;
const id = e.currentTarget.dataset.id;
const index = e.currentTarget.dataset.index;
let url = '/portal/Active/perfect';
let header = {
"XX-Token": wx.getStorageSync('token')
};
let params = {
token: wx.getStorageSync('token'),
commonId: id,
};
app.post(url, params, {}).then((res) => {
console.log('点赞', res);
if (+res.code === 1) { //
wx.showToast({title:res.message,icon:'none'});
self.setData({
[`commentList[${index}].is_prefect`]: true,
[`commentList[${index}].prefect`]: res.message == '该评论已赞'?+self.data.commentList[index].prefect:+self.data.commentList[index].prefect + 1,
});
// console.log('paise_user', paise_user);
}
})
},
swiperChange(e) {
// console.log(e);
this.setData({current_swiper: e.detail.current})
},
onPageScroll(e) {
// console.log('页面滚动', e);
if(e.scrollTop > 140) {
this.setData({hidden_top:true})
}else if(e.scrollTop <=140){
this.setData({hidden_top:false})
}
},
// 增加数量
addCount(e) {
// let k = e.currentTarget.dataset.idx;
// let t = e.currentTarget.dataset.children_idx;
// let cartslist = this.data.cartslist;
// let num = cartslist[k].children[t].num;
// let product_id = cartslist[k].children[t].product_id;
let num = this.data.num;
num ++;
this.setData({
num: num
});
},
// 减少数量
minusCount(e) {
let num = this.data.num;
if (num <= 1) {
return false;
}
num --;
this.setData({
num: num
});
},
//获取详情
getDetail() {
const self = this;
console.log('city',self.data.city);
let url = '/portal/Active/mealDetail';
let params = {
token:wx.getStorageSync('token'),
activeId: self.data.detail_id,
};
let header = {
"token": wx.getStorageSync('token')
};
app.post(url, params, {}).then((res) => {
console.log('获取详情', res);
if (+res.code === 1) {
self.setData({
detail: res.data.active,
'detail.time': app.initTime(res.data.active.surplus),
end_time: res.data.active.time,
over_hours:res.data.active.over_time,//几小时截止
join_people: res.data.son,
commentList:res.data.common,
is_collect:res.data.is_collect,
count:res.data.count,
});
// self.countDown();
// (0全部,2待处理,4已拼成,5已取消,6已完成
// let newTime = new Date().getTime();//当前时间戳
// let end_time = app.nextTime(this.data.end_time, this.data.over_hours);//截止时间
// let endTime = new Date(end_time).getTime(); //截止时间戳
// if (endTime - newTime > 0) {}
const status = res.data.active.status;
if(status ===2 || status ===4 || status ===6 || status ===7) {
console.log('调用倒计时');
self.countDown();
}else {
console.log('不调用倒计时');
let countDownArr = [];
let obj = null;
obj = {
day: '00',
hou: '00',
min: '00',
sec: '00'
};
countDownArr.push(obj);
this.setData({
'detail.time': countDownArr,
});
}
}
// wx.hideLoading()
})
},
//确认拼餐
confirmJoin(e) {
const self = this;
let url = '/portal/Active/join';
let params = {
token: wx.getStorageSync('token'),
number: self.data.num,
activeId: self.data.detail_id,
formId: e.detail.formId,
};
let header = {
"token": wx.getStorageSync('token')
};
app.post(url, params, {}).then((res) => {
console.log('确认拼餐', res);
if (+res.code === 1) {
// wx.showToast({title:'拼餐成功',icon:'success'});
self.setData({is_showRelease_modal:true,order_id:+res.data.orderId});
self.getDetail();
}
})
},
timeFormat(param) { //小于10的格式化函数
return param < 10 ? '0' + param : param;
},
time() {
const self = this;
self.data.detail.surplus--;
//定時器,每秒重新計算
// setTimeout(function () {
// self.time();
// },1000)
},
countDown() { //倒计时函数
t = setTimeout(this.countDown, 1000);
let countDownArr = [];
let obj = null;
if (this.data.detail.surplus > 0) { //未结束
this.time();
// console.log('surplus', this.data.detail.surplus);
// t = setTimeout(this.countDown, 1000);
const time = app.initTime(this.data.detail.surplus);
// console.log('time', time);
obj = {
hou: time[0].hou,
min: time[0].min,
sec: time[0].sec
};
t;
// this.setData({'detail.time': app.initTime(this.data.detail.surplus),})
} else {
obj = {
day: '00',
hou: '00',
min: '00',
sec: '00'
};
clearTimeout(t);
this.end();
}
countDownArr.push(obj);
// 渲染,然后每隔一秒执行一次倒计时函数
this.setData({
// countDownList: countDownArr,
'detail.time': countDownArr,
});
// console.log('time',this.data.detail.time);
},
//倒计时结束
end() {
const self = this;
let url = '/portal/Active/activity';
let params = {
activeId: self.data.detail_id,
};
let header = {
"token": wx.getStorageSync('token')
};
app.post(url, params, {}).then((res) => {
console.log('倒计时结束', res);
if (+res.code === 1) {
// wx.showToast({title:'拼活动结束',icon:'success'})
}
})
},
//导航
getNavigate() {
const self = this;
const arr = self.data.detail.latng.split(',');
console.log('arr',arr,arr[0],arr[1]);
wx.openLocation({//使用微信内置地图查看位置。
latitude: +arr[0],//要去的纬度-地址
longitude: +arr[1],//要去的经度-地址
// lat:39.086437,
// lng:117.122583,
name: self.data.detail.address,
address: self.data.detail.address
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log('详情options', options);
this.setData({detail_id:+options.id?+options.id:''});
},
onShareAppMessage: function() {
let self = this;
// 设置菜单中的转发按钮触发转发事件时的转发内容
var shareObj = {
title: '火柴西路', // 默认是小程序的名称(可以写slogan等)
path: '', // 默认是当前页面,必须是以‘/’开头的完整路径
imageUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
success: function(res) {
if (res.errMsg == 'shareAppMessage:ok') {}
},
fail: function() {
// 转发失败之后的回调
if (res.errMsg == 'shareAppMessage:fail cancel') {
// 用户取消转发
} else if (res.errMsg == 'shareAppMessage:fail') {
// 转发失败,其中 detail message 为详细失败信息
}
},
complete: function() {
// 转发结束之后的回调(转发成不成功都会执行)
}
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.getDetail();
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
clearTimeout(t)
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
})