恢复商品和详情页面

This commit is contained in:
Dev
2026-10-22 15:41:39 +08:00
parent 0ef4ac4cea
commit b9122fd6c8
37 changed files with 2489 additions and 2 deletions
+277
View File
@@ -0,0 +1,277 @@
import { fetchGoodsList } from '../../../services/good/fetchGoodsList';
import { getCategoryList } from '../../../services/good/fetchCategoryList';
import { fetchGoodsCaseView } from '../../../services/home/home';
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: [],
caseView: wx.getStorageSync('goodsCaseView') === true, // 案例展示:标题改为软件案例,不显示价格和购物车
},
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) {
if (!reset && (this._loading || this.data.loadMoreStatus !== 0)) {
return;
}
const seq = (this._listSeq || 0) + 1;
this._listSeq = seq;
this._loading = true;
const page = reset ? 1 : this.data.page;
const { pageSize, keywords, tabValue } = this.data;
this.setData({
loadMoreStatus: 1,
loading: true,
});
try {
const result = await fetchGoodsList({
page,
categoryId: tabValue,
pageSize,
keywords,
});
if (seq !== this._listSeq) {
return;
}
if (!result || result.code !== 1 || !result.data) {
this.setData({
loading: false,
hasLoaded: true,
loadMoreStatus: 0,
});
wx.showToast({
title: (result && result.msg) || '查询失败,请稍候重试',
icon: 'none',
});
return;
}
const { spuList = [], totalCount = 0 } = result.data;
if (totalCount === 0 && reset) {
this.setData({
emptyInfo: {
tip: '抱歉,未找到相关商品',
},
total: totalCount,
hasLoaded: true,
loadMoreStatus: 2,
loading: false,
goodsList: [],
page: 1,
});
return;
}
const start = reset ? 0 : this.data.goodsList.length;
const loaded = start + spuList.length;
const patch = {
total: totalCount,
page: page + 1,
loadMoreStatus: loaded >= totalCount ? 2 : 0,
hasLoaded: true,
loading: false,
};
if (reset) {
patch.goodsList = spuList;
} else {
spuList.forEach((item, i) => {
patch[`goodsList[${start + i}]`] = item;
});
}
this.setData(patch);
} catch (error) {
if (seq !== this._listSeq) {
return;
}
console.error('loadGoodsList failed:', error);
this.setData({
loading: false,
hasLoaded: true,
loadMoreStatus: 0,
});
} finally {
if (seq === this._listSeq) {
this._loading = false;
}
}
},
onLoad() {
this.applyCaseView();
this.init();
this.loadGoodsList(true);
},
onShow() {
// 自定义 tabBar 每个 Tab 页各有一份实例,切过来后要按当前路由重设选中项
const tabBar = typeof this.getTabBar === 'function' && this.getTabBar();
if (tabBar) {
tabBar.init();
}
},
async applyCaseView() {
if (this.data.caseView) {
wx.setNavigationBarTitle({ title: '软件案例' });
}
const caseView = await fetchGoodsCaseView();
this.setData({ caseView });
wx.setNavigationBarTitle({ title: caseView ? '软件案例' : '软件列表' });
},
onReachBottom() {
if (this._loading || this.data.loadMoreStatus !== 0) {
return;
}
const { goodsList, total } = this.data;
if (goodsList.length >= total) {
this.setData({
loadMoreStatus: 2,
});
return;
}
this.loadGoodsList(false);
},
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,40 @@
<view class="goods-list-container">
<view class="list-header">
<view class="search">
<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>
<view class="category-goods-list" wx:if="{{goodsList.length}}">
<goods-list wr-class="wr-goods-list" goodsList="{{goodsList}}" show-buy="{{!caseView}}" show-price="{{!caseView}}" bind:click="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,91 @@
page {
background-color: var(--bg-page);
}
.goods-list-container {
display: block;
min-height: 100vh;
background-color: var(--bg-page);
}
/* 顶部搜索 + 分类:吸顶固定,滚动时不遮挡内容 */
.goods-list-container .list-header {
position: sticky;
top: 0;
z-index: 20;
background-color: var(--bg-card);
box-shadow: 0 4rpx 16rpx rgba(29, 33, 41, 0.03);
}
.goods-list-container .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 {
padding: 0 8rpx;
background: var(--bg-card);
border-radius: 0;
}
.goods-list-container .tabs-external__active {
color: var(--brand) !important;
font-size: 32rpx;
font-weight: 600;
}
.goods-list-container .tabs-external__track {
width: 48rpx !important;
height: 6rpx !important;
background-color: var(--brand) !important;
border-radius: var(--radius-round) !important;
}
.goods-list-container .t-tabs.t-tabs--top .t-tabs__scroll {
border-bottom: none;
}
.goods-list-container .t-tabs.t-tabs--top .t-tabs__item {
height: 84rpx !important;
}
.goods-list-container .category-goods-list {
padding: 24rpx 24rpx 0;
background-color: var(--bg-page);
}
.goods-list-container .t-image__mask {
display: flex !important;
}
.goods-list-container .empty-wrap {
display: flex;
align-items: center;
justify-content: center;
height: 640rpx;
}
.goods-list-container .empty-wrap .empty-tips .empty-content .content-text {
margin-top: 40rpx;
}
.safe-bottom {
width: 100%;
min-height: 150rpx;
}