luban-mall/pagesA/shop/shop.vue

227 lines
5.9 KiB
Vue

<template>
<view>
<status-nav :ifReturn="true" navBarTitle="商品列表" :marginBottom="0"></status-nav>
<!-- 商品排序分类 -->
<view class="pull-all-bg" v-if="sortShow || cateShow" @tap="closePullBg"></view>
<view class="shop-nav flex" :style="{'top':topHieght+'px'}">
<view class="shop-sort flex" @tap.stop="openSort()">
<text>{{sortList[sortIndex].name}}</text>
<image src="/static/public/icon-shop.png" mode="widthFix"></image>
</view>
<view class="shop-cate flex" @tap.stop="openCate()" v-if="cateList.length>0">
<text>{{cateList[cateIndex].title}}</text>
<image src="/static/public/icon-shop.png" mode="widthFix"></image>
</view>
<view class="shop-sort-list flex" v-if="sortShow">
<view class="shop-sort-item" :class="sortIndex == index?'cur':''" @tap.stop="checkSort(index)" v-for="(item,index) in sortList" :key="index">{{item.name}}</view>
</view>
<view class="shop-cate-list flex" v-if="cateShow">
<view class="shop-cate-item" :class="cateIndex == index?'cur':''" @tap.stop="checkCate(index)" v-for="(item,index) in cateList" :key="index">{{item.title}}</view>
</view>
</view>
<!-- 商品列表 -->
<scroll-view scroll-y class="shop-bg">
<view class="shop-ul flex">
<view class="shop-li" @tap="toDetail(item.id)" v-for="(item,index) in shopList" :key="index">
<view class="img"><image :src="item.imgsrc" mode="widthFix"></image></view>
<view class="txt clips2">{{item.title}}</view>
</view>
</view>
</scroll-view>
<!-- 暂无更多内容 -->
<view class="more-txt" style="padding-bottom: 40rpx;" v-if="totalAll==total"></view>
</view>
</template>
<script>
import statusNav from '@/components/status-navs/status-nav';
import {getCartNum,userInfoEv} from '@/jsFile/public-api.js';
import {mapState} from 'vuex'//引入mapState
export default {
components:{
statusNav,
},
data() {
return {
scrollHeight:uni.getSystemInfoSync().windowHeight - uni.getSystemInfoSync().statusBarHeight - 50,
newWidth:uni.getSystemInfoSync().windowWidth,
topHieght: uni.getSystemInfoSync().statusBarHeight + 50,
sortShow:false, //是否显示排序
sortList:[], //排序列表
sortIndex:0,
cateShow:false, //是否显示分类
cateList:[], //分类导航列表
cateIndex:0,
shopList:[], //商品列表
total:0,
flag:true,
ifLoading:false,
category_id:'', //分类id
company_id:'', //商户id
sort:'new' ,//排序
page:1, //页数
size:10, //数量
total:0, //总数
totalAll:-1, //计算总数
cacheBusinessId:-1, //商户id
}
},
computed:{
...mapState({
footHeight: state => state.moduleA.footHeight,
}),
},
onLoad(op) {
this.category_id = op.category_id;
this.company_id = op.company_id;
if(op.business_id){
this.cacheBusinessId = op.business_id;
}
},
onShow() {
if(this.cacheBusinessId !== -1){
this.$requst.post('/api/index/change-business',{business_id:this.cacheBusinessId}).then(res=>{
if(res.code == 0){
this.shopList = [];
this.getShopScreen(); //查询商品分类
userInfoEv();
}
})
}else{
this.shopList = [];
this.getShopScreen(); //查询商品分类
userInfoEv();
}
},
onReachBottom(e) {
if(this.shopList.length<this.total){
this.page++;
//
this.getShopList();
}
},
methods: {
//
openSort(){
this.cateShow = false;
if(!this.sortShow){
this.sortShow = true;
}else{
this.sortShow = false;
}
},
//
closeSort(){
this.sortShow = false;
},
//
checkSort(index){
this.sortIndex = index;
this.sort = this.sortList[this.sortIndex].value;
this.shopList = [];
//
this.closeSort();
//
this.getShopList();
},
//
openCate(){
this.sortShow = false;
if(!this.cateShow){
this.cateShow = true;
}else{
this.cateShow = false;
}
},
//
closeCate(){
this.cateShow = false;
},
//
checkCate(index){
this.cateIndex = index;
this.category_id = this.cateList[this.cateIndex].value;
this.shopList = [];
//
this.closeCate();
//
this.getShopList();
},
//
closePullBg(){
this.closeSort();
//
this.closeCate();
},
//
getShopScreen(){
let params = {
category_id:this.category_id,
business_id:this.company_id
}
this.$requst.post('/api/spu/condition',params).then(res=>{
if(res.code==0) {
this.sortList = res.data[0].children; //排序
this.cateList = res.data[1].children; //分类
if(this.cateList.length>0){
for(let key in this.cateList){
if(this.cateList[key].value == this.category_id){
this.cateIndex = key;
}
}
}
//查询商品列表
this.getShopList();
}
})
},
// 查询商品列表
getShopList(){
uni.showLoading({
title: '加载中'
});
this.ifLoading = true;
let params = {
business_id:this.company_id,
page:this.page,
size:this.size,
category_id:this.category_id,
sort:this.sort
}
this.$requst.get('/api/spu/list',params).then(res=>{
if(res.code==0) {
this.total = res.data.total;
let newArr = [];
res.data.list.forEach(item=>{
let obj = {
id:item.id,
imgsrc:item.cover,
title:item.name
}
newArr.push(obj);
})
this.shopList = this.shopList.concat(newArr);
if(this.shopList.length == this.total){
this.totalAll = this.total;
}
}
uni.hideLoading();
})
},
// 跳转详情页
toDetail(id) {
uni.navigateTo({
url:`/pagesA/shop/detail?id=${id}&source=shop`
})
},
}
}
</script>
<style>
</style>