Initial commit
This commit is contained in:
@@ -0,0 +1,241 @@
|
||||
import { fetchGoodsList } from '../../../services/good/fetchGoodsList';
|
||||
import { getCategoryList } from '../../../services/good/fetchCategoryList';
|
||||
import Toast from 'tdesign-miniprogram/toast/index';
|
||||
|
||||
const initFilters = {
|
||||
overall: 1,
|
||||
sorts: '',
|
||||
layout: 0,
|
||||
};
|
||||
|
||||
Page({
|
||||
data: {
|
||||
goodsList: [],
|
||||
layout: 0,
|
||||
sorts: '',
|
||||
overall: 1,
|
||||
show: false,
|
||||
minVal: '',
|
||||
maxVal: '',
|
||||
keywords: '',
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
tabValue: 0,
|
||||
filter: initFilters,
|
||||
hasLoaded: false,
|
||||
loadMoreStatus: 0,
|
||||
loading: true,
|
||||
tabList: [],
|
||||
},
|
||||
|
||||
handleFilterChange(e) {
|
||||
const { layout, overall, sorts } = e.detail;
|
||||
this.setData({
|
||||
layout,
|
||||
sorts,
|
||||
page: 1,
|
||||
overall,
|
||||
loadMoreStatus: 0,
|
||||
});
|
||||
this.loadGoodsList(true);
|
||||
},
|
||||
tabChangeHandle(e) {
|
||||
const tabValue = e.detail.value;
|
||||
this.setData({
|
||||
tabValue,
|
||||
});
|
||||
this.loadGoodsList(true);
|
||||
},
|
||||
//搜索
|
||||
onChangeInput(e) {
|
||||
const { value } = e.detail;
|
||||
this.setData({
|
||||
keywords: value
|
||||
});
|
||||
if (!value) {
|
||||
this.loadGoodsList(true);
|
||||
}
|
||||
},
|
||||
onChangeSearch(e) {
|
||||
const { value } = e.detail;
|
||||
if (value !== undefined) {
|
||||
this.setData({
|
||||
keywords: value
|
||||
});
|
||||
}
|
||||
console.log(e)
|
||||
console.log(value)
|
||||
this.loadGoodsList(true);
|
||||
},
|
||||
navToSearchPage() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/goods/search/index'
|
||||
});
|
||||
},
|
||||
|
||||
async init() {
|
||||
try {
|
||||
const result = await getCategoryList();
|
||||
this.setData({
|
||||
tabList: result,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('err:', error);
|
||||
}
|
||||
},
|
||||
|
||||
// 产品列表
|
||||
async loadGoodsList(reset = false) {
|
||||
try {
|
||||
const { loadMoreStatus, goodsList = [], page, pageSize, keywords, tabValue } = this.data;
|
||||
const params = {
|
||||
page: reset ? 1 : page,
|
||||
categoryId: tabValue,
|
||||
pageSize,
|
||||
keywords,
|
||||
};
|
||||
if (loadMoreStatus !== 0 && !reset) return;
|
||||
this.setData({
|
||||
loadMoreStatus: 1,
|
||||
loading: true,
|
||||
});
|
||||
const result = await fetchGoodsList(params);
|
||||
console.log('fetchGoodsList', result)
|
||||
const data = result.data;
|
||||
if (result.code == 1) {
|
||||
const { spuList, totalCount = 0 } = data;
|
||||
if (totalCount === 0 && reset) {
|
||||
this.setData({
|
||||
emptyInfo: {
|
||||
tip: '抱歉,未找到相关商品',
|
||||
},
|
||||
total: totalCount,
|
||||
hasLoaded: true,
|
||||
loadMoreStatus: 0,
|
||||
loading: false,
|
||||
goodsList: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
const _goodsList = reset ? spuList : goodsList.concat(spuList);
|
||||
const _loadMoreStatus = _goodsList.length === totalCount ? 2 : 0;
|
||||
this.setData({
|
||||
total: totalCount,
|
||||
page: params.page + 1,
|
||||
goodsList: _goodsList,
|
||||
loadMoreStatus: _loadMoreStatus,
|
||||
});
|
||||
} else {
|
||||
this.setData({
|
||||
loading: false,
|
||||
});
|
||||
wx.showToast({
|
||||
title: '查询失败,请稍候重试',
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
loading: false,
|
||||
});
|
||||
}
|
||||
this.setData({
|
||||
hasLoaded: true,
|
||||
loading: false,
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
onLoad() {
|
||||
this.init();
|
||||
this.loadGoodsList(true);
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadGoodsList(true);
|
||||
},
|
||||
|
||||
onReachBottom() {
|
||||
const { goodsList, total } = this.data;
|
||||
if (goodsList.length === total) {
|
||||
this.setData({
|
||||
loadMoreStatus: 2,
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.loadGoodsList(false);
|
||||
},
|
||||
|
||||
handleAddCart() {
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: '点击加购',
|
||||
});
|
||||
},
|
||||
|
||||
tagClickHandle() {
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: '点击标签',
|
||||
});
|
||||
},
|
||||
|
||||
gotoGoodsDetail(e) {
|
||||
console.log(e);
|
||||
const { index } = e.detail;
|
||||
const { spuId } = this.data.goodsList[index];
|
||||
wx.navigateTo({
|
||||
url: `/pages/goods/details/index?spuId=${spuId}`,
|
||||
});
|
||||
},
|
||||
|
||||
showFilterPopup() {
|
||||
this.setData({
|
||||
show: true,
|
||||
});
|
||||
},
|
||||
|
||||
showFilterPopupClose() {
|
||||
this.setData({
|
||||
show: false,
|
||||
});
|
||||
},
|
||||
|
||||
onMinValAction(e) {
|
||||
const { value } = e.detail;
|
||||
this.setData({ minVal: value });
|
||||
},
|
||||
|
||||
onMaxValAction(e) {
|
||||
const { value } = e.detail;
|
||||
this.setData({ maxVal: value });
|
||||
},
|
||||
|
||||
reset() {
|
||||
this.setData({ minVal: '', maxVal: '' });
|
||||
},
|
||||
|
||||
confirm() {
|
||||
let message = ''
|
||||
if (message) {
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message,
|
||||
});
|
||||
}
|
||||
this.setData(
|
||||
{
|
||||
show: false,
|
||||
page: 1,
|
||||
goodsList: [],
|
||||
loadMoreStatus: 0,
|
||||
},
|
||||
() => {
|
||||
this.loadGoodsList();
|
||||
},
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"navigationBarTitleText": "软件列表",
|
||||
"usingComponents": {
|
||||
"t-tabs": "tdesign-miniprogram/tabs/tabs",
|
||||
"t-tab-panel": "tdesign-miniprogram/tab-panel/tab-panel",
|
||||
"t-search": "tdesign-miniprogram/search/search",
|
||||
"t-input": "tdesign-miniprogram/input/input",
|
||||
"t-empty": "tdesign-miniprogram/empty/empty",
|
||||
"t-toast": "tdesign-miniprogram/toast/toast",
|
||||
"goods-list": "/components/goods-list/index",
|
||||
"filter": "/components/filter/index",
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"filter-popup": "/components/filter-popup/index",
|
||||
"load-more": "/components/load-more/index"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<view class="goods-list-container">
|
||||
<view class="search" style="margin-bottom: 5rpx;">
|
||||
<t-search t-class-input-container="t-class__input-container" t-class-input="t-search__input" t-class-left="t-search__left-icon" value="{{keywords}}" left-icon="{{null}}" placeholder="请输入关键词搜索" bind:blur="onChangeInput" bind:change="onChangeInput" bind:submit="onChangeSearch">
|
||||
<t-icon slot="left-icon" prefix="wr" name="search" size="40rpx" color="#bbb" />
|
||||
</t-search>
|
||||
</view>
|
||||
<view class="home-page-tabs">
|
||||
<t-tabs t-class="t-tabs" t-class-active="tabs-external__active" t-class-item="tabs-external__item" defaultValue="{{0}}" space-evenly="{{false}}" bind:change="tabChangeHandle">
|
||||
<t-tab-panel wx:for="{{tabList}}" wx:for-index="index" wx:key="index" label="{{item.text}}" value="{{item.key}}" />
|
||||
</t-tabs>
|
||||
</view>
|
||||
<view class="category-goods-list" wx:if="{{goodsList.length}}">
|
||||
<goods-list wr-class="wr-goods-list" goodsList="{{goodsList}}" bind:click="gotoGoodsDetail" bind:addcart="gotoGoodsDetail" />
|
||||
</view>
|
||||
<view class="empty-wrap" wx:if="{{goodsList.length === 0 && hasLoaded}}">
|
||||
<t-empty t-class="empty-tips" size="240rpx" description="暂无相关产品" />
|
||||
</view>
|
||||
<load-more wx:if="{{goodsList.length > 0}}" status="{{loadMoreStatus}}" no-more-text="没有更多了" />
|
||||
<view class="safe-bottom" />
|
||||
</view>
|
||||
<t-toast id="t-toast" />
|
||||
@@ -0,0 +1,131 @@
|
||||
page {
|
||||
background-color: var(--bg-page);
|
||||
}
|
||||
|
||||
.goods-list-container {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.goods-list-container .t-search {
|
||||
padding: 16rpx 24rpx 8rpx;
|
||||
background-color: var(--bg-card);
|
||||
}
|
||||
|
||||
.goods-list-container .t-class__input-container {
|
||||
height: 72rpx !important;
|
||||
border-radius: var(--radius-round) !important;
|
||||
background: var(--bg-grey);
|
||||
}
|
||||
|
||||
.goods-list-container .t-search__left-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.goods-list-container .t-search__input {
|
||||
font-size: 28rpx !important;
|
||||
color: var(--text-primary) !important;
|
||||
}
|
||||
|
||||
.goods-list-container .home-page-tabs {
|
||||
background: var(--bg-card);
|
||||
border-radius: 0;
|
||||
padding: 0 8rpx;
|
||||
}
|
||||
|
||||
.goods-list-container .tabs-external__active {
|
||||
color: var(--text-primary) !important;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.goods-list-container .tabs-external__track {
|
||||
background-color: var(--brand) !important;
|
||||
height: 6rpx !important;
|
||||
border-radius: var(--radius-round) !important;
|
||||
width: 48rpx !important;
|
||||
}
|
||||
|
||||
.goods-list-container .t-tabs.t-tabs--top .t-tabs__scroll {
|
||||
border-bottom: 1rpx solid var(--border-level-1);
|
||||
}
|
||||
|
||||
.goods-list-container .t-tabs.t-tabs--top .t-tabs__item {
|
||||
height: 84rpx !important;
|
||||
}
|
||||
|
||||
.goods-list-container .category-goods-list {
|
||||
background-color: var(--bg-page);
|
||||
overflow-y: scroll;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
padding: 24rpx;
|
||||
}
|
||||
|
||||
.goods-list-container .wr-goods-list {
|
||||
background: var(--bg-page) !important;
|
||||
}
|
||||
|
||||
.goods-list-container .t-image__mask {
|
||||
display: flex !important;
|
||||
}
|
||||
|
||||
.goods-list-container .empty-wrap {
|
||||
margin-top: 184rpx;
|
||||
margin-bottom: 120rpx;
|
||||
height: 300rpx;
|
||||
}
|
||||
|
||||
.goods-list-container .empty-wrap .empty-tips .empty-content .content-text {
|
||||
margin-top: 40rpx;
|
||||
}
|
||||
|
||||
.goods-list-container .price-container {
|
||||
padding: 32rpx;
|
||||
height: 100vh;
|
||||
max-width: 632rpx;
|
||||
background-color: var(--bg-card);
|
||||
border-radius: 30rpx 0 0 30rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.goods-list-container .price-between {
|
||||
font-size: 26rpx;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.goods-list-container .price-ipts-wrap {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
margin-top: 24rpx;
|
||||
|
||||
--td-input-bg-color: var(--bg-grey);
|
||||
--td-input-vertical-padding: 4rpx;
|
||||
--td-input-border-color: transparent;
|
||||
}
|
||||
|
||||
.goods-list-container .price-ipts-wrap .price-divided {
|
||||
width: 16rpx;
|
||||
margin: 0 24rpx;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.goods-list-container .price-ipts-wrap .t-input__wrap {
|
||||
margin: 0 !important;
|
||||
}
|
||||
|
||||
.goods-list-container .price-ipts-wrap .t-input__content,
|
||||
.goods-list-container .price-ipts-wrap .t-input__placeholder {
|
||||
font-size: 24rpx !important;
|
||||
}
|
||||
|
||||
.goods-list-container .price-ipts-wrap .price-ipt {
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
|
||||
.safe-bottom {
|
||||
min-height: 150rpx;
|
||||
width: 100%;
|
||||
}
|
||||
Reference in New Issue
Block a user