<template>
	<view class="basic-data">
		<view class="basic-top">
			<view class="service_header_left">
				<view class="btn" :class="isSelect===0?'active':''" @click="handleData(0)">车辆管理</view>
				<view class="btn" :class="isSelect===2?'active':''" @click="handleData(2)">电池管理</view>
				<view class="btn" :class="isSelect===1?'active':''" @click="handleData(1)" v-if="$storage.getJson('userId')==1">站控配置</view>
			</view>
			<view class="basci-header-right" v-if="isSelect===0">
				<view class="times">最近同步时间：{{synchronizationTime || '-'}}</view>
				<view class="sync-btn" @click="syncCloud">云端同步</view>
				<!-- <view class="title">车辆管理</view> -->
			</view>
			
		</view>
		<view v-if="isSelect===0">
			<view class="basic-search">
				<uni-forms ref="form" :modelValue="queryParams" class="searchForm">
					<uni-forms-item label="车牌号码:" label-width="72px" label-align="right" name="vehiclePlate">
						<uni-easyinput type="text" v-model="queryParams.vehiclePlate" placeholder="请输入车牌号码" />
					</uni-forms-item>
					<uni-forms-item label="车辆识别码:" label-width="128px" label-align="right" name="vehicleVin">
						<uni-easyinput type="text" v-model="queryParams.vehicleVin" placeholder="请输入车辆识别码" />
					</uni-forms-item>
					<uni-forms-item label="来源:" label-width="80px" label-align="right">
						<uni-data-select v-model="queryParams.source" :localdata="formSelect" style="width: 100px;"
							@change="change"></uni-data-select>
					</uni-forms-item>
				</uni-forms>
				<view class="search-btn" @click="handleQuery">查询</view>
				<view class="reset-btn" @click="resetForm">重置</view>
			</view>
			<view class="basic-table">
				<!-- <view class="search-btn marginZero" @click="OpenAddDrawer">新增</view> -->
				<baseDateTable @DelCarData="DelCarData" @EditCarData="EditCarData" @bindHandle="bindHandle" :isBind="true" :headerFixed="true"
					:showLoadMore="showLoadMore" :loadMore="loadMore" :columnFixed=1 :contents="datalist" :headers="carheaders"
					@onPullup="pullup">
				</baseDateTable>
			</view>
		</view>
		<view v-else-if="isSelect===1">
			<view class="basic-zkset">
				<view class="setTitle">配置管理：</view>
				<view class="setCont">
					<uni-forms ref="formSet" :modelValue="queryParamsSet" class="formSet">
						<uni-forms-item label="充电机温度(°C):" label-width="116px" label-align="left">
							<uni-easyinput type="text" class="tempIpt" @blur="regTemp" :maxlength="3" placeholder="充电机温度" :clearable="false" v-model="queryParamsSet.temp" />
							<view class="search-temp" @click="resetTemp">恢复默认</view>
						</uni-forms-item>
						<uni-forms-item label="换电站连接方式:" label-width="128px" label-align="right">
							<uni-data-checkbox v-model="connWayArr" multiple :localdata="connWays" />
						</uni-forms-item>
						<uni-forms-item label="中转仓:" label-width="116px" label-align="right">
							<uni-data-checkbox v-model="queryParamsSet.transitWarehouse" :localdata="transitWarehouse" />
						</uni-forms-item>
						<uni-forms-item v-if="queryParamsSet.transitWarehouse==1">
							<uni-easyinput type="text" class="tempIpt" :clearable="false" :maxlength="2" v-model.trim="queryParamsSet.positionNumber" placeholder="中转仓仓位号" />
						</uni-forms-item>
						<uni-forms-item label="雷达:" label-width="116px" qlabel-align="right">
							<uni-data-checkbox v-model="queryParamsSet.radar" :localdata="radarList" />
						</uni-forms-item>
						<view class="search-btn" @click="handleSave">保存</view>
					</uni-forms>
				</view>
			</view>
			<view class="basic-table">
				<view class="search-temp marginZero" @click="AddCangDrawer">新增仓位</view>
				<cangDateTable @DelCangData="DelCangData" @EditCangData="EditCangData" :isEdit="1" :headerFixed="true"
					:showLoadMore="showLoadMore" :loadMore="loadMore" :contents="dataCanglist" :headers="headers"
					@onPullup="pullCangup">
				</cangDateTable>
			</view>
		</view>
		<view v-else>
			<view class="basic-search">
				<uni-forms ref="form" :modelValue="batteryParams" class="searchForm">
					<uni-forms-item label="电池编号:" label-width="72px" label-align="right" name="sn">
						<uni-easyinput type="text" v-model="batteryParams.sn" placeholder="请输入电池编号" />
					</uni-forms-item>
				</uni-forms>
				<view class="search-btn" @click="handleBatteryQuery">查询</view>
				<view class="reset-btn" @click="resetBatteryForm">重置</view>
			</view>
			<view class="basic-table">
				<view class="search-temp marginZero" @click="AddBatteryDrawer">新增</view>
				<baseDateTable @DelBatteryData="DelBatteryData" @EditBatteryData="EditBatteryData" :isEdit="2" :headerFixed="true"
					:showLoadMore="showLoadMore" :loadMore="loadMore" :columnFixed=1 :contents="dataBatterylist" :headers="batteryheaders"
					@onPullup="pullBatteryup">
				</baseDateTable>
			</view>
		</view>
		<!--右侧抽屉 -->
		<uni-drawer ref="BasicDrawer" mode="right" :width="400" :mask-click="true">
			<scroll-view style="height: 100%;" scroll-y="true" v-if="isSelect===0">
				<PublicDrawer :flag="false" :title="dialogType=='new'?'新增车辆':'编辑车辆'" @closeDrawer="closeDrawer"
					@AddCarinfo="AddCarinfo" @EditCarInfo="EditCarInfo">
					<view class="drawer_main">
						<view>
							<BasicDrawer :basicFrom="basicFrom" :range="range" @redHandle="redHandle"></BasicDrawer>
						</view>
					</view>
				</PublicDrawer>
			</scroll-view>
			<scroll-view style="height: 100%;" scroll-y="true" v-else-if="isSelect===1">
				<PublicDrawer :flag="false" :title="dialogCangType=='new'?'新增仓位':'编辑仓位'" @closeDrawer="closeDrawer"
					@AddCanginfo="AddCanginfo" @EditCangInfo="EditCangInfo">
					<view class="drawer_main">
						<view>
							<ChargeDrawer ref="addSetForm" @changeChargerId="changeChargerId" :setForm="setForm" :rangeCharge="rangeCharge" :rangePower="rangePower" :rules="rules"></ChargeDrawer>
						</view>
					</view>
				</PublicDrawer>
			</scroll-view>
			<scroll-view style="height: 100%;" scroll-y="true" v-else>
				<PublicDrawer :flag="false" :title="dialogBatteryType=='new'?'新增电池':'编辑电池'" @closeDrawer="closeDrawer"
					@AddBatteryinfo="AddBatteryinfo" @EditBatteryInfo="EditBatteryInfo">
					<view class="drawer_main">
						<view>
							<BatteryDrawer ref="addBatteryForm" :BatteryForm="BatteryForm" :rules="batteryRules"></BatteryDrawer>
						</view>
					</view>
				</PublicDrawer>
			</scroll-view>
		</uni-drawer>
		<uni-drawer ref="BindDrawer" mode="right" :width="400" :mask-click="true">
			<scroll-view style="height: 100%;" scroll-y="true" v-if="isSelect===0">
				<PublicDrawer :flag="false" :title="'绑定RFID'" @closeDrawer="closeDrawer" @BindFRIDHandle="BindFRIDHandle">
					<view class="drawer_main">
						<view>
							<BindDrawer :basicFrom="basicFrom" :range="range" @redHandle="redHandle" @inputHandle="inputHandle"></BindDrawer>
						</view>
					</view>
				</PublicDrawer>
			</scroll-view>
		</uni-drawer>
		<!-- 右侧抽屉结束 -->
		<!-- 顶部公共提示信息 -->
		<uni-popup ref="Exchangepopup" type="message">
			<uni-popup-message :type="popupType" :message="popupMessage" :duration="2000"></uni-popup-message>
		</uni-popup>
		<!-- 顶部提示信息结束-->
	</view>
</template>

<script>
	import baseDateTable from './baseData-table/baseDateTable'
	import cangDateTable from './baseData-table/cangDateTable'
	import BasicDrawer from './BasicDrawer'
	import BindDrawer from './BindDrawer'
	import ChargeDrawer from './ChargeDrawer'
	import BatteryDrawer from './BatteryDrawer'
	export default {
		name: 'BasicData',
		components: {
			baseDateTable,
			cangDateTable,
			BasicDrawer,
			ChargeDrawer,
			BatteryDrawer,
			BindDrawer
		},
		data() {
			return {
				popupMessage: '成功消息',
				popupType: 'success',
				formSelect: [{
						value: 0,
						text: "站控"
					},
					{
						value: 1,
						text: "云端"
					},
				],
				//站控配置
				queryParamsSet:{
					temp:null,
					oneLink:0,//单连：0未启用，1启用
					fourLink:0,//四连：0未启用，1启用
					transitWarehouse:null,//中转仓：0无中转仓，1有固定中转仓
					positionNumber:null,//固定中转仓位号
					radar: null,//雷达  0-无， 1-有
				},
				connWayArr:[],
				basicFrom: {
					id: 0,
					CarDistance: null,
					CarPlate: undefined,
					CarVin: undefined,
					state: undefined,
					rfidEpc: undefined,
					epcFour: undefined,
					frid: undefined,
				},
				//充电机仓位抽屉
				setForm:{
					chargerId:null,//仓位号
					chargerCode:null,//桩编号
					isSwap:null,//是否可以换电(0不支持 1支持)
					isCheck:null,//连接器类型(-1空架子 0单四连可切换 1单连 4四连)
				},
				//电池抽屉数据
				BatteryForm:{
					sn:null,//编号
					length:null,//长
					width:null,//宽
					height:null,//高
					weight:null,//重量
				},
				batteryRules:{
					sn:{
						rules:[
							{
								required: true,
								errorMessage: '请输入电池编号',
							},
						]
					},
					length:{
						rules:[
							{
								required: true,
								errorMessage: '请输入长度',
							},
							{
								validateFunction:function(rule,value,data,callback){
									let reg=/^[1-9]\d*$/
									if (!reg.test(value)) {
										callback('请输入正整数')
									}
									return true
								},
							}
						]
					},
					width:{
						rules:[
							{
								required: true,
								errorMessage: '请输入宽度',
							},
							{
								validateFunction:function(rule,value,data,callback){
									let reg=/^[1-9]\d*$/
									if (!reg.test(value)) {
										callback('请输入正整数')
									}
									return true
								},
							}
						]
					},
					height:{
						rules:[
							{
								required: true,
								errorMessage: '请输入高度',
							},
							{
								validateFunction:function(rule,value,data,callback){
									let reg=/^[1-9]\d*$/
									if (!reg.test(value)) {
										callback('请输入正整数')
									}
									return true
								},
							}
						]
					},
					weight:{
						rules:[
							{
								required: true,
								errorMessage: '请输入重量',
							},
							{
								validateFunction:function(rule,value,data,callback){
									let reg=/^[1-9]\d*$/
									if (!reg.test(value)) {
										callback('请输入正整数')
									}
									return true
								},
							}
						]
					}
				},
				rules:{
					chargerId:{
						rules:[
							{
								required: true,
								errorMessage: '请输入仓位号',
							},
							{
								format: 'number',
								errorMessage: '请输入数字'
							},
						]
					},
					chargerCode:{
						rules:[
							{
								required: true,
								errorMessage: '请输入桩编号',
							},
							{
								pattern:/^[A-Za-z0-9]+$/,
								errorMessage:'请输入正确的桩编号'
							}
						]
					},
					isSwap:{
						rules:[
							{
								required: true,
								errorMessage: '请选择是否可换电',
							},
						]
					},
					isCheck:{
						rules:[
							{
								required: true,
								errorMessage: '请选择充电连接控制方式',
							},
						]
					}
				},
				range: [{
						value: 0,
						text: "停用"
					},
					{
						value: 1,
						text: "启用"
					},
				],
				//中转仓
				transitWarehouse: [{
					text: '无中转仓',
					value: 0
				}, {
					text: '有中转仓',
					value: 1
				}],
				//连接方式
				connWays: [{
					text: '单连',
					value: 1
				}, {
					text: '四连',
					value: 4
				}],
				//雷达
				radarList: [{
					text: '有雷达',
					value: 1
				}, {
					text: '无雷达',
					value: 0
				}],
				//是否可换电
				rangePower: [{
						value: 1,
						text: "是"
					},
					{
						value: 0,
						text: "否"
					},
				],
				//是否切换充电
				rangeCharge: [{
						value: 1,
						text: "单连不可切换"
					},
					{
						value: 4,
						text: "四连不可切换"
					},
					{
						value: 0,
						text: "单四联切换"
					},
					{
						value: -1,
						text: "无"
					}
				],
				datalist: [],//车辆列表
				dataCanglist: [],//仓位列表
				dataBatterylist: [],//电池列表
				queryParams: {
					page: 1, //当前页
					pageSize: 10, //每页条数
					source: undefined, //来源
					vehiclePlate: undefined, //车牌号
					vehicleVin: undefined, //VIN码
					orderByField: 'id', //排序字段
					orderByWays: 'desc' //排序方式
				},
				cangParams: {
					page: 1, //当前页
					pageSize: 10, //每页条数
					orderByField: 'id', //排序字段
					orderByWays: 'desc' //排序方式
				},
				batteryParams: {
					page: 1, //当前页
					pageSize: 10, //每页条数
					orderByField: 'id', //排序字段
					orderByWays: 'desc' ,//排序方式
					sn:null,//电池编号
				},
				total: 0, //总条数，
				cangTotal: 0, //仓位总条数，
				batteryTotal: 0, //电池总条数，
				loading: false,
				headers: [{
					label: '仓位号',
					key: 'chargerId',
					widtd: 98,
				}, {
					label: '桩编号',
					key: 'chargerCode',
					widtd: 315,
				}, {
					label: '是否可换电',
					key: 'isSwap',
					widtd: 200,
				}, {
					label: '充电连接控制方式',
					key: 'isCheck',
					widtd: 218,
				}, 
				{
					label: '操作',
					key: 'id',
					widtd: 118,
				},
				],
				batteryheaders: [{
					label: '电池编号',
					key: 'sn',
					widtd: 278
				}, {
					label: '长(cm)',
					key: 'length',
					widtd: 148
				}, {
					label: '宽(cm)',
					key: 'width',
					widtd: 148
				},{
					label: '高(cm)',
					key: 'height',
					widtd: 148,
				}, 
				{
					label: '重量(kg)',
					key: 'weight',
					widtd: 148,
				}, 
				{
					label: '操作',
					key: 'id',
					widtd: 88,
				},
				],
				//车辆列表
				carheaders: [{
					label: '车牌号',
					key: 'vehiclePlate',
					widtd: 130
				}, {
					label: '车辆识别码(VIN码)',
					key: 'vehicleVin',
					widtd: 225
				}, {
					label: 'RFID',
					key: 'rfidEpc',
					widtd: 255,
				}, {
					label: '前端电池距离(mm)',
					key: 'modelDistance',
					widtd: 200
				}, 
				{
					label: '供电接口',
					key: 'link',
					widtd: 100,
				}, 
				// {
				// 	label: '来源',
				// 	key: 'source',
				// 	widtd: 100,
				// }, 
				{
					label: '操作',
					key: 'id',
					widtd: 108,
				},
				],
				showLoadMore: false,
				loadMore: 'more',
				dialogType: 'new', // 按钮类型(new、edit)
				EditCarForm: {}, //编辑车辆表单数据接收
				synchronizationTime:'',//同步时间
				isSelect:0,
				dialogCangType:'new',
				dialogBatteryType:'new',
			}
		},
		mounted() {
			this.vehicleList();
			this.getsynchronization()
		},
		methods: {
			//充电机温度正则
			regTemp(e){
				const reg=/^\d*$/
				if(!reg.test(e.detail.value) || e.detail.value==0){
					this.queryParamsSet.temp=90
				}
			},
			//温度恢复默认
			resetTemp(){
				this.$http.setTemp(90+'').then((res) => {
					if(res.code===0){
						this.queryParamsSet.temp=90
						this.ExchangeMessage('success','恢复成功!')
					}
				})
			},
			//设置温度
			handleSettemp(){
				this.$http.setTemp(this.queryParamsSet.temp).then((res) => {
					if(res.code!==0){
						this.ExchangeMessage('error',res.msg)
					}else{
						this.getCurrentTemp()
					}
				})
			},
			//获取站控配置
			getStationConfig(){
				this.$http.getOtherStation(4+'').then((res) => {
					if(res.data.content==1){
						this.connWayArr.push(1)
					}
				});
				this.$http.getOtherStation(8+'').then((res) => {
					if(res.data && res.data.content && (res.data.content=='0' || res.data.content=='1')){
						this.queryParamsSet.radar = Number(res.data.content)
					}
				});
				this.$http.getOtherStation(5+'').then((res) => {
					if(res.data.content==1){
						this.connWayArr.push(4)
					}
				});
				this.$http.getOtherStation(6+'').then((res) => {
					if(res.data.content==1){
						this.queryParamsSet.transitWarehouse=1
						this.$http.getOtherStation(7+'').then((res) => {
							this.queryParamsSet.positionNumber=res.data.content*1
						});
					}else{
						this.queryParamsSet.transitWarehouse=0
					}
				});
				this.getCurrentTemp()
			},
			//获取温度
			getCurrentTemp(){
				//获取温度
				this.$http.serchTemp().then((res) => {
					if(res.code===0){
						this.queryParamsSet.temp=res.data*1
					}
				});
			},
			//读取frid
			redHandle() {
				this.$http.getEpc().then((res) => {
					if(res.code===0){
						let frid = res.data
						this.basicFrom.frid=frid;//frid.replace(/.{4}$/, '****')
						this.basicFrom.rfidEpc=frid
					} else {
						return this.ExchangeMessage('warn', '未获取FRID卡号')
					}
				});
			},
			inputHandle(data) {
				console.log(data.toUpperCase(), '000')
				this.basicFrom.epcFour = data.toUpperCase()
				console.log(this.basicFrom, '333')
			},
			//保存站控配置
			handleSave(){
				const reg=/^\d*$/
				if(!this.queryParamsSet.temp){
					this.ExchangeMessage('warn', '请输入充电机温度!')
					return
				}
				if(this.connWayArr.length===0){
					this.ExchangeMessage('warn', '请选择换电站连接方式!')
					return
				}
				if(this.queryParamsSet.transitWarehouse==null){
					this.ExchangeMessage('warn', '请选择中转仓!')
					return
				}
				if(this.queryParamsSet.radar==null){
					this.ExchangeMessage('warn', '请选择是否有雷达!')
					return
				}
				if(this.queryParamsSet.transitWarehouse==1){
					if(!this.queryParamsSet.positionNumber){
						this.ExchangeMessage('warn', '请输入中转仓仓位号!')
						return
					}else{
						if(!reg.test(this.queryParamsSet.positionNumber) || this.queryParamsSet.positionNumber<=0){
							this.ExchangeMessage('warn', '请输入正整数!')
							return
						}
					}
					this.queryParamsSet.positionNumber=this.queryParamsSet.positionNumber*1
				}else{
					this.queryParamsSet.positionNumber=undefined
				}
				
				if(this.connWayArr.length===2){
					this.queryParamsSet.oneLink=1
					this.queryParamsSet.fourLink=1
				}else{
					if(this.connWayArr[0]===1){
						this.queryParamsSet.oneLink=1
						this.queryParamsSet.fourLink=0
					}else{
						this.queryParamsSet.oneLink=0
						this.queryParamsSet.fourLink=1
					}
				}
				this.$http.setStation(this.queryParamsSet).then((res) => {
					if(res.code === 0){
						this.getStationConfig()
						this.handleSettemp()
					}
					this.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.code === 0 ? '设置成功' : res.msg)
				});
			},
			//切换数据按钮
			handleData(num){
				this.showLoadMore=false
				this.isSelect=num
				if(num===0){
					this.vehicleList()
				}else if(num===1){
					this.getStationConfig()
					this.encodeList()
				}else{
					this.batteryList()
				}
				
			},
			//顶部公共消息提示
			ExchangeMessage(type, message) {
				this.popupType = type
				this.popupMessage = message ? message : '后端接口404错误!'
				this.$refs.Exchangepopup.open()
			},
			//获取最近同步时间
			getsynchronization(){
				this.$http.getSyncTime().then(res=>{
					if(res.code == 0){
						this.synchronizationTime = res.data
					}
				})
			},
			//删除车辆
			DelCarData(id) {
				let that = this
				uni.showModal({
					title: `确认删除车辆信息吗?`,
					content: '',
					success: function(res) {
						if (res.confirm) {
							that.$http.delvehicle(id + '')
								.then(res => {
									if (res.code === 0) {
										that.vehicleList()
									}
									that.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.code === 0 ? '删除车辆成功' : '删除车辆失败')
								}).catch(err => {
									console.error(err)
								})
						} else if (res.cancel) {
							return false
							//用户点击取消按钮触发
						}
					}
				})

			},
			//删除充电机仓位
			DelCangData(id) {
				let that = this
				uni.showModal({
					title: `确认删除仓位吗?`,
					content: '',
					success: function(res) {
						if (res.confirm) {
							that.$http.delEncode(id+'')
								.then(res => {
									if (res.code === 0) {
										that.encodeList()
									}
									that.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.code === 0 ? '删除成功' : res.msg)
								}).catch(err => {
									console.error(err)
								})
						} else if (res.cancel) {
							return false
							//用户点击取消按钮触发
						}
					}
				})
			},
			//删除电池
			DelBatteryData(id) {
				let that = this
				uni.showModal({
					title: `确认删除电池信息吗?`,
					content: '',
					success: function(res) {
						if (res.confirm) {
							that.$http.delBattery(id+'')
								.then(res => {
									if (res.code === 0) {
										that.batteryList()
									}
									that.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.code === 0 ? '删除成功' : res.msg)
								}).catch(err => {
									console.error(err)
								})
						} else if (res.cancel) {
							return false
							//用户点击取消按钮触发
						}
					}
				})
			},
			// 打开添加车辆抽屉
			OpenAddDrawer() {
				this.dialogType = 'new'
				this.basicFrom = {
					id: 0,
					CarDistance: null,
					CarPlate: undefined,
					CarVin: undefined,
					state: undefined,
				}
				this.$refs.BasicDrawer.open();
			},
			//新增仓位抽屉
			AddCangDrawer(){
				this.dialogCangType='new'
				this.setForm={
					cangNum:null,//桩编号
					isPower:null,//是否可换电
					isCharger:null,//是否切换充电连接
				},
				this.$refs.BasicDrawer.open()
			},
			//新增电池抽屉
			AddBatteryDrawer(){
				this.dialogBatteryType='new'
				this.BatteryForm={
					sn:null,//编号
					length:null,//长
					width:null,//宽
					height:null,//高
					weight:null,//重量
				},
				this.$refs.BasicDrawer.open()
			},
			//编辑充电仓位抽屉
			EditCangData(row){
				this.dialogCangType='edit'
				this.$refs.BasicDrawer.open()
				this.setForm={...row}
			},
			//编辑电池抽屉
			EditBatteryData(row){
				this.dialogBatteryType='edit'
				this.$refs.BasicDrawer.open()
				this.BatteryForm={...row}
			},
			//编辑充电仓位请求接口
			EditCangInfo() {
				this.$refs.addSetForm.$refs.setvalueForm.validate().then(res=>{
					const params = {
						id: this.setForm.id,
						chargerId: this.setForm.chargerId*1,
						chargerCode: this.setForm.chargerCode,
						isSwap: this.setForm.isSwap,
						isCheck: this.setForm.isCheck,
					}
					this.$http.editEncode(params)
					.then(res => {
						this.closeDrawer()
						this.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.code === 0 ? '修改成功!' : res.msg)
						if (res.code === 0) {
							this.encodeList()
						}
					}).catch(err => {
						console.error(err)
					})
				})
				// if (!this.basicFrom.CarDistance || !this.basicFrom.CarPlate || !this.basicFrom.CarVin) {
				// 	this.ExchangeMessage('warn', '请填写完整!')
				// } else {
				// 	const params = {
				// 		modelDistance: this.basicFrom.CarDistance,
				// 		vehiclePlate: this.basicFrom.CarPlate,
				// 		vehicleVin: this.basicFrom.CarVin,
				// 		state: this.basicFrom.state * 1,
				// 		id: this.basicFrom.id
				// 	}
				// 	this.$http.Editvehicle(params)
				// 		.then(res => {
				// 			this.closeDrawer()
				// 			this.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.msg)
				// 			if (res.code === 0) {
				// 				this.vehicleList()
				// 			}
				// 		}).catch(err => {
				// 			console.error(err)
				// 		})
				// }
			},
			//编辑电池
			EditBatteryInfo() {
				this.$refs.addBatteryForm.$refs.valueForm.validate().then(res=>{
					const params = {
						id: this.BatteryForm.id,
						sn: this.BatteryForm.sn,
						length: this.BatteryForm.length*1,
						width: this.BatteryForm.width*1,
						height: this.BatteryForm.height*1,
						weight: this.BatteryForm.weight*1,
					}
					this.$http.editBattery(params)
					.then(res => {
						this.closeDrawer()
						this.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.code === 0 ? '修改成功!' : res.msg)
						if (res.code === 0) {
							this.batteryList()
						}
					}).catch(err => {
						console.error(err)
					})
				})
			},
			//添加充电仓位请求接口
			AddCanginfo() {
				this.$refs.addSetForm.$refs.setvalueForm.validate().then(res=>{
					const params = {
						chargerId: this.setForm.chargerId*1,
						chargerCode: this.setForm.chargerCode,
						isSwap: this.setForm.isSwap,
						isCheck: this.setForm.isCheck,
					}
					this.$http.addEncode(params)
					.then(res => {
						this.closeDrawer()
						this.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.code === 0 ? '新增仓位成功' : res.msg)
						if (res.code === 0) {
							this.encodeList()
						}
					}).catch(err => {
						console.error(err)
					})
				})
			},
			//添加电池请求接口
			AddBatteryinfo() {
				this.$refs.addBatteryForm.$refs.valueForm.validate().then(res=>{
					const params = {
						sn: this.BatteryForm.sn,
						length: this.BatteryForm.length*1,
						width: this.BatteryForm.width*1,
						height: this.BatteryForm.height*1,
						weight: this.BatteryForm.weight*1,
					}
					this.$http.addBattery(params)
					.then(res => {
						this.closeDrawer()
						this.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.code === 0 ? '新增电池成功' : res.msg)
						if (res.code === 0) {
							this.batteryList()
						}
					}).catch(err => {
						console.error(err)
					})
				})
			},
			//打开编辑车辆抽屉
			EditCarData(row) {
				this.dialogType = 'edit'
				this.$refs.BasicDrawer.open();
				this.basicFrom.CarDistance = row.modelDistance
				this.basicFrom.CarPlate = row.vehiclePlate
				this.basicFrom.CarVin = row.vehicleVin
				this.basicFrom.state = row.state
				this.basicFrom.id = row.id
			},
			//打开绑定frid
			bindHandle(row) {
				let _that = this
				if(row.rfidEpc) {
					uni.showModal({
						title:`该车已经绑定FRID,是否继续绑定?`,
						content:'',
						success: function(res) {
							if (res.confirm) {
								_that.$refs.BindDrawer.open();
								_that.basicFrom.CarDistance = row.modelDistance
								_that.basicFrom.CarPlate = row.vehiclePlate
								_that.basicFrom.CarVin = row.vehicleVin
								_that.basicFrom.state = row.state
								_that.basicFrom.id = row.id
								_that.basicFrom.rfidEpc = row.rfidEpc
								_that.basicFrom.frid = row.rfidEpc.replace(/.{4}$/, '****')
							} else if (res.cancel) {
								return false
								//用户点击取消按钮触发
							}
						}
					})
				} else {
					_that.$refs.BindDrawer.open();
					_that.basicFrom.CarDistance = row.modelDistance
					_that.basicFrom.CarPlate = row.vehiclePlate
					_that.basicFrom.CarVin = row.vehicleVin
					_that.basicFrom.state = row.state
					_that.basicFrom.id = row.id
					_that.basicFrom.rfidEpc = row.rfidEpc
					_that.basicFrom.frid = row.rfidEpc.replace(/.{4}$/, '****')
				}
			},
			//绑定建权
			BindFRIDHandle() {
				if (!this.basicFrom.rfidEpc || !this.basicFrom.epcFour) {
					this.ExchangeMessage('warn', '请填写完整!')
				} else {
					const params = {
						id: this.basicFrom.id,
						rfidEpc: this.basicFrom.rfidEpc,
						epcFour: this.basicFrom.epcFour
					}
					this.$http.vehicleBind(params)
						.then(res => {
							this.closeDrawer()
							this.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.msg)
							if (res.code === 0) {
								this.vehicleList()
							}
						}).catch(err => {
							console.error(err)
						})
				}
			},
			//编辑车辆请求接口
			EditCarInfo() {
				if (!this.basicFrom.CarDistance || !this.basicFrom.CarPlate || !this.basicFrom.CarVin) {
					this.ExchangeMessage('warn', '请填写完整!')
				} else {
					const params = {
						modelDistance: this.basicFrom.CarDistance,
						vehiclePlate: this.basicFrom.CarPlate,
						vehicleVin: this.basicFrom.CarVin,
						state: this.basicFrom.state * 1,
						id: this.basicFrom.id
					}
					this.$http.Editvehicle(params)
						.then(res => {
							this.closeDrawer()
							this.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.msg)
							if (res.code === 0) {
								this.vehicleList()
							}
						}).catch(err => {
							console.error(err)
						})
				}
			},
			// 添加车辆请求接口
			AddCarinfo() {
				if (!this.basicFrom.CarDistance || !this.basicFrom.CarPlate || !this.basicFrom.CarVin) {
					this.ExchangeMessage('warn', '请填写完整!')
				} else {
					const params = {
						modelDistance: this.basicFrom.CarDistance,
						vehiclePlate: this.basicFrom.CarPlate,
						vehicleVin: this.basicFrom.CarVin,
						source: 0,
					}
					this.$http.addvehicle(params)
						.then(res => {
							this.closeDrawer()
							this.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.code === 0 ? '新增车辆成功' : '新增车辆失败')
							if (res.code === 0) {
								this.vehicleList()
							}
						}).catch(err => {
							console.error(err)
						})
				}

			},
			//查询
			handleQuery() {
				this.queryParams.page = 1
				this.datalist = []
				this.showLoadMore = false
				this.vehicleList()
			},
			//查询电池
			handleBatteryQuery () {
				this.batteryParams.page = 1
				this.dataBatterylist = []
				this.showLoadMore = false
				this.batteryList()
			},
			//重置
			resetForm() {
				this.queryParams = {
					page: 1,
					pageSize: 10,
					source: undefined, //来源
					vehiclePlate: undefined, //车牌号
					vehicleVin: undefined, //VIN码
				}
				this.vehicleList()
			},
			//重置电池
			resetBatteryForm() {
				this.batteryParams = {
					page: 1,
					pageSize: 10,
					orderByField: 'id', //排序字段
					orderByWays: 'desc' ,//排序方式
					sn: null, //来源
				}
				this.batteryList()
			},
			//车辆列表，
			vehicleList() {
				uni.showLoading({
					title:'数据加载中...'
				})
				this.$http.vehicleList(this.queryParams).then((res) => {
					this.datalist = res.data.records;
					this.total = res.data.total;
					uni.hideLoading()
				}).catch(err => {uni.hideLoading()});
			},
			//仓位列表
			encodeList() {
				uni.showLoading({
					title:'数据加载中...'
				})
				this.$http.encodeList(this.cangParams).then((res) => {
					
					this.dataCanglist = res.data;
					uni.hideLoading()
				}).catch(err => {uni.hideLoading()});
			},
			//电池列表
			batteryList() {
				uni.showLoading({
					title:'数据加载中...'
				})
				this.$http.batteryList(this.batteryParams).then((res) => {
					this.dataBatterylist = res.data.records;
					this.batteryTotal=res.data.total
					uni.hideLoading()
				}).catch(err => {uni.hideLoading()});
			},
			//关闭抽屉
			closeDrawer() {
				this.$refs.BasicDrawer.close();
				this.$refs.BindDrawer.close();
			},
			//车辆触底加载数据
			pullup() {
				this.showLoadMore = true
				if(this.isSelect!==0){
					this.loadMore = 'no-more'
				}else{
					if (this.total == this.datalist.length) {
						this.loadMore = 'no-more'
						return
					} else {
						this.queryParams.page++
						this.vehicleList()
						this.loadMore = 'loading'
					}
				}
				
			},
			//仓位触底加载数据
			pullCangup() {
				this.showLoadMore = true
				if(this.isSelect!==1){
					this.loadMore = 'no-more'
				}else{
					if (this.cangTotal == this.dataCanglist.length) {
						this.loadMore = 'no-more'
						return
					} else {
						this.cangParams.page++
						this.encodeList()
						this.loadMore = 'loading'
					}
				}
			},
			//仓位触底加载数据
			pullBatteryup() {
				this.showLoadMore = true
				if(this.isSelect!==2){
					this.loadMore = 'no-more'
				}else{
					if (this.batteryTotal == this.dataBatterylist.length) {
						this.loadMore = 'no-more'
						return
					} else {
						this.batteryParams.page++
						this.batteryList()
						this.loadMore = 'loading'
					}
				}
			},
			//同步云端
			syncCloud() {
				let that = this
				uni.showModal({
					title: "是否云端同步",
					content: "",
					success: function(res) {
						if (res.confirm) {
							that.$http.getSync().then(res=>{
								that.ExchangeMessage(res.code === 0 ? 'success' : 'error', res.code === 0 ? '同步成功':'同步失败')
							})
							//用户点击确认按钮触发
						} else if (res.cancel) {
							return
							//用户点击取消按钮触发
						}
					}
				})
			},
			//chargerId等于0时更改为1
			changeChargerId(){
				this.setForm.chargerId=1
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .uni-forms-item__content {
		.is-input-error-border .uni-easyinput__placeholder-class{
			color: #999;
		}
		.uni-easyinput,.uni-select{
			background: rgba(255, 255, 255, 0);
			border-radius: 2px;
			border: 1px solid #263042;
			
		}
		.uni-select__selector {
			background: none;
			border: 1px solid #263042;
		}

		.uni-select__selector-item {
			font-size: 14px;
			font-weight: 400;
			color: #A8ADC8;
		}

		.uni-popper__arrow {
			display: none;
		}

		.uni-select__input-text {
			color: white;
		}

		.uni-easyinput__content {
			background: none !important;
			border: none !important;
			color: #fff;
			width: 188px;
		}
		.tempIpt{
			.uni-easyinput__content{
				width: 92px !important;
			}
		}
	}

	::v-deep .uni-forms-item__label {
		font-size: 14px;
		font-weight: 400;
		color: #FFFFFF;
	}
	::v-deep .uni-select__selector {
		background: #111827 !important;
		border: 1px solid #263042;
		color: #606266;
		z-index: 9999999;
	}
	.basic-data {
		width: 100%;
		height: 100%;
		color: white;
		font-size: 24px;
		overflow: hidden;

		.basic-top {
			display: flex;
			justify-content: space-between;
			.service_header_left {
				display: flex;
			
				.btn {
					width: 100px;
					height: 48px;
					background: #263042;
					border-radius: 0px 2px 2px 0px;
					font-size: 16px;
					text-align: center;
					line-height: 48px;
				}
			
				.active {
					background: #91FDB9;
					border-radius: 2px 0px 0px 2px;
					color: black;
				}
			}
			.basci-header-right{
				display:flex;
				align-items: center;
			}
			.times {
				font-size: 14px;
				font-weight: 400;
				color: #A8ADC8;
				line-height: 32px;
			}

			.sync-btn {
				width: 88px;
				height: 32px;
				border-radius: 2px;
				line-height: 32px;
				text-align: center;
				border: 1px solid #91FDB9;
				font-size: 14px;
				font-weight: 400;
				color: #91FDB9;
				margin-left: 20px;
			}

			.title {
				margin-left: auto;
				line-height: 32px;
				font-size: 16px;
				font-weight: 600;
				color: rgba(255, 255, 255, 0.85);
				line-height: 19px;
				text-shadow: 0px 0px 4px #0027D8
			}
		}

		.basic-search {
			display: flex;
			padding: 16px 20px;
			width: 100%;
			height: 66px;
			box-sizing: border-box;
			background: #111827;
			box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
			border-radius: 2px;
			border: 1px solid #192337;
			// margin-top: 20px;
			::v-deep .searchForm {
				span {
					display: flex;
				}
			}
		}
		.basic-zkset{
			display: flex;
			padding: 16px 20px;
			width: 100%;
			min-height: 66px;
			box-sizing: border-box;
			background: #111827;
			box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
			border-radius: 2px;
			border: 1px solid #192337;
			flex-direction: column;
			.setTitle{
				font-size: 15px;
				 font-weight: bold;
			}
			.setCont{
				.tempIpt{
					width: 88px;
					
				}
				::v-deep .uni-data-checklist{
					margin-top: 5px !important;
					.checklist-box{
						margin-right: 12px;
					}
					.checklist-text{
						color: white
					}
					.checklist-group .checklist-box.is--default.is-checked .checklist-text{
						color: #91FDB9;
					}
					.checklist-group .checklist-box.is--default.is-checked .radio__inner{
						border-color:#91FDB9;
					}
					.checklist-group .checklist-box.is--default.is-checked .radio__inner .radio__inner-icon{
						background-color:#91FDB9;
					}
					.checklist-group .checklist-box.is--default.is-checked .checkbox__inner{
						border-color:#91FDB9;
						background-color:#91FDB9;
					}
				}
				::v-deep .formSet {
					span {
						display: flex;
						flex-wrap: wrap;
						align-items: center;
					}
					.uni-forms-item__content{
						display: flex;
					}
					.uni-forms-item{
						margin-bottom: 0;
					}
				}
			}
		}
		.search-btn {
			width: 60px;
			height: 34px;
			background: #91FDB9;
			border-radius: 2px;
			font-size: 14px;
			font-weight: 400;
			color: #000000;
			text-align: center;
			line-height: 34px;
			margin-left: 20px;
			margin-top: 1px;
		}
		.search-temp {
			width: 68px;
			height: 34px;
			background: #91FDB9;
			border-radius: 2px;
			font-size: 14px;
			font-weight: 400;
			color: #000000;
			text-align: center;
			line-height: 34px;
			margin-left: 20px;
			margin-top: 1px;
			margin-right: 15px;
		}
		.reset-btn {
			width: 60px;
			height: 32px;
			border-radius: 2px;
			font-size: 14px;
			font-weight: 400;
			color: #FFFFFF;
			text-align: center;
			line-height: 32px;
			margin-left: 20px;
			margin-top: 1px;
			border: 1px solid #263042;
		}

		.basic-table {
			width: 100%;
			height: 576px;
			background: #111827;
			box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
			border-radius: 2px;
			border: 1px solid #192337;
			margin-top: 16px;
			box-sizing: border-box;
			padding: 16px 20px;
			display: flex;
			flex-direction: column;

			.marginZero {
				margin-left: 0px;
				margin-bottom: 15px;
			}
		}
	}
</style>