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

View File

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

View File

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

View File

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

View File

@ -16,6 +16,8 @@
bind:change="handleFilterChange"
layout="{{layout}}"
sorts="{{sorts}}"
priceSorts="{{priceSorts}}"
soldSorts="{{soldSorts}}"
overall="{{overall}}"
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);
}
});
});
}