<template>
	<view>
		<view>
			<u-navbar
			 :title="title" 
			 title-color="#fff" 
			 :custom-back="customBack"
			 :border-bottom="false" 
			 back-icon-color="#CCE8FF" 
			 :background="{background: 'linear-gradient(99deg, #7A4398 0%, #5A5DB9 100%)' }"></u-navbar>
		</view>
		<mescroll-uni ref="mescrollRef" @init="mescrollInit" :top="config.platform=='h5'?100:180" @down="downCallback" :up="upOption" @up="upCallback" @emptyclick="emptyClick">
			<view class="device-list u-flex u-flex-wrap u-row-start">
				<view class="device-item"
				@click="goListPage(item)" 
				v-for="item in dataList" :key="item.roadNo"
				>
					<u-icon name="star-fill" color="#0082FF" size="45"></u-icon>
					<!-- <image class="img" src="/static/img/icon-device.png" mode="widthFix"></image> -->
					<!-- <view class="device-name">{{item.deviceName}}</view> -->
					<view class="txt u-line-1">{{item.roadName}}</view>
				</view>
			</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default{
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		data(){
			return{
				title:"选择路段",
				deviceTypeId:'',
				dataList:[],
				upOption:{
					// page: {
					// 	size: 10 // 每页数据的数量
					// },
					// auto:false,
					// use:false,
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty:{
						tip: '~ 暂无数据 ~', // 提示
						// btnText: '去看看'
					}
				},
			}
		},
		onLoad(page){
			// console.log('page',page);
			this.deviceType = page.param;
		},
		onShow(){
			
		},
		methods:{
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				// console.log('page',page)
				//联网加载数据
				// let keyword = this.tabs[this.tabIndex]?.text;
				// let type = '';
				// if(this.deviceType==1){
				// 	type=1
				// }else if(this.deviceType==2){
				// 	type=2
				// }else if(this.deviceType==3){
				// 	type=3
				// }
				let params ={
					type:this.deviceType,
					pageNum:page.num,
					pageSize:page.size
				} 
				this.$u.api.getRoadList(params).then(curPageData=>{
					console.log('curPageData',curPageData)
					//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
					// this.mescroll.endSuccess(curPageData.data.total);
					this.mescroll.endBySize(curPageData.data.length, curPageData.data.length);
					//设置列表数据
					if(page.num == 1) this.dataList = []; //如果是第一页需手动制空列表
					this.dataList=this.dataList.concat(curPageData.data); //追加新数据
					if(this.dataList.length>=1){
						// this.title = this.dataList[0].roadwayName
					}
				}).catch((err)=>{
					uni.showToast({
						title:'链接失败'
					});
					console.log('err',err)
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
			//点击空布局按钮的回调
			emptyClick(){
				
			},
			customBack(){
				uni.reLaunch({
				    url: '/pages/index/index'
				});
			},
			goListPage(roadItem) {
				console.log('this.deviceType',this.deviceType)
				console.log('roadItem',roadItem)
				let path = '';
				if(this.deviceType==1){
					path = 'pages/deviceList/deviceListType1/deviceListType1'
				}else if(this.deviceType==2){
					path = 'pages/deviceList/deviceListType2/deviceListType2'
				}else if(this.deviceType==3){
					// path = 'pages/deviceList/deviceListType3/deviceListType3'
					path = 'pages/parkingInfo/parkingInfo'
				}
			  this.$u.route({
			    url: path,
				params:{
					roadNo:roadItem.roadNo,
					roadName:roadItem.roadName,
					deviceType:this.deviceType
				}
			  })
			},
			openPage(path,param) {
			  this.$u.route({
			    url: path,
				params:{
					param:param,
					deviceTypeId:this.deviceTypeId
				}
			  })
			},
			
		}
	}
</script>
<style>
	page{background: #fff;}
</style>
<style lang="scss" scoped>
	// @import  './deviceList.scss'
	.device-list{
		margin: 24rpx 0;
		.device-item{
			background-color: #F1F8FF;
			border-radius: 10rpx;
			box-sizing: border-box;
			padding: 20rpx 10rpx;
			text-align: center;
			width: 45%;
			margin: 0 0 24rpx 3.3%;
			.img{
				width: 57rpx;
				height: 55rpx;
				margin-bottom: 10rpx;
			}
			.device-name{
				font-size: 24rpx;
				color: #606266;
				margin-bottom: 5rpx;
			}
			.text{
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #474747;
				line-height: 40rpx;
				letter-spacing: 1px;
			}
		}
	}
</style>
