<template>
	<view class="details">
		<z-paging ref="paging" v-model="list" @query="queryList">
			<view class="details-tabs" slot="top">
				<u-tabs :list="tabList" @click="tabClick" lineWidth="40"></u-tabs>
			</view>
			<view class="details-total" slot="top">
				<view>已停车位：{{ 30 }}个；空余车位：{{ 36 }}个</view>
			</view>
			<view class="details-list">
				<view class="details-list-item" v-for="(item, index) in list" :key="index" @click="jumpPage('pages/index/deviceDetails/deviceDetails', { type: 3 })">
					<view class="details-list-item-header">
						<view>{{ item.roadNo }}</view>
						<view>{{ item.signal }}</view>
					</view>
					<view class="details-list-item-img">
						<u--image v-if="item.type === 1" src="../../../static/icons/daozhakongzhi.svg" width="174rpx" height="174rpx"></u--image>
						<u--image v-else-if="item.type === 2" src="../../../static/icons/shipinjiankongyemian.svg" width="174rpx" height="174rpx"></u--image>
						<u--image v-else-if="item.type === 3" src="../../../static/icons/chengguan-wu-bujian-gonggongsheshi-daoluxinxixianshiping.svg" width="174rpx" height="174rpx"></u--image>
					</view>
					<view class="details-list-item-bottom">
						<view>设备号{{ item.deviceNo }}</view>
					</view>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				roadInfo: {
					roadName: ''
				},
				tabList: [{
						name: '全部',
						value: ''
					},
					{
						name: '异常',
						value: 1
					},
					{
						name: '离线',
						value: 2
					}
				],
				list: []
			}
		},
		onLoad(page) {
			if (page.roadName) {
				this.roadInfo.roadName = page.roadName
				uni.setNavigationBarTitle({
					title: page.roadName
				})
			}
		},
		methods: {
			queryList(pageNo, pageSize) {
				this.$refs.paging.complete([{
					roadNo: '入口道闸',
					signal: '降板',
					type: 1,
					deviceNo: '202103051265',
					electric: 9.9
				}, {
					roadNo: '入口车牌识别',
					signal: '在线',
					type: 2,
					deviceNo: '202103051265',
					electric: 10
				}, {
					roadNo: '入口显示屏',
					signal: '在线',
					type: 3,
					deviceNo: '202103051265',
					electric: 10
				}])
			},
			tabClick(val) {
				console.log(val)
			},
			getTimeLong(date) {
				const nowDate = (new Date()).valueOf()
				const curDate = (new Date(date)).valueOf()
				const timeLen = (nowDate - curDate) / 1000
				const day = parseInt(timeLen / (24 * 3600));
				const hour = parseInt((timeLen - day * 24 * 3600) / 3600);
				const minutes = parseInt((timeLen - day * 24 * 3600 - hour * 3600) / 60)
				const second = parseInt(timeLen % 60)
				return `${day}天${hour}时${minutes}分${second}秒`
			},
			jumpPage(url, params) {
				uni.$u.route({
					url, params
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		min-height: calc(100vh - 88rpx);
		background-color: #F6F6FF;
	}

	.details {
		font-family: 'PingFangSC-regular';
		&-tabs {
			background-color: #fff;
		}
		&-total {
			display: flex;
			justify-content: flex-end;
			margin-top: 32rpx;
			font-size: 26rpx;
			color: #000;
			padding-right: 20rpx;
		}
		&-list {
			padding: 40rpx 20rpx;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			&-item {
				width: calc(50% - 52rpx);
				background-color: #fff;
				border-radius: 16rpx;
				padding: 20rpx;
				margin-bottom: 20rpx;
				&-header {
					display: flex;
					justify-content: space-between;
					color: #101010;
					font-size: 26rpx;
				}
				&-img {
					width: 152rpx;
					height: 152rpx;
					margin: 16rpx auto 46rpx;
				}
				&-bottom {
					text-align: center;
					font-size: 24rpx;
					color: #101010;
				}
			}
		}
	}
</style>
