aa
This commit is contained in:
		
							parent
							
								
									8846de03b9
								
							
						
					
					
						commit
						d7763b5923
					
				|  | @ -46,7 +46,7 @@ | |||
| 			<view class="tongyi"> | ||||
| 				<u-checkbox-group> | ||||
| 					<u-checkbox v-model="checked" @change="checkboxChange" active-color="#8883F0 ">我已同意 | ||||
| 						 </u-checkbox><text>《用户服务协议》</text> | ||||
| 					</u-checkbox><text>《用户服务协议》</text> | ||||
| 				</u-checkbox-group> | ||||
| 				<view class="zf" @click="btnzhifu"> | ||||
| 					立即支付 | ||||
|  | @ -59,13 +59,13 @@ | |||
| </template> | ||||
| 
 | ||||
| <script> | ||||
| 	var xBlufi = require("@/page_components/blufi/xBlufi.js"); | ||||
| 	export default { | ||||
| 		data() { | ||||
| 			return { | ||||
| 				indexactive: 0, | ||||
| 				checked: false, | ||||
| 				deviceobj: {}, | ||||
| 				deviceid: '', | ||||
| 				timer: null, | ||||
| 				expireTimeStr: '', | ||||
| 				zfobj: {}, | ||||
|  | @ -73,7 +73,13 @@ | |||
| 				id: '', | ||||
| 				czflag: false, | ||||
| 				sytime: 0, | ||||
| 				datetime: 0 | ||||
| 				datetime: 0, | ||||
| 				mac: '', | ||||
| 				deviceId: '', | ||||
| 				name: '', | ||||
| 				ver_data: '', | ||||
| 				devicesList: [], | ||||
| 				onlineStatus: '' | ||||
| 			} | ||||
| 		}, | ||||
| 		onLoad(option) { | ||||
|  | @ -89,12 +95,31 @@ | |||
| 				console.log(this.id) | ||||
| 				this.startTimer() | ||||
| 				this.gettaoc() | ||||
| 				this.getmac() | ||||
| 			} else { | ||||
| 				this.id = option.id | ||||
| 				this.startTimer() | ||||
| 				this.gettaoc() | ||||
| 				this.getmac() | ||||
| 			} | ||||
| 
 | ||||
| 			// 一开始搜索设备 | ||||
| 			xBlufi.initXBlufi(1) | ||||
| 			xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent); | ||||
| 			xBlufi.notifyStartDiscoverBle({ | ||||
| 				'isStart': true | ||||
| 			}) | ||||
| 			setTimeout(() => { | ||||
| 				xBlufi.notifyStartDiscoverBle({ | ||||
| 					'isStart': false | ||||
| 				}) | ||||
| 				if (this.devicesList.length > 0) { | ||||
| 					xBlufi.notifyConnectBle({ | ||||
| 						isStart: true, | ||||
| 						deviceId: this.deviceId, | ||||
| 						name: this.name | ||||
| 					}) | ||||
| 				} | ||||
| 			}, 2000) | ||||
| 		}, | ||||
| 		computed: { | ||||
| 
 | ||||
|  | @ -104,11 +129,41 @@ | |||
| 				this.gethuidaio() | ||||
| 			} | ||||
| 		}, | ||||
| 		onUnload: function() { | ||||
| 			if (this.timer) { | ||||
| 				clearInterval(this.timer); | ||||
| 				this.timer = null; | ||||
| 			} | ||||
| 			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 | ||||
| 			}); | ||||
| 		}, | ||||
| 		methods: { | ||||
| 			startTimer() { | ||||
| 				this.timer = setInterval(() => { | ||||
| 					this.gettaoc(); // 每隔30秒请求一次数据   | ||||
| 				}, 30000); // 30秒   | ||||
| 					this.gettaoc(); | ||||
| 				}, 30000); | ||||
| 			}, | ||||
| 			getmac() { | ||||
| 				this.$u.get(`/app/device/${this.id}/bySn`).then((res) => { | ||||
| 					if (res.code == 200) { | ||||
| 						this.mac = 'CTKG-' + res.data.mac | ||||
| 						this.onlineStatus = res.data.onlineStatus | ||||
| 					} | ||||
| 				}) | ||||
| 			}, | ||||
| 			gettaoc() { | ||||
| 				this.$u.get(`/app/device/${this.id}/withSuitList`).then((res) => { | ||||
|  | @ -125,7 +180,7 @@ | |||
| 						let differenceInMinutes = Math.floor(differenceInMs / (1000 * 60)); | ||||
| 						this.expireTimeStr = parseInt(differenceInMinutes) <= 0 ? '0' : differenceInMinutes | ||||
| 					} | ||||
| 				}); | ||||
| 				}) | ||||
| 			}, | ||||
| 			btnzhifu() { | ||||
| 				if (this.checked == false) { | ||||
|  | @ -133,18 +188,19 @@ | |||
| 						title: '请勾选用户服务协议 !', | ||||
| 						icon: 'none', | ||||
| 						duration: 1000 | ||||
| 					}); | ||||
| 				} else { | ||||
| 					}) | ||||
| 				} else if (this.onlineStatus == 1) { | ||||
| 					let that = this | ||||
| 					let data = { | ||||
| 						deviceNo: this.id, | ||||
| 						suitId: this.zfobj.suitId, | ||||
| 						money: this.zfobj.price, | ||||
| 						suitTime: this.zfobj.value | ||||
| 						deviceNo: that.id, | ||||
| 						suitId: that.zfobj.suitId, | ||||
| 						money: that.zfobj.price, | ||||
| 						suitTime: that.zfobj.value | ||||
| 					} | ||||
| 					this.$u.post('/app/bill/recharge', data).then((res) => { | ||||
| 					that.$u.post('/app/bill/recharge', data).then((res) => { | ||||
| 						if (res.code == 200) { | ||||
| 							this.orderno = res.data | ||||
| 							this.$u.get(`/app/pay/wx/${this.orderno}`).then((res) => { | ||||
| 							that.orderno = res.data | ||||
| 							that.$u.get(`/app/pay/wx/${that.orderno}`).then((res) => { | ||||
| 								if (res.code == 200) { | ||||
| 									uni.requestPayment({ | ||||
| 										provider: 'wxpay', | ||||
|  | @ -155,15 +211,17 @@ | |||
| 										paySign: res.data.paySign, | ||||
| 										success: (res) => { | ||||
| 											console.log(res, '支付成功'); | ||||
| 											if (this.timer) { | ||||
| 												clearInterval(this.timer); | ||||
| 												this.timer = null; | ||||
| 											if (that.timer) { | ||||
| 												clearInterval(this | ||||
| 													.timer); | ||||
| 												that.timer = null; | ||||
| 											} | ||||
| 											// 支付成功逻辑 | ||||
| 											uni.reLaunch({ | ||||
| 												url: '/pages/shouye/index' | ||||
| 											}) | ||||
| 											uni.setStorageSync('time', this.expireTimeStr) | ||||
| 											uni.setStorageSync('time', | ||||
| 												that.expireTimeStr) | ||||
| 										}, | ||||
| 										fail(err) { | ||||
| 											// 支付失败逻辑 | ||||
|  | @ -182,11 +240,92 @@ | |||
| 							}) | ||||
| 						} | ||||
| 					}) | ||||
| 				} else { | ||||
| 					if (this.ver_data == '') { | ||||
| 						let that = this | ||||
| 						uni.showModal({ | ||||
| 							title: '提示', | ||||
| 							content: '支付的时候请靠近设备并打开蓝牙', | ||||
| 							success: function(res) { | ||||
| 								if (res.confirm) { | ||||
| 									xBlufi.initXBlufi(1); | ||||
| 									xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent); | ||||
| 									xBlufi.notifyStartDiscoverBle({ | ||||
| 										'isStart': true | ||||
| 									}) | ||||
| 									setTimeout(() => { | ||||
| 										xBlufi.notifyStartDiscoverBle({ | ||||
| 											'isStart': false | ||||
| 										}) | ||||
| 										if (this.devicesList.length > 0) { | ||||
| 											xBlufi.notifyConnectBle({ | ||||
| 												isStart: true, | ||||
| 												deviceId: this.deviceId, | ||||
| 												name: this.name | ||||
| 											}) | ||||
| 										} | ||||
| 									}, 2000) | ||||
| 								} else if (res.cancel) { | ||||
| 									console.log('用户点击了取消'); | ||||
| 								} | ||||
| 							} | ||||
| 						}) | ||||
| 					}else{ | ||||
| 						let that = this | ||||
| 						let data = { | ||||
| 							deviceNo: that.id, | ||||
| 							suitId: that.zfobj.suitId, | ||||
| 							money: that.zfobj.price, | ||||
| 							suitTime: that.zfobj.value | ||||
| 						} | ||||
| 						that.$u.post('/app/bill/recharge', data).then((res) => { | ||||
| 							if (res.code == 200) { | ||||
| 								that.orderno = res.data | ||||
| 								that.$u.get(`/app/pay/wx/${that.orderno}`).then((res) => { | ||||
| 									if (res.code == 200) { | ||||
| 										uni.requestPayment({ | ||||
| 											provider: 'wxpay', | ||||
| 											timeStamp: res.data.timeStamp, | ||||
| 											nonceStr: res.data.nonceStr, | ||||
| 											package: res.data.packageVal, | ||||
| 											signType: res.data.signType, | ||||
| 											paySign: res.data.paySign, | ||||
| 											success: (res) => { | ||||
| 												console.log(res, '支付成功'); | ||||
| 												if (that.timer) { | ||||
| 													clearInterval(this | ||||
| 														.timer); | ||||
| 													that.timer = null; | ||||
| 												} | ||||
| 												// 支付成功逻辑 | ||||
| 												uni.reLaunch({ | ||||
| 													url: '/pages/shouye/index' | ||||
| 												}) | ||||
| 												uni.setStorageSync('time', | ||||
| 													that.expireTimeStr) | ||||
| 											}, | ||||
| 											fail(err) { | ||||
| 												// 支付失败逻辑 | ||||
| 												uni.showToast({ | ||||
| 													title: '支付失败', | ||||
| 													icon: 'none', | ||||
| 													duration: 2000 | ||||
| 												}); | ||||
| 											} | ||||
| 										}); | ||||
| 									} | ||||
| 								}) | ||||
| 							} else if (res.code == 401) { | ||||
| 								uni.reLaunch({ | ||||
| 									url: '/pages/login/login' | ||||
| 								}) | ||||
| 							} | ||||
| 						}) | ||||
| 					} | ||||
| 
 | ||||
| 				} | ||||
| 			}, | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 			btnactive(item) { | ||||
| 				this.sytime = item.value | ||||
| 				this.zfobj = item | ||||
|  | @ -195,13 +334,89 @@ | |||
| 			checkboxChange(e) { | ||||
| 				this.checked = e.value | ||||
| 			}, | ||||
| 			onUnload() { | ||||
| 				// 页面卸载时   | ||||
| 				if (this.timer) { | ||||
| 					clearInterval(this.timer); | ||||
| 					this.timer = null; | ||||
| 
 | ||||
| 
 | ||||
| 			funListenDeviceMsgEvent: function(options) { | ||||
| 				switch (options.type) { | ||||
| 					case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS: | ||||
| 						if (options.result) { | ||||
| 							let devicesarr = options.data | ||||
| 							devicesarr.forEach(device => { | ||||
| 								const mac = device.name.substring(4); | ||||
| 								if (device.name == this.mac) { | ||||
| 									this.deviceId = device.deviceId | ||||
| 									this.name = device.name | ||||
| 									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) { | ||||
| 							{ | ||||
| 								xBlufi.notifyInitBleEsp32({ | ||||
| 									deviceId: this.deviceId | ||||
| 								}); | ||||
| 								xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvents); | ||||
| 								this.deviceIds = options.data.deviceId | ||||
| 								this.name = this.name | ||||
| 							} | ||||
| 						} | ||||
| 
 | ||||
| 						break; | ||||
| 					case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA: | ||||
| 
 | ||||
| 						this.ver_data = this.parseCustomData(options.data) | ||||
| 						uni.hideLoading() | ||||
| 						console.log("1收到设备发来的自定义数据结果:", this.ver_data); | ||||
| 						break; | ||||
| 					case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP: | ||||
| 						if (options.result) { | ||||
| 							let uniqueDevicesList = Array.from(new Set(this.devicesList)); | ||||
| 							let filteredDevices = uniqueDevicesList.filter(device => device.name.substring(0, 4) === | ||||
| 								"CTKG"); | ||||
| 							// 将过滤后的数组重新赋值给 this.devicesList | ||||
| 							this.devicesList = filteredDevices; | ||||
| 							filteredDevices.forEach(device => { | ||||
| 								// 从设备名称中提取 MAC 地址(假设 MAC 地址是设备名称的后6个字符) | ||||
| 								let macFromName = device.name.substring(device.name.length - 12); | ||||
| 								console.log(macFromName); | ||||
| 								// 与 this.mac 进行比较 | ||||
| 								if (macFromName == this.mac) { | ||||
| 									this.ishave = true; | ||||
| 								} | ||||
| 							}) | ||||
| 						} | ||||
| 						this.searching = false | ||||
| 						break; | ||||
| 				} | ||||
| 			}, | ||||
| 
 | ||||
| 			parseCustomData(data) { | ||||
| 				// 将字符串按照 "@" 分割成数组 | ||||
| 				const dataArray = data.split('@'); | ||||
| 				// 根据约定,解析各个字段的值 | ||||
| 				const voltage = parseFloat(dataArray[0].substring(1)); // 去除前缀 "V",并将字符串转换为浮点数 | ||||
| 				const switchState = dataArray[1].substring(1); // 去除前缀 "S" | ||||
| 				const current = parseFloat(dataArray[2].substring(1)); // 去除前缀 "A",并将字符串转换为浮点数 | ||||
| 				const power = parseFloat(dataArray[4].substring(1)); // 去除前缀 "P",并将字符串转换为浮点数 | ||||
| 				const remainingPower = parseFloat(dataArray[5].substring(1)); // 去除前缀 "M",并将字符串转换为浮点数 | ||||
| 				const setMode = dataArray[6].substring(1); // 去除前缀 "T" | ||||
| 				// 返回解析后的数据对象 | ||||
| 				return { | ||||
| 					voltage, | ||||
| 					switchState, | ||||
| 					current, | ||||
| 					power, | ||||
| 					remainingPower, | ||||
| 					setMode | ||||
| 				}; | ||||
| 			}, | ||||
| 
 | ||||
| 		} | ||||
| 	} | ||||
| </script> | ||||
|  | @ -210,9 +425,11 @@ | |||
| 	/deep/ .u-title { | ||||
| 		padding-bottom: 22rpx; | ||||
| 	} | ||||
|     /deep/ .u-checkbox__label{ | ||||
| 
 | ||||
| 	/deep/ .u-checkbox__label { | ||||
| 		margin-right: 0 !important; | ||||
| 	} | ||||
| 
 | ||||
| 	// /deep/ .u-icon__icon{ | ||||
| 	// 	padding-bottom: 41rpx; | ||||
| 	// } | ||||
|  |  | |||
|  | @ -38,9 +38,9 @@ | |||
| 			</view> | ||||
| 		</view> | ||||
| 
 | ||||
| 		<view class="anniu" @click="Search"> | ||||
| 		<!-- <view class="anniu" @click="Search"> | ||||
| 			<button>重新扫描</button> | ||||
| 		</view> | ||||
| 		</view> --> | ||||
| 		<!-- 加载状态 --> | ||||
| 		<view class="containers" v-show="statusflag"> | ||||
| 			<uni-section> | ||||
|  | @ -122,7 +122,6 @@ | |||
| 			xBlufi.notifyStartDiscoverBle({ | ||||
| 				'isStart': true | ||||
| 			}); | ||||
| 			// this.dl = ((this.orderinfo.deviceAmount / this.orderinfo.unitPrice)*1000).toFixed(2); | ||||
| 
 | ||||
| 			// 两秒后停止蓝牙搜索 | ||||
| 			setTimeout(() => { | ||||
|  | @ -135,14 +134,14 @@ | |||
| 						title: '暂无发现对应设备,请靠近设备', | ||||
| 						icon: 'none', | ||||
| 						duration:2000 | ||||
| 					}); | ||||
| 					}) | ||||
| 					// uni.hideLoading() | ||||
| 				} else { | ||||
| 					xBlufi.notifyConnectBle({ | ||||
| 						isStart: true, | ||||
| 						deviceId: this.deviceId, | ||||
| 						name: this.name | ||||
| 					}); | ||||
| 					}) | ||||
|                     // uni.hideLoading() | ||||
| 				} | ||||
| 				this.status = true | ||||
|  | @ -275,8 +274,6 @@ | |||
| 						} | ||||
| 					} | ||||
| 				}) | ||||
| 
 | ||||
| 
 | ||||
| 			}, | ||||
| 			bind() { | ||||
| 				if (this.ishave && this.isband) { | ||||
|  | @ -449,14 +446,13 @@ | |||
| 			}, | ||||
| 			// 点击重新搜索 | ||||
| 			Search() { | ||||
| 				this.bluthlist = [] | ||||
| 				this.devicesList = [] | ||||
| 				if (this.status) { | ||||
| 					xBlufi.notifyStartDiscoverBle({ | ||||
| 						'isStart': true | ||||
| 					}); | ||||
| 					// 重新搜索清空蓝牙数组 | ||||
| 					this.bluthlist = [] | ||||
| 					this.devicesList = [] | ||||
| 					// 重新搜索 | ||||
| 					// this.startBluetoothDevicesDiscovery() | ||||
| 					this.statusflag = true | ||||
| 					this.texts = '正在扫描蓝牙设备...' | ||||
|  |  | |||
|  | @ -79,8 +79,9 @@ | |||
| 				this.curtitidx = e.detail.current | ||||
| 			}, | ||||
| 			getlist() { | ||||
| 				this.$u.get(`/app/device/list?storeId=${this.storeId}&pageNum=${this.pagenum}&pageSize=${this.pagesize}`) | ||||
| 					.then((res) => { | ||||
| 				// /app/device/listByStore/{storeId}?pageNum=1&pageSize=10 | ||||
| 				this.$u.get(`/app/device/listByStore/${this.storeId}?pageNum=${this.pagenum}&pageSize=${this.pagesize}`) | ||||
| 					.then((res) => {  | ||||
| 						if (res.code == 200) { | ||||
| 							this.total = res.total | ||||
| 							if (this.total > 0) { | ||||
|  |  | |||
|  | @ -462,7 +462,7 @@ | |||
| 						} | ||||
| 
 | ||||
| 						.bu { | ||||
| 							margin-left: 32rpx; | ||||
| 							margin-left: 22rpx; | ||||
| 							background: #D9D8FF; | ||||
| 							color: #4D48B5; | ||||
| 						} | ||||
|  |  | |||
|  | @ -145,13 +145,14 @@ | |||
| 									content: `连接成功`, | ||||
| 									showCancel: false, | ||||
| 									success: function(res) { | ||||
| 										uni.switchTab({ | ||||
| 											url: '/pages/index/index' | ||||
| 										}) | ||||
| 										// let ids = that.$store.state.user.deviceId | ||||
| 										wx.closeBLEConnection({ | ||||
| 											deviceId: this.objlist.deviceId, | ||||
| 										}) | ||||
| 										uni.switchTab({ | ||||
| 											url: '/pages/index/index' | ||||
| 										}) | ||||
| 										 | ||||
| 										// getwifi(ids).then(res => { | ||||
| 										// 	console.log(res); | ||||
| 										// 	uni.switchTab({ | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user