feat: 搜索页开发

This commit is contained in:
zc 2025-12-05 17:46:14 +08:00
parent 34a861fc36
commit 6c56c7f55a
6 changed files with 89 additions and 74 deletions

View File

@ -92,6 +92,14 @@ export const apiGetCartList = (data) => {
);
}
// 删除购物车
export const apiDeleteCart = (data) => {
return httpRequest.post(
`${baseUrl}/shipping/cart/delete`,
data
);
}
// 获取订单详情
export const apiGetOrderDetail = (data) => {
return httpRequest.post(

View File

@ -80,7 +80,7 @@
</view>
<view class="action">
<view class="btn-cart" :style="{ color: itemStyle.btnCartColor }" @click.stop="handleAddCart(dataItm)">
<text class="cart-icon iconfont" :class="[`icon-jiagou${itemStyle.btnCartStyle || 1}`]"></text>
<text class="cart-icon iconfont" :class="[`icon-jiagou1`]"></text>
</view>
</view>
</view>
@ -371,6 +371,7 @@
text-align: center;
.cart-icon {
color: $main-bg;
font-size: 36rpx;
}
}

View File

@ -270,7 +270,7 @@
//
onClearCart() {
const app = this
CartApi.clear(app.checkedIds)
OrderApi.apiDeleteCart({ shoppingCartIds: app.checkedIds })
.then(result => {
app.getCartList()
app.handleToggleMode()

View File

@ -168,9 +168,6 @@
const app = this
const categoryId = app.getCategoryId()
return new Promise((resolve, reject) => {
GoodsApi.list({ categoryId, page: pageNo }, { load: false }).then(res => {
console.warn('----- my data is categoryId: ', res)
})
// testorigin GoodsApi.list({ categoryId, page: pageNo }, { load: false })
GoodsApi.apiGetCommodityList({ categoryId })
.then(result => {

View File

@ -51,7 +51,7 @@
import { apiGetCommentList } from '@/api/goods'
const pageSize = 15
const tabs = [{ name: `全部`, scoreType: -1 }, { name: `好评`, scoreType: 10 }, { name: `中评`, scoreType: 20 }, { name: `差评`, scoreType: 30 }]
const tabs = [{ name: `全部`, level: '' }, { name: `好评`, level: 'good' }, { name: `中评`, level: 'common' }, { name: `差评`, level: 'notgood' }]
export default {
components: {
@ -88,11 +88,10 @@
methods: {
/**
* 上拉加载的回调 (页面初始化时也会执行一次)
* @param {Object} page
*/
upCallback(page) {
const app = this
apiGetCommentList({ productId: app.goodsId, scoreType: app.tabs[app.curTab].scoreType, page: page.num }).then(res => {
apiGetCommentList({ productId: app.goodsId, level: app.tabs[app.curTab].level, page: page.num }).then(res => {
const data = res.data.map(item => ({
...item,
skuInfo: JSON.parse(item.skuInfo)
@ -100,7 +99,7 @@
app.list.data = getMoreListData({ data }, app.list, page.num)
app.mescroll.endBySize(data.length, data.length)
}).catch(() => app.mescroll.endErr())
CommentApi.list({})
// CommentApi.list({})
},
//
getTotal() {

View File

@ -24,10 +24,10 @@
<view class="sort-item sort-item-price" :class="{ active: sortType === 'price' }" @click="handleSortType('price')">
<text>价格</text>
<view class="price-arrow">
<view class="icon up" :class="{ active: sortType === 'price' && !sortPrice }">
<view class="icon up" :class="{ active: sortType === 'price' && sortPrice === 'ASC' }">
<text class="iconfont icon-arrow-up"></text>
</view>
<view class="icon down" :class="{ active: sortType === 'price' && sortPrice }">
<view class="icon down" :class="{ active: sortType === 'price' && sortPrice === 'DESC' }">
<text class="iconfont icon-arrow-down"></text>
</view>
</view>
@ -35,56 +35,68 @@
</view>
<!-- 商品列表 -->
<view class="goods-list clearfix" :class="['column-' + (showView ? '1' : '2')]">
<view class="goods-item" v-for="(item, index) in list.data" :key="index" @click="onTargetDetail(item.goods_id)">
<view class="goods-item" v-for="(item, index) in list.data" :key="index" @click="onTargetDetail(item.id)">
<!-- 单列显示 -->
<view v-if="showView" class="dis-flex">
<!-- 商品图片 -->
<view class="goods-item-left">
<image class="image" :src="item.goods_image"></image>
<image class="image" :src="item.mainImageUrl"></image>
</view>
<view class="goods-item-right">
<!-- 商品名称 -->
<view class="goods-name">
<text class="twoline-hide">{{ item.goods_name }}</text>
<text class="twoline-hide">{{ item.title }}</text>
</view>
<view class="goods-item-desc">
<!-- 商品卖点 -->
<view class="desc-selling-point dis-flex">
<text class="oneline-hide">{{ item.selling_point }}</text>
<text class="oneline-hide">{{ item.feature1 }} {{ item.feature2 }}</text>
</view>
<!-- 商品销量 -->
<view class="desc-goods-sales dis-flex">
<text>已售{{ item.goods_sales }}</text>
<text>已售{{ item.showSaleCount }}</text>
</view>
<!-- 商品价格 -->
<view class="desc-footer">
<text class="price-x">¥{{ item.goods_price_min }}</text>
<text class="price-y col-9" v-if="item.line_price_min > 0">¥{{ item.line_price_min }}</text>
<text class="price-x">¥{{ item.showPromotionPrice }}</text>
<text class="price-y col-9" v-if="item.showSalePrice > 0">¥{{ item.showSalePrice }}</text>
</view>
</view>
<view class="action">
<view class="btn-cart" @click.stop="handleAddCart(item)">
<text class="cart-icon iconfont" :class="[`icon-jiagou1`]"></text>
</view>
</view>
</view>
</view>
<!-- 多列显示 -->
<view v-else class="">
<!-- 商品图片 -->
<view class="goods-image">
<image class="image" mode="aspectFill" :src="item.goods_image"></image>
<image class="image" mode="aspectFill" :src="item.mainImageUrl"></image>
</view>
<view class="detail">
<!-- 商品名称 -->
<view class="goods-name">
<text class="twoline-hide">{{ item.goods_name }}</text>
<text class="twoline-hide">{{ item.title }}</text>
</view>
<!-- 商品价格 -->
<view class="detail-price oneline-hide">
<text class="goods-price f-30 col-m">{{ item.goods_price_min }}</text>
<text v-if="item.line_price_min > 0" class="line-price col-9 f-24">{{ item.line_price_min }}</text>
<text class="goods-price f-30 col-m">{{ item.showPromotionPrice }}</text>
<text v-if="item.showSalePrice > 0" class="line-price col-9 f-24">{{ item.showSalePrice }}</text>
</view>
<view class="action">
<view class="btn-cart" @click.stop="handleAddCart(item)">
<text class="cart-icon iconfont" :class="[`icon-jiagou1`]"></text>
</view>
</view>
</view>
</view>
</view>
</view>
</mescroll-body>
<!-- 加入购物车组件 -->
<AddCartPopup ref="AddCartPopup" @addCart="onAddCart" />
</view>
</template>
@ -93,23 +105,24 @@
import * as GoodsApi from '@/api/goods'
import { getEmptyPaginateObj, getMoreListData } from '@/core/app'
import Search from '@/components/search'
import AddCartPopup from '@/components/add-cart-popup'
const pageSize = 15
const showViewKey = 'GoodsList-ShowView';
export default {
components: {
Search
Search,
AddCartPopup
},
mixins: [MescrollMixin],
data() {
return {
showView: false, // (truefalse)
sortType: 'all', //
sortPrice: false, // (true false)
sortType: 'all', // : all, sales, price
sortPrice: undefined, // (true false) ASCDESC
options: {}, //
list: getEmptyPaginateObj(), //
//
upOption: {
//
@ -121,51 +134,36 @@
}
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// options
this.options = options
//
this.setShowView()
this.showView = uni.getStorageSync(showViewKey) || false //
},
methods: {
/**
* 上拉加载的回调 (页面初始化时也会执行一次)
* 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
* @param {Object} page
*/
// ()
upCallback(page) {
const app = this
//
app.getGoodsList(page.num)
.then(list => {
const curPageLen = list.data.length
const totalSize = list.total
app.mescroll.endBySize(curPageLen, totalSize)
})
.catch(() => app.mescroll.endErr())
GoodsApi.apiGetCommodityList({
page: page.num,
pageSize: page.size,
productName: app.options.search || undefined,
saleCountSort: app.sortType === 'sales' ? 'DESC' : undefined,
salePriceSort: app.sortType === 'price' ? app.sortPrice : undefined,
}).then(res => {
app.list.data = getMoreListData({ data: res.data.rows }, app.list, page.num)
app.mescroll.endBySize(res.data.rows.length, res.data.total)
console.log(res)
}).catch(() => app.mescroll.endErr())
// app.getGoodsList(page.num)
},
//
setShowView() {
this.showView = uni.getStorageSync(showViewKey) || false
},
/**
* 获取商品列表
* @param {number} pageNo 页码
*/
getGoodsList(pageNo = 1) {
const app = this
console.log(app.options)
const param = {
sortType: app.sortType,
sortPrice: Number(app.sortPrice),
sortPrice: app.sortPrice,
categoryId: app.options.categoryId || 0,
goodsName: app.options.search || '',
page: pageNo
@ -181,33 +179,38 @@
.catch(reject)
})
},
//
handleSortType(newSortType) {
const app = this
const newSortPrice = newSortType === 'price' ? !app.sortPrice : true
if (newSortType === 'price') {
app.sortPrice = app.sortPrice === 'ASC' ? 'DESC' : 'ASC'
} else {
app.sortPrice = undefined
}
app.sortType = newSortType
app.sortPrice = newSortPrice
//
app.list = getEmptyPaginateObj()
app.mescroll.resetUpScroll()
},
//
handleShowView() {
const app = this
app.showView = !app.showView
uni.setStorageSync(showViewKey, app.showView)
},
//
onTargetDetail(goodsId) {
this.$navTo('pages/goods/detail', { goodsId })
},
/**
* 商品搜索
*/
//
handleAddCart(item) {
this.$refs.AddCartPopup.handle(item)
},
//
onAddCart(total) {
setCartTabBadge()
},
//
handleSearch() {
const searchPageUrl = 'pages/search/index'
//
@ -220,12 +223,8 @@
//
this.$navTo(searchPageUrl)
},
},
/**
* 设置分享内容
*/
//
onShareAppMessage() {
//
const app = this
@ -234,7 +233,6 @@
path: "/pages/goods/list?" + this.$getShareUrlParams(app.options)
}
},
/**
* 分享到朋友圈
* 本接口为 Beta 版本暂只在 Android 平台支持详见分享到朋友圈 (Beta)
@ -351,8 +349,8 @@
.image {
display: block;
width: 240rpx;
height: 240rpx;
width: 200rpx;
height: 200rpx;
}
}
@ -398,7 +396,14 @@
text-decoration: line-through;
}
}
}
}
.action{
position: absolute;
right: 30rpx;
bottom: -30rpx;
font-size: 36rpx;
color: $main-bg;
}
//
.goods-list.column-2 {
@ -438,6 +443,7 @@
}
.detail {
position: relative;
padding: 8rpx;
background: #fff;
@ -459,6 +465,10 @@
text-decoration: line-through;
}
}
.action{
bottom: 0;
right: 15rpx;
}
}
}
</style>