<template>
	<view>
		<view>
			<view class="item ddflex">
				<view class="label">所属门店</view>
				<view class="item-input fflex ddflex">
					<view>{{info.storeName}}</view>
					<!-- <view class="state">在线</view> -->
				</view>
			</view>
			<view class="item ddflex">
				<!-- <view class="label">机柜名称</view> -->
				<view class="label">设备名称</view>
				<view class="item-input fflex">
					{{info.name}}
				</view>
			</view>
			<view class="item ddflex">
				<view class="label">电池编号</view>
				<view class="item-input fflex">
					{{info.batteryId}}
				</view>
			</view>
			<!-- <view class="item ddflex">
				<view class="label">租赁用户</view>
				<view class="item-input fflex">
					王鸿  15700317367
				</view>
			</view> -->
			<!-- <view class="item ddflex">
				<view class="label">品牌</view>
				<view class="item-input fflex">
					乐享换电
				</view>
			</view> -->
			<view class="item ddflex">
				<view class="label">型号</view>
				<view class="item-input fflex">
					{{info.model}}
				</view>
			</view>
			<view class="item ddflex">
				<view class="label">设备类型</view>
				<view class="item-input fflex">
					{{info.macName}}
				</view>
			</view>
			<view class="item ddflex">
				<view class="label">电芯</view>
				<view class="item-input fflex">
					{{info.type}}
				</view>
			</view>
			<!-- <view class="item ddflex">
				<view class="label">BMS保护板</view>
				<view class="item-input fflex">
					V1.2
				</view>
			</view> -->
			<!-- <view class="item ddflex">
				<view class="label">软件版本</view>
				<view class="item-input fflex">
					百维
				</view>
			</view> -->
			<view class="item ddflex">
				<view class="label">押金</view>
				<view class="item-input fflex">
					{{info.deposit}}
				</view>
			</view>
			<view class="item ddflex">
				<view class="label">单价</view>
				<view class="item-input fflex">
					{{info.price}}
				</view>
			</view>
			<!-- <view class="item ddflex">
				<view class="label">起租时间</view>
				<view class="item-input fflex">
					2022-07-0314:07:15
				</view>
			</view> -->
			<view class="item ddflex">
				<view class="label">到期时间</view>
				<view class="item-input fflex">
					{{info.blockDate}}
				</view>
			</view>
			<!-- <view class="item ddflex">
				<view class="label">备注</view>
				<view class="item-input fflex">
					2.18更换新品头
				</view>
			</view> -->
			
		</view>
		
		<!-- 保存按钮 -->
		<view style="height: 165rpx;" class="savepadding"></view>
		<view class="bottom-btns savepadding">
			<view class="ddflex" style="margin: 30rpx;justify-content: space-between;">
				<view class="btn1 fflex" @click="switchChange(!DHON)">{{DHON?'断电':'通电'}}</view>
				<!-- <view class="btn1" @click="jumpUrl('/machineAndCell/machineDetail/machineDetail')">通电</view>
				<view class="btn2">解绑</view>
				<view class="btn3">保存</view> -->
			</view>
		</view>
		
	</view>
</template>

<script>
	const app = getApp();
	const req = require("../../utils/request.js");
	export default {
		components: {
		},
		props: {},
		data() {
			return {
				id:null,
				info:{},
				DHON:false
			}
		},
		onLoad(options) {
			this.id = options.id
			this.getData()
		},
		onShow() {
			
		},
		methods: {
			jumpUrl(url) {
				if (req.isLogins(true)) {
					uni.navigateTo({
						url: url
					})
				}
			},
			getData(){
				uni.showLoading({
					title:'加载中'
				})
				req.getRequest('/admin/v2/battery/'+this.id,{},res=>{
					this.info = res
					uni.hideLoading()
				})
				req.getRequest('/admin/v2/battery/bmsData',{batteryId:this.id},res=>{
					this.DHON = JSON.parse(res[0].State).DHON==1?true:false
				})
			},
			switchChange(value){
				uni.showModal({
					title:'提示',
					content:value?'确定开启放电开关？':'确定关闭放电开关？',
					success: (r) => {
						if(r.confirm){
							uni.showLoading({
								title:value?'开启中':'关闭中',
							})
							req.postRequest('/admin/v2/battery/bmsSend',{batteryId:this.id,type:value},res=>{
								uni.hideLoading()
								if(res){
									// req.msg(event.detail.value?'开启成功':'关闭成功')
									uni.showModal({
										title:'提示',
										content:'操作成功,该操作会有延迟，请稍候查看最新状态',
										showCancel:false,
										success:() =>{
											this.DHON = value
											this.getData()
										}
									})
								}else {
									req.msg(value?'开启失败':'关闭失败')
								}
							})
						}else{
						}
						
					}
				})
			},
		},
		mounted() {
		},
		onPageScroll: function(e) {
			
		}
	}
</script>

<style>
	@import "./cellDetail.css";
</style>