feat 搜索结果

This commit is contained in:
Cxpller 2023-10-18 21:30:42 +08:00
parent 6ab71eb4bf
commit 3b7ab290db
6 changed files with 165 additions and 69 deletions

View File

@ -46,6 +46,7 @@ Component({
isAllSelectedSku: false, isAllSelectedSku: false,
selectSkuSellsPrice: 0, selectSkuSellsPrice: 0,
details: {}, details: {},
buyNum: 1,
}, },
lifetimes: { lifetimes: {
@ -77,6 +78,12 @@ Component({
this.getDetail(e.detail.goods.spuId) this.getDetail(e.detail.goods.spuId)
}, },
changeNum(e) {
this.setData({
buyNum: e.detail.buyNum,
});
},
addCartFun() { addCartFun() {
const { const {
isAllSelectedSku, isAllSelectedSku,
@ -88,14 +95,13 @@ Component({
shopGuid, shopGuid,
spuId, spuId,
} = this.data.details; } = this.data.details;
let data = { let data = {
shopGuid: shopGuid, shopGuid: shopGuid,
goodsGuid: spuId, goodsGuid: spuId,
goodsSkuId: selectedSkuId, goodsSkuId: selectedSkuId,
cartGoodsNum: buyNum cartGoodsNum: buyNum
} }
console.log(data, '加入购物车的数据'); // console.log(data, '加入购物车的数据');
// 添加购物车接口 // 添加购物车接口
addOrUpdateCart(data).then((res) => { addOrUpdateCart(data).then((res) => {

View File

@ -350,6 +350,7 @@ Component({
// 总处理 // 总处理
setBuyNum(buyNum) { setBuyNum(buyNum) {
console.log(buyNum, 'setBuyNum');
this.setData({ this.setData({
buyNum, buyNum,
}); });

View File

@ -70,7 +70,7 @@
<block wx:else> <block wx:else>
<view class="no_storage"> <view class="no_storage">
<view>请重新选择商品规格</view> <view>请重新选择商品规格</view>
<view class="no_storage__right">重选</view> <view class="no_storage__right" bind:handleClick="reSelect">重选</view>
</view> </view>
</block> </block>
</view> </view>

View File

@ -1,5 +1,7 @@
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
import { getSearchResult } from '../../../services/good/fetchSearchResult'; import {
getGoodsList
} from '~/services/home/getGoodsList';
import Toast from 'tdesign-miniprogram/toast/index'; import Toast from 'tdesign-miniprogram/toast/index';
const initFilters = { const initFilters = {
@ -10,7 +12,8 @@ const initFilters = {
Page({ Page({
data: { data: {
goodsList: [], goodsList: [],
sorts: '', priceSorts: '',
soldSorts: '',
overall: 1, overall: 1,
show: false, show: false,
minVal: '', minVal: '',
@ -29,9 +32,10 @@ Page({
pageSize: 30, pageSize: 30,
onLoad(options) { onLoad(options) {
const { searchValue = '' } = options || {}; const {
this.setData( searchValue = ''
{ } = options || {};
this.setData({
keywords: searchValue, keywords: searchValue,
}, },
() => { () => {
@ -41,27 +45,44 @@ Page({
}, },
generalQueryData(reset = false) { generalQueryData(reset = false) {
const { filter, keywords, minVal, maxVal } = this.data; const {
const { pageNum, pageSize } = this; filter,
const { sorts, overall } = filter; keywords,
minVal,
maxVal
} = this.data;
const {
pageNum,
pageSize
} = this;
const {
sorts,
overall
} = filter;
const params = { const params = {
sort: 0, // 0 综合1 价格 goodsSort: 0, // 0 综合1 价格
pageNum: 1, pageNum: 1,
pageSize: 30, pageSize: 6,
keyword: keywords, goodsName: keywords,
}; };
if (sorts) { if (sorts) {
params.sort = 1; params.goodsSort = 1;
params.sortType = sorts === 'desc' ? 1 : 0; params.sortType = sorts === 'desc' ? 1 : 0;
} }
if (overall) { if (overall) {
params.sort = 0; params.goodsSort = 0;
} else { } else {
params.sort = 1; params.goodsSort = 1;
} }
params.minPrice = minVal ? minVal * 100 : 0; if (minVal) {
params.maxPrice = maxVal ? maxVal * 100 : undefined; params.minPrice = minVal * 100
}
if (maxVal) {
params.maxPrice = maxVal * 100
}
// params.minPrice = minVal ? minVal * 100 : 0;
// params.maxPrice = maxVal ? maxVal * 100 : undefined;
if (reset) return params; if (reset) return params;
return { return {
...params, ...params,
@ -71,7 +92,10 @@ Page({
}, },
async init(reset = true) { async init(reset = true) {
const { loadMoreStatus, goodsList = [] } = this.data; const {
loadMoreStatus,
goodsList = []
} = this.data;
const params = this.generalQueryData(reset); const params = this.generalQueryData(reset);
if (loadMoreStatus !== 0) return; if (loadMoreStatus !== 0) return;
this.setData({ this.setData({
@ -79,13 +103,18 @@ Page({
loading: true, loading: true,
}); });
try { try {
const result = await getSearchResult(params); const result = await getGoodsList(params);
const code = 'Success'; const data = result.data;
const data = result; if (result.code == 200) {
if (code.toUpperCase() === 'SUCCESS') { const {
const { spuList, totalCount = 0 } = data; result,
if (totalCount === 0 && reset) { totalPage = 0
this.total = totalCount; } = data;
// console.log(data, 'data');
// console.log(result, 'result');
// console.log(totalPage, 'totalPage');
if (totalPage === 0 && reset) {
this.total = totalPage;
this.setData({ this.setData({
emptyInfo: { emptyInfo: {
tip: '抱歉,未找到相关商品', tip: '抱歉,未找到相关商品',
@ -98,14 +127,10 @@ Page({
return; return;
} }
const _goodsList = reset ? spuList : goodsList.concat(spuList); const _goodsList = reset ? result : goodsList.concat(result);
_goodsList.forEach((v) => { const _loadMoreStatus = _goodsList.length === totalPage ? 2 : 0;
v.tags = v.spuTagList.map((u) => u.title);
v.hideKey = { desc: true };
});
const _loadMoreStatus = _goodsList.length === totalCount ? 2 : 0;
this.pageNum = params.pageNum || 1; this.pageNum = params.pageNum || 1;
this.total = totalCount; this.total = totalPage;
this.setData({ this.setData({
goodsList: _goodsList, goodsList: _goodsList,
loadMoreStatus: _loadMoreStatus, loadMoreStatus: _loadMoreStatus,
@ -136,8 +161,7 @@ Page({
}, },
handleSubmit() { handleSubmit() {
this.setData( this.setData({
{
goodsList: [], goodsList: [],
loadMoreStatus: 0, loadMoreStatus: 0,
}, },
@ -148,8 +172,12 @@ Page({
}, },
onReachBottom() { onReachBottom() {
const { goodsList } = this.data; const {
const { total = 0 } = this; goodsList
} = this.data;
const {
total = 0
} = this;
if (goodsList.length === total) { if (goodsList.length === total) {
this.setData({ this.setData({
loadMoreStatus: 2, loadMoreStatus: 2,
@ -168,38 +196,64 @@ Page({
}, },
gotoGoodsDetail(e) { gotoGoodsDetail(e) {
const { index } = e.detail; const {
const { spuId } = this.data.goodsList[index]; index
} = e.detail;
const {
spuId
} = this.data.goodsList[index];
wx.navigateTo({ wx.navigateTo({
url: `/pages/goods/details/index?spuId=${spuId}`, url: `/pages/goods/details/index?spuId=${spuId}`,
}); });
}, },
handleFilterChange(e) { handleFilterChange(e) {
const { overall, sorts } = e.detail; const {
const { total } = this; layout,
const _filter = {
sorts,
overall, overall,
}; priceSorts,
this.setData({ soldSorts
filter: _filter, } = e.detail;
sorts,
overall,
});
this.pageNum = 1; this.pageNum = 1;
this.setData( this.setData({
{ layout,
goodsList: [], priceSorts,
loadMoreStatus: 0, soldSorts,
}, overall,
() => { loadMoreStatus: 0,
total && this.init(true); });
}, this.init(true);
);
}, },
// handleFilterChange(e) {
// const {
// overall,
// sorts
// } = e.detail;
// const {
// total
// } = this;
// const _filter = {
// sorts,
// overall,
// };
// this.setData({
// filter: _filter,
// sorts,
// overall,
// });
// this.pageNum = 1;
// this.setData({
// goodsList: [],
// loadMoreStatus: 0,
// },
// () => {
// total && this.init(true);
// },
// );
// },
showFilterPopup() { showFilterPopup() {
this.setData({ this.setData({
show: true, show: true,
@ -213,21 +267,35 @@ Page({
}, },
onMinValAction(e) { onMinValAction(e) {
const { value } = e.detail; const {
this.setData({ minVal: value }); value
} = e.detail;
this.setData({
minVal: value
});
}, },
onMaxValAction(e) { onMaxValAction(e) {
const { value } = e.detail; const {
this.setData({ maxVal: value }); value
} = e.detail;
this.setData({
maxVal: value
});
}, },
reset() { reset() {
this.setData({ minVal: '', maxVal: '' }); this.setData({
minVal: '',
maxVal: ''
});
}, },
confirm() { confirm() {
const { minVal, maxVal } = this.data; const {
minVal,
maxVal
} = this.data;
let message = ''; let message = '';
if (minVal && !maxVal) { if (minVal && !maxVal) {
message = `价格最小是${minVal}`; message = `价格最小是${minVal}`;
@ -246,8 +314,7 @@ Page({
}); });
} }
this.pageNum = 1; this.pageNum = 1;
this.setData( this.setData({
{
show: false, show: false,
minVal: '', minVal: '',
goodsList: [], goodsList: [],
@ -259,4 +326,4 @@ Page({
}, },
); );
}, },
}); });

View File

@ -16,6 +16,8 @@
bind:change="handleFilterChange" bind:change="handleFilterChange"
layout="{{layout}}" layout="{{layout}}"
sorts="{{sorts}}" sorts="{{sorts}}"
priceSorts="{{priceSorts}}"
soldSorts="{{soldSorts}}"
overall="{{overall}}" overall="{{overall}}"
bind:showFilterPopup="showFilterPopup" bind:showFilterPopup="showFilterPopup"
> >

View File

@ -0,0 +1,20 @@
import {
request
} from '../_utils/request';
/** 获取轮播图列表 */
export function getGoodsList(data) {
return new Promise((resolve, reject) => {
request({
url: `GoodsApi/getGoodsList`,
method: 'GET',
data: data,
success: function (res) {
resolve(res);
},
fail: function (error) {
reject(error);
}
});
});
}