dever před 4 roky
rodič
revize
f8a9cfa65b
1 změnil soubory, kde provedl 12 přidání a 48 odebrání
  1. 12 48
      pages/index/list.vue

+ 12 - 48
pages/index/list.vue

@@ -1,6 +1,6 @@
 <template>
 	<view class="container" slot="gBody">
-		<view class="main" v-if="fetch.cate.length > 0">
+		<view class="main" v-if="state == 1">
 			<view class="content" :style="height">
 				<scroll-view class="menus" :scroll-into-view="view" scroll-with-animation scroll-y>
 					<view class="wrapper">
@@ -10,7 +10,7 @@
 					</view>
 				</scroll-view>
 				<!-- goods list begin -->
-				<scroll-view class="goods" scroll-with-animation scroll-y :scroll-top="top" @scroll="scoll">
+				<scroll-view class="goods" scroll-with-animation scroll-y :scroll-top="top">
 					<view class="wrapper">
 						<swiper class="ads" id="ads" autoplay :interval="3000" indicator-dots v-if="fetch.focus.length > 0">
 							<swiper-item v-for="(v, k) in fetch.focus" :key="k" @tap="go" :data-url="v.link">
@@ -19,11 +19,7 @@
 						</swiper>
 						<view class="list">
 							<!-- category begin -->
-							<view class="category" v-for="(v, k) in fetch.cate" :key="k" :id="`cate-${v.id}`">
-								<view class="title">
-									<text>{{ v.name }}</text>
-									<image :src="v.logo" class="icon"></image>
-								</view>
+							<view class="category" v-for="(v, k) in fetch.cate" :key="k" :id="`cate-${v.id}`"  v-if="k == cate_index">
 								<view class="items">
 									<!-- 商品 begin -->
 									<view class="good" v-for="(v1, k1) in fetch.info[v.id]" :key="k1">
@@ -47,7 +43,7 @@
 			</view>
 			<!-- content end -->
 		</view>
-		<view v-if="fetch.cate.length <= 0" class="d-flex w-100 h-100 flex-column just-content-center align-items-center" style="margin-top:200rpx;">
+		<view v-if="state == 2" class="d-flex w-100 h-100 flex-column just-content-center align-items-center" style="margin-top:200rpx;">
 			<view class="tips d-flex flex-column align-items-center font-size-base text-color-assist">
 				<view>您还没有任何阅览的小记</view>
 				<view>小记可能就在你身边,快去寻找吧~</view>
@@ -65,7 +61,8 @@ export default {
 		
 	},
 	data() {
-		return {
+		return {
+			state : 0,
 			fetch : {
 				cate : [],
 				info : [],
@@ -75,7 +72,6 @@ export default {
 			cate_index: 0,//默认分类
 			top: 0,
 			view: '',
-			sizeState: false,
 		}
 	},
 	onLoad() {
@@ -97,7 +93,12 @@ export default {
 	methods: {
 		getData : function() {
 			var self = this;
-			this.Dever.get(this, 'app/collection/?l=api.getList', {id:-1}, function(t) {
+			this.Dever.get(this, 'app/collection/?l=api.getList', {id:-1}, function(t) {
+				if (t.cate.length > 0) {
+					self.state = 1;
+				} else {
+					self.state = 2;
+				}
 				uni.getSystemInfo({
 					success: function (res) {
 						self.height = 'height:' + res.windowHeight + 'px';
@@ -120,44 +121,7 @@ export default {
 		},
 		
 		menu : function(index, id) {
-			if(!this.sizeState) {
-				this.size()
-			}
-			
 			this.cate_index = index
-			this.$nextTick(() => this.top = this.fetch.cate.find(item => item.id == id).top)
-		},
-		scoll : function({detail}) {	//商品列表滚动事件
-			if(!this.sizeState) {
-				this.size()
-			}
-			const {scrollTop} = detail
-			let tabs = this.fetch.cate.filter(item=> item.top <= scrollTop).reverse()
-			if(tabs.length > 0){
-				this.cate_id = tabs[0].id
-			}
-		},
-		size : function() {
-			let h = 10
-			
-			let view = uni.createSelectorQuery().select('#ads')
-			view.fields({
-				size: true
-			}, data => {
-				h += Math.floor(data.height)
-			}).exec()
-			
-			this.fetch.cate.forEach(item => {
-				let view = uni.createSelectorQuery().select(`#cate-${item.id}`)
-				view.fields({
-					size: true
-				}, data => {
-					item.top = h
-					h += data.height
-					item.bottom = h
-				}).exec()
-			})
-			this.sizeState = true
 		},
 	}
 };