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) => {
|
export const apiGetOrderDetail = (data) => {
|
||||||
return httpRequest.post(
|
return httpRequest.post(
|
||||||
|
|||||||
@ -80,7 +80,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="action">
|
<view class="action">
|
||||||
<view class="btn-cart" :style="{ color: itemStyle.btnCartColor }" @click.stop="handleAddCart(dataItm)">
|
<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>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -371,6 +371,7 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
.cart-icon {
|
.cart-icon {
|
||||||
|
color: $main-bg;
|
||||||
font-size: 36rpx;
|
font-size: 36rpx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -270,7 +270,7 @@
|
|||||||
// 确认删除商品
|
// 确认删除商品
|
||||||
onClearCart() {
|
onClearCart() {
|
||||||
const app = this
|
const app = this
|
||||||
CartApi.clear(app.checkedIds)
|
OrderApi.apiDeleteCart({ shoppingCartIds: app.checkedIds })
|
||||||
.then(result => {
|
.then(result => {
|
||||||
app.getCartList()
|
app.getCartList()
|
||||||
app.handleToggleMode()
|
app.handleToggleMode()
|
||||||
|
|||||||
@ -168,9 +168,6 @@
|
|||||||
const app = this
|
const app = this
|
||||||
const categoryId = app.getCategoryId()
|
const categoryId = app.getCategoryId()
|
||||||
return new Promise((resolve, reject) => {
|
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 })
|
// testorigin GoodsApi.list({ categoryId, page: pageNo }, { load: false })
|
||||||
GoodsApi.apiGetCommodityList({ categoryId })
|
GoodsApi.apiGetCommodityList({ categoryId })
|
||||||
.then(result => {
|
.then(result => {
|
||||||
|
|||||||
@ -51,7 +51,7 @@
|
|||||||
import { apiGetCommentList } from '@/api/goods'
|
import { apiGetCommentList } from '@/api/goods'
|
||||||
|
|
||||||
const pageSize = 15
|
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 {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -88,11 +88,10 @@
|
|||||||
methods: {
|
methods: {
|
||||||
/**
|
/**
|
||||||
* 上拉加载的回调 (页面初始化时也会执行一次)
|
* 上拉加载的回调 (页面初始化时也会执行一次)
|
||||||
* @param {Object} page
|
|
||||||
*/
|
*/
|
||||||
upCallback(page) {
|
upCallback(page) {
|
||||||
const app = this
|
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 => ({
|
const data = res.data.map(item => ({
|
||||||
...item,
|
...item,
|
||||||
skuInfo: JSON.parse(item.skuInfo)
|
skuInfo: JSON.parse(item.skuInfo)
|
||||||
@ -100,7 +99,7 @@
|
|||||||
app.list.data = getMoreListData({ data }, app.list, page.num)
|
app.list.data = getMoreListData({ data }, app.list, page.num)
|
||||||
app.mescroll.endBySize(data.length, data.length)
|
app.mescroll.endBySize(data.length, data.length)
|
||||||
}).catch(() => app.mescroll.endErr())
|
}).catch(() => app.mescroll.endErr())
|
||||||
CommentApi.list({})
|
// CommentApi.list({})
|
||||||
},
|
},
|
||||||
// 获取指定评分总数
|
// 获取指定评分总数
|
||||||
getTotal() {
|
getTotal() {
|
||||||
|
|||||||
@ -24,10 +24,10 @@
|
|||||||
<view class="sort-item sort-item-price" :class="{ active: sortType === 'price' }" @click="handleSortType('price')">
|
<view class="sort-item sort-item-price" :class="{ active: sortType === 'price' }" @click="handleSortType('price')">
|
||||||
<text>价格</text>
|
<text>价格</text>
|
||||||
<view class="price-arrow">
|
<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>
|
<text class="iconfont icon-arrow-up"></text>
|
||||||
</view>
|
</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>
|
<text class="iconfont icon-arrow-down"></text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -35,31 +35,36 @@
|
|||||||
</view>
|
</view>
|
||||||
<!-- 商品列表 -->
|
<!-- 商品列表 -->
|
||||||
<view class="goods-list clearfix" :class="['column-' + (showView ? '1' : '2')]">
|
<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 v-if="showView" class="dis-flex">
|
||||||
<!-- 商品图片 -->
|
<!-- 商品图片 -->
|
||||||
<view class="goods-item-left">
|
<view class="goods-item-left">
|
||||||
<image class="image" :src="item.goods_image"></image>
|
<image class="image" :src="item.mainImageUrl"></image>
|
||||||
</view>
|
</view>
|
||||||
<view class="goods-item-right">
|
<view class="goods-item-right">
|
||||||
<!-- 商品名称 -->
|
<!-- 商品名称 -->
|
||||||
<view class="goods-name">
|
<view class="goods-name">
|
||||||
<text class="twoline-hide">{{ item.goods_name }}</text>
|
<text class="twoline-hide">{{ item.title }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="goods-item-desc">
|
<view class="goods-item-desc">
|
||||||
<!-- 商品卖点 -->
|
<!-- 商品卖点 -->
|
||||||
<view class="desc-selling-point dis-flex">
|
<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>
|
||||||
<!-- 商品销量 -->
|
<!-- 商品销量 -->
|
||||||
<view class="desc-goods-sales dis-flex">
|
<view class="desc-goods-sales dis-flex">
|
||||||
<text>已售{{ item.goods_sales }}件</text>
|
<text>已售{{ item.showSaleCount }}件</text>
|
||||||
</view>
|
</view>
|
||||||
<!-- 商品价格 -->
|
<!-- 商品价格 -->
|
||||||
<view class="desc-footer">
|
<view class="desc-footer">
|
||||||
<text class="price-x">¥{{ item.goods_price_min }}</text>
|
<text class="price-x">¥{{ item.showPromotionPrice }}</text>
|
||||||
<text class="price-y col-9" v-if="item.line_price_min > 0">¥{{ item.line_price_min }}</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>
|
</view>
|
||||||
@ -68,23 +73,30 @@
|
|||||||
<view v-else class="">
|
<view v-else class="">
|
||||||
<!-- 商品图片 -->
|
<!-- 商品图片 -->
|
||||||
<view class="goods-image">
|
<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>
|
||||||
<view class="detail">
|
<view class="detail">
|
||||||
<!-- 商品名称 -->
|
<!-- 商品名称 -->
|
||||||
<view class="goods-name">
|
<view class="goods-name">
|
||||||
<text class="twoline-hide">{{ item.goods_name }}</text>
|
<text class="twoline-hide">{{ item.title }}</text>
|
||||||
</view>
|
</view>
|
||||||
<!-- 商品价格 -->
|
<!-- 商品价格 -->
|
||||||
<view class="detail-price oneline-hide">
|
<view class="detail-price oneline-hide">
|
||||||
<text class="goods-price f-30 col-m">¥{{ item.goods_price_min }}</text>
|
<text class="goods-price f-30 col-m">¥{{ item.showPromotionPrice }}</text>
|
||||||
<text v-if="item.line_price_min > 0" class="line-price col-9 f-24">¥{{ item.line_price_min }}</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>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</mescroll-body>
|
</mescroll-body>
|
||||||
|
<!-- 加入购物车组件 -->
|
||||||
|
<AddCartPopup ref="AddCartPopup" @addCart="onAddCart" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -93,23 +105,24 @@
|
|||||||
import * as GoodsApi from '@/api/goods'
|
import * as GoodsApi from '@/api/goods'
|
||||||
import { getEmptyPaginateObj, getMoreListData } from '@/core/app'
|
import { getEmptyPaginateObj, getMoreListData } from '@/core/app'
|
||||||
import Search from '@/components/search'
|
import Search from '@/components/search'
|
||||||
|
import AddCartPopup from '@/components/add-cart-popup'
|
||||||
|
|
||||||
const pageSize = 15
|
const pageSize = 15
|
||||||
const showViewKey = 'GoodsList-ShowView';
|
const showViewKey = 'GoodsList-ShowView';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
Search
|
Search,
|
||||||
|
AddCartPopup
|
||||||
},
|
},
|
||||||
mixins: [MescrollMixin],
|
mixins: [MescrollMixin],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
showView: false, // 列表显示方式 (true列表、false平铺)
|
showView: false, // 列表显示方式 (true列表、false平铺)
|
||||||
sortType: 'all', // 排序类型
|
sortType: 'all', // 排序类型: all, sales, price
|
||||||
sortPrice: false, // 价格排序 (true高到低 false低到高)
|
sortPrice: undefined, // 价格排序 (true高到低 false低到高) ASC升序、DESC降序
|
||||||
options: {}, // 当前页面参数
|
options: {}, // 当前页面参数
|
||||||
list: getEmptyPaginateObj(), // 商品列表数据
|
list: getEmptyPaginateObj(), // 商品列表数据
|
||||||
|
|
||||||
// 上拉加载配置
|
// 上拉加载配置
|
||||||
upOption: {
|
upOption: {
|
||||||
// 首次自动执行
|
// 首次自动执行
|
||||||
@ -121,51 +134,36 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* 生命周期函数--监听页面加载
|
|
||||||
*/
|
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
// 记录options
|
|
||||||
this.options = options
|
this.options = options
|
||||||
// 设置默认列表显示方式
|
this.showView = uni.getStorageSync(showViewKey) || false // 设置默认列表显示方式
|
||||||
this.setShowView()
|
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
// 上拉加载的回调 (页面初始化时也会执行一次)
|
||||||
/**
|
|
||||||
* 上拉加载的回调 (页面初始化时也会执行一次)
|
|
||||||
* 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
|
|
||||||
* @param {Object} page
|
|
||||||
*/
|
|
||||||
upCallback(page) {
|
upCallback(page) {
|
||||||
const app = this
|
const app = this
|
||||||
// 设置列表数据
|
GoodsApi.apiGetCommodityList({
|
||||||
app.getGoodsList(page.num)
|
page: page.num,
|
||||||
.then(list => {
|
pageSize: page.size,
|
||||||
const curPageLen = list.data.length
|
productName: app.options.search || undefined,
|
||||||
const totalSize = list.total
|
saleCountSort: app.sortType === 'sales' ? 'DESC' : undefined,
|
||||||
app.mescroll.endBySize(curPageLen, totalSize)
|
salePriceSort: app.sortType === 'price' ? app.sortPrice : undefined,
|
||||||
})
|
}).then(res => {
|
||||||
.catch(() => app.mescroll.endErr())
|
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 页码
|
* @param {number} pageNo 页码
|
||||||
*/
|
*/
|
||||||
getGoodsList(pageNo = 1) {
|
getGoodsList(pageNo = 1) {
|
||||||
const app = this
|
const app = this
|
||||||
console.log(app.options)
|
|
||||||
const param = {
|
const param = {
|
||||||
sortType: app.sortType,
|
sortType: app.sortType,
|
||||||
sortPrice: Number(app.sortPrice),
|
sortPrice: app.sortPrice,
|
||||||
categoryId: app.options.categoryId || 0,
|
categoryId: app.options.categoryId || 0,
|
||||||
goodsName: app.options.search || '',
|
goodsName: app.options.search || '',
|
||||||
page: pageNo
|
page: pageNo
|
||||||
@ -181,33 +179,38 @@
|
|||||||
.catch(reject)
|
.catch(reject)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// 切换排序方式
|
// 切换排序方式
|
||||||
handleSortType(newSortType) {
|
handleSortType(newSortType) {
|
||||||
const app = this
|
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.sortType = newSortType
|
||||||
app.sortPrice = newSortPrice
|
|
||||||
// 刷新列表数据
|
// 刷新列表数据
|
||||||
app.list = getEmptyPaginateObj()
|
app.list = getEmptyPaginateObj()
|
||||||
app.mescroll.resetUpScroll()
|
app.mescroll.resetUpScroll()
|
||||||
},
|
},
|
||||||
|
|
||||||
// 切换列表显示方式
|
// 切换列表显示方式
|
||||||
handleShowView() {
|
handleShowView() {
|
||||||
const app = this
|
const app = this
|
||||||
app.showView = !app.showView
|
app.showView = !app.showView
|
||||||
uni.setStorageSync(showViewKey, app.showView)
|
uni.setStorageSync(showViewKey, app.showView)
|
||||||
},
|
},
|
||||||
|
|
||||||
// 跳转商品详情页
|
// 跳转商品详情页
|
||||||
onTargetDetail(goodsId) {
|
onTargetDetail(goodsId) {
|
||||||
this.$navTo('pages/goods/detail', { goodsId })
|
this.$navTo('pages/goods/detail', { goodsId })
|
||||||
},
|
},
|
||||||
|
// 点击加入购物车
|
||||||
/**
|
handleAddCart(item) {
|
||||||
* 商品搜索
|
this.$refs.AddCartPopup.handle(item)
|
||||||
*/
|
},
|
||||||
|
// 更新购物车角标
|
||||||
|
onAddCart(total) {
|
||||||
|
setCartTabBadge()
|
||||||
|
},
|
||||||
|
// 商品搜索
|
||||||
handleSearch() {
|
handleSearch() {
|
||||||
const searchPageUrl = 'pages/search/index'
|
const searchPageUrl = 'pages/search/index'
|
||||||
// 判断来源页面
|
// 判断来源页面
|
||||||
@ -220,12 +223,8 @@
|
|||||||
// 跳转到商品搜索页
|
// 跳转到商品搜索页
|
||||||
this.$navTo(searchPageUrl)
|
this.$navTo(searchPageUrl)
|
||||||
},
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
|
// 设置分享内容
|
||||||
/**
|
|
||||||
* 设置分享内容
|
|
||||||
*/
|
|
||||||
onShareAppMessage() {
|
onShareAppMessage() {
|
||||||
// 构建分享参数
|
// 构建分享参数
|
||||||
const app = this
|
const app = this
|
||||||
@ -234,7 +233,6 @@
|
|||||||
path: "/pages/goods/list?" + this.$getShareUrlParams(app.options)
|
path: "/pages/goods/list?" + this.$getShareUrlParams(app.options)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分享到朋友圈
|
* 分享到朋友圈
|
||||||
* 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
|
* 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
|
||||||
@ -351,8 +349,8 @@
|
|||||||
|
|
||||||
.image {
|
.image {
|
||||||
display: block;
|
display: block;
|
||||||
width: 240rpx;
|
width: 200rpx;
|
||||||
height: 240rpx;
|
height: 200rpx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,7 +396,14 @@
|
|||||||
text-decoration: line-through;
|
text-decoration: line-through;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.action{
|
||||||
|
position: absolute;
|
||||||
|
right: 30rpx;
|
||||||
|
bottom: -30rpx;
|
||||||
|
font-size: 36rpx;
|
||||||
|
color: $main-bg;
|
||||||
|
}
|
||||||
|
|
||||||
// 平铺显示
|
// 平铺显示
|
||||||
.goods-list.column-2 {
|
.goods-list.column-2 {
|
||||||
@ -438,6 +443,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.detail {
|
.detail {
|
||||||
|
position: relative;
|
||||||
padding: 8rpx;
|
padding: 8rpx;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
|
|
||||||
@ -459,6 +465,10 @@
|
|||||||
text-decoration: line-through;
|
text-decoration: line-through;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.action{
|
||||||
|
bottom: 0;
|
||||||
|
right: 15rpx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
Loading…
x
Reference in New Issue
Block a user