Authored by 黄敬囿

优化商品列表 review by 肖亚东

... ... @@ -11,7 +11,6 @@ Component({
},
attached: function () {
let item = this.data.item;
debugger
console.log(item.filterName)
... ...
... ... @@ -12,7 +12,30 @@ Component({
},
methods: {
// 自定义方法 跳转到商品详情
customMethod: function(){},
cancle: function(e){
let itemInfo = {
actionId: 1,
actionName: "cancle",
}
var option = {} // 触发事件的选项
this.triggerEvent(
'onButtonAction',
itemInfo,
option
)
},
submit: function(e) {
let itemInfo = {
actionId: 2,
actionName: "submit",
}
var option = {} // 触发事件的选项
this.triggerEvent(
'onButtonAction',
itemInfo,
option
)
},
},
... ...
... ... @@ -12,6 +12,7 @@
</block> -->
</scroll-view>
<view class="filter-item-bootom-button-view">
<button class="filter-item-bootom-button" bindtap="cancle">取消</button>
<button class="filter-item-bootom-button" bindtap="submit">确定</button>
<text class="filter-item-bootom-button" bindtap="cancle">取消</text>
<view class="filter-item-bootom-button-split-view"></view>
<text class="filter-item-bootom-button" bindtap="submit">确定</text>
</view>
\ No newline at end of file
... ...
... ... @@ -21,14 +21,24 @@
justify-content: center;
}
.filter-item-bootom-button-view {
display: flex;
flex-direction: row;
align-items: center;
height: 80rpx;
background-color: #444444;
bottom: 0;
}
.filter-item-bootom-button {
display: flex;
width: 375rpx;
height: 80rpx;
align-content: center;
width: 374rpx;
justify-content: center;
font-family: PingFang-SC;
font-size: 26rpx;
text-align: center;
color: #ffffff;
}
.filter-item-bootom-button-split-view {
width: 2rpx;
height: 100%;
background-color: #ffffff;
}
... ...
... ... @@ -206,7 +206,7 @@ Page({
let queryString = "?gender=" + gender + "&sort=" + sort + "&title=" + categoryName +
"&categoryId=" + parentCategoryId + "&subCategoryId=" + categoryId;
tt.navigateTo({
url: '../goodsList/goodsList' + queryString
url: '../productList/index' + queryString
});
}
},
... ... @@ -277,7 +277,7 @@ Page({
"&categoryId=" + parentCategoryId + "&subCategoryId=" + categoryId + "&firstProductSkn=" + firstProductSkn;
tt.navigateTo({
url: '../goodsList/goodsList' + queryString
url: '../productList/index' + queryString
});
},
... ... @@ -315,7 +315,7 @@ Page({
//拼接url
let queryString = "?gender=" + gender + "&sort=" + sort + "&title=" + categoryName + "&categoryId=" + categoryId + "&subCategoryId=";
tt.navigateTo({
url: '../goodsList/goodsList' + queryString
url: '../productList/index' + queryString
});
},
... ...
... ... @@ -42,6 +42,8 @@ Page({
activeIndex: 0,
contentWidth: 0,
contentHeight: 0,
isRefresh: false,
filterParams: {},
},
onLoad: function (option) {
... ... @@ -73,9 +75,29 @@ Page({
console.log(e.message)
}
let tab = this.data.tabs[0];
// let filterParams = this.data.filterParams;
this.fechProductList(tab,1);
this.fechFilter();
},
onShow: function () {
if(this.data.isRefresh){
let filter = this.data.filter;
if(filter){
for(var i = 0; i < filter.length; i++){
let filterItem = filter[i];
let itemId = filterItem.filterId;
let selectedIdParam = filterItem.selectedIdParam;
if(selectedIdParam){
this.data.filterParams[itemId] = selectedIdParam;
}
}
let current = this.data.activeIndex
let tab = this.data.tabs[current];
this.fechProductList(tab,1);
}
}
},
onTabClick: function (e) {
//获取到点击当前Tab的信息
... ... @@ -97,16 +119,13 @@ Page({
if(tabData && tabData.page){
page = tabData.page;
}
console.log("onTabClick page:"+page);
// let filterParams = {};
this.fechProductList(tab,page);
}
},
fechProductList: function (tab,currentPage) {
// debugger
let filterParams = this.data.filterParams;
let id = tab.id;
let orderType = tab.iconType;
let iconUrl = tab.iconUrl;
... ... @@ -151,7 +170,8 @@ Page({
title: "POLO",
order: order,
}
api.get({data: param})
let params = Object.assign(filterParams, param);
api.get({data: params})
.then(data => {
let listData = data.data;
let productList = listData.product_list;
... ... @@ -166,11 +186,16 @@ Page({
productList = parseProductListData(productList);
listData.product_list = productList;
tabs[id].showLoadMoreView = false;
if(tabs[id].data && tabs[id].data.product_list){
tabs[id].data.page = listData.page;
tabs[id].data.product_list = tabs[id].data.product_list.concat(productList);
}else {
let isRefresh = this.data.isRefresh;
if(isRefresh){
tabs[id].data = listData;
}else {
if(tabs[id].data && tabs[id].data.product_list){
tabs[id].data.page = listData.page;
tabs[id].data.product_list = tabs[id].data.product_list.concat(productList);
}else {
tabs[id].data = listData;
}
}
// tablist[id].iconType = orderType;
... ... @@ -188,8 +213,7 @@ Page({
let current = this.data.activeIndex
let tab = this.data.tabs[current];
let page = tab.data.page + 1;
let totalPage = tab.data.page_total
console.log(totalPage+"onLoadMore page:"+page);
let totalPage = tab.data.page_total;
if(page < totalPage){
this.fechProductList(tab,page);
}
... ... @@ -244,7 +268,6 @@ Page({
},
onItemClick: function(e) {
let subItem = e.detail;
// debugger
if(subItem){
let subItemIndex = subItem.subItemIndex;
let itemIndex = subItem.itemIndex;
... ... @@ -313,19 +336,9 @@ Page({
}else {
itemInfo.isShowItem = true;
}
// filter[itemIndex] = itemInfo;
this.setData({
filter: filter,
});
},
cancle: function () {
tt.navigateBack({
});
},
submit: function () {
let filter = this.data.filter;
}
})
\ No newline at end of file
... ...
... ... @@ -22,25 +22,4 @@
</swiper-item>
</swiper>
</view>
</view>
<view class="product-filter-view">
<!-- <scroll-view class="filter-item-scroll-view" scroll-y="true"> -->
<proFilter id="proFilter">
<block tt:for="{{filter}}" tt:for-item="filterItem" tt:key="{{filterItem.filterId}}">
<!-- <view> -->
<filter-title id="filterTitle" item="{{filterItem}}" bind:onShowItem="onShowItem"></filter-title>
<view tt:if="{{!filterItem.isShowItem}}" class="filter-item-sub-view">
<block tt:for="{{filterItem.itemList}}" tt:for-item="filtersub" tt:key="{{filtersub.itemId}}">
<filter-item id="filterItem" item="{{filtersub}}" itemIndex="{{index}}" bind:onItemClick="onItemClick"></filter-item>
</block>
</view>
<!-- </view> -->
</block>
</proFilter>
<!-- </scroll-view> -->
<!-- <view class="filter-item-bootom-button-view">
<button class="filter-item-bootom-button" bindtap="cancle">取消</button>
<button class="filter-item-bootom-button" bindtap="submit">确定</button>
</view> -->
</view>
\ No newline at end of file
... ...
... ... @@ -10,50 +10,30 @@ Page({
this.data.sort = option.sort;
this.data.firstProductSkn = option.firstProductSkn;
}
this.fechFilter();
},
fechFilter: function() {
let that = this;
let sort = that.data.sort;
let categoryId = that.data.categoryId;
let subCategoryId = that.data.subCategoryId;
let firstProductSkn = that.data.firstProductSkn;
let params = {
categoryId: categoryId,
firstProductSkn: firstProductSkn,
limit: 20,
method: "app.search.category.filter",
new_filter: 1,
// order: "",
page: 1,
sort: sort,
subCategoryId: subCategoryId,
}
api.get({data: params})
.then(data => {
let filter = data.data.filter;
let newFilter = this.parseFilter(filter);
that.setData({
filter: newFilter,
});
let pages = getCurrentPages();
let length =pages.length;
if(length > 1){
let lastPageData = pages[length - 2].data;
let filter = lastPageData.filter;
let newFilter = this.parseFilter(filter);
this.setData({
filter: newFilter,
});
}
},
parseFilter: function (filter){
let newFilter = [];
for(var i = 0; i < filter.length; i++){
let itemList = filter[i].itemList;
// let newItemList = [];
for(var j = 0; j < itemList.length; j++){
let item = itemList[j];
let columnIndex = j % 3;
item.columnIndex = columnIndex;
item.subItemIndex = j;
item.itemIndex = i;
// newItemList.push(item)
}
// newFilter.push(newItemList);
}
let new_filter = filter;
... ... @@ -61,7 +41,6 @@ Page({
},
onItemClick: function(e) {
let subItem = e.detail;
// debugger
if(subItem){
let subItemIndex = subItem.subItemIndex;
let itemIndex = subItem.itemIndex;
... ... @@ -111,9 +90,11 @@ Page({
this.setData({
filter: filter,
});
console.log(itemId)
let pages = getCurrentPages();
let length =pages.length;
if(length > 1){
pages[length - 2].data.filter = filter;
}
}
... ... @@ -131,19 +112,44 @@ Page({
itemInfo.isShowItem = true;
}
// filter[itemIndex] = itemInfo;
this.setData({
filter: filter,
});
},
cancle: function () {
tt.navigateBack({
});
},
submit: function () {
},
onButtonAction: function (e) {
let detail = e.detail;
let actionId = detail.actionId;
//取消
if(actionId === 2){
let filterparams = {}
let filter = this.data.filter;
for(var i = 0; i < filter.length; i++){
let item = filter[i];
let filterId = item.filterId;
let filterValue = item.selectedIdParam;
if(filterValue){
filterparams[filterId] = filterValue;
}
}
let pages = getCurrentPages();
let length =pages.length;
if(length > 1){
pages[length - 2].data.isRefresh = true;
}
}else {
}
//返回上一页
tt.navigateBack({
delta: 1,
success (res) {
console.log(`${res}`);
},
fail (res) {
console.log(`navigateBack调用失败`);
}
});
}
... ...
<!-- <view class="filter-item-root-view"> -->
<scroll-view class="filter-item-scroll-view">
<block tt:for="{{filter}}" tt:for-item="filterItem" tt:key="{{index}}">
<!-- <view> -->
<filter-title id="filterTitle" item="{{filterItem}}" bind:onShowItem="onShowItem"></filter-title>
<view tt:if="{{filterItem.isShowItem}}" class="filter-item-sub-view">
<block tt:for="{{filterItem.itemList}}" tt:for-item="filtersub" tt:key="{{filtersub.itemId}}">
<filter-item id="filterItem" item="{{filtersub}}" itemIndex="{{index}}" bind:onItemClick="onItemClick"></filter-item>
</block>
</view>
<!-- </view> -->
</block>
</scroll-view>
<view class="filter-item-bootom-button-view">
<button class="filter-item-bootom-button" bindtap="cancle">取消</button>
<button class="filter-item-bootom-button" bindtap="submit">确定</button>
</view>
<!-- </view> -->
\ No newline at end of file
<proFilter id="proFilter" bind:onButtonAction="onButtonAction">
<block tt:for="{{filter}}" tt:for-item="filterItem" tt:key="{{filterItem.filterId}}">
<filter-title id="filterTitle" item="{{filterItem}}" bind:onShowItem="onShowItem"></filter-title>
<view tt:if="{{filterItem.isShowItem}}" class="filter-item-sub-view">
<block tt:for="{{filterItem.itemList}}" tt:for-item="filtersub" tt:key="{{filtersub.itemId}}">
<filter-item id="filterItem" item="{{filtersub}}" itemIndex="{{index}}" bind:onItemClick="onItemClick"></filter-item>
</block>
</view>
</block>
</proFilter>
\ No newline at end of file
... ...
... ... @@ -26,11 +26,11 @@
display: flex;
flex-direction: row;
height: 80rpx;
bottom: 0;
}
.filter-item-bootom-button {
display: flex;
width: 375rpx;
height: 80rpx;
align-content: center;
}
... ...