|
|
import api from '../../common/api.js';
|
|
|
import { parseBrandListData } from '../../utils/productListUtil';
|
|
|
import { shouldDiscardTap } from '../../utils/util';
|
|
|
import queryString from '../../vendors/query-string';
|
|
|
const { Actionsheet, extend } = require('../../vendors/zanui/index');
|
|
|
import { getQRCodeSource } from '../../utils/miniQRCodeRoute.js'
|
|
|
// import { jumpByUrl } from '../../libs/urlRoute';
|
|
|
// import {
|
|
|
// logEvent,
|
|
|
// YB_PAGE_OPEN_L,
|
|
|
// YB_SHARE_RESULT_L
|
|
|
// } from '../../libs/analytics.js'
|
|
|
|
|
|
//获取应用实例
|
|
|
let app = getApp();
|
|
|
|
|
|
const screenHeight = app.globalData.systemInfo.screenHeight;
|
|
|
const windowWidth = app.globalData.systemInfo.windowWidth;
|
|
|
const windowHeight = app.globalData.systemInfo.windowHeight;
|
|
|
|
|
|
let PV_ID = new Date().getTime() + '';
|
|
|
|
|
|
Page(extend({}, Actionsheet,{
|
|
|
data:{
|
|
|
lastTapTimeStamp: 0,
|
|
|
|
|
|
screenHeight,
|
|
|
windowHeight,
|
|
|
from_page_name: '',
|
|
|
from_page_param: '',
|
|
|
current_page_name: 'goodsList',
|
|
|
current_page_param: '',
|
|
|
|
|
|
title: '',
|
|
|
page_param: {},
|
|
|
origin_param: {},
|
|
|
|
|
|
list: {
|
|
|
isLoading: false,
|
|
|
error: null,
|
|
|
data: null,
|
|
|
pageSize: 60,
|
|
|
currentPage: 0,
|
|
|
pageCount: 0,
|
|
|
total: 0,
|
|
|
endReached: false,
|
|
|
},
|
|
|
|
|
|
isShowIndicator: false,
|
|
|
scrollTop: 0,
|
|
|
filterStorageKey: '',
|
|
|
isUnionShare: false,
|
|
|
msort: '',
|
|
|
misort: '',
|
|
|
sort: '',
|
|
|
|
|
|
isShowSnapshoot: false,
|
|
|
snapshootShareData: {},
|
|
|
|
|
|
actionsheet: {
|
|
|
componentId: 'shareActionSheet',
|
|
|
show: false,
|
|
|
closeOnClickOverlay: true,
|
|
|
isNewShareStyle: true,
|
|
|
cancelText: '取消',
|
|
|
actions: []
|
|
|
},
|
|
|
},
|
|
|
|
|
|
onLoad:function(options){
|
|
|
if (options && options.scene && options.scene.length == 32) {
|
|
|
let code = options.scene;
|
|
|
getQRCodeSource(code).then(json => {
|
|
|
if (json) {
|
|
|
this.loadElement(json);
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
});
|
|
|
}else {
|
|
|
this.loadElement(options);
|
|
|
}
|
|
|
},
|
|
|
|
|
|
onReady:function(){
|
|
|
// 生命周期函数--监听页面初次渲染完成
|
|
|
|
|
|
tt.setNavigationBarTitle({
|
|
|
title: this.data.title,
|
|
|
});
|
|
|
},
|
|
|
|
|
|
onShow:function(){
|
|
|
// 生命周期函数--监听页面显示
|
|
|
|
|
|
},
|
|
|
|
|
|
onHide:function(){
|
|
|
// 生命周期函数--监听页面隐藏
|
|
|
},
|
|
|
|
|
|
onUnload:function(){
|
|
|
// 生命周期函数--监听页面卸载
|
|
|
var key = this.data.filterStorageKey;
|
|
|
tt.removeStorage({
|
|
|
key: key,
|
|
|
success: function(res) {
|
|
|
},
|
|
|
})
|
|
|
},
|
|
|
onPullDownRefresh: function() {
|
|
|
// 页面相关事件处理函数--监听用户下拉动作
|
|
|
// 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,
|
|
|
// };
|
|
|
// logEvent(YB_PAGE_OPEN_L, params);
|
|
|
},
|
|
|
|
|
|
loadMore: function() {
|
|
|
// 页面上拉触底事件的处理函数
|
|
|
|
|
|
this.fetchListData();
|
|
|
},
|
|
|
|
|
|
loadElement(options){
|
|
|
// 生命周期函数--监听页面加载
|
|
|
// console.log('before',options)
|
|
|
if(options.gender){
|
|
|
options.gender = decodeURIComponent(options.gender);
|
|
|
}
|
|
|
if(options.title){
|
|
|
options.title = decodeURIComponent(options.title);
|
|
|
}
|
|
|
|
|
|
let title = options.title;
|
|
|
let page_param = options;
|
|
|
let from_page_name = options.page_name ? options.page_name : '';
|
|
|
let from_page_param = options.page_param ? options.page_param : '';
|
|
|
let current_page_param = options.categoryId ? options.categoryId:'';
|
|
|
let cagetoryID = options.categoryId ? options.categoryId : options.msort + options.misort;
|
|
|
let filterStorageKey = 'category_storageKey_' + cagetoryID
|
|
|
let isUnionShare = app.globalData.user_union_type ? true : false;//user_union_type 有值 需要显示 联盟share按钮
|
|
|
let msort = options.msort ? options.msort : '';
|
|
|
let misort = options.misort ? options.misort : '';
|
|
|
let sort = options.sort ? options.sort : '';
|
|
|
|
|
|
|
|
|
//解析渠道号
|
|
|
let unionType = options.union_type ? options.union_type : '';
|
|
|
if (unionType) {
|
|
|
app.updateUnionType(unionType);
|
|
|
}
|
|
|
|
|
|
// console.log(options)
|
|
|
// console.log('goodsList')
|
|
|
|
|
|
if (page_param.sort) {
|
|
|
delete page_param["misort"];
|
|
|
delete page_param["msort"];
|
|
|
}
|
|
|
|
|
|
this.setData({
|
|
|
title,
|
|
|
page_param,
|
|
|
origin_param: { ...options },
|
|
|
from_page_name,
|
|
|
from_page_param,
|
|
|
current_page_param,
|
|
|
filterStorageKey,
|
|
|
isUnionShare,
|
|
|
msort,
|
|
|
misort,
|
|
|
sort,
|
|
|
});
|
|
|
|
|
|
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.fetchListData();
|
|
|
|
|
|
tt.setNavigationBarTitle({
|
|
|
title: this.data.title,
|
|
|
});
|
|
|
this.setShareSettingDatafunction();
|
|
|
},
|
|
|
setShareSettingDatafunction(){
|
|
|
if (app.globalData.user_union_type) {//user_union_type_imageUrl
|
|
|
let actionsheet = this.data.actionsheet;
|
|
|
let actionsheetParam = [
|
|
|
{
|
|
|
name: '分享给朋友',
|
|
|
className: 'action-class',
|
|
|
loading: false,
|
|
|
openType: 'share',
|
|
|
image_src: '../../images/share_union_wechat@2x.png'
|
|
|
},
|
|
|
{
|
|
|
// name: '生成卡片并分享',
|
|
|
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;
|
|
|
|
|
|
this.setData({
|
|
|
actionsheet,
|
|
|
})
|
|
|
this.setUnionShareSnapData();
|
|
|
}
|
|
|
},
|
|
|
//设置生成快照的数据
|
|
|
setUnionShareSnapData:function(){
|
|
|
let params = queryString.stringify(this.data.page_param, { encode: false });
|
|
|
let shareInfo = app.globalData.shareInfo;
|
|
|
let user_union_type = app.globalData.user_union_type ? app.globalData.user_union_type : '';
|
|
|
let title = shareInfo ? shareInfo.title : '';
|
|
|
let misort = this.data.misort ? this.data.misort : '';
|
|
|
let msort = this.data.msort ? this.data.msort : '';
|
|
|
var default_image = '';
|
|
|
let page_param = this.data.page_param;
|
|
|
page_param['union_type'] = user_union_type;
|
|
|
// console.log('zjj',shareInfo)
|
|
|
let union_qrCode = API_HOST + '/wechat/miniapp/img-check.jpg?param=' + encodeURIComponent(JSON.stringify(page_param)) + '&miniQrType=6';
|
|
|
var shareData = {
|
|
|
title: title,
|
|
|
goodListName: this.data.title,
|
|
|
content: shareInfo ? shareInfo.content : '',
|
|
|
default_image: shareInfo ? shareInfo.bigImage : '',
|
|
|
union_qrCode,
|
|
|
msort: msort,
|
|
|
misort: misort,
|
|
|
page_name: this.data.current_page_name,
|
|
|
sharePath: '/pages/productList/index?union_type=' + app.globalData.user_union_type + "&" + params,
|
|
|
sort: this.data.sort,
|
|
|
categoryID: this.data.current_page_param,
|
|
|
}
|
|
|
this.setData({
|
|
|
snapshootShareData:shareData
|
|
|
})
|
|
|
},
|
|
|
onShareAppMessage: function (res) {
|
|
|
let param = {
|
|
|
FROM: res.from,
|
|
|
SHARE_RESUIL: 0,
|
|
|
TITLE: '创建推广',
|
|
|
DESC: this.data.snapshootShareData.content,
|
|
|
PATH: this.data.snapshootShareData.sharePath,
|
|
|
SHARE_TYPE: 1,
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
title: this.data.title ? this.data.title : this.data.snapshootShareData.title ? this.data.snapshootShareData.title:param.TITLE, // 分享标题
|
|
|
imageUrl: this.data.snapshootShareData.default_image,
|
|
|
desc: this.data.snapshootShareData.content, // 分享描述
|
|
|
path: this.data.snapshootShareData.sharePath, // 分享路径
|
|
|
success: function (res) {
|
|
|
// param.SHARE_RESUIL = 1
|
|
|
// logEvent(YB_SHARE_RESULT_L, param);
|
|
|
},
|
|
|
fail: function (res) {
|
|
|
// param.SHARE_RESUIL = 2
|
|
|
// logEvent(YB_SHARE_RESULT_L, param);
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
//品牌商品列表
|
|
|
fetchListData: function() {
|
|
|
if (this.data.list.isLoading || this.data.list.endReached) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let page = this.data.list.currentPage + 1;
|
|
|
let param = {
|
|
|
method: 'app.search.category',
|
|
|
page,
|
|
|
limit: this.data.list.pageSize
|
|
|
}
|
|
|
Object.assign(param, this.data.page_param);
|
|
|
let list = Object.assign(this.data.list, {isLoading: true,});
|
|
|
this.setData({list});
|
|
|
|
|
|
api.get({data:param})
|
|
|
.then(json => {
|
|
|
if (!json || !json.code || json.code != 200) {
|
|
|
let list = Object.assign(this.data.list, {isLoading: false, error: {code: json.code, message: json.message}});
|
|
|
this.setData({list});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
json = json.data;
|
|
|
|
|
|
let currentPage = json && json.page ? json.page : 1;
|
|
|
let pageCount = json && json.page_total ? json.page_total : 0;
|
|
|
let total = json && json.total ? json.total : 0;
|
|
|
let endReached = currentPage == pageCount;
|
|
|
|
|
|
let data = json.product_list;
|
|
|
data = parseBrandListData(data);
|
|
|
|
|
|
if (currentPage > 1) {
|
|
|
let oldList = this.data.list.data;
|
|
|
data = [...oldList, ...data];
|
|
|
}
|
|
|
|
|
|
let newList = {
|
|
|
isLoading: false,
|
|
|
data,
|
|
|
currentPage,
|
|
|
pageCount,
|
|
|
total,
|
|
|
endReached,
|
|
|
};
|
|
|
let list = Object.assign(this.data.list, newList);
|
|
|
this.setData({list});
|
|
|
})
|
|
|
.catch(error => {
|
|
|
let list = Object.assign(this.data.list, {isLoading: false, error,});
|
|
|
this.setData({list});
|
|
|
});
|
|
|
},
|
|
|
|
|
|
//点击筛选
|
|
|
updateProductList: function(event) {
|
|
|
var order = event.detail.order;
|
|
|
var param = {
|
|
|
order
|
|
|
}
|
|
|
this.updateProductListWithFilterParam(param);
|
|
|
},
|
|
|
|
|
|
jumpToFilterPage: function() {
|
|
|
let params = Object.assign({method: 'app.search.category.filter'},this.data.origin_param);
|
|
|
let storageKey = this.data.filterStorageKey;
|
|
|
let paramString = JSON.stringify(params);
|
|
|
tt.navigateTo({
|
|
|
url: './productListFilterPage?storageKey=' + storageKey + '¶ms=' + paramString
|
|
|
})
|
|
|
},
|
|
|
|
|
|
updateProductListWithFilterParam: function(param) {
|
|
|
let page_param = this.data.page_param;
|
|
|
page_param = Object.assign(page_param, param);
|
|
|
let newList = Object.assign(this.data.list, { currentPage: 0, pageCount: 0, total: 0, endReached: false, });
|
|
|
this.setData({
|
|
|
page_param,
|
|
|
list: newList
|
|
|
});
|
|
|
this.fetchListData();
|
|
|
},
|
|
|
|
|
|
onScroll: function(e) {
|
|
|
var { scrollTop } = e.detail;
|
|
|
var isShow = scrollTop > windowHeight * 2 ? true : false;
|
|
|
if (isShow != this.data.isShowIndicator) {
|
|
|
this.setData({
|
|
|
isShowIndicator: isShow
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
|
|
|
backToTop: function () {
|
|
|
this.setData({
|
|
|
scrollTop: 0
|
|
|
})
|
|
|
},
|
|
|
|
|
|
hiddenSheet: function () {
|
|
|
this.setData({
|
|
|
isShowSnapshoot: false
|
|
|
})
|
|
|
},
|
|
|
|
|
|
handleZanActionsheetCancel({ componentId }) {
|
|
|
this.setData({
|
|
|
'actionsheet.show': false
|
|
|
})
|
|
|
},
|
|
|
|
|
|
handlerJumpToUnionUrl() {
|
|
|
// this.setData({
|
|
|
// 'actionsheet.show': false
|
|
|
// })
|
|
|
// 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)
|
|
|
},
|
|
|
// 当行动按钮中有一个被点击时触发
|
|
|
// index 代表被点击按钮在传入参数 actions 中的位置
|
|
|
handleZanActionsheetClick({ componentId, index }) {
|
|
|
this.setData({
|
|
|
'actionsheet.show': false
|
|
|
})
|
|
|
|
|
|
if (index === 1) {
|
|
|
this.setData({
|
|
|
isShowSnapshoot: true
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
//进入创建联盟分享页面
|
|
|
unionShare: function() {
|
|
|
this.setData({
|
|
|
'actionsheet.show': true
|
|
|
})
|
|
|
// let params = queryString.stringify(this.data.page_param, { encode: false });
|
|
|
// let shareInfo = app.globalData.shareInfo;
|
|
|
// let user_union_type = app.globalData.user_union_type ? app.globalData.user_union_type : '';
|
|
|
// let title = shareInfo ? shareInfo.title : '';
|
|
|
// let misort = this.data.misort ? this.data.misort : '';
|
|
|
// let msort = this.data.msort ? this.data.msort : '';
|
|
|
// var default_image = '';
|
|
|
// let page_param = this.data.page_param;
|
|
|
// page_param['union_type'] = user_union_type;
|
|
|
|
|
|
// let union_qrCode = API_HOST + '/wechat/miniapp/img-check.jpg?param=' + encodeURIComponent(JSON.stringify(page_param)) + '&miniQrType=6';
|
|
|
// var shareData = {
|
|
|
// title: title,
|
|
|
// goodListName: this.data.title,
|
|
|
// content: shareInfo ? shareInfo.content : '',
|
|
|
// default_image: shareInfo ? shareInfo.bigImage : '',
|
|
|
// union_qrCode,
|
|
|
// msort: msort,
|
|
|
// misort: misort,
|
|
|
// page_name: this.data.current_page_name,
|
|
|
// sharePath: '/pages/goodsList/goodsList?union_type=' + app.globalData.user_union_type + "&" + params,
|
|
|
// sort: this.data.sort,
|
|
|
// categoryID: this.data.current_page_param,
|
|
|
// }
|
|
|
|
|
|
// var timestamp = Date.parse(new Date());
|
|
|
// try {
|
|
|
// tt.setStorageSync(timestamp + '', shareData);
|
|
|
// } catch (e) {
|
|
|
// }
|
|
|
// tt.navigateTo({
|
|
|
// url: '../../page/subPackage/pages/unionShare/unionShare?timestamp=' + timestamp + '&page_name=' + this.data.current_page_name + '&page_param=' + this.data.current_page_param,
|
|
|
// })
|
|
|
}
|
|
|
|
|
|
})) |
|
|
\ No newline at end of file |