uni-app开发scroll-view下拉加载和滑动至底部加载

<template>
	<view class="category">
		<searchBar style="margin-bottom: 10px;" @search="handleSearch"></searchBar>
		<view class="content">
			<scroll-view scroll-y class="left-aside">
				<view v-for="item in flist" :key="item.id" class="f-item b-b" :class="{active: item.id === currentId}" @click="tabtap(item)">
					{{item.name}}
				</view>
			</scroll-view>
			<scroll-view scroll-with-animation scroll-y class="right-aside" :refresher-triggered="loading" refresher-enabled @refresherrefresh="handleRefresh" @scrolltolower="scrolltolower">
				<view class="s-list">
					<view @click="navToList(item.id)" class="s-item" v-for="item in slist" :key="item.id">
						<view class="item-left"><image :src="item.icon||'http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20190519/default.png'"></image></view>
						<view class="item-right">
							<view class="item-title">
								<image v-if="item.type==='1'" class="item-type" src="@/static/otc-green.png"></image>
								<image v-if="item.type==='2'" class="item-type" src="@/static/otc-red.png"></image>
								<image v-if="item.type==='3'" class="item-type" src="@/static/rx-blue.png"></image>
								<span>{{ item.name }}</span><span> {{ item.guige }}</span>
							</view>
							<view class="sale-num">
								<span class="sale-type">活动款</span>
								<span class="sale-number">{{item.num}} 销量</span>
							</view>
							<view class="item-tag">
								<span class="item-tag-type">满减满赠</span>
								<span class="item-tag-type">加价购</span>
							</view>
							<view class="price">
								<span class="price-prefix">¥<span class="price-num">{{ item.price }}</span></span>
								<image class="car-logo" src="@/static/shopCar.png"></image>
							</view>
						</view>
					</view>
					<uni-load-more :status="status" :content-text="contentText"></uni-load-more>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import searchBar from '@/components/search-bar.vue'
	export default {
		components:{
			searchBar
		},
		data() {
			return {
				currentId: 0,
				flist: [
					{ name: '营养保健', id: 0 },
					{ name: '感冒咳嗽', id: 1 },
					{ name: '胃肠用药', id: 2 },
					{ name: '胃肠用药', id: 3 },
					{ name: '胃肠用药', id: 4 },
					{ name: '胃肠用药', id: 5 },
					{ name: '营养保健', id: 6 },
					{ name: '营养保健', id: 7 },
					{ name: '营养保健', id: 8 },
					{ name: '营养保健', id: 9 },
					{ name: '营养保健', id: 10 },
					{ name: '营养保健', id: 11 },
					{ name: '营养保健', id: 12 },
					{ name: '营养保健', id: 13 },
					{ name: '营养保健', id: 14 },
					{ name: '营养保健', id: 15 },
					{ name: '营养保健', id: 16 },
				],
				slist: [
					{ id: 0, name: '小柴胡颗粒', guige: '2.5克*15袋', num: '800', price: '29.8', type: '1'  },
					{ id: 1, name: '小柴胡颗粒', guige: '2.5克*15袋', num: '800', price: '29.8', type: '2'  },
					{ id: 2, name: '小柴胡颗粒', guige: '2.5克*15袋', num: '800', price: '29.8', type: '3'  },
					{ id: 3, name: '小柴胡颗粒', guige: '2.5克*15袋', num: '800', price: '29.8', type: '1'  },
					{ id: 4, name: '小柴胡颗粒', guige: '2.5克*15袋', num: '800', price: '29.8', type: '3'  },
					{ id: 5, name: '小柴胡颗粒', guige: '2.5克*15袋', num: '800', price: '29.8', type: '1'  },
					{ id: 6, name: '小柴胡颗粒', guige: '2.5克*15袋', num: '800', price: '29.8', type: '1'  },
					{ id: 7, name: '小柴胡颗粒', guige: '2.5克*15袋', num: '800', price: '29.8', type: '1'  },
					{ id: 8, name: '小柴胡颗粒', guige: '2.5克*15袋', num: '800', price: '29.8', type: '1'  },
					{ id: 9, name: '小柴胡颗粒', guige: '2.5克*15袋', num: '800', price: '29.8', type: '1'  },
					{ id: 10, name: '小柴胡颗粒', guige: '2.5克*15袋', num: '800', price: '29.8', type: '1'  },
					{ id: 11, name: '小柴胡颗粒', guige: '2.5克*15袋', num: '800', price: '29.8', type: '1'  },
					{ id: 12, name: '小柴胡颗粒', guige: '2.5克*15袋', num: '800', price: '29.8', type: '1'  },
					{ id: 14, name: '小柴胡颗粒', guige: '2.5克*15袋', num: '800', price: '29.8', type: '1'  },
				],
				loading: false,
				status: 'more',
				reload: false,
				pageNum: 0,
				contentText: {
					contentdown: '上拉加载更多~',
					contentrefresh: '加载中',
					contentnomore: '我是有底线的~'
				},
				searchValue: ''
			}
		},
		onLoad() {
			// this.getCategory() //联调放开
		},
		methods: {
			// 联调放开此方法
			// getData() {// 获取右侧列表数据
			// 	const params = {
			// 		// 左边类目id
			// 		currentId: this.currentId,
			// 		// 当前页数
			// 		pageNum: this.pageNum,
			// 		// 查询参数
			// 		searchValue: this.searchValue
			// 	}
			// 	请求地址(params).then(res => {
			// 		this.totalCount = res.data.total
			// 		// 如果是下拉重新加载数据
			// 		if(this.reload) {
			// 			this.closeLoading()
			// 		}
			// 		if (res.data.total > 0) {
			// 				const dataMap = res.data.list
			// 				this.slist = this.reload ? dataMap : this.slist.concat(dataMap);
			// 				this.reload = false;
			// 		} else {
			// 				this.slist = [];
			// 		}
			// 		if (this.totalCount == this.slist.length) {
			// 				this.reload = false;
			// 				this.status = 'noMore'
			// 		}
			// 	})
			// },
			// 获取左侧类目数据
			// getCategory() {
			// 	const params = {}
			// 	请求地址(params).then((res)=>{
			// 		this.flist = res.data
			// 		this.currentId = this.flist[0].id;
			// 		this.getData()
			// 	})
			// }
			//一级分类点击
			tabtap(item) {
				this.currentId = item.id;
				// this.getData() // 联调放开
			},
			navToList(sid) {
				uni.navigateTo({
					url: `/pages/product/product?id=41`
				})
			},
			// 滑动到底部加载数据
			scrolltolower() {
				// 联调放开此以下代码
				// if (this.totalCount > this.dataList.length) {
				// 	this.status = 'loading';
				// 	this.pageNum++
				// 	this.getData(); // 加载数据
				// } else {
				// 	//停止加载
				// 	this.status = 'noMore'
				// }
			},
			// 下拉刷新回调函数
			handleRefresh() {
				// this.reload = true
				// this.pageNum = 1
				// this.getData()
			},
			// 改变下拉刷新状态的显示与隐藏
			closeLoading() {
				if(!this.loading){
					this.loading = true; //下拉加载,先让其变true再变false才能关闭
					//关闭加载状态 (转动的圈),需要一点延时才能关闭
					setTimeout(e =>{
						this.loading = false;
					},300)
				}
			},
			// 查询框回调
			handleSearch(v) {
				console.log('查询条件====》', v)
				this.searchValue = v
				// this.getData()
			}
		}
	}
</script>

<style lang='scss'>
	page {
		height: 100%;
	}
	.category {
		height: 100%;
		padding: 15px 15px 0 15px;
		background-color: #F5F7FA;
	}
	.content {
		height: calc(100% - 100upx);
		background-color: #f8f8f8;
	}

	.content {
		display: flex;
	}

	.left-aside {
		flex-shrink: 0;
		width: 150upx;
		height: 100%;
		background-color: #fff;
	}

	.f-item {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		height: 100upx;
		font-size: 28upx;
		color: #343434;
		position: relative;

		&.active {
			color: $base-color;
			background: rgba(57, 113, 254, .1);
			&:before {
				content: '';
				position: absolute;
				left: 0;
				top: 50%;
				transform: translateY(-50%);
				height: 36upx;
				width: 8upx;
				background-color: $base-color;
				border-radius: 0 4px 4px 0;
				opacity: .8;
			}
		}
	}

	.right-aside {
		flex: 1;
		/* height: 300px; */
		/* overflow: hidden; */
	}

	.s-list {
		width: 100%;
		background: #fff;
		padding: 16upx;
	}

	.s-item {
		display: flex;
		/* height: 100px; */
		margin-bottom: 20px;
		.item-left {
			width: 200upx;
			image {
				width: 200upx;
				height: 200upx;
			}
			margin-right: 10px;
		}
		.item-right {
			flex: 1;
			.item-title {
				/* display: flex; */
				.item-type {
					width: 60upx;
					height: 30upx;
					margin-right: 8px;
					margin-bottom: -2px;
				}
			}
			.sale-num {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 5px 0;
				.sale-type {
					display: inline-block;
					padding: 0 8upx;
					height: 34upx;
					line-height: 34upx;
					font-size: 20upx;
					background: linear-gradient(90deg, #FF7F00 0%, #FF4300 100%);
					border-radius: 4rpx;
					color: #FFFFFF;
					text-align: center;
				}
				.sale-number {
					/* height: 30upx; */
					color: #999999;
				}
			}
			.item-tag {
				.item-tag-type {
					display: inline-block;
					padding: 0 8upx;
					height: 28upx;
					line-height: 28upx;
					text-align: center;
					font-size: 19upx;
					border: 1px solid #FE4F42;
					border-radius: 4rpx;
					color: #FE4F42;
					margin-right: 8upx;
				}
			}
			.price {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 5px;
				.price-prefix {
					color: #FF5000;
					font-size: 22upx;
					.price-num {
						font-size: 36upx;
						font-weight: bold;
					}
				}
				.car-logo {
					width: 60upx;
					height: 60upx;
				}
			}
		}
	}
</style>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值