2022-07-08 08:15:29 +00:00
< template >
< view class = "pad-b150" >
< status -nav :ifReturn ="false" navBarTitle = "分类" :marginBottom ="0" > < / s t a t u s - n a v >
<!-- 选择厂家 -- >
< view class = "pull-all-bg" v-show ="isShow" @tap="closeMore" > < / view >
< view class = "company-top" v-if ="businessId==0" > < / view >
< view class = "company" :style ="{'top':topHieght+'px'}" v-if ="businessId==0" >
2022-07-15 10:29:01 +00:00
< input type = "text" : value = "companyList[companyIndex].name?'工厂选择:'+ companyList[companyIndex].name:''" @tap ="openMore" disabled >
2022-07-18 10:02:41 +00:00
< scroll -view scroll -y = " true " class = "company-list" v-if ="isShow" >
2022-07-08 08:15:29 +00:00
< view @tap ="checkValue(index,item.id)" class = "company-item" : class = "companyIndex == index?'cur':''" v-for ="(item,index) in companyList" > {{ item.name }} < / view >
2022-07-18 10:02:41 +00:00
< / s c r o l l - v i e w >
2022-07-08 08:15:29 +00:00
< / view >
<!-- 一级分类列表 -- >
2022-07-18 10:02:41 +00:00
< scroll -view scroll -y = " true " class = "cate-nav-bg" :style ="{'height':scrollHeight+'px','top':topHieght+'px'}" :class ="businessId==0?'':'to-top'" v-if ="cateList.length>0" >
2022-07-08 08:15:29 +00:00
< view class = "cate-nav" >
< view class = "cate-nav-item" : class = "cateIndex == index?'active':''" @tap ="changeCate(index,item.id)" v-for ="(item,index) in cateList" :key ="index" > {{ item.title }} < / view >
< / view >
2022-07-18 10:02:41 +00:00
< / s c r o l l - v i e w >
2022-07-08 08:15:29 +00:00
<!-- 二级分类列表 -- >
2022-07-18 10:02:41 +00:00
< scroll -view scroll -y = " true " class = "shop-list-bg" :class ="businessId==0?'':'to-top'" >
2022-07-08 08:15:29 +00:00
< view class = "shop-list flex" >
< view class = "shop-item" @tap ="toShop(item.id)" v-for ="(item,index) in secondList" :key ="index" >
< view class = "img flex" > < image :src ="item.cover" mode = "widthFix" > < / image > < / view >
< view class = "txt clips1" > { { item . title } } < / view >
< / view >
< / view >
2022-07-13 08:04:38 +00:00
< view class = "tips" v-if ="secondList.length==0 && isTips" > - - - 没 有 更 多 分 类 - - - < / view >
2022-07-08 08:15:29 +00:00
< / s c r o l l - v i e w >
2022-07-14 03:09:02 +00:00
< view class = "cate-nothing-tips" v-if ="cateList.length==0" > - - - 该 商 户 没 有 分 类 - - - < / view >
2022-07-08 08:15:29 +00:00
<!-- 购物车btn -- >
< enter -cart > < / e n t e r - c a r t >
<!-- 底部tab -- >
< foot -tab current = "1" > < / f o o t - t a b >
< / view >
< / template >
< script >
import statusNav from '@/components/status-navs/status-nav' ;
import enterCart from '@/components/enter-cart/enter-cart.vue' ;
2022-07-25 03:18:38 +00:00
import { getCartNum , userInfoEv } from '@/jsFile/public-api.js' ;
2022-07-08 08:15:29 +00:00
// 底部组件
import footTab from '@/components/foot-tab/foot-tab.vue' ;
export default {
components : {
statusNav ,
enterCart ,
footTab
} ,
data ( ) {
return {
scrollHeight : uni . getSystemInfoSync ( ) . windowHeight - uni . getSystemInfoSync ( ) . statusBarHeight - 50 ,
newWidth : uni . getSystemInfoSync ( ) . windowWidth ,
topHieght : uni . getSystemInfoSync ( ) . statusBarHeight + 50 ,
companyList : [ ] , //工厂列表
companyIndex : 0 , //当前厂家
isShow : false , //显示弹窗
cateList : [ ] , //一级分类列表
cateIndex : 0 ,
secondList : [ ] , //二级分类列表
total : 0 ,
flag : true ,
ifLoading : false ,
businessId : 0 , //分类id
isTips : false , //是否提示
2022-07-15 03:05:54 +00:00
cacheBusinessId : - 1 , //商户id
2022-07-08 08:15:29 +00:00
}
} ,
onLoad ( op ) {
2022-07-12 10:07:08 +00:00
if ( op . business _id ) {
2022-07-15 03:05:54 +00:00
this . cacheBusinessId = op . business _id ;
}
} ,
onShow ( ) {
2022-07-27 03:12:29 +00:00
this . cateList = [ ] ;
this . secondList = [ ] ;
2022-07-15 03:05:54 +00:00
if ( this . cacheBusinessId !== - 1 ) {
this . $requst . post ( '/api/index/change-business' , { business _id : this . cacheBusinessId } ) . then ( res => {
2022-07-12 10:07:08 +00:00
if ( res . code == 0 ) {
this . getUserInfo ( ) ;
2022-07-13 08:04:38 +00:00
userInfoEv ( ) ;
2022-07-12 10:07:08 +00:00
}
} )
2022-07-11 10:35:14 +00:00
} else {
2022-07-12 10:07:08 +00:00
this . getUserInfo ( ) ;
2022-07-13 08:04:38 +00:00
userInfoEv ( ) ;
2022-07-11 10:35:14 +00:00
}
2022-07-25 03:18:38 +00:00
getCartNum ( ) ;
2022-07-08 08:15:29 +00:00
} ,
onReachBottom ( e ) {
} ,
// 分享到微信
onShareAppMessage ( ) {
2022-07-11 10:35:14 +00:00
let path = uni . getStorageSync ( 'page-path-options' ) + '?business_id=' + uni . getStorageSync ( 'business_id' ) ;
return {
path : path
}
2022-07-08 08:15:29 +00:00
} ,
// 分享到朋友圈
2022-07-11 10:35:14 +00:00
onShareTimeline ( res ) {
let path = uni . getStorageSync ( 'page-path-options' ) + '?business_id=' + uni . getStorageSync ( 'business_id' ) ;
return {
path : path
}
2022-07-08 08:15:29 +00:00
} ,
methods : {
// 获取用户信息
getUserInfo ( ) {
this . $requst . get ( '/api/user/info' ) . then ( res => {
if ( res . code == 0 ) {
this . businessId = res . data . business _id ;
2022-07-12 10:07:08 +00:00
this . getCompanyList ( res . data . business _id ) ; //查询商户
2022-07-27 03:12:29 +00:00
if ( this . businessId > 0 ) {
this . getCateList ( res . data . business _id ) ; //查询一级分类
}
2022-07-08 08:15:29 +00:00
}
} )
} ,
// 弹出厂家选择框
openMore ( ) {
if ( ! this . isShow ) {
this . isShow = true ;
} else {
this . isShow = false ;
}
} ,
// 关闭厂家选择
closeMore ( ) {
this . isShow = false ;
} ,
// 选择厂家
checkValue ( index , id ) {
this . companyIndex = index ;
this . getCateList ( id ) ; //查询一级分类
// 关闭厂家选择
this . closeMore ( ) ;
} ,
// 选择分类
changeCate ( index , id ) {
this . cateIndex = index ;
// 查询二级
this . isTips = false ;
this . secondList = [ ] ;
this . getSecondList ( this . cateIndex ) ;
} ,
// 查询工厂列表
2022-07-11 10:35:14 +00:00
getCompanyList ( business _id ) {
this . $requst . get ( '/api/spu/business' , { business _id : business _id } ) . then ( res => {
2022-07-08 08:15:29 +00:00
if ( res . code == 0 ) {
this . companyList = res . data ; //商户列表
// 查询一级分类
if ( this . companyList . length > 0 ) {
2022-07-27 03:12:29 +00:00
this . getCateList ( this . companyList [ this . companyIndex ] . id ) ;
2022-07-08 08:15:29 +00:00
} else {
this . getCateList ( 0 ) ;
}
}
} )
} ,
// 查询一级分类
getCateList ( pid ) {
2022-07-15 02:11:42 +00:00
uni . showLoading ( {
title : '加载中'
} ) ;
2022-07-08 08:15:29 +00:00
this . $requst . get ( '/api/spu/category' , { business _id : pid } ) . then ( res => {
if ( res . code == 0 ) {
2022-07-15 02:11:42 +00:00
// uni.setStorageSync('businessId',this.businessId); //工厂id
2022-07-14 03:09:02 +00:00
this . cateIndex = 0 ;
this . cateList = [ ] ;
this . cateList = res . data ; //一级分类
// 查询二级
this . getSecondList ( this . cateIndex ) ;
2022-07-08 08:15:29 +00:00
}
} )
} ,
// 查询二级分类
getSecondList ( index ) {
2022-07-14 03:09:02 +00:00
this . secondList = [ ] ;
2022-07-15 01:04:30 +00:00
if ( this . cateList . length > 0 ) {
if ( this . cateList [ index ] . has _children ) {
this . secondList = this . cateList [ index ] . children ;
} else {
this . isTips = true ;
}
2022-07-08 08:15:29 +00:00
}
2022-07-15 02:11:42 +00:00
uni . hideLoading ( ) ;
2022-07-08 08:15:29 +00:00
} ,
// 跳转详情页
toShop ( id ) {
uni . navigateTo ( {
2022-07-15 02:11:42 +00:00
url : ` /pagesA/shop/shop?category_id= ${ id } &company_id= ${ this . companyList [ this . companyIndex ] . id } `
2022-07-08 08:15:29 +00:00
} )
} ,
}
}
< / script >
< style >
< / style >