<template>
	<view class="page">
		<view class="fixed">
			<u-navbar title=" " :border-bottom="false" :background="background" title-color='#fff' title-size='36'
				height='45' back-icon-color='#000'></u-navbar>

		</view>
		<view class="top">
			<view class="model">
				{{deviceInfos.model}}
			</view>
			<view class="switch" v-if="false">
				<image src="https://lxnapi.ccttiot.com/bike/img/static/uXLYdSpcdiKGoNpJBiGZ" mode="" class="replay">
				</image>
				正在连接
				<image src="https://lxnapi.ccttiot.com/bike/img/static/ukhgaoFSHmlJWkgyC4U4" mode="" class="bluetooth">
				</image>
			</view>
		</view>
		<view class="power">
			<view class="tit">
				电量
			</view>
			<view class="num">
				{{deviceInfos.remainingPower}}%
			</view>
		</view>
		<view class="car_img">
			<image src="https://lxnapi.ccttiot.com/bike/img/static/ukC1CG1uAz1pwV0qZ03n" mode=""></image>
		</view>
		<view class="tips">
			<view class="yuan">

			</view>
			当前车辆状态： {{deviceInfos.lockStatus==1?'开锁': '关锁' }}
		</view>
		<view class="btn_box">
			<view class="btn1" @click="btn(2)">
				<image src="https://lxnapi.ccttiot.com/bike/img/static/uaW9kLzl1RYoU8WyiuYL" mode=""></image>
				鸣笛寻车
			</view>
			<!-- <view class="btn2" @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd">
			          <view class="slider" :style="{ transform: 'translateX(' + translateX + 'rpx)' }"></view>
			          右滑启动
			        </view> -->
			<view class="btn1" @click="btn(1)" v-if="deviceInfos.lockStatus==1">
				<image src="https://lxnapi.ccttiot.com/bike/img/static/uEUTkjiSqIDTjnLxGvP8" mode=""></image>
				已启动
			</view>
			<view class="btn1" @click="btn(0)" v-else>
				<image src="https://lxnapi.ccttiot.com/bike/img/static/uAx8pleqdhKswoupY8Wo" mode=""></image>
				已关锁
			</view>
			<view class="btn1">
				<image src="https://lxnapi.ccttiot.com/bike/img/static/uGrptW1UAUQy0v1pQQvC" mode=""></image>
				鸣笛寻车
			</view>
		</view>
		<view class="order_info">
			<view class="info_top">
				<view class="tit1">
					欢迎使用电动车
				</view>
				<view class="txt1" @click="topage(1)">
					查看订单 <image src="https://lxnapi.ccttiot.com/bike/img/static/uAxKe5Or9LMUn4DNBL9B" mode=""></image>
				</view>
			</view>
			<view class="info_cont">
				<image src="https://lxnapi.ccttiot.com/bike/img/static/ueWcek6yF0kSadYfYhyV" mode=""></image>
				<view class="infos">
					<view class="time">
						{{time1()}}
					</view>
					<view class="data">
						{{time2()}}
					</view>
					<view class="tips1">
						到期后将产生超时费用
					</view>
				</view>
			</view>
			<view class="btns" @click="topage(0)">
				去续租
			</view>
		</view>
		<view class="store_car">
			<view class="tops">
				<view class="type">
					租车门店
				</view>
				{{storeInfo.name}}
			</view>
			<view class="address">
				{{storeInfo.simpleAddress}}
			</view>
			<view class="time">
				营业时间：{{storeInfo.businessTimeStart}}-{{storeInfo.businessTimeEnd}}
			</view>
			<view class="store_btn_li">
				<view class="store_btn" @click="callPhone(storeInfo.contactMobile)">
					<image src="https://lxnapi.ccttiot.com/bike/img/static/umkJCfPac4Mrzni8aoda" mode=""></image>
					联系门店
				</view>
				<view class="store_btn" @click="mapFun">
					<image src="https://lxnapi.ccttiot.com/bike/img/static/uolYZ4dLvxxI2n2WzZ4J" mode="" ></image>
					导航到店
				</view>
			</view>
		</view>
		<view class="bot_btn" @click="toback">
			<view class="btn">
				还车
			</view>
		</view>
	</view>
</template>

<script>
	
	const app = getApp();
	var xBlufi = require("@/utils/blufi/xBlufi.js");
	let _this = null;
	export default {
		data() {
			return {
				devicesList: [
					// {name:'110000',
					// mac:'11111'}
				],
				searching: false,
				texts: '正在扫描蓝牙设备...',
				btnflag: true,
				tishiflag: false,
				option: '',
				bluthlist: [], //蓝牙数组
				// status: 'loading',
				statusflag: false,
				Bluetoothmac: '',
				mac: '',
				ishave: false,
				ver_data: null,
				deviceInfoss: {},
				gps: {},
				isband: false,
				// status: false,
				deviceIds: '',
				name: '',
				
				dl: 0,
				czmoney: true,
				iscz: true,



				bgc: {
					backgroundColor: "#F7FAFE",
				},
				show: true,
				showgj: true,
				searchKeyword: '11',
				latitude: 39.916527,
				longitude: 116.397128,
				isMap: false,
				zoomSize: 15,
				markers: [],
				polyline: [],
				polygons: [],
				cardId: '001区域',
				sn: '',
				deviceInfos: {},
				carstause: false,

				maskloading: false,
				toploadtxt: "开锁中0%",
				loadimg: 'https://lxnapi.ccttiot.com/bike/img/static/urJQJnOI1DEjWatFqHYh',
				tiptxt: '请定点停放，规范用车',
				maskepage: 0,
				backgps: {},
				buletxt: '',

				buleclose: false,
				buleopen: false,
				bulering: false,
				bulerebort: false,
				
				orderinfo:{},
				storeInfo:{}
			
				

			}
		},
		onLoad(e) {
			this.sn = e.sn
			this.deviceInfo()
			this.getorderInfo()

		},
		onUnload: function() {
			xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
			xBlufi.notifyStartDiscoverBle({
				'isStart': false
			});
		},
		onHide() {
			xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
			xBlufi.notifyStartDiscoverBle({
				'isStart': false
			});
		},
		onBeforeUnmount() {
			xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
			xBlufi.notifyStartDiscoverBle({
				'isStart': false
			});
		},
		watch: {



		},
		methods: {
			toback(){
				uni.redirectTo({
					url:'/page_user/user_order?orderNo='+this.orderinfo.orderNo
				})
			},
			callPhone(phone){
				uni.makePhoneCall({
					phoneNumber:phone
				})
				// setTimeout(()=>{
				// 	this.showkf=false
				// },500)
			},
			topage(num){
				console.log(this.orderinfo.orderNo);
			 if (this.orderinfo && this.orderinfo.orderNo) {
			    // console.log(this.orderInfo.orderNo);
			    if (num == 0) {
			      uni.redirectTo({
			        url: '/page_user/renewCar?orderNo=' + this.orderinfo.orderNo
			      });
			    } else if (num == 1) {
			      uni.redirectTo({
			        url: '/page_user/user_order?orderNo=' + this.orderinfo.orderNo
			      });
			    }
			  } else {
			    console.error('orderInfo is undefined or orderNo is missing');
			  }
			},
			time1() {
			  const expiryTime = new Date(this.orderinfo.expiryTime); // 获取过期时间
			  const now = new Date(); // 获取当前时间
			
			  // 计算时间差（毫秒）
			  const timeDifference = expiryTime - now;
			
			  if (timeDifference < 0) {
			    return '已超时';
			  } else {
			    const days = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
			    if (days > 0) {
			      return `${days}天`;
			    }
			
			    const hours = Math.floor((timeDifference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
			    if (hours > 0) {
			      return `${hours}小时`;
			    }
			
			    const minutes = Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60));
			    if (minutes > 0) {
			      return `${minutes}分钟`;
			    }
			
			    return '即将超时'; // 如果时间差小于1分钟
			  }
			},
			time2(){
				console.log(this.orderinfo);
				  const expiryTime = new Date(this.orderinfo.expiryTime);
				
				  const month = (expiryTime.getMonth() + 1).toString().padStart(2, '0'); // 获取月份并补零
				  const day = expiryTime.getDate().toString().padStart(2, '0'); // 获取日期并补零
				  const hours = expiryTime.getHours().toString().padStart(2, '0'); // 获取小时并补零
				  const minutes = expiryTime.getMinutes().toString().padStart(2, '0'); // 获取分钟并补零
				
				  return `${month}/${day} ${hours}:${minutes}到期`;
			},
			mapFun() {
				console.log('点击了');
				uni.openLocation({
					latitude: this.storeInfo.lat,
					//纬度 - 目的地/坐标点
					longitude: this.storeInfo.lng,
					//经度 - 目的地/坐标点
					// name: "荆门市",
					address: this.storeInfo.simpleAddress
				});
			},
			getorderInfo(){
			
				let data = {
					sn: this.sn
				}
				this.$u.get(`appVerify/getInProgressOrder?`, data).then((res) => {
					if (res.code == 200) {
						this.orderinfo = res.data
						this.getstoreInfo()
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				});
			},
			getstoreInfo() {
				let data = {
					storeId: this.orderinfo.storeId
				}
				this.$u.get(`app/getStore?`, data).then((res) => {
					if (res.code == 200) {
						this.storeInfo = res.data
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				});
			},
			deviceInfo(){
				this.$u.get('app/getDeviceBySn?sn=' + this.sn).then((res) => {
					console.log(res, 'rererer');
					if (res.code === 200) {
						// console.log(this.areaId,);
						this.deviceInfos = res.data
						
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
				
			},
			bulebtn(num) {
				if (num == 1) {
					if (this.carstause) {
						this.ring()
					} else {
						this.bulering = true
						this.Binddevice()
					}
				} else if (num == 2) {
					if (this.carstause) {
						this.open()
					} else {
						this.buleopen = true
						this.Binddevice()
					}
				} else if (num == 3) {
					if (this.carstause) {
						this.close()
					} else {
						this.buleclose = true
						this.Binddevice()
					}
				} else if (num == 4) {
					if (this.carstause) {
						this.reboot()
					} else {
						this.bulerebort = true
						this.Binddevice()
					}
				}
			},
			btn(num) {
				// this.showbtntip = false
				if (num == 0) {
					uni.showLoading({
						title: '加载中...'
					})
					console.log('点击了....1');
					this.$u.post('/appVerify/device/unlock?sn=' + this.sn+'&orderNo='+this.orderinfo.orderNo).then((res) => {

						if (res.code == 200) {
							// 处理接口返回的数据，将边界数据转换为地图组件需要的折线结构
							this.deviceInfo()
							uni.showToast({
								title: '操作成功',
								icon: 'none',
								duration: 2000
							});
						} else {
							uni.hideLoading()
							this.bulebtn(2)
						}
					}).catch(error => {
						console.error("Error fetching area data:", error);
					});
				} else if (num == 1) {
					uni.showLoading({
						title: '加载中...'
					})
					console.log('点击了....2');
					this.$u.post('/appVerify/device/lock?sn=' + this.sn+'&orderNo='+this.orderinfo.orderNo).then((res) => {
						if (res.code == 200) {
							// 处理接口返回的数据，将边界数据转换为地图组件需要的折线结构
							this.deviceInfo()
							uni.showToast({
								title: '操作成功',
								icon: 'none',
								duration: 2000
							});
						} else {
							uni.hideLoading()
							this.bulebtn(3)
						}
					}).catch(error => {
						console.error("Error fetching area data:", error);
					});
				} else if (num == 2) {
					uni.showLoading({
						title: '加载中...'
					})
					this.$u.post('/app/device/ring?sn=' + this.sn).then((res) => {
						if (res.code == 200) {
							uni.hideLoading()
							uni.showToast({
								title: '操作成功',
								icon: 'none',
								duration: 2000
							});
						} else {
							uni.hideLoading()
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 2000
							});
							this.bulebtn(1)
						}
					})
				} else if (num == 3) {
					
				} else if (num == 4) {
					

				} else if (num == 5) {
					
				} else if (num == 6) {
					

				} else if (num == 7) {

					
				} else if (num == 8) {
					uni.showLoading({
						title: '加载中...'
					})
					this.$u.post('/appVerify/device/reboot?sn=' + this.sn).then((res) => {
						if (res.code == 200) {
							this.deviceInfo()
							uni.showToast({
								title: '操作成功',
								icon: 'none',
								duration: 2000
							});
						} else {
							// uni.hideLoading()
							// this.bulebtn(4)
						}
					})


				} else if (num == 9) {
					uni.showLoading({
						title: '加载中...'
					})
					this.$u.post('/appVerify/device/seatCushionLock?sn=' + this.sn).then((res) => {
						if (res.code == 200) {
							this.deviceInfo()
							uni.showToast({
								title: '操作成功',
								icon: 'none',
								duration: 2000
							});
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 2000
							});
						}
					})
				} else if (num == 10) {
					uni.showLoading({
						title: '加载中...'
					})
					this.$u.post('/appVerify/refreshDevice?sn=' + this.sn).then((res) => {
						if (res.code == 200) {
							this.deviceInfo()
							uni.showToast({
								title: '操作成功',
								icon: 'none',
								duration: 2000
							});
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 2000
							});
						}
					})
				}
			},
			Binddevice() {
				uni.getBluetoothAdapterState({
					success: function(res) {
						console.log('蓝牙状态：', res.available)
					},
					fail: function(res) {
						console.log('获取蓝牙状态失败')
					}
				})
				this.maskloading = true
				this.devicesList = []
				this.maskepage = 4
				this.buletxt = '蓝牙连接中'
				// uni.showLoading({
				// 	title: '蓝牙扫描中..'
				// })
				xBlufi.initXBlufi(1);
				console.log("xBlufi", xBlufi.XMQTT_SYSTEM);
				xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
				xBlufi.notifyStartDiscoverBle({
					'isStart': true
				});


				// 两秒后停止蓝牙搜索
				setTimeout(() => {
					xBlufi.notifyStartDiscoverBle({
						'isStart': false
					});
					setTimeout(() => {
						// uni.hideLoading()
						if (this.devicesList.length == 0) {
							// uni.showToast({
							// 	title: '暂无发现对应设备,请靠近设备',
							// 	icon: 'none',
							// 	duration: 1500
							// });
							this.maskepage = 5
						} else {
							let uniqueDevicesList = Array.from(new Set(this.devicesList));

							// 将去重后的数组重新赋值给 this.devicesList
							this.devicesList = uniqueDevicesList;
							console.log(this.devicesList, 'this.devicesListthis.devicesList');
							let istrue = false
							this.devicesList.forEach(device => {
								// 从设备名称中提取 MAC 地址（假设 MAC 地址是设备名称的后6个字符）
								let macFromName = device.name.substring(device.name.length - 12);
								console.log(macFromName, 'macFromNamemacFromName');
								// 与 this.mac 进行比较
								if (macFromName == this.mac) {
									// 如果相同，则将 this.ishave 设置为 true
									console.log(device);
									this.deviceInfoss = device
									// this.ishave = true;
									istrue = true
									this.createBLEConnection(device)

									console.log('对比正确1111111111');
								} else {
									console.log('对比错误');

								}
							});
							setTimeout(() => {
								if (!istrue) {
									this.buletxt = '蓝牙连接失败'


									setTimeout(() => {
										this.maskepage = 5
									}, 500)
								}

							}, 500)
						}


					}, 200)
					// 判断是否存在浇花器设备

					// this.status = true
				}, 5000)

			},

			reboot() {
				let vm = this; // 将外部的 this 绑定到 vm 上
				uni.getNetworkType({
					success(res) {
						if (res.networkType !== 'none') {
							uni.getConnectedBluetoothDevices({
								success(res) {
									console.log('已连接的蓝牙设备信息：', res);
									// vm.dl = (vm.orderinfo.deviceAmount / vm.orderinfo.unitPrice).toFixed(2); // 使用 vm 访问 Vue 实例的属性
									xBlufi.notifySendCustomData({
										customData: "11reboot"
									});
									vm.maskloading = false
									// uni.hideLoading()
									// vm.remakr()
								},
								fail(err) {
									uni.hideLoading()
									console.error('获取已连接蓝牙设备信息失败：', err);
								}
							});
						} else {
							console.log('手机未连接网络');
						}
					}
				});
			},
			open() {
				let vm = this; // 将外部的 this 绑定到 vm 上
				uni.getNetworkType({
					success(res) {
						if (res.networkType !== 'none') {
							uni.getConnectedBluetoothDevices({
								success(res) {
									console.log('已连接的蓝牙设备信息：', res);
									// vm.dl = (vm.orderinfo.deviceAmount / vm.orderinfo.unitPrice).toFixed(2); // 使用 vm 访问 Vue 实例的属性
									xBlufi.notifySendCustomData({
										customData: "11open"
									});
									vm.maskloading = false
									vm.deviceInfo()
									// uni.hideLoading()
									// vm.remakr()
								},
								fail(err) {
									uni.hideLoading()
									console.error('获取已连接蓝牙设备信息失败：', err);
								}
							});
						} else {
							console.log('手机未连接网络');
						}
					}
				});
			},
			close() {
				let vm = this; // 将外部的 this 绑定到 vm 上
				uni.getNetworkType({
					success(res) {
						if (res.networkType !== 'none') {
							uni.getConnectedBluetoothDevices({
								success(res) {
									console.log('已连接的蓝牙设备信息：', res);
									// vm.dl = (vm.orderinfo.deviceAmount / vm.orderinfo.unitPrice).toFixed(2); // 使用 vm 访问 Vue 实例的属性
									xBlufi.notifySendCustomData({
										customData: "11close"
									});
									vm.maskloading = false
									vm.deviceInfo()
									// uni.hideLoading()
									// vm.remakr()
								},
								fail(err) {
									uni.hideLoading()
									console.error('获取已连接蓝牙设备信息失败：', err);
								}
							});
						} else {
							console.log('手机未连接网络');
						}
					}
				});
			},
		
		
			ring() {
				let vm = this; // 将外部的 this 绑定到 vm 上
				uni.getNetworkType({
					success(res) {
						if (res.networkType !== 'none') {
							uni.getConnectedBluetoothDevices({
								success(res) {
									console.log('已连接的蓝牙设备信息：', res);
									// vm.dl = (vm.orderinfo.deviceAmount / vm.orderinfo.unitPrice).toFixed(2); // 使用 vm 访问 Vue 实例的属性
									xBlufi.notifySendCustomData({
										customData: "11play1@"
									});
									vm.maskloading = false
									vm.deviceInfo()
									// uni.hideLoading()
									// vm.remakr()
								},
								fail(err) {
									uni.hideLoading()
									console.error('获取已连接蓝牙设备信息失败：', err);
								}
							});
						} else {
							console.log('手机未连接网络');
						}
					}
				});
			},
			
			
			funListenDeviceMsgEvent: function(options) {
				switch (options.type) {
					case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
						if (options.result) {
							let devicesarr = options.data
							// this.devicesList = options.data

							devicesarr.forEach(device => {


								// this.$u.get(`/app/device/${mac}/isBind`, data).then((res) => {
								// if (res.data == false) {
								this.devicesList.push(device);

								let uniqueDevicesList = Array.from(new Set(this.devicesList));

								// 将去重后的数组重新赋值给 this.devicesList
								this.devicesList = uniqueDevicesList;

							});
						}
						break;

					case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
						console.log("连接回调：" + JSON.stringify(options));
						if (options.result) {
							// uni.hideLoading();


							xBlufi.notifyInitBleEsp32({
								deviceId: options.data.deviceId
							});

							// xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvents);

							// this.deviceIds = options.data.deviceId
							// this.name = options.data.name
							// 连接成功绑定设备
							// let params = {
							// 	mac: this.Bluetoothmac,
							// 	userId: this.$store.state.user.userId
							// }
							let systemInfo = uni.getSystemInfoSync();
							if (systemInfo.platform === 'android') {
								// 当前设备是 Android  

							} else if (systemInfo.platform === 'ios') {
								// 当前设备是 iOS  
								// uni.navigateTo({
								// 	url: '/pages/wifilist/index?deviceId=' + options
								// 		.data.deviceId + '&name=' + options.data.name
								// })
							}
						}
						if (options.result == false) {
							// this.loadingmask=false
							this.carstause = false
							if (this.maskepage == 4) {
								this.buletxt = '设备连接失败'


								setTimeout(() => {
									this.maskepage = 5
								}, 800)
							}

							// uni.showModal({
							// 	title: '很抱歉提醒你！',
							// 	content: '小程序与设备异常断开',
							// 	showCancel: false,
							// 	success: function(res) {
							// 		// uni.navigateBack({
							// 		// 	url: '../search/search'
							// 		// });
							// 	}
							// });
							// this.statusflag = false
							// uni.hideLoading();
						}
						break;
					case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:

						// this.ver_data = this.parseCustomData(options.data)
						if (options.data) {
							this.carstause = true


							if (this.maskloading && this.maskepage == 4) {
								// setTimeout(() => {
								// 	this.maskloading = false
								// }, 700)
								if (this.buleclose == false && this.buleopen == false && this.bulerebort == false &&
									this
									.bulering == false) {
									if (this.buletxt == '蓝牙连接中') {
										this.buletxt = '蓝牙连接成功！'
									}

								}
								if (this.buleclose) {
									this.buleclose = false
									this.close()
								}
								if (this.buleopen) {
									this.buleopen = false
									this.open()
								}
								if (this.bulerebort) {
									this.buleopen = false
									this.reboot()
								}
								if (this.bulering) {
									this.bulering = false
									this.ring()
								}


							}






						} else {
							this.carstause = false
							if (this.maskepage == 4) {
								this.buletxt = '设备连接失败'


								setTimeout(() => {
									this.maskepage = 5
								}, 800)
							}
						}
						console.log("1收到设备发来的自定义数据结果：", options.data);
						break;
					case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED: {
						console.log('状态', options.result)
						if (options.result == false) {
							this.carstause = false
							if (this.maskepage == 4) {
								this.buletxt = '设备连接失败'


								setTimeout(() => {
									this.maskepage = 5
								}, 800)
							}
							// uni.showToast({
							// 	title: '设备断开链接，请重新点击蓝牙链接',
							// 	icon: 'none'
							// });
							// uni.showModal({
							// 	title: '很抱歉提醒你！',
							// 	content: '小程序与设备异常断开',
							// 	showCancel: false,
							// 	success: function(res) {
							// 		// uni.navigateBack({
							// 		// 	url: '../search/search'
							// 		// });
							// 	}
							// });
							// this.statusflag = false
							// uni.hideLoading();
						}
					}
					break;
					case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
						if (options.result) {
							let uniqueDevicesList = Array.from(new Set(this.devicesList));

							// 过滤出名称字段的前五个字母为 "CTPOW" 的项
							let filteredDevices = uniqueDevicesList.filter(device => device.name.substring(0,
									4) ===
								"BBLE");

							// 将过滤后的数组重新赋值给 this.devicesList
							this.devicesList = filteredDevices;

							// console.log('蓝牙停止搜索ok',this.devicesList);
						} else {
							//蓝牙停止搜索失败
							// console.log('蓝牙停止搜索失败');
						}
						this.searching = false
						// _this.setData({
						// 	searching: false
						// });

						break;
				}
			},



			//4、建立连接
			createBLEConnection(e) {
				console.log('调用了');
				xBlufi.notifyStartDiscoverBle({
					'isStart': false
				});
				console.log(e, '蓝牙信息')
				const deviceId = e.deviceId
				this.Bluetoothmac = e.localName.substring(5) //从第七位开始截取 只取后面的mac号
				console.log(this.Bluetoothmac, '11111');
				let name = e.name;
				console.log('点击了，蓝牙准备连接的deviceId:' + e.deviceId);
				xBlufi.notifyConnectBle({
					isStart: true,
					deviceId: e.deviceId,
					name
				});
				// for (var i = 0; i < this.devicesList.length; i++) {
				// 	if (e.deviceId === this.devicesList[i].deviceId) {

				// 		uni.showLoading({
				// 			title: '连接蓝牙设备中...'
				// 		});
				// 	}
				// }
			},

			funListenDeviceMsgEvents: function(options) {
				let that = this;
				switch (options.type) {
					case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED: {
						console.log('状态', options.result)
						if (options.result == false) {
							this.carstause = false
							uni.showToast({
								title: '设备断开链接，请重新点击蓝牙链接',
								icon: 'none'
							});
							// uni.showModal({
							// 	title: '很抱歉提醒你！',
							// 	content: '小程序与设备异常断开',
							// 	showCancel: false,
							// 	success: function(res) {
							// 		// uni.navigateBack({
							// 		// 	url: '../search/search'
							// 		// });
							// 	}
							// });
							// this.statusflag = false
							uni.hideLoading();
						}
					}
					break;

					case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_MY_DATA:
						this.loadPercent = options.data;
						this.loadText = '文件读取中'
						console.log("文件读取中", options.data);
						break;
					case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
						// this.isband = true
						// this.ver_data = this.parseCustomData(options.data)
						console.log("1收到设备发来的自定义数据结果：", options.data);
						if (options.data) {
							this.carstause = true
						}
						break;

					case xBlufi.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT:
						uni.hideLoading();
						if (options.result) {
							console.log('初始化成功');
						} else {
							console.log('初始化失败');


						}
						break;
				}
			},	
		}
	}
</script>




<style lang="scss">
	page {
		overflow-y: auto;
		background-image: url('https://lxnapi.ccttiot.com/bike/img/static/uYRs7Cv2Pbp95w3KjGO3');
		background-size: cover;
		/* 背景图片等比缩放以覆盖整个容器 */
		background-position: center;
		/* 背景图片居中显示 */
		background-repeat: no-repeat;
		/* 防止背景图片重复 */
		min-height: 100vh;
		/* 确保页面至少有 100% 的视窗高度，避免高度不足导致无法滚动 */
		
	}

	.page {
		width: 750rpx;
		// height: 100vh;
		padding-bottom: 200rpx;
		.bot_btn{
			position: fixed;
			
			bottom: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 750rpx;
			height: 174rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 8rpx 20rpx 0rpx rgba(0,0,0,0.3);
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			.btn{
				display: flex;
				align-items: center;
				justify-content: center;
				width: 682rpx;
					height: 84rpx;
					background: #4297F3;
					border-radius: 42rpx 42rpx 42rpx 42rpx;
					font-weight: 500;
					font-size: 36rpx;
					color: #FFFFFF;
				}
			}
			
		.order_info {

			position: relative;
			margin: 0 auto;
			margin-top: 44rpx;
			padding: 18rpx 24rpx 40rpx;
			width: 698rpx;
			border-radius: 30rpx;
			background: #FFFFFF;

			.btns {
				position: absolute;
				right: 32rpx;
				bottom: 52rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				width: 174rpx;
				height: 68rpx;
				background: #4297F3;
				border-radius: 42rpx 42rpx 42rpx 42rpx;
				font-weight: 600;
				font-size: 36rpx;
				color: #FFFFFF;
			}

			.info_top {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.tit1 {
					font-weight: 600;
					font-size: 28rpx;
					color: #3D3D3D;
				}

				.txt1 {
					font-weight: 400;
					font-size: 24rpx;
					color: #3D3D3D;

					image {
						margin-left: 6rpx;
						width: 20rpx;
						height: 20rpx;
					}
				}
			}

			.info_cont {
				width: 100%;
				display: flex;
				flex-wrap: nowrap;
				align-items: center;

				image {
					width: 108rpx;
					height: 108rpx;
				}

				.infos {
					margin-top: 30rpx;
					margin-left: 36rpx;

					.time {
						font-weight: 600;
						font-size: 32rpx;
						color: #3D3D3D;
					}

					.data {
						margin-top: 10rpx;
						font-weight: 400;
						font-size: 32rpx;
						color: #F14C4C;
					}

					.tips1 {
						margin-top: 8rpx;
						font-weight: 400;
						font-size: 28rpx;
						color: #3D3D3D;
					}
				}
			}
		}

		.store_car {

			border-radius: 30rpx;
			width: 696rpx;
			padding: 30rpx 28rpx 0 28rpx;
			margin: 0 auto;
			margin-top: 50rpx;
			// height: 342rpx;
			// margin-bottom: 100rpx;
			background: #FFFFFF;

			.store_btn_li {
				display: flex;
				flex-wrap: nowrap;
				margin-top: 26rpx;
				margin-left: -28rpx;
				border-top: 1rpx solid #D8D8D8;
				width: 696rpx;
				height: 102rpx;

				.store_btn:first-child {
					border-right: 1rpx solid #D8D8D8;
				}

				.store_btn {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 50%;
					height: 102rpx;

					image {
						font-weight: 400;
						font-size: 28rpx;
						color: #3D3D3D;
						margin-right: 18rpx;
						width: 40rpx;
						height: 40rpx;
					}

				}
			}

			.line {
				width: 100%;
				height: 1rpx;
				background: #D8D8D8;
			}

			.address {
				margin-top: 48rpx;
				font-weight: 400;
				font-size: 36rpx;
				color: #3D3D3D;
			}

			.time {
				font-weight: 400;
				font-size: 28rpx;
				color: #3D3D3D;
			}

			.tops {
				display: flex;
				align-items: center;
				font-weight: 600;
				font-size: 36rpx;
				color: #3D3D3D;

				.type {
					margin-right: 10rpx;
					font-weight: 400;
					font-size: 24rpx;
					color: #0D75E5;
					padding: 6rpx 12rpx;
					background: #DCEDFF;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
				}

			}
		}

		.btn_box {
			width: 100%;

			display: flex;
			flex-wrap: nowrap;
			align-items: center;
			justify-content: space-around;

			.btn1 {
				width: 130rpx;
				display: flex;
				flex-wrap: wrap;
				justify-content: center;
				font-weight: 400;
				font-size: 32rpx;
				color: #3D3D3D;

				image {
					margin-bottom: 10rpx;
					width: 120rpx;
					height: 120rpx;
				}
			}

			.btn2 {
				width: 268rpx;
				height: 90rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background-color: #ebebeb;
				border-radius: 45rpx;
				padding-right: 30rpx;
				position: relative;
				overflow: hidden;

				.slider {
					width: 90rpx;
					height: 90rpx;
					background-color: #fff;
					border-radius: 45rpx;
					position: absolute;
					left: 0;
				}
			}
		}

		.tips {
			margin-top: 18rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-weight: 400;
			font-size: 28rpx;
			color: #3D3D3D;

			.yuan {
				margin-right: 14rpx;
				border-radius: 50%;
				width: 16rpx;
				height: 16rpx;
				background: #FF8282;
			}
		}

		.car_img {
			margin: 0 auto;
			margin-top: -108rpx;
			width: 440rpx;
			height: 340rpx;
		}

		.power {
			padding-top: 60rpx;
			margin: 0 auto;
			margin-top: 60rpx;
			width: 562rpx;
			height: 348rpx;
			background-image: url('https://lxnapi.ccttiot.com/bike/img/static/unqrw7KFxtvIjYBfBGus');
			background-size: cover;
			/* 背景图片等比缩放以覆盖整个容器 */
			background-position: center;

			/* 背景图片居中显示 */
			.tit {

				width: 100%;
				text-align: center;
				font-weight: 600;
				font-size: 32rpx;
				color: #3D3D3D;
			}

			.num {
				margin-top: 16rpx;
				width: 100%;
				text-align: center;
				font-weight: 600;
				font-size: 88rpx;
				color: #3D3D3D;

				span {
					font-size: 32rpx;
					font-weight: 500;
				}
			}
		}

		.top {
			margin-top: 200rpx;
			width: 750rpx;
			padding: 0 32rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.model {
				font-weight: 600;
				font-size: 48rpx;
				color: #3D3D3D;
			}

			.switch {
				// margin-left: auto;
				width: 272rpx;
				height: 60rpx;
				background: #FFFFFF;
				border-radius: 30rpx 30rpx 30rpx 30rpx;
				font-weight: 400;
				font-size: 32rpx;
				color: #FF8282;
				display: flex;
				flex-wrap: nowrap;
				align-items: center;

				.replay {
					margin-left: 22rpx;
					margin-right: 14rpx;
					width: 32rpx;
					height: 32rpx;
				}

				.bluetooth {
					margin-left: auto;
					width: 60rpx;
					height: 60rpx;
				}
			}
		}

		.fixed {
			z-index: 999;
			position: fixed;
			top: 0;
		}
	}
</style>