<template>
	<view>
		<ujp-navbar title="我的充电桩">
			<view  slot="right" >
				
				<view  @click="popupShow=true"  
				 style="margin-right: 10px;" >
					筛选<u-icon name="plus"></u-icon>

				</view>
				
			</view>
			
		</ujp-navbar>
		
		<u-popup v-model="popupShow" mode="bottom" border-radius="20"  >
		<view class="popup-screen">
			<view class="screen">
				<view class="screen-item">
					<view class="screen-head">站点名称</view>
					<view class="screen-main">
						<u-search  v-model="nameTemp" 
						@custom="form.name=nameTemp,getList(true)"
						@search="form.name=nameTemp,getList(true)" placeholder="按站点名称搜索"  />
						
					</view>
				</view>
				
				<view class="screen-item">
					<view class="screen-head">站点类型</view>
					<view class="screen-main">
						<view class="screen-entry  "
						 @click="form.no='',getList(true)"
						 :class="{
						 	active:form.no==''
						 }"
						 
						 >全部</view>
						
						<view class="screen-entry  "
						 v-for="(item,i) in ['A','B','C','D','E']" 
						 @click="form.no=item,getList(true)"
						:class="{
							active:form.no==item
						}"
						
						>{{item}}类</view>
						
					
					</view>
				</view>
				
			</view>
			<view class="screen-foot">
				<view class="screen-btn-l" @click="resetBtn" v-if="0" >重置</view>
				<view class="screen-btn-r" @click="popupShow=false" >关闭</view>
			</view>
		</view>
		</u-popup>
		<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="gotoItem(item)"
			
			class="deviceList-item deviceList-bg1 "
			 :class="{
				 'deviceList-bg-none':item.totalNum==0&&item.stationType==50
			 }"
			 
			 >
				<view class="deviceList-main">
					 <template v-if="item.category=='超充'">  <span class="btn12 btn3"  >超充</span></template>
				 <template v-else >
					 <span class="btn12 " v-if="item.type=='1,2'" >快/慢</span>
					 <span class="btn12 btn2"  v-if="item.type=='1'"  >快充</span>
					 <span class="btn12 btn1" v-if="item.type=='2'" >慢充</span>
				 </template>
				
				{{item.name}}
				
				</view>
 				<view class="deviceList-head">{{item.address}}<span style="float: right;" class="iconfont more">&#xe600;</span></view>
				
				<view class="deviceList-foot" v-if="item.totalNum==0&&item.stationType==50" >
					<view class="deviceList-label" style="color: #5cbe7d;"   >前往绑定充电桩</view>
				</view>
				<view class="deviceList-foot" v-else >
					
					<view class="deviceList-label" style="color: #333333;"  >总数<b>{{item.totalNum}}</b></view>
					
					<view class="deviceList-label" style="color: #7a68f6;" v-if="item.superNum"  >/直流超充<b>{{item.superNum}}</b></view>
					
					<view class="deviceList-label" style="color: #185AC6;" v-if="item.fastNum"  >/直流快充<b>{{item.fastNum-item.superNum}}</b></view>
					
					<view class="deviceList-label" style="color: #5cbe7d;"  v-if="item.slowNum" >/交流慢充<b>{{item.slowNum}}</b></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="#f7f7f7">已经到底了</u-divider>
			
		 
		</view>
	</view>
</template>

<script>
	import * as API from '@/apis/finance.js'
	
	export default {
		data() {
			return {
				popupShow:false,
				name:"",
				nameTemp:"",
				no:"",
				form: {
					name:"",
					
					no:"",
				},
				startDate:'',
				endDate:'',
				pageIndex: 1,
				recordsTotal: 0,
				list: [],
				value1: -1,
				value2: -1,
				value3: -1,
				stationList:[],
				options0: [
					{
							label: '全部',
							value: -1,
						},
					{
						label: '自行车充电',
						value: 0,
					},
					{
						label: '交流慢充',
						value: 2,
					},
					{
						label: '直流快充',
						value: 1,
					}
				],
				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();
			}
		},
		methods: {
			gotoItem(item){
				if(item.totalNum==0&&item.stationType==50){
					this.adddevice(item.id,item.name)
				}else{
					this.gotoUrl('pagesFinance/user/'+(item.type!=0?'pileManagement':'deviceList')+'?id='+item.id)
					
				}
			},
			adddevice(id,name){
				uni.navigateTo({
					url:'/pagesFinance/user/activatedChargingPile?id='+id+"&name="+name
				})
			},
			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.stationsList(this.form).then((res) => {
					this.recordsTotal=res.data.recordsTotal
					this.list = [
						...this.list,
						...res.data.data
					];
					
					// if(this.list.length==1){
					// 	uni.redirectTo({
					// 		url:"pagesFinance/user/pileManagement?id="+this.list[0].id
					// 	})
					// }
					uni.hideLoading()

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

						title: error
					})
				})
			},
			onShow() {
				//this.getStation()
				this.getList(true)
				
			}
		}
	}
</script>
<style>
	page{
		background-color: #F7F7F7;
	}
</style>
<style lang="scss" scoped>
	.btn12{
		color: #fff;
		background-color: #449ca8;
		font-size: 16px;
		    border-radius: 50px;
		    padding: 1px 5px;
	}
	.btn1{
	
		background-color: #5cbe7d;
		
	}
	.btn3{
	
		background-color: #7a68f6;
		
	}
	.btn2{
	
		background-color: #185AC6;
		
	}
	.deviceDropdown{
		background-color: #fff;
	}
	.deviceList-item{
		margin: 16px;
		border-radius: 8px;
		.deviceList-head{
			color: #9e9e9e;
			font-size: 16px;
			padding: 8px 16px;
		}
		.deviceList-main{
			font-size: 20px/*  */;
			padding:5px 16px 0px 16px;
			font-weight: bold;
		}
		.deviceList-foot{
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			padding: 0 16px 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%;
		background-color: #ffffff ;
	}
	.deviceList-bg-none{
		background:url(../../assets/img/nobood.svg) no-repeat #fff;
		background-size:45px;
		background-position-x: right;
		background-color: #ffffff ;
	}
	.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%;
	}
	.popup-screen{
		padding: 20px;
		position: relative;
		.screen{
			padding-bottom: 60px;
		}
		.screen-item{
			margin-bottom: 20px;
			.screen-head{
				margin-bottom: 8px;
				font-size: 16px;
			}
			.screen-main{
				display: flex;
				//    display: -webkit-box;
				flex-wrap: wrap;
			
			}
			.screen-entry{
				width: 29%;
				padding:6px 0;
								display: flex;
								align-items: center;
								justify-content: center;
	
	
				background-color: #F2F5FA ;
				text-align: center;
				margin-bottom: 10px;
				border-radius: 3px;
			
				margin-right: 6px;
	
			}
			.screen-entry.active{
				background-color: #185AC6;
				color:#fff;
			}
		}
		.screen-foot{
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			display: flex;
			height:50px;
			border-top: 1px solid #ededed;
			    justify-content: space-around;
			.screen-btn-l{
				 background-color: #fff;
				flex: 0.2;
				text-align: center;
				line-height: 50px;
			}
			.screen-btn-r{
				flex: 0.8;
				text-align: center;
				line-height: 50px;
				background-color: #185AC6;
				color:#fff;
			}
		}
	}
</style>
