feat: 搜索页开发
This commit is contained in:
parent
34a861fc36
commit
6c56c7f55a
@ -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(
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,7 +270,7 @@
|
||||
// 确认删除商品
|
||||
onClearCart() {
|
||||
const app = this
|
||||
CartApi.clear(app.checkedIds)
|
||||
OrderApi.apiDeleteCart({ shoppingCartIds: app.checkedIds })
|
||||
.then(result => {
|
||||
app.getCartList()
|
||||
app.handleToggleMode()
|
||||
|
||||
@ -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 => {
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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, // 列表显示方式 (true列表、false平铺)
|
||||
sortType: 'all', // 排序类型
|
||||
sortPrice: false, // 价格排序 (true高到低 false低到高)
|
||||
sortType: 'all', // 排序类型: all, sales, price
|
||||
sortPrice: undefined, // 价格排序 (true高到低 false低到高) ASC升序、DESC降序
|
||||
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>
|
||||
Loading…
x
Reference in New Issue
Block a user