|
|
import Yas from '../../../common/yas';
|
|
|
import categoryModel from '../../../models/product/category';
|
|
|
import shopModel from '../../../models/product/shop';
|
|
|
|
|
|
const app = getApp();
|
|
|
const router = global.router;
|
|
|
|
|
|
const genderMap = {
|
|
|
1: '1,3',
|
|
|
2: '2,3'
|
|
|
};
|
|
|
|
|
|
let yas;
|
|
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
data: {
|
|
|
scrollHeight: app.globalData.systemInfo.windowHeight - 120,
|
|
|
currentId: null,
|
|
|
currentName: '',
|
|
|
categoryList: [],
|
|
|
subCategoryList: []
|
|
|
show: false
|
|
|
},
|
|
|
onLoad: function() {
|
|
|
this.categoryGroup = {};
|
|
|
this.subCategoryGroup = {};
|
|
|
|
|
|
this.loadCategoryList();
|
|
|
this.loadShopList();
|
|
|
|
|
|
yas = new Yas(app);
|
|
|
},
|
|
|
onShow: function() {
|
|
|
yas.pageOpenReport();
|
|
|
yas.report('YB_MAIN_TAB_C', {TAB_ID: 2});
|
|
|
},
|
|
|
loadCategoryList() {
|
|
|
const channelList = [
|
|
|
{name: 'Men', id: '1'},
|
|
|
{name: 'Women', id: '2'},
|
|
|
{name: 'Kids', id: '3'}
|
|
|
];
|
|
|
|
|
|
new Promise(resolve => {
|
|
|
let group = {};
|
|
|
let backNum = 0;
|
|
|
|
|
|
const backFn = () => {
|
|
|
backNum++;
|
|
|
|
|
|
if (backNum >= channelList.length) {
|
|
|
return resolve(group);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
channelList.map(value => {
|
|
|
categoryModel.categoryList(value.id).then(res => {
|
|
|
if (res.code === 200 && res.data && res.data.length) {
|
|
|
value.hasCate = true;
|
|
|
group[value.id] = res.data;
|
|
|
}
|
|
|
|
|
|
backFn();
|
|
|
}).catch(() => {
|
|
|
backFn();
|
|
|
});
|
|
|
return value;
|
|
|
});
|
|
|
}).then(res => {
|
|
|
let currentChannel;
|
|
|
let channelLength = 0;
|
|
|
|
|
|
this.categoryGroup = res || {};
|
|
|
|
|
|
channelList.forEach(value => {
|
|
|
if (!value.hasCate) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
channelLength++;
|
|
|
if (!currentChannel) {
|
|
|
currentChannel = value.id;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
expandItem: function(e) {
|
|
|
if (e.target) {
|
|
|
this.setData({
|
|
|
pageLoaded: true,
|
|
|
channelList,
|
|
|
channelLength
|
|
|
});
|
|
|
|
|
|
this.changeChannel({currentTarget: {dataset: {
|
|
|
id: currentChannel
|
|
|
}}});
|
|
|
});
|
|
|
},
|
|
|
loadSubCategoryList(id, channelId) {
|
|
|
let subCateList = this.subCategoryGroup[id];
|
|
|
|
|
|
if (subCateList) {
|
|
|
return Promise.resolve(subCateList);
|
|
|
} else {
|
|
|
return categoryModel.subCategoryList({id, channelId}).then(res => {
|
|
|
if (res && res.code === 200) {
|
|
|
let list = res.data || [];
|
|
|
|
|
|
this.subCategoryGroup[id] = list;
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
return false;
|
|
|
}).catch(() => {
|
|
|
return false;
|
|
|
show: !this.data.show
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
loadShopList() {
|
|
|
shopModel.shopList().then(res => {
|
|
|
if (res.code !== 200) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
this.setData({shopList: res.data.shop_product_list || []});
|
|
|
});
|
|
|
},
|
|
|
changeChannel(e) {
|
|
|
let currentChannel = e.currentTarget.dataset.id;
|
|
|
|
|
|
if (currentChannel === this.data.currentChannel) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let categoryList = this.categoryGroup[currentChannel] || [];
|
|
|
let defaultCate = categoryList[0];
|
|
|
|
|
|
this.setData({
|
|
|
currentChannel,
|
|
|
categoryList
|
|
|
});
|
|
|
|
|
|
if (defaultCate) {
|
|
|
this.changeCategory({currentTarget: {dataset: {
|
|
|
id: defaultCate.category_id,
|
|
|
name: defaultCate.category_name
|
|
|
}}});
|
|
|
}
|
|
|
},
|
|
|
changeCategory(e) {
|
|
|
let data = e.currentTarget.dataset || {};
|
|
|
|
|
|
if (data.id === this.data.currentId) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
this.loadSubCategoryList(data.id, this.data.currentChannel).then(list => {
|
|
|
if (!list) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (!list.length && e.type) {
|
|
|
return this.goCategoryListWithId({currentTarget: {dataset: {
|
|
|
cid: data.id
|
|
|
}}});
|
|
|
}
|
|
|
|
|
|
this.setData({
|
|
|
currentId: data.id,
|
|
|
currentName: data.name,
|
|
|
subCategoryList: list || []
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
goCategoryList(e) {
|
|
|
const key = e.currentTarget.dataset.key;
|
|
|
|
|
|
let cate = this.data.subCategoryList[key] || {};
|
|
|
let params = cate.relation_parameter || {};
|
|
|
|
|
|
params.title = cate.category_name;
|
|
|
|
|
|
yas.report('YB_CATEGORY_FLR_C', {
|
|
|
TAB_ID: this.data.currentChannel,
|
|
|
L1_CATE_ID: this.data.currentId,
|
|
|
F_ID: 1002,
|
|
|
I_INDEX: key + 1,
|
|
|
L2_CATE_ID: cate.category_id
|
|
|
});
|
|
|
|
|
|
params.gender = genderMap[this.data.currentChannel] || '';
|
|
|
|
|
|
router.go('productList', params);
|
|
|
},
|
|
|
goCategoryListWithId(e) {
|
|
|
const cateId = e.currentTarget.dataset.cid;
|
|
|
const categoryList = this.data.categoryList || [];
|
|
|
let cate;
|
|
|
|
|
|
categoryList.forEach(value => {
|
|
|
if (cateId === value.category_id) {
|
|
|
cate = value;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (cate) {
|
|
|
let params = cate.relation_parameter || {};
|
|
|
|
|
|
params.title = cate.category_name;
|
|
|
|
|
|
if (e.type) {
|
|
|
yas.report('YB_CATEGORY_FLR_C', {
|
|
|
TAB_ID: this.data.currentChannel,
|
|
|
L1_CATE_ID: this.data.currentId,
|
|
|
F_ID: 1002,
|
|
|
I_INDEX: 0,
|
|
|
L2_CATE_ID: 0
|
|
|
});
|
|
|
}
|
|
|
|
|
|
params.gender = genderMap[this.data.currentChannel] || '';
|
|
|
|
|
|
router.go('productList', params);
|
|
|
}
|
|
|
},
|
|
|
goProductDetail(e) {
|
|
|
const dataset = e.currentTarget.dataset;
|
|
|
const skn = dataset.skn;
|
|
|
|
|
|
yas.report('YB_CATEGORY_FLR_C', {
|
|
|
SHOP_ID: dataset.sid,
|
|
|
I_INDEX: dataset.shopIndex + 1,
|
|
|
L_INDEX: dataset.index + 1,
|
|
|
PRD_SKN: skn
|
|
|
});
|
|
|
|
|
|
router.go('productDetail', {productSkn: skn});
|
|
|
},
|
|
|
goShopList(e) {
|
|
|
const shopId = e.currentTarget.dataset.id;
|
|
|
const index = e.currentTarget.dataset.index;
|
|
|
|
|
|
yas.report('YB_CATEGORY_FLR_C', {
|
|
|
SHOP_ID: shopId,
|
|
|
TAB_ID: this.data.currentChannel,
|
|
|
L1_CATE_ID: this.data.currentId,
|
|
|
F_ID: 1003,
|
|
|
I_INDEX: index + 1,
|
|
|
L_INDEX: 0
|
|
|
});
|
|
|
|
|
|
router.go('productShop', {shopId});
|
|
|
}
|
|
|
}); |
...
|
...
|
|