<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-list">
				<view class="details-list-item" v-for="(item, index) in list" :key="index" @click="jumpPage('pages/index/deviceDetails/deviceDetails', { type: 1 })">
					<view class="details-list-item-header">
						<view>{{ item.roadNo }}</view>
						<view>{{ item.signal }}信号</view>
					</view>
					<view class="details-list-item-cardNo">
						{{ item.cardNum }}
					</view>
					<view class="details-list-item-img">
						<u--image v-if="item.cardNum" src="../../../static/icons/has-car-icon.svg" width="152rpx" height="152rpx"></u--image>
						<u--image v-else src="../../../static/icons/no-car-icon.svg" width="152rpx" height="152rpx"></u--image>
					</view>
					<view class="details-list-item-time">
						{{ item.inTime ? getTimeLong(item.inTime) : '' }}
					</view>
					<view class="details-list-item-bottom">
						<view>{{ item.deviceNo }}</view>
						<view>
							<view>{{ item.electric }}V</view>
							<view class="ele">
								<u--image v-if="item.electric < 10" src="../../../static/icons/no-ele-icon.svg" width="48rpx" height="48rpx"></u--image>
								<u--image v-else src="../../../static/icons/has-ele-icon.svg" width="48rpx" height="48rpx"></u--image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				roadInfo: {
					roadName: ''
				},
				tabList: [{
						name: '全部',
						value: ''
					},
					{
						name: '异常',
						value: 1
					},
					{
						name: '低电量',
						value: 2
					},
					{
						name: '低信号',
						value: 3
					}
				],
				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: 'KC001',
					signal: '-90',
					inTime: '2021-12-17 09:30:50',
					cardNum: '贵A12345',
					deviceNo: '202103051265',
					electric: 9.9
				}, {
					roadNo: 'KC001',
					signal: '-90',
					inTime: '',
					cardNum: '',
					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;
		}

		&-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;
				&-header {
					display: flex;
					justify-content: space-between;
					color: #101010;
					font-size: 26rpx;
				}
				&-cardNo {
					text-align: center;
					color: #101010;
					height: 40rpx;
					line-height: 40rpx;
					font-size: 26rpx;
					margin-bottom: 10rpx;
				}
				&-img {
					width: 152rpx;
					height: 152rpx;
					margin: 0 auto;
				}
				&-time {
					text-align: center;
					margin-top: 12rpx;
					margin-bottom: 20rpx;
					font-size: 26rpx;
					color: #101010;
					height: 40rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
				&-bottom {
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-size: 24rpx;
					color: #101010;
					view {
						&:last-child {
							display: flex;
							align-items: center;
						}
					}
					.ele {
						transform: rotate(-90deg);
					}
				}
			}
		}
	}
</style>
