Browse Source

优化商品分类左右联动

feature/feature-compatible
wenghaocan 7 years ago
parent
commit
44134cc409
1 changed files with 29 additions and 13 deletions
  1. 42
      src/view/goods-classify.vue

42
src/view/goods-classify.vue

@ -6,7 +6,7 @@
<div class="content">
<div class="left" ref="menuWrapper">
<ul>
<li v-if="goodsList.length != 0" v-for="(item,index) in goodsList" :key="index" :class="{'on': currentIndex === index}" @click="selectMenu(index,$event)">
<li v-if="goodsList.length != 0" :class="{'on': (currentIndex < 0 ? 0 : currentIndex) === index}" v-for="(item,index) in goodsList" :key="index" @click="selectMenu(index,$event)">
<a href="javascript:void(0)">
{{item.combinationName}}
<img src="../assets/images/icon/hot.png" class="i-hot" v-if="item.label == '2'" />
@ -62,22 +62,30 @@
imghost: "http://medou.oss-cn-shenzhen.aliyuncs.com/",
listHeight: [], //
scrollY: {},
clickTrue: false,
currentNum: 0
}
},
computed: {
/*currentIndex () {
const { scrollY, listHeight } = this
currentIndex () {
const { scrollY, listHeight, clickTrue, currentNum } = this
let index = listHeight.findIndex((height, index) => {
return scrollY >= listHeight[index] && scrollY < listHeight[index + 1]
})
if (scrollY > listHeight[index] + 50) {
index++
}
if(listHeight[listHeight.length-1] - this.$refs.foodWrapper.clientHeight <= scrollY ) {
if(clickTrue) {
return currentNum
} else {
return (listHeight.length-1)
}
}
return index
}*/
}
currentIndex(){
/*currentIndex() {
for (let i = 0; i < this.listHeight.length; i++){
let height = this.listHeight[i]
let height2 = this.listHeight[i + 1]
@ -95,7 +103,7 @@
}
}
return 0
}
}*/
},
components: {
Toast,
@ -129,13 +137,20 @@
that.showLoading = false
if ( res.code == 0 ){
this.goodsList = res.data || []
let list = []
for (var i = 0; i < this.goodsList.length; i++) {
if (this.goodsList[i].goodsList.length != 0) {
list.push(this.goodsList[i])
}
}
this.goodsList = list
this.$nextTick(function(){
//scroll
this._initScroll()
//
this._calculateHeight();
//
this.autoSelect()
this.autoSelect(list, this.c_no)
})
} else {
this.$vux.toast.text(res.msg,"middle");
@ -182,24 +197,25 @@
this.foodsScroll.scrollToElement(el,300)
},*/
selectMenu(index, event){
this.clickTrue = true //clickTruetrue
this.clickTrue = true //clickTruetrue
this.currentNum = index
//better-scrolleventevent_constructed
// _constructedreturn
if (event && !event._constructed){
return
} else {
let foodList = this.$refs.foodWrapper.getElementsByClassName("food-list-hook");
let foodList = this.$refs.foodWrapper.getElementsByClassName("food-list-hook");
let el = foodList[index];
this.foodsScroll.scrollToElement(el,300)
}
},
autoSelect() {
for (let i = 0; i < this.goodsList.length; i++) {
if(this.goodsList[i].combinationNo == this.c_no) {
autoSelect(list, no) {
list.forEach((v, i, a) => {
if(v.combinationNo === no) {
this.selectMenu(i)
}
}
  })
},
ShareWenXin (){
var merchantNo = this.no

Loading…
Cancel
Save