Browse Source

【进度】等待测试

程志平 4 years ago
parent
commit
eeff084165
3 changed files with 127 additions and 101 deletions
  1. 23 29
      pages/jiaofei/jiaofei.vue
  2. 103 69
      pages/reshui/reshui.vue
  3. 1 3
      static/api.js

+ 23 - 29
pages/jiaofei/jiaofei.vue

@@ -82,12 +82,12 @@
 		},
 		onLoad(options) {
 			// console.log(options);
-			if (typeof(options.from) != 'undefined' && options.from == 2) {
-				uni.navigateTo({
-					url: '../index/index?from=' + options.from
-				})
-				return
-			}
+			// if (typeof(options.from) != 'undefined' && options.from == 2) {
+			// 	uni.navigateTo({
+			// 		url: '../index/index?from=' + options.from
+			// 	})
+			// 	return
+			// }
 			// 获取基本信息
 			this.get_base_info(options, 'onLoad')
 		},
@@ -109,7 +109,7 @@
 						this.dorm_number = this.$store.state.building.dorm_number;
 
 						this.add_class = 1
-						if (this.roomSelect != '' && typeof(this.roomSelect) != 'undefined') {
+						if (this.roomSelect && typeof(this.roomSelect) != 'undefined') {
 							this.getDianLiang()
 						}
 					}
@@ -187,14 +187,18 @@
 						}
 					})
 
-					// console.log('获得openid', res);
+					console.log('获得openid', res);
 					if (res.data.mess == '返回成功') {
 						// 栋宿舍号
 						this.dorm_number = res.data.info[0].build + res.data.info[0].dom
 						// 校区
 						this.compus = res.data.info[0].campus
-						// 填充校区宿舍号 
-						this.roomSelect = this.compus + this.dorm_number.split('栋')[1]
+						// 填充校区宿舍号
+						if (typeof(this.dorm_number.split('栋')[1]) == 'undefined') {
+							this.roomSelect = this.compus + ''
+						} else {
+							this.roomSelect = this.compus + this.dorm_number.split('栋')[1]
+						}
 						// 存储选择
 						this.$store.state.building.roomSelect = this.roomSelect
 						// 样式
@@ -215,27 +219,16 @@
 						}
 					}
 
-					if (this.roomSelect == '' || typeof(this.roomSelect) == 'undefined') {
+					if (!this.roomSelect || this.roomSelect == '' || typeof(this.roomSelect) == 'undefined') {
 						const userinfo = uni.getStorageSync('userinfo_storage_key')
-						if (typeof(userinfo) != 'undefined' && typeof(userinfo.campus) != 'undefined' && typeof(
-								userinfo.dorm_number) != 'undefined') {
+						if (userinfo && typeof(userinfo) != 'undefined' && typeof(userinfo.campus) != 'undefined' &&
+							typeof(userinfo.dorm_number) != 'undefined' && userinfo.campus != '' && userinfo
+							.dorm_number != '') {
 							this.roomSelect = userinfo.campus + userinfo.dorm_number
 						} else {
-							uni.navigateTo({
-								url: '../index/index?from=' + options.from
-							})
-
-							uni.showToast({
-								icon: 'none',
-								title: '未获得宿舍号,请进行授权',
-								duration: 3000
-							});
+							this.roomSelect = '请选择宿舍号'
 						}
 					}
-					
-					if (this.roomSelect == '' || typeof(this.roomSelect) == 'undefined') {
-						this.roomSelect = '请选择宿舍号'
-					}
 				} else {
 					uni.showToast({
 						title: 'code为空!',
@@ -270,8 +263,9 @@
 					}
 				} else {
 					uni.showToast({
-						title: '未获得宿舍号',
-						icon: 'success'
+						title: '请先选择宿舍号,\n再查询电量 或 充值',
+						icon: 'none',
+						duration: 3000
 					});
 				}
 			},
@@ -301,7 +295,7 @@
 			 */
 			confirm_room(op) {
 				// 检查房间号
-				if (this.roomSelect == '') {
+				if (this.roomSelect == '' || this.roomSelect == '请选择宿舍号') {
 					uni.showToast({
 						title: '请选择宿舍号',
 						icon: 'success'

+ 103 - 69
pages/reshui/reshui.vue

@@ -81,7 +81,7 @@
 				}),
 				startDate: this.$getDate('start_date'),
 				endDate: this.$getDate('end_date'),
-				flag: false,
+				flag: false, //  控制说明弹窗
 				isUserClose: false, // 是否是用户自己关闭
 				isChecked: false,
 				isConnected: false, // 是否连接上
@@ -113,6 +113,7 @@
 				amount: 0.0.toFixed(2), // 余额
 				dorm_number: '', // 宿舍号
 				stu_number: '', // 学号
+				user_name: '',
 				// compus: '', // 校区
 				ceshi: 'code',
 				changeDate: false // 是否是手动选择日期
@@ -124,19 +125,36 @@
 				// 获取基本信息
 				this.get_base_info(options, 'onLoad')
 			} else if (typeof(options.from) != 'undefined' && options.from != 0) {
-				uni.navigateTo({
-					url: '../index/index?from=' + options.from
+			// 	uni.showToast({
+			// 		icon: 'none',
+			// 		title: '跳转首页'
+			// 	})
+			// 	uni.navigateTo({
+			// 		url: '../index/index?from=' + options.from
+			// 	})
+			// } else {
+				uni.showToast({
+					icon: 'none',
+					title: '初始化蓝牙'
 				})
-			} else {
 				// wxminicode=KB580002652
 				this.start_code = decodeURIComponent(options.q).split('=')[1]
 				// 初始化蓝牙
 				this.openBluetoothAdapter()
 			}
+			
+			const value = uni.getStorageSync('instruction_noshow');
+			if (!(value == true)) {
+				this.flag = true
+			}
 		},
 		onShow() {
-			// 获取基本信息
-			this.get_base_info('options', 'onShow')
+			if (this.stu_number && typeof(this.stu_number) != 'undefined') {
+				return
+			} else {
+				// 获取基本信息
+				this.get_base_info('options', 'onShow')
+			}
 		},
 		methods: {
 			/**
@@ -163,13 +181,6 @@
 								duration: 3000
 							});
 						}
-					} else {
-						const value = uni.getStorageSync('instruction_noshow');
-						if (!value) {
-							this.flag = true
-						}
-						// 获取code
-						this.getCode(options, param)
 					}
 				} catch (e) {
 					console.log(e);
@@ -187,10 +198,11 @@
 						})
 
 						// this.amount = this.$store.state.reshui_amount + this.amount
-						// 重新调用一次,刷新金额
-						this.getCode(options, param)
 					}
 				}
+
+				// 获取code
+				this.getCode(options, param)
 			},
 			/**
 			 * 获得code
@@ -232,8 +244,9 @@
 					// 判断存储的stu_number与返回的stu_number是否一致
 					let cardNumber = res.data.info[0].card_number
 					if (typeof(cardNumber) != 'undefined' && cardNumber != '' && JSON.stringify(cardNumber) != '{}') {
-						// 学号
+						// 学号 和 姓名
 						this.stu_number = res.data.info[0].stu_number
+						this.user_name = res.data.info[0].user_name
 						// 剩余金额
 						this.amount = res.data.info[0].balance.toFixed(2)
 						if (this.amount > 0)
@@ -317,7 +330,7 @@
 						}
 					});
 
-					// console.log(res);
+					console.log(res);
 					if (res.data.mess == '返回成功') {
 						this.xiaofei_items = []
 						// 消费记录
@@ -422,7 +435,7 @@
 			},
 
 			/**
-			 * 跳转到充值页面并传参数
+			 * 跳转到充值页面
 			 */
 			chongzhi_yemian() {
 				//在起始页面跳转到recharge.vue页面并传递参数
@@ -505,7 +518,7 @@
 						// rawData: "aHR0cDovL3Rvb2xzLjlrYnMuY29tLz93eG1pbmljb2RlPUtCNTgwMDAyNjUy"
 						// result: "http://tools.9kbs.com/?wxminicode=KB580002652"
 						// scanType: "QR_CODE"
-						this.device_code = res.result.split('?')[1].split('=')[1]
+						this.device_code = res.result.split('=')[1]
 
 						if (this.device_code === '') {
 							uni.showToast({
@@ -632,6 +645,10 @@
 						}
 
 						if (device.name == this.device_code) {
+							this.process_control(0);
+
+							this.stopBluetoothDevicesDiscovery()
+
 							//data里面建立一个deviceId、device_code,存储起来
 							// this.device_code = device.name;
 							this.deviceId = device.deviceId
@@ -640,9 +657,7 @@
 								this.devices.push(res.devices[0].deviceId)
 							}
 
-							this.process_control(0);
-
-							this.stopBluetoothDevicesDiscovery()
+							return
 						}
 					})
 				});
@@ -656,7 +671,7 @@
 				//连接蓝牙
 				uni.createBLEConnection({
 					deviceId: this.deviceId,
-					timeout: 3000,
+					timeout: 5000,
 					success: (res) => {
 						// console.log(res)
 						this.connect_BLE()
@@ -665,7 +680,7 @@
 						// console.log(err)
 						this.isScan = false
 						if (err.errMsg.indexOf('already connect') != -1) {
-							this.connect_BLE()
+							// this.connect_BLE()
 						} else {
 							uni.showToast({
 								title: '建立连接失败',
@@ -776,7 +791,7 @@
 						setTimeout(() => {
 							// 发送 AAABAC,采集数据(会返回 35字节 的数据)
 							this.send('')
-						}, 300)
+						}, 800)
 
 						// // 请求设备信息
 						// this.request_device_info()
@@ -791,6 +806,9 @@
 							content: err.errMsg,
 							showCancel: false
 						})
+
+						// 初始化
+						this.setInit()
 					}
 				})
 			},
@@ -801,7 +819,7 @@
 			 */
 			onBLECharacteristicValueChange() {
 				uni.onBLECharacteristicValueChange((characteristic) => {
-					let condition = ab2hex(characteristic.value)
+					let condition = this.ab2hex(characteristic.value)
 
 					// console.log(condition)
 					if (condition.length > 2) {
@@ -964,12 +982,12 @@
 					// this.createBLEConnection()
 					// 发送 17字节 启动代码(会返回 35字节 的数据)
 					// b58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0103bc
-					newArr = str2StrArray(this.start_code)
+					newArr = this.str2StrArray(this.start_code)
 				} else if (val == 'stop') { // 结束当前使用,设备成功返回:AD+35字节 消费结算代码
 					this.isUserClose = true
 					// 发送 AAABAD+17字节 启动代码(会返回 ad+35字节 的数据)
 					// adb58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0104bc
-					newArr = ['AA', 'AB', 'AD'].concat(str2StrArray(this.start_code))
+					newArr = ['AA', 'AB', 'AD'].concat(this.str2StrArray(this.start_code))
 				} else {
 					// 发送 AAABAC 采集数据(会返回 35字节 的数据)
 					// b58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0103bc
@@ -979,7 +997,7 @@
 				buffer = new ArrayBuffer(newArr.length)
 				dataView = new DataView(buffer)
 				newArr.forEach((item, i) => {
-					dataView.setUint8(i, sixteen_to_ten(item))
+					dataView.setUint8(i, this.sixteen_to_ten(item))
 				})
 
 				// 写特征值数据到设备
@@ -1060,13 +1078,20 @@
 					})
 
 					// console.log(res)
-					if (res.data.start_code != 'undefined' && res.data.start_code != '') {
-						this.start_code = res.data.start_code
-						this.send('start')
+					let sc = res.data.start_code
+					if (typeof(sc) != 'undefined' && sc != '') {
+						this.start_code = sc
+						setTimeout(() => {
+							this.send('start')
+						}, 100)
+						
+						// 刷新选定的月份消费记录
+						this.request_consumption_records()
 					} else {
+						this.isChecked = false
 						uni.showToast({
 							title: res.data.mess,
-							duration: 3000
+							duration: 3000,
 						})
 					}
 				} else {
@@ -1087,6 +1112,8 @@
 						host: this.ceshi,
 						url: '/HotWaters/wpconsume.action',
 						data: {
+							stu_number: this.stu_number,
+							user_name: this.user_name,
 							collect_code: this.byte35.substring(2)
 						}
 					})
@@ -1118,46 +1145,53 @@
 					// 初始化
 					this.setInit()
 				}
-			}
-		}
-	}
+			},
+			/**
+			 * 返回字符处理
+			 */
+			str2StrArray(start_code) {
+				if (typeof(start_code) == 'undefined' || start_code == '') {
+					uni.showToast({
+						icon: 'none',
+						title: '设备码获取失败'
+					})
 
-	/**
-	 * 返回字符处理
-	 */
-	function str2StrArray(start_code) {
-		if (start_code.length != 34) {
-			// console.log('启动码长度错误')
-			throw new Error("启动码长度错误");
-			return
-		}
-		var resultArray = new Array()
-		for (var i = 0; i < start_code.length; i += 2) {
-			resultArray.push(start_code.substr(i, 2));
-		}
+					this.setInit()
 
-		return resultArray;
-	}
+					return
+				}
+				if (start_code.length != 34) {
+					// console.log('启动码长度错误')
+					throw new Error("启动码长度错误");
+					return
+				}
+				var resultArray = new Array()
+				for (var i = 0; i < start_code.length; i += 2) {
+					resultArray.push(start_code.substr(i, 2));
+				}
 
-	/**
-	 * ArrayBuffer转16进度字符串
-	 */
-	function ab2hex(buffer) {
-		const hexArr = Array.prototype.map.call(
-			new Uint8Array(buffer),
-			function(bit) {
-				// console.log('====================' + bit + '==========================')
-				return ('00' + bit.toString(16)).slice(-2)
+				return resultArray;
+			},
+			/**
+			 * ArrayBuffer转16进度字符串
+			 */
+			ab2hex(buffer) {
+				const hexArr = Array.prototype.map.call(
+					new Uint8Array(buffer),
+					function(bit) {
+						// console.log('====================' + bit + '==========================')
+						return ('00' + bit.toString(16)).slice(-2)
+					}
+				)
+				return hexArr.join('');
+			},
+			/**
+			 * 16进制转10进制
+			 */
+			sixteen_to_ten(str) {
+				return parseInt(str, 16);
 			}
-		)
-		return hexArr.join('');
-	}
-
-	/**
-	 * 16进制转10进制
-	 */
-	function sixteen_to_ten(str) {
-		return parseInt(str, 16);
+		}
 	}
 </script>
 

+ 1 - 3
static/api.js

@@ -1,8 +1,8 @@
 const WEXIN_BASE_URL = 'https://api.mch.weixin.qq.com' // wexin
 const WECARD_BASE_URL = 'https://open.wecard.qq.com' // wecard
 const CODE_BASE_URL = 'https://jtishfw.ncjti.edu.cn/jxch-smartmp' // code
+// const CODE_BASE_URL = 'http://cfnifb.natappfree.cc' // code
 const IP_BASE_URL = 'https://pv.sohu.com/cityjson' // ip
-// const LOCAL_BASE_URL = 'http://baibai.natapp1.cc' // local
 
 const myRequest = (options) => {
 	// 域名 或 url 为空,则不执行任何操作
@@ -21,8 +21,6 @@ const myRequest = (options) => {
 			BASE_URL = CODE_BASE_URL;
 		} else if (options.host == 'ip') {
 			BASE_URL = IP_BASE_URL;
-		// } else if (options.host == 'local') {
-			// BASE_URL = LOCAL_BASE_URL;
 		} else {
 			uni.showToast({
 				title: '域名无效',