|
|
import wx from '../../utils/wx';
|
|
|
import Yas from '../../common/yas';
|
|
|
import config from '../../config';
|
|
|
import listModel from '../../models/product/list';
|
|
|
import shopModel from '../../models/product/shop';
|
|
|
import { Actionsheet } from '../../vendors/zanui/index';
|
|
|
|
|
|
let app = getApp();
|
|
|
let { windowHeight } = app.getSystemInfo();
|
|
|
|
|
|
let yas;
|
|
|
|
|
|
Page(Object.assign({
|
|
|
data: {
|
|
|
query: '',
|
|
|
order: '',
|
|
|
gender: '',
|
|
|
shopId: 0,
|
|
|
shopName: '',
|
|
|
searched: false,
|
|
|
productList: [],
|
|
|
snapshootShareData: {},
|
|
|
floor: {},
|
|
|
actionsheet: {
|
|
|
componentId: 'shareActionSheet',
|
|
|
show: false,
|
|
|
closeOnClickOverlay: true,
|
|
|
cancelText: '取消',
|
|
|
actions: [{
|
|
|
name: '分享给朋友',
|
|
|
className: 'action-class',
|
|
|
loading: false,
|
|
|
openType: 'share'
|
|
|
}]
|
|
|
},
|
|
|
shopInfoHeight: 0,
|
|
|
scrollTop: 0,
|
|
|
fixedFilter: false,
|
|
|
windowHeight,
|
|
|
currentPage: 1,
|
|
|
totalPage: 0,
|
|
|
showLoading: false,
|
|
|
showNoMore: false,
|
|
|
isLoading: false,
|
|
|
noResult: false
|
|
|
},
|
|
|
onLoad: function(options) {
|
|
|
Object.keys(options).map(key => {
|
|
|
options[key] = decodeURIComponent(options[key] || '');
|
|
|
});
|
|
|
|
|
|
let shopId = options.shop_id || options.shopId;
|
|
|
|
|
|
this.data.shopId = shopId;
|
|
|
this.setData({
|
|
|
shopId
|
|
|
});
|
|
|
this.shopInfo();
|
|
|
this.shopDecFloor();
|
|
|
this.productList({page: 1, limit: 20, shop_id: shopId});
|
|
|
|
|
|
yas = new Yas(app);
|
|
|
yas.pageOpenReport();
|
|
|
},
|
|
|
onReady: function() {
|
|
|
wx.createSelectorQuery().select('.shop-info').boundingClientRect(rect => {
|
|
|
this.setData({
|
|
|
shopInfoHeight: rect.height
|
|
|
});
|
|
|
}).exec();
|
|
|
},
|
|
|
onShareAppMessage: function(res) {
|
|
|
let params = {
|
|
|
FROM: res.from,
|
|
|
SHARE_RESUIL: 0,
|
|
|
TITLE: this.data.shopName,
|
|
|
DESC: '我在有货发现了一个不错的店铺,赶快来看看吧!',
|
|
|
PATH: `/pages/product/list/shop?shop_id=${this.data.shopId}`,
|
|
|
};
|
|
|
|
|
|
return {
|
|
|
title: params.TITLE, // 分享标题
|
|
|
desc: params.DESC, // 分享描述
|
|
|
path: params.PATH, // 分享路径
|
|
|
success: function() {
|
|
|
params.SHARE_RESUIL = 1;
|
|
|
yas.report('YB_SHARE_RESULT_L', params);
|
|
|
},
|
|
|
fail: function() {
|
|
|
params.SHARE_RESUIL = 2;
|
|
|
yas.report('YB_SHARE_RESULT_L', params);
|
|
|
}
|
|
|
};
|
|
|
},
|
|
|
productList: function(params) {
|
|
|
if (this.data.isLoading) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
this.data.isLoading = true;
|
|
|
wx.showLoading({title: '加载中'});
|
|
|
params.order = this.data.order;
|
|
|
params.gender = this.data.gender;
|
|
|
params.shop_id = this.data.shopId;
|
|
|
listModel.productList(params).then(res => {
|
|
|
if (res.code === 200) {
|
|
|
const keyAdapter = {
|
|
|
skn: 'product_skn',
|
|
|
salesPrice: 'sales_price',
|
|
|
marketPrice: 'market_price',
|
|
|
productName: 'product_name',
|
|
|
defaultImages: 'default_images'
|
|
|
};
|
|
|
let list = [];
|
|
|
|
|
|
(res.data.product_list || []).forEach(product => {
|
|
|
let item = {};
|
|
|
|
|
|
Object.keys(keyAdapter).forEach(key => {
|
|
|
item[key] = product[keyAdapter[key]];
|
|
|
});
|
|
|
list.push(item);
|
|
|
});
|
|
|
|
|
|
this.data.isLoading = false;
|
|
|
wx.hideLoading();
|
|
|
this.setData({
|
|
|
showLoading: false,
|
|
|
productList: this.data.productList.concat(list),
|
|
|
currentPage: params.page,
|
|
|
totalPage: res.data.page_total,
|
|
|
noResult: !this.data.productList.concat(list).length
|
|
|
});
|
|
|
|
|
|
if (this.data.fixedFilter && params.resetScroll) {
|
|
|
wx.pageScrollTo({
|
|
|
scrollTop: this.data.shopInfoHeight,
|
|
|
duration: 10
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}).catch(() => {
|
|
|
this.data.isLoading = false;
|
|
|
});
|
|
|
},
|
|
|
shareShop: function() {
|
|
|
this.setData({
|
|
|
'actionsheet.show': true
|
|
|
});
|
|
|
},
|
|
|
handleZanActionsheetCancel() {
|
|
|
this.setData({
|
|
|
'actionsheet.show': false
|
|
|
});
|
|
|
},
|
|
|
handleZanActionsheetClick() {
|
|
|
this.setData({
|
|
|
'actionsheet.show': false
|
|
|
});
|
|
|
},
|
|
|
sortChange: function(e) {
|
|
|
let params;
|
|
|
let {curSort, gender} = e.detail;
|
|
|
|
|
|
this.data.gender = gender || '';
|
|
|
this.data.order = curSort;
|
|
|
|
|
|
params = {
|
|
|
gender,
|
|
|
order: curSort,
|
|
|
page: 1,
|
|
|
limit: 20
|
|
|
};
|
|
|
this.data.productList = [];
|
|
|
params.resetScroll = true;
|
|
|
this.productList(params);
|
|
|
},
|
|
|
|
|
|
// 店铺信息
|
|
|
shopInfo: function() {
|
|
|
let params = {
|
|
|
shop_id: this.data.shopId,
|
|
|
fromePage: 'iFP_RedPersonBrand'
|
|
|
};
|
|
|
|
|
|
this.setData({
|
|
|
info: {
|
|
|
isLoading: true,
|
|
|
}
|
|
|
});
|
|
|
shopModel.shopInfo(params)
|
|
|
.then(data => {
|
|
|
if (!data || !data.code || data.code !== 200) {
|
|
|
this.setData({
|
|
|
info: {
|
|
|
isLoading: false,
|
|
|
error: { code: data.code, message: data.message },
|
|
|
}
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (data.data.shop_name) {
|
|
|
let shopName = data.data.shop_name;
|
|
|
|
|
|
wx.setNavigationBarTitle({
|
|
|
title: shopName,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
let shopInfo = data.data;
|
|
|
let logoUrl = shopInfo.shop_logo.replace(/{width}/g, 100).replace(/{height}/g, 100).replace('{mode}', 2); // eslint-disable-line
|
|
|
|
|
|
shopInfo.shop_logo = logoUrl;
|
|
|
|
|
|
let shareData = this.data.snapshootShareData;
|
|
|
|
|
|
shareData.shop_logo = logoUrl;
|
|
|
shareData.shop_intro_simple = shopInfo.shop_intro_simple;
|
|
|
shareData.shop_id = shopInfo.shops_id;
|
|
|
shareData.shop_name = shopInfo.shop_name;
|
|
|
shareData.shop_qrCode = config.domains.api + '/wechat/miniapp/img-check.jpg?miniQrType=3¶m=' + shopInfo.shops_id; // eslint-disable-line
|
|
|
|
|
|
this.setData({
|
|
|
info: {
|
|
|
isLoading: false,
|
|
|
data: shopInfo,
|
|
|
},
|
|
|
shopName: shopInfo.shop_name,
|
|
|
snapshootShareData: shareData
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
shopDecFloor: function() {
|
|
|
let params = {
|
|
|
shop_id: this.data.shopId,
|
|
|
fromePage: 'iFP_RedPersonBrand'
|
|
|
};
|
|
|
|
|
|
shopModel.shopDecorator(params)
|
|
|
.then(res => {
|
|
|
let floor = res.data.modules;
|
|
|
|
|
|
if (floor && floor.length > 0) {
|
|
|
let shopBanner = floor[0];
|
|
|
|
|
|
if (shopBanner && shopBanner.module_type === 'ShopBanner') {
|
|
|
let module_data = JSON.parse(shopBanner.module_data);
|
|
|
|
|
|
let data = module_data.data;
|
|
|
|
|
|
if (data && data.length > 0) {
|
|
|
let resource = data[0];
|
|
|
let shareData = this.data.snapshootShareData;
|
|
|
|
|
|
shareData.bannerUrl = resource.pic;
|
|
|
this.setData({
|
|
|
bannerUrl: resource.pic,
|
|
|
snapshootShareData: shareData
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
this.setData({
|
|
|
floor: {
|
|
|
isLoading: false,
|
|
|
data: res.data
|
|
|
},
|
|
|
});
|
|
|
})
|
|
|
.catch(error =>{
|
|
|
this.setData({
|
|
|
floor: {
|
|
|
isLoading: false,
|
|
|
error,
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
onPageScroll: function({scrollTop}) {
|
|
|
const floatSign = scrollTop >= this.data.shopInfoHeight;
|
|
|
|
|
|
if (floatSign !== this.data.fixedFilter) {
|
|
|
this.setData({
|
|
|
fixedFilter: floatSign
|
|
|
});
|
|
|
}
|
|
|
|
|
|
const backSign = scrollTop > windowHeight * 2;
|
|
|
|
|
|
if (backSign !== this.data.showBackTop) {
|
|
|
this.setData({
|
|
|
showBackTop: backSign
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
backTop: function() {
|
|
|
wx.pageScrollTo({
|
|
|
scrollTop: 0
|
|
|
});
|
|
|
},
|
|
|
onReachBottom: function() {
|
|
|
if (this.data.currentPage < this.data.totalPage) {
|
|
|
this.setData({
|
|
|
showLoading: true
|
|
|
});
|
|
|
this.productList({page: this.data.currentPage + 1, limit: 20, order: this.data.order});
|
|
|
} else {
|
|
|
this.setData({
|
|
|
showNoMore: true
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}, Actionsheet)); |
...
|
...
|
|