Browse Source

调整分类页

master
梁欣 1 year ago
parent
commit
64fed7379f
  1. 4
      api/category/index.js
  2. 144
      pages/goods/list.vue

4
api/category/index.js

@ -7,8 +7,8 @@ const api = {
} }
// 页面数据 // 页面数据
export function list() {
return request.get(api.list)
export function list(param) {
return request.get(api.list, param)
} }

144
pages/goods/list.vue

@ -4,7 +4,7 @@
@down="downCallback" :up="upOption" @up="upCallback"> @down="downCallback" :up="upOption" @up="upCallback">
<!-- 页面头部 --> <!-- 页面头部 -->
<view class="header"> <view class="header">
<search class="search" :tips="options.search ? options.search : '搜索商品'" @event="handleSearch" />
<search class="search" :tips="options.search ? options.search : '搜索商品'" @event="handleSearch"/>
<!-- 切换列表显示方式 --> <!-- 切换列表显示方式 -->
<view class="show-view" @click="handleShowView"> <view class="show-view" @click="handleShowView">
<text class="iconfont icon-view-tile" v-if="showView"></text> <text class="iconfont icon-view-tile" v-if="showView"></text>
@ -16,9 +16,6 @@
<view class="sort-item" :class="{ active: sortType === 'all' }" @click="handleSortType('all')"> <view class="sort-item" :class="{ active: sortType === 'all' }" @click="handleSortType('all')">
<text>综合</text> <text>综合</text>
</view> </view>
<view class="sort-item" :class="{ active: sortType === 'category' }" @click="changeCategory">
<text>{{ categoryText }}</text>
</view>
<view class="sort-item" :class="{ active: sortType === 'sales' }" @click="handleSortType('sales')"> <view class="sort-item" :class="{ active: sortType === 'sales' }" @click="handleSortType('sales')">
<text>销量</text> <text>销量</text>
</view> </view>
@ -35,6 +32,21 @@
</view> </view>
</view> </view>
</view> </view>
<scroll-view scroll-x>
<view class="cate-filter">
<u-tag text="全部分类" shape="circle"
@click="changeCategory('all')"
:bgColor="selectedCategoryList.length === childCategoryList.length ? '#9e1a91' : 'transparent'"
:color="selectedCategoryList.length === childCategoryList.length ? 'white' : '#9e1a91'"
borderColor="#9e1a91"/>
<u-tag :text="item.name" shape="circle" plain v-for="(item, index) in childCategoryList"
:key="index"
@click="changeCategory(item.category_id)"
:bgColor="(selectedCategoryList.length === 1 && selectedCategoryList[0] === item.category_id) ? '#9e1a91' : 'transparent'"
:color="(selectedCategoryList.length === 1 && selectedCategoryList[0] === item.category_id) ? 'white' : '#9e1a91'"
borderColor="#9e1a91"/>
</view>
</scroll-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" <view class="goods-item" v-for="(item, index) in list.data" :key="index"
@ -68,7 +80,8 @@
<view class="desc_footer"> <view class="desc_footer">
<text class="price_x">¥{{ item.goods_price_min }}</text> <text class="price_x">¥{{ item.goods_price_min }}</text>
<text class="price_y col-9" <text class="price_y col-9"
v-if="item.line_price_min > 0">¥{{ item.line_price_min }}</text>
v-if="item.line_price_min > 0">¥{{ item.line_price_min }}
</text>
</view> </view>
</view> </view>
</view> </view>
@ -122,7 +135,8 @@
<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.goods_price_min }}</text>
<text v-if="item.line_price_min > 0" <text v-if="item.line_price_min > 0"
class="line-price col-9 f-24">{{ item.line_price_min }}</text>
class="line-price col-9 f-24">{{ item.line_price_min }}
</text>
</view> </view>
</view> </view>
</view> </view>
@ -130,32 +144,30 @@
</view> </view>
</mescroll-body> </mescroll-body>
</view> </view>
</template> </template>
<script> <script>
import Shortcut from '@/components/shortcut'
import {
import Shortcut from '@/components/shortcut'
import {
inArray inArray
} from '@/utils/util'
import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
import * as GoodsApi from '@/api/goods'
import {
} from '@/utils/util'
import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
import * as GoodsApi from '@/api/goods'
import * as CategoryApi from '@/api/category'
import {
getEmptyPaginateObj, getEmptyPaginateObj,
getMoreListData getMoreListData
} from '@/core/app'
import Search from '@/components/search'
} from '@/core/app'
import Search from '@/components/search'
const pageSize = 15
const showViewKey = 'GoodsList-ShowView';
const pageSize = 15
const showViewKey = 'GoodsList-ShowView';
export default {
export default {
components: { components: {
MescrollBody, MescrollBody,
Search, Search,
@ -165,7 +177,7 @@
data() { data() {
return { return {
newIds: [], newIds: [],
hotIds:[],
hotIds: [],
inArray, inArray,
showView: false, // (truefalse) showView: false, // (truefalse)
sortType: 'all', // sortType: 'all', //
@ -186,24 +198,39 @@
}, },
mainCategoryId: 0, // id mainCategoryId: 0, // id
categoryText: '全部分类', categoryText: '全部分类',
childCategoryList: []
childCategoryList: [],
showPopup: false,
selectedCategoryList: []
} }
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad(options) {
async onLoad(options) {
// options // options
this.options = options this.options = options
await this.getChildCategory(options.categoryId)
// //
this.setShowView() this.setShowView()
this.getNews() this.getNews()
this.getHots() this.getHots()
await this.getGoodsList(1)
}, },
methods: { methods: {
getChildCategory(parent_id) {
return new Promise(resolve => {
CategoryApi.list({
parent_id,
}).then(res => {
this.childCategoryList = res.data.list
this.selectedCategoryList = this.childCategoryList.map(item => parseInt(item.category_id))
resolve()
})
})
},
/** /**
* 上拉加载的回调 (页面初始化时也会执行一次) * 上拉加载的回调 (页面初始化时也会执行一次)
@ -230,8 +257,8 @@
getNews() { getNews() {
const app = this const app = this
const param = { const param = {
categoryId: app.options.categoryId || 0,
// categoryId: app.options.categoryId || 0,
categoryIds: this.selectedCategoryList.join(),
} }
GoodsApi.newIds(param) GoodsApi.newIds(param)
.then(result => { .then(result => {
@ -244,8 +271,8 @@
getHots() { getHots() {
const app = this const app = this
const param = { const param = {
categoryId: app.options.categoryId || 0,
// categoryId: app.options.categoryId || 0,
categoryIds: this.selectedCategoryList.join(),
} }
GoodsApi.hotIds(param) GoodsApi.hotIds(param)
.then(result => { .then(result => {
@ -262,10 +289,11 @@
*/ */
getGoodsList(pageNo = 1) { getGoodsList(pageNo = 1) {
const app = this const app = this
console.log(this.selectedCategoryList)
const param = { const param = {
sortType: app.sortType, sortType: app.sortType,
sortPrice: Number(app.sortPrice), sortPrice: Number(app.sortPrice),
categoryId: app.options.categoryId || 0,
categoryIds: this.selectedCategoryList.join(),
goodsName: app.options.search || '', goodsName: app.options.search || '',
page: pageNo page: pageNo
} }
@ -281,6 +309,14 @@
}) })
}, },
changeCategory(cateId) {
if (cateId === 'all') this.selectedCategoryList = this.childCategoryList.map(item => parseInt(item.category_id))
else this.selectedCategoryList = [parseInt(cateId)]
this.getNews()
this.getHots()
this.getGoodsList()
},
// //
handleSortType(newSortType) { handleSortType(newSortType) {
const app = this const app = this
@ -292,10 +328,6 @@
app.mescroll.resetUpScroll() app.mescroll.resetUpScroll()
}, },
changeCategory(category){
},
// //
handleShowView() { handleShowView() {
const app = this const app = this
@ -353,12 +385,12 @@
} }
} }
}
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
//
.header {
//
.header {
display: flex; display: flex;
align-items: center; align-items: center;
background-color: #fff; background-color: #fff;
@ -377,10 +409,10 @@
display: flex; display: flex;
align-items: center; align-items: center;
} }
}
}
//
.store-sort {
//
.store-sort {
position: sticky; position: sticky;
top: var(--window-top); top: var(--window-top);
display: flex; display: flex;
@ -424,16 +456,16 @@
} }
}
}
//
.goods-list {
//
.goods-list {
padding: 4rpx; padding: 4rpx;
box-sizing: border-box; box-sizing: border-box;
}
}
//
.goods-list.column-1 {
//
.goods-list.column-1 {
.goods-item { .goods-item {
width: 100%; width: 100%;
height: 280rpx; height: 280rpx;
@ -503,16 +535,16 @@
text-decoration: line-through; text-decoration: line-through;
} }
} }
}
}
//
.goods-list.column-2 {
//
.goods-list.column-2 {
.goods-item { .goods-item {
width: 50%; width: 50%;
} }
}
}
.goods-item {
.goods-item {
float: left; float: left;
box-sizing: border-box; box-sizing: border-box;
padding: 6rpx; padding: 6rpx;
@ -565,5 +597,17 @@
} }
} }
} }
}
.cate-filter {
padding: 20rpx 8rpx;
display: flex;
align-items: center;
justify-content: flex-start;
* {
margin-right: 10rpx;
flex-shrink: 0;
} }
}
</style> </style>
Loading…
Cancel
Save