detail.js
14.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
423
424
425
426
427
428
// 逛文章详情
import api from '../../common/api.js';
import guangUtil from './util';
import Promise from '../../vendors/es6-promise';
import util from '../../utils/util';
import WxParse from '../../vendors/wxParse/wxParse';
import config from '../../config';
// import {
// logEvent,
// YB_PAGE_OPEN_L,
// } from '../../../../libs/analytics.js'
const { Actionsheet, extend } = require('../../vendors/zanui/index');
import { getQRCodeSource } from '../../utils/miniQRCodeRoute.js'
// import { jumpByUrl } from '../../../../libs/urlRoute';
// import { getUnionID } from '../../../../utils/login';
//获取应用实例
let app = getApp();
let PV_ID = new Date().getTime() + '';
const screenHeight = app.globalData.systemInfo.screenHeight;
const windowWidth = app.globalData.systemInfo.windowWidth;
const windowHeight = app.globalData.systemInfo.windowHeight;
Page(extend({}, Actionsheet, {
data: {
options: {},
windowHeight: windowHeight,
screenHeight: screenHeight - 60,
isShowIndicator: false,
yasParam: '',
from_page_name: '',
from_page_param: '',
current_page_name: 'guangDetail',
current_page_param: '',
replyTemArray: [],
articleInfo: {},
authorInfo: {},
articleContent: {},
brands: [],
otherArticles: [],
page: 0,
end: false,
actionsheet: {
componentId: 'shareActionSheet',
show: false,
closeOnClickOverlay: true,
cancelText: '取消',
isNewShareStyle:true,
unionUserImageUrl:'',
actions: [{
name: '分享给好友',
className: 'action-class',
loading: false,
openType: 'share',
image_src: '../../../../images/share_wechat@2x.png'
},
{
name: '生成海报分享',
className: 'action-class',
loading: false,
image_src: '../../../../images/share_wxpeng@2x.png'
}]
},
isShowSnapshoot: false,
snapshootShareData: {},
},
onLoad: function(options) {
if (options && options.scene && options.scene.length == 32) {
getQRCodeSource(options.scene).then(json => {
if (json) {
this.loadElement(json);
}
})
.catch(error => {
});
} else {
this.loadElement(options);
}
},
onShareAppMessage: function (res) {
let param = {
FROM: res.from,
SHARE_RESUIL: 0,
TITLE: this.data.articleInfo.article_title || '潮流有货逛不停',
imageUrl: this.data.articleInfo.cover_image && util.formatImageUrl(this.data.articleInfo.cover_image, 750, 480),
DESC: '我在有货发现一篇不错的文章赶快来看看吧!',
PATH: './detail?id=' + this.options.id,
}
if (app.globalData.user_union_type) {
param.PATH += '&union_type=' + app.globalData.user_union_type
}
return {
title: param.TITLE, // 分享标题
imageUrl: param.imageUrl,
desc: param.DESC, // 分享描述
path: param.PATH , // 分享路径
success: function (res) {
},
fail: function (res) {
}
}
},
loadElement: function(options) {
this.setData({
options,
yasParam: `&page_name=${this.data.current_page_name}&page_param=${options.id || ''}`,
current_page_param: options.id || '',
from_page_name: options.page_name || '',
from_page_param: options.page_param || '',
});
//解析 渠道号
let unionType = options.union_type ? options.union_type : '';
if (unionType) {
app.updateUnionType(unionType);
}
this._init();
var pages = getCurrentPages();
var currentPage = pages[pages.length - 1];
// var url = currentPage.route;
// let params = {
// PAGE_NAME: this.data.current_page_name,
// PAGE_PARAM: this.data.current_page_param,
// FROM_PAGE_NAME: this.data.from_page_name,
// FROM_PAGE_PARAM: this.data.from_page_param,
// PV_ID: PV_ID,
// PAGE_PATH: url,
// };
// logEvent(YB_PAGE_OPEN_L, params);
this._initActionSheet()
},
share: function(event){
this.setData({
'actionsheet.show': true
})
},
handleZanActionsheetCancel({ componentId }) {
this.setData({
'actionsheet.show': false
})
},
handlerJumpToUnionUrl(){
this.setData({
'actionsheet.show': false
})
if (app.globalData.user_union_type){
jumpByUrl("https://activity.yoho.cn/feature/2213.html?title=说明详情&openby:yohobuy={\"action\":\"go.h5\",\"params\":{\"title\":\"说明详情\",\"url\":\"https://activity.yoho.cn/feature/2213.html\"}}", this.data.current_page_name)
} else if (app.globalData.userInfo.uid){
jumpByUrl("https://activity.yoho.cn/feature/2601.html?title=有货有赚&openby:yohobuy={\"action\":\"go.h5\",\"params\":{\"title\":\"有货有赚\",\"url\":\"https://activity.yoho.cn/feature/2601.html\"}}", this.data.current_page_name)
}else{
//未登录 状态去登录
this.loginAndRegisterTapped()
}
},
//跳转到登录页面
loginAndRegisterTapped:function(needBind) {
// let app = getApp()
// if(tt.getSetting){
// tt.getSetting({
// success: (res) => {
// if (res && res.authSetting && res.authSetting["scope.userInfo"] !== null && res.authSetting["scope.userInfo"] !== undefined && res.authSetting["scope.userInfo"] === false) {
// tt.showModal({
// title: '',
// content: '检测到您未打开微信用户信息授权,开启后即可进行登录',
// confirmText: "去开启",
// confirmColor: "#000000",
// success: function (res) {
// if (res.confirm) {
// tt.openSetting({
// success: (res) => {
// // console.log(res.authSetting["scope.userInfo"])
// if (res.authSetting["scope.userInfo"] !== null && res.authSetting["scope.userInfo"] !== undefined && res.authSetting["scope.userInfo"] === true) {
// getUnionID(app.getWechatThirdSession(), function (response) {
// // console.log(response)
// })
// }
// }
// })
// } else {
// tt.navigateTo({
// url: '/pages/bindPhoneNumber/bindPhoneNumber',
// })
// }
// }
// })
// } else {
// tt.navigateTo({
// url: '/pages/bindPhoneNumber/bindPhoneNumber',
// })
// }
// }
// })
// } else {
// tt.showModal({
// title: '提示',
// content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
// })
// }
},
// 当行动按钮中有一个被点击时触发
// index 代表被点击按钮在传入参数 actions 中的位置
handleZanActionsheetClick({ componentId, index }) {
this.setData({
'actionsheet.show': false
})
if (index === 1) {
this.setData({
isShowSnapshoot: true
})
}
},
hiddenSheet: function () {
this.setData({
isShowSnapshoot: false
})
},
_initActionSheet: function() {
let actionsheet = this.data.actionsheet;
//user_union_type 有值 需要显示 联盟share按钮
if (app.globalData.user_union_type) {//user_union_type_imageUrl
let actionsheetParam = [
{
name: '分享给朋友',
className: 'action-class',
loading: false,
openType: 'share',
image_src: '../../../../images/share_union_wechat@2x.png'
},
{
name: '生成海报分享',
className: 'action-class',
loading: false,
image_src: '../../../../images/share_union_wxpeng@2x.png'
}
];
actionsheet.unionUserImageUrl = app.globalData.user_union_type_imageUrl
actionsheet.actions = actionsheetParam;
} else if (app.globalData.userInfo.uid) {
//登录状态
actionsheet.unionUserImageUrl = app.globalData.user_nounion_type_imageUrl
}
this.setData({
actionsheet
})
},
_init: function() {
return Promise.all([
this._getArticleExec(),
this._getArticleContentExec(),
this._getBrandExec(),
this._getShareDate()
]).then(result => {
return Promise.all([
this._getAuthorExec(result[0].author_id),
this._recomandLi(result[1]),
this._getOtherArticleExec(result[0].tag)
]);
});
},
_getShareDate: function() {
return guangUtil._getShareDate({
id: this.data.options.id
}).then(res => {
if (res) {
let page_param = this.data.options;
let guang_qrCode = '';
if (app.globalData.user_union_type) {
page_param.union_type = app.globalData.user_union_type;
}
guang_qrCode = config.domains.api + '/wechat/miniapp/img-check.jpg?param=' + (JSON.stringify(page_param)) + '&miniapp_typ=0&miniQrType=18';
this.setData({
snapshootShareData: {
cover_image: res.pic,
article_title: res.title,
guang_qrCode,
id: this.data.options.id,
tag: res.minSortName
}
});
}
return res;
});
},
_getArticleExec: function() {
return guangUtil._getArticle({
article_id: this.data.options.id
}).then(rdata => {
if (rdata.author_id) {
tt.setNavigationBarTitle({title: rdata.article_title || '文章详情'});
this.setData({articleInfo: rdata});
}
return rdata;
});
},
_getArticleContentExec: function() {
return guangUtil._getArticleContent({
article_id: this.data.options.id
}).then(rdata => {
rdata = guangUtil._processArticleDetail(rdata);
rdata.replyTexts.map((text, tindex) => {
WxParse.wxParse('reply' + tindex, 'html', text, this, 0);
if (tindex === rdata.replyTexts.length - 1) {
WxParse.wxParseTemArray("replyTemArray", 'reply', rdata.replyTexts.length, this);
}
});
let replyTemArray = this.data.replyTemArray;
rdata.finalDetail.map(item => {
if (item.text) {
item.wxText = replyTemArray.shift();
}
});
this.setData({articleContent: rdata, replyTemArray: []});
return rdata;
});
},
_getAuthorExec: function(author_id) {
return guangUtil._getAuthor({
author_id: author_id
}).then(rdata => {
if (rdata.avatar) {
rdata.avatar = util.formatImageUrl(rdata.avatar, 80, 80);
}
this.setData({authorInfo: rdata});
return rdata;
});
},
_recomandLi: function(data) {
return guangUtil._recomandLi({skns: data.allGoods}).then(rdata => {
data.finalDetail = guangUtil._pushGoodsInfo(data.finalDetail, rdata.product_list);
this.setData({articleContent: data});
});
},
_getBrandExec: function() {
return guangUtil._getBrand({
article_id: this.data.options.id
}).then(rdata => {
rdata.map(item => {
if (item.thumb) {
item.thumb = util.formatImageUrl(item.thumb.replace(/\?(.*)/, ''), 160, 80, 1);
}
});
this.setData({brands: rdata});
return rdata;
});
},
_getOtherArticleExec: function(tag) {
return guangUtil._getOtherArticle({
article_id: this.data.options.id,
tags: tag || ''
}).then(rdata => {
rdata.map(item => {
if (item.thumb) {
item.thumb = util.formatImageUrl(item.thumb, 240, 150, 1);
}
});
this.setData({otherArticles: rdata});
return rdata;
});
},
setGoodsMore: function(event) {
let data = event.currentTarget.dataset;
let findex = data.findex || 0;
let flen = data.flen || 0;
let articleContent = this.data.articleContent;
articleContent.finalDetail[findex].relatedReco.moreNum = flen;
this.setData({articleContent: articleContent});
},
onPageScroll: function(event) {
var { scrollTop } = event;
var isShow = scrollTop > windowHeight * 2 ? true : false;
if (isShow != this.data.isShowIndicator) {
this.setData({
isShowIndicator: isShow
});
}
},
backToTop: function () {
tt.pageScrollTo({
scrollTop: 0,
});
},
clickCartIcon: function(event) {
// console.log('cartIcon')
},
productCellTapped: function(event) {
let data = event.currentTarget.dataset;
let skn = data.skn;
if (!skn) {
return;
}
tt.navigateTo({
url: `/pages/goodsDetail/goodsDetail?productSkn=${skn}&${this.data.yasParam}`
});
},
}));