<template>
	<view>
		<u-navbar title="我的设备"></u-navbar>
		<view class="deviceDropdown">
			<u-dropdown>
				<u-dropdown-item v-model="value1" @change="change1" title="充电桩类型" :options="options1"></u-dropdown-item>
<!-- 				<u-dropdown-item v-model="value2" @change="change2" title="所属站点" :options="options2"></u-dropdown-item>
 -->				<u-dropdown-item v-model="value3" @change="change3" title="运行状态" :options="options3"></u-dropdown-item>
			</u-dropdown>
		</view>
		<view class="deviceList"
		
		>
		<view style="text-align: center;margin-top: 100px" v-if="!list.length">
			<img src="@/assets/img/blankpage.png">
			<view>查询为空</view>
		</view>
			<view v-for="(item ,index) in list" :key="item.id"
			@click="gotoUrl('pagesFinance/user/'+(item.type!=0?'pileManagement':'deviceDetails')+'?id='+item.id)"
			:class="{
				'deviceList-bg1':item.type==1,
				'deviceList-bg2':item.type==2,
				'deviceList-bg3':item.type==0
				
			}"
			class="deviceList-item " >
				<view class="deviceList-head">{{item.name}}</view>
				<view class="deviceList-main">{{item.deviceNo}}</view>
 				<view class="deviceList-foot">
					<view class="deviceList-label">{{ options0[item.type].label}}</view>
					<view class="deviceList-label" 
					:style="item.online?'':'color:red'"
					>{{item.online?'在线':'离线'}}</view>
				<!-- 	<view class="deviceList-label">{{item.roleName}}</view> -->
				</view>
			</view>
			<u-divider v-if="list.length&&list.length == recordsTotal" color="#B6BDC3" style="margin-top:20px;" bg-color="#f4f0f0">已经到底了</u-divider>
			
		<!-- 	<view class="deviceList-item deviceList-bg2">
				<view class="deviceList-head">荆鹏软件园充电站</view>
				<view class="deviceList-main">A0001</view>
				<view class="deviceList-foot">
					<view class="deviceList-label">直流快充</view>
					<view class="deviceList-label">正常运行</view>
					<view class="deviceList-label">市场服务 70%</view>
				</view>
			</view>
			<view class="deviceList-item deviceList-bg3">
				<view class="deviceList-head">荆鹏软件园充电站</view>
				<view class="deviceList-main">A0001</view>
				<view class="deviceList-foot">
					<view class="deviceList-label">直流快充</view>
					<view class="deviceList-label">正常运行</view>
					<view class="deviceList-label">市场服务 70%</view>
				</view>
			</view> -->
		</view>
	</view>
</template>

<script>
	import * as API from '@/apis/finance.js'
	
	export default {
		data() {
			return {
				form: {
				
				},
				startDate:'',
				endDate:'',
				pageIndex: 1,
				recordsTotal: 0,
				list: [],
				value1: -1,
				value2: -1,
				value3: -1,
				stationList:[],
				options0: [
				
					{
						label: '自行车充电',
						value: 0,
					},
					{
						label: '直流快充',
						value: 1,
					},
					{
						label: '交流慢充',
						value: 2,
					}
					
				],
				options1: [{
						label: '全部',
						value: '-1',
					},
					{
						label: '自行车充电',
						value: 0,
					},
					{
						label: '交流慢充',
						value: 2,
					},
					{
						label: '直流快充',
						value: 1,
					}
				],
				options2: [
				],
				options3: [
					{
						label: '全部',
						value: -1,
					},
					{
						label: '在线',
						value: 1,
					},
					{
						label: '离线',
						value: 0,
					},
				],
			}
		},
		onReachBottom() {
			if (this.list.length < this.recordsTotal) {
				this.myLoadmore();
			}
		},
		onLoad(op) {
				this.form.stationId=op.id
		},
		methods: {
			change1(e){
				this.form.type=e
				if(e==-1){
					this.form.type=""
				}
				this.getList(true)
			},
			change2(e){
				this.form.stationId=e
				if(e==-1){
					this.form.stationId=""
				}
				this.getList(true)
			},
			change3(e){
				this.form.onlineStatus=e
				if(e==-1){
					this.form.onlineStatus=""
				}
				this.getList(true)
			},
			getStation() {
				
				API.stationList().then((res) => {
					this.options2.push({
						label: '全部',
						value:-1,
					})
					this.stationList = res.data.stationList
					this.stationList.forEach(item=>{
						this.options2.push({
							label: item.name,
							value: item.id,
						})
					})
					
				}).catch(error => {
					uni.showToast({
					
						title: error
					})
				})
			},
		myLoadmore() {

				this.pageIndex += 1;
				this.getList()
			},
			getList(bl) {
				
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				if (bl) {
					this.list = [];
					this.pageIndex = 1;
				}
				this.form.pageIndex= this.pageIndex
				
				API.devicesList(this.form).then((res) => {

					this.list = [
						...this.list,
						...res.data.data
					];
					this.recordsTotal = res.data.recordsTotal
					uni.hideLoading()

				}).catch(error => {
					uni.showToast({

						title: error
					})
				})
			},
			onReady() {
				this.getStation()
				this.getList()
				
			}
		}
	}
</script>
<style>
	page{
		background-color: #F7F7F7;
	}
</style>
<style lang="scss" scoped>
	.deviceDropdown{
		background-color: #fff;
	}
	.deviceList-item{
		margin: 16px;
		border-radius: 8px;
		.deviceList-head{
			font-size: 16px;
			padding: 8px 16px;
		}
		.deviceList-main{
			font-size: 28px;
			padding: 0px 16px;
			font-weight: bold;
		}
		.deviceList-foot{
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			padding: 16px;
			.deviceList-label{
				background-color: #F0F2F4 ;
				padding: 4px 10px;
				margin: 1px;
				border-radius: 4px;
			}
		}
	}
	.deviceList-bg1{
		background:url(../../assets/img/charging_type_fast.png) no-repeat #fff;
		background-size:100%;
	}
	.deviceList-bg2{
		background:url(../../assets/img/charging_type_slow.png) no-repeat #fff;
		background-size:100%;
	}
	.deviceList-bg3{
		background:url(../../assets/img/charging_type_bike.png) no-repeat #fff;
		background-size:100%;
	}
</style>
