deming/pageB/search/searchGoods.vue

193 lines
4.8 KiB
Vue
Raw Normal View History

2020-08-08 18:15:07 +08:00
<template>
<view class="classify-goods">
<view class="tab-container">
<view class="salenum" :class="{ 'current' : current == 0 }" @click="switchCurrent(0)">销量</view>
<view class="price" :class="{ 'current' : current == 1 }" @click="switchCurrent(1)">
<view class="text">价格</view>
<view class="icon">
<u-icon name="arrow-up-fill" :color="(current == 1 && priceOrderAsc) ? '#FF780F' : '#333333'" size="22"></u-icon>
<u-icon name="arrow-down-fill" :color="(current == 1 && !priceOrderAsc) ? '#FF780F' : '#333333'" size="22"></u-icon>
</view>
</view>
<view class="evaluation" :class="{ 'current' : current == 2 }" @click="switchCurrent(2)">好评</view>
</view>
<scroll-view scroll-y class="goods-container" :style="{ height: scrollHeight }" @scrolltolower="loadMore">
<view v-for="goods in goodsList" :key="goods.goods_id" class="goods-item" @click="toDetailsPage(goods.goods_id)">
<image :src="goods.goods_image"></image>
<view class="right">
<view class="name u-line-1">{{ goods.goods_name }}</view>
<view class="briefing u-line-2">{{ goods.goods_advword }}</view>
</view>
</view>
<u-loadmore :status="loadStatus" bgColor="#FFFFFF" margin-top="20" margin-bottom="20" v-if="goodsList.length >= pageSize"></u-loadmore>
<u-empty mode="list" v-if="!goodsList.length"></u-empty>
</scroll-view>
</view>
</template>
<script>
export default {
data() {
return {
pageSize: 12,
cid: '',
page: 1,
current: 0,
priceOrderAsc: true, // 是否升序
goodsList: [],
scrollHeight: '',
loadStatus: 'loadmore',
2020-08-09 18:29:36 +08:00
timer: true, // 防止上拉加载短时间内多次调用,
value:""
2020-08-08 18:15:07 +08:00
}
},
watch: {
current(value) {
this.page = 1;
2020-08-09 18:29:36 +08:00
this.ShopSearch({ laod: 'reload' });
2020-08-08 18:15:07 +08:00
},
priceOrderAsc(value) {
this.page = 1;
2020-08-09 18:29:36 +08:00
this.ShopSearch({ laod: 'reload' });
2020-08-08 18:15:07 +08:00
}
},
onLoad(option) {
2020-08-09 18:29:36 +08:00
this.value = option.value
2020-08-08 18:15:07 +08:00
this.setViewHeight();
2020-08-09 18:29:36 +08:00
this.ShopSearch()
},
onNavigationBarSearchInputConfirmed(value) {
this.value = value.text
this.ShopSearch()
2020-08-08 18:15:07 +08:00
},
methods: {
setOrderSort() {
let sort = '';
if(this.current == 0) {
sort = 'goods_salenum';
} else if (this.current == 1) {
if(this.priceOrderAsc) sort = 'goods_price_asc';
else sort = 'goods_price_desc';
} else if (this.current == 2) {
sort = 'evaluation_count';
}
return sort;
},
// 排序方式 goods_salenum销量 evaluation_count评价 goods_price_asc价格从低到高 goods_price_desc价格从高到低
2020-08-09 18:29:36 +08:00
async ShopSearch({ load = 'reload' } = {}) {
2020-08-08 18:15:07 +08:00
const sort = this.setOrderSort();
2020-08-09 18:29:36 +08:00
const res = await this.$u.api.ShopSearch({
keyword: this.value,
2020-08-08 18:15:07 +08:00
page: this.page,
order: sort,
})
this.timer = true;
if(res.errCode == 0) {
if(load == 'reload') this.goodsList = res.data.data;
else if(load == 'loadmore') this.goodsList.push(...res.data.data);
}
return res.data.data.length;
},
loadMore() {
if(this.goodsList.length < this.pageSize) return false;
if(!this.timer) return false;
this.loadStatus = "loading";
this.page++;
2020-08-09 18:29:36 +08:00
this.ShopSearch({ load: 'loadmore' }).then(length => {
2020-08-08 18:15:07 +08:00
if(length == 0) {
this.page--;
this.loadStatus = 'nomore';
} else {
this.loadStatus = 'loading';
}
}).catch(() => {
this.loadStatus = "nomore";
this.page--;
})
},
switchCurrent(current) {
2020-08-09 18:29:36 +08:00
this.ShopSearch()
2020-08-08 18:15:07 +08:00
if(current == 1 && this.current == 1) this.priceOrderAsc = !this.priceOrderAsc;
this.current = current;
},
setViewHeight() {
const res = uni.getSystemInfoSync();
2020-08-09 18:29:36 +08:00
this.scrollHeight = res.windowHeight - res.windowWidth / 750 * 90 + 'px';
2020-08-08 18:15:07 +08:00
},
toDetailsPage(id) {
this.$u.route('/pageB/sdetails/index', {
2020-08-09 18:29:36 +08:00
id: id
2020-08-08 18:15:07 +08:00
});
}
}
};
</script>
<style lang="scss" scoped>
.classify-goods {
.tab-container {
box-sizing: border-box;
padding: 30rpx 40rpx;
display: flex;
margin-bottom: 30rpx;
> view {
height: 30rpx;
line-height: 30rpx;
flex: 1;
font-size: 32rpx;
color: rgba(51,51,51,1);
}
.salenum {
text-align: left;
}
.price {
display: flex;
align-items: center;
justify-content: center;
.text {
margin-right: 5rpx;
}
.icon {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
}
.evaluation {
text-align: right;
}
.current {
color: rgba(255,120,15,1);
}
}
.goods-container {
.goods-item {
margin: 0 auto;
width: 690rpx;
display: flex;
background-color: #F5F5F5;
margin-bottom: 30rpx;
align-items: center;
> image {
width: 220rpx;
height: 200rpx;
flex-shrink: 0;
margin-right: 30rpx;
}
.right {
width: 418rpx;
.name {
font-size: 30rpx;
color: rgba(51,51,51,1);
margin-bottom: 20rpx;
}
.briefing {
font-size: 28rpx;
color: rgba(102,102,102,1);
line-height: 42rpx;
}
}
}
}
}
</style>