Sfoglia il codice sorgente

【增加】1.余额限制,可动态变化;2.空中连接功能,不用扫描热水表中的二维码即可连接启动热水表。

程志平 4 anni fa
parent
commit
4db2477432
3 ha cambiato i file con 209 aggiunte e 66 eliminazioni
  1. 2 1
      pages/index/index.vue
  2. 206 65
      pages/reshui/reshui.vue
  3. 1 0
      store/index.js

+ 2 - 1
pages/index/index.vue

@@ -82,7 +82,8 @@
 
 
 				// console.log(res);
 				// console.log(res);
 				if (res.data.mess == '返回成功') {
 				if (res.data.mess == '返回成功') {
-					// 0 测试环境, 1 部署环境
+					// value为0 测试环境, 为1 部署环境;amount限制启动金额
+					this.$store.state.amount = res.data.data[0].amount
 					if (res.data.data[0].value == 0) {
 					if (res.data.data[0].value == 0) {
 						this.$store.state.test = true
 						this.$store.state.test = true
 					} else {
 					} else {

+ 206 - 65
pages/reshui/reshui.vue

@@ -32,15 +32,22 @@
 					</view>
 					</view>
 				</view>
 				</view>
 				<view class="start_bot">
 				<view class="start_bot">
-					<text class="start_bot_txt" v-if="false">时长:00:00:00</text>
+					<button class="kongzhonglianjie" @click="open">空中连接</button>
 					<text class="start_bot_txt">当前结算消费:¥{{use_amount}}</text>
 					<text class="start_bot_txt">当前结算消费:¥{{use_amount}}</text>
 				</view>
 				</view>
 			</view>
 			</view>
+			<view v-if="showRoom" style="width: 100%; height: 100%; ">
+				<view style="display: flex; flex-wrap: wrap;">
+					<button v-for="item in rooms" :key="item.id" @tap="clickRoom(item.id)"
+						class="btn_room">{{item.room}}</button>
+				</view>
+			</view>
 			<view class="start_up_process">
 			<view class="start_up_process">
 				<uni-steps :options="list1" :active-color="colorPrimary" :active="active" />
 				<uni-steps :options="list1" :active-color="colorPrimary" :active="active" />
 			</view>
 			</view>
 			<view class="ad">
 			<view class="ad">
-				<image src="../../static/image/ad_reshui.png" mode="aspectFit" class="ad_img" @tap="ad_redirect"></image>
+				<image src="../../static/image/ad_reshui.png" mode="aspectFit" class="ad_img" @tap="ad_redirect">
+				</image>
 			</view>
 			</view>
 			<view class="title">
 			<view class="title">
 				消费记录
 				消费记录
@@ -86,6 +93,7 @@
 				startDate: this.$getDate('start_date'),
 				startDate: this.$getDate('start_date'),
 				endDate: this.$getDate('end_date'),
 				endDate: this.$getDate('end_date'),
 				flag: false, //  控制说明弹窗
 				flag: false, //  控制说明弹窗
+				showRoom: false,
 				isUserClose: false, // 是否是用户自己关闭
 				isUserClose: false, // 是否是用户自己关闭
 				isChecked: false,
 				isChecked: false,
 				isConnected: false, // 是否连接上
 				isConnected: false, // 是否连接上
@@ -101,6 +109,7 @@
 					title: '启动'
 					title: '启动'
 				}],
 				}],
 				devices: [], // 保存设备
 				devices: [], // 保存设备
+				rooms: [], // 保存水表id及对应的宿舍号
 				device_code: '', // 设备编号
 				device_code: '', // 设备编号
 				deviceId: '',
 				deviceId: '',
 				serviceId: '',
 				serviceId: '',
@@ -120,7 +129,8 @@
 				user_name: '',
 				user_name: '',
 				// compus: '', // 校区
 				// compus: '', // 校区
 				ceshi: 'code',
 				ceshi: 'code',
-				changeDate: false // 是否是手动选择日期
+				changeDate: false, // 是否是手动选择日期
+				get_Bluetooth_Bevice: false // 自动获取蓝牙设备,并列表
 			}
 			}
 		},
 		},
 		onLoad(options) {
 		onLoad(options) {
@@ -172,12 +182,14 @@
 			if (!(value == true)) {
 			if (!(value == true)) {
 				this.flag = true
 				this.flag = true
 			}
 			}
+
+			// 获取蓝牙设备,并列表
+			this.openBluetoothAdapter();
 		},
 		},
 		onShow() {
 		onShow() {
 			// 充值后更新金额
 			// 充值后更新金额
-			if (this.$store.state.reshui_amount > 0.00) {
-				this.amount = this.$store.state.reshui_amount
-			}
+			this.amount = this.$store.state.reshui_amount
+
 			if (this.stu_number && typeof(this.stu_number) != 'undefined') {
 			if (this.stu_number && typeof(this.stu_number) != 'undefined') {
 				// 获取基本信息
 				// 获取基本信息
 				this.get_base_info('options', 'onShow')
 				this.get_base_info('options', 'onShow')
@@ -185,6 +197,34 @@
 		},
 		},
 		methods: {
 		methods: {
 			/**
 			/**
+			 * 单击连接热水表
+			 */
+			clickRoom(e) {
+				if (this.judgeBalance() == false) {
+					return
+				}
+				// console.log(e);
+				this.device_code = 'K' + e
+				for (var i = 0, len = this.devices.length; i < len; i++) {
+					if (this.devices[i].dname == e) {
+						this.deviceId = this.devices[i].did
+						// console.log(this.deviceId)
+						break
+					}
+				}
+
+				this.process_control(0);
+
+				// 开始连接匹配的蓝牙设备
+				this.createBLEConnection()
+			},
+			/**
+			 * 空中连接热水表
+			 */
+			open() {
+				this.showRoom = !this.showRoom
+			},
+			/**
 			 * 跳转到广告ad页
 			 * 跳转到广告ad页
 			 */
 			 */
 			ad_redirect() {
 			ad_redirect() {
@@ -195,7 +235,7 @@
 			/**
 			/**
 			 * 保留小数点数值后两位,尾数四舍五入
 			 * 保留小数点数值后两位,尾数四舍五入
 			 * @param {Object} value
 			 * @param {Object} value
-			 */ 
+			 */
 			numFilter(value) {
 			numFilter(value) {
 				// 截取当前数据到小数点后两位
 				// 截取当前数据到小数点后两位
 				let realVal = parseFloat(value).toFixed(2)
 				let realVal = parseFloat(value).toFixed(2)
@@ -293,8 +333,8 @@
 						this.user_name = res.data.info[0].user_name
 						this.user_name = res.data.info[0].user_name
 						// 剩余金额
 						// 剩余金额
 						this.amount = res.data.info[0].balance.toFixed(2)
 						this.amount = res.data.info[0].balance.toFixed(2)
-						if (this.amount > 0)
-							this.$store.state.reshui_amount = this.amount
+						// if (this.amount > 0)
+						this.$store.state.reshui_amount = this.amount
 						// 组合楼栋宿舍号
 						// 组合楼栋宿舍号
 						this.dorm_number = res.data.info[0].build + res.data.info[0].dom
 						this.dorm_number = res.data.info[0].build + res.data.info[0].dom
 						// 校区
 						// 校区
@@ -319,11 +359,11 @@
 				} else if (res.data.mess == '未查询到用户信息') {
 				} else if (res.data.mess == '未查询到用户信息') {
 					// 数据库中 未查询到用户信息,就清除本地存储
 					// 数据库中 未查询到用户信息,就清除本地存储
 					uni.removeStorageSync('userinfo_storage_key');
 					uni.removeStorageSync('userinfo_storage_key');
-					
+
 					uni.showToast({
 					uni.showToast({
 						title: '获取用户信息失败!'
 						title: '获取用户信息失败!'
 					})
 					})
-					
+
 					if (options && typeof(options.from) != 'undefined' && typeof(options.from) != '') {
 					if (options && typeof(options.from) != 'undefined' && typeof(options.from) != '') {
 						uni.navigateTo({
 						uni.navigateTo({
 							url: '../index/index?from=' + options.from
 							url: '../index/index?from=' + options.from
@@ -500,64 +540,75 @@
 					url: '../recharge/recharge'
 					url: '../recharge/recharge'
 				});
 				});
 			},
 			},
-
 			/**
 			/**
-			 * 111111111111111111111111111111
-			 * 扫码连接设备
+			 * 判断余额是否充足
 			 */
 			 */
-			scan() {
+			judgeBalance() {
+				var limit_amount = parseFloat(this.$store.state.amount)
 				var amount = parseFloat(this.amount);
 				var amount = parseFloat(this.amount);
 				// 启动最低金额限制
 				// 启动最低金额限制
-				if (amount < 2.00) {
+				if (amount < limit_amount) {
 					uni.showModal({
 					uni.showModal({
 						title: '提示',
 						title: '提示',
-						content: '当前余额不足¥2元',
+						content: '当前余额不足¥' + limit_amount + '元',
 						cancelText: '我知道了',
 						cancelText: '我知道了',
 						confirmText: '我要充值',
 						confirmText: '我要充值',
 						success: (res) => {
 						success: (res) => {
 							if (res.confirm) {
 							if (res.confirm) {
 								// 跳转充值页面
 								// 跳转充值页面
 								this.chongzhi_yemian()
 								this.chongzhi_yemian()
-							} else if (res.cancel) {
-								return
+							// 	return false
+							// } else if (res.cancel) {
+							// 	return false
 							}
 							}
 						}
 						}
 					})
 					})
+					return false
 				} else {
 				} else {
-					// 已经启动扫描连接设备中
-					if (this.isScan) {
-						uni.showToast({
-							icon: 'none',
-							title: '正在扫描,请耐心等待',
-						})
-						return
-					}
-					// 已经启动设备,不启动扫描
-					if (this.isChecked) {
-						uni.showToast({
-							icon: 'none',
-							title: '设备已启动,无需重新扫码',
-						})
-						return
-					}
+					return true
+				}
+			},
+			/**
+			 * 111111111111111111111111111111
+			 * 扫码连接设备
+			 */
+			scan() {
+				if (this.judgeBalance() == false) {
+					return
+				}
+				// 已经启动扫描连接设备中
+				if (this.isScan) {
+					uni.showToast({
+						icon: 'none',
+						title: '正在扫描,请耐心等待',
+					})
+					return
+				}
+				// 已经启动设备,不启动扫描
+				if (this.isChecked) {
+					uni.showToast({
+						icon: 'none',
+						title: '设备已启动,无需重新扫码',
+					})
+					return
+				}
 
 
-					if (this.deviceId) {
-						uni.showModal({
-							title: '提示',
-							content: '设备已经连接,需要重新连接吗?',
-							success: res => {
-								if (res.confirm) {
-									this.closeBLEConnection()
+				if (this.deviceId) {
+					uni.showModal({
+						title: '提示',
+						content: '设备已经连接,需要重新连接吗?',
+						success: res => {
+							if (res.confirm) {
+								this.closeBLEConnection()
 
 
-									this.scan_qr()
-								} else if (res.cancel) {
-									return
-								}
+								this.scan_qr()
+							} else if (res.cancel) {
+								return
 							}
 							}
-						})
-					} else {
-						this.scan_qr()
-					}
+						}
+					})
+				} else {
+					this.scan_qr()
 				}
 				}
 			},
 			},
 			/**
 			/**
@@ -649,10 +700,10 @@
 					// services: ['FEE7'],   // 要搜索但蓝牙设备主 service 的 uuid 列表
 					// services: ['FEE7'],   // 要搜索但蓝牙设备主 service 的 uuid 列表
 					allowDuplicatesKey: true,
 					allowDuplicatesKey: true,
 					success: (res) => {
 					success: (res) => {
+						if (this.get_Bluetooth_Bevice == true)
+							this.process_control(0)
 
 
-						this.process_control(0);
-
-						this.onBluetoothDeviceFound() //监听搜索到新设备  同时进行
+						this.onBluetoothDeviceFound() // 监听搜索到新设备  同时进行
 
 
 						setTimeout(() => {
 						setTimeout(() => {
 							if (this.isScan) {
 							if (this.isScan) {
@@ -703,11 +754,15 @@
 						// 	title: '停止蓝牙搜索',
 						// 	title: '停止蓝牙搜索',
 						// 	duration: 2000
 						// 	duration: 2000
 						// })
 						// })
+						if (this.get_Bluetooth_Bevice == true) {
+							this.process_control(0);
 
 
-						this.process_control(0);
-
-						// 开始连接匹配的蓝牙设备
-						this.createBLEConnection()
+							// 开始连接匹配的蓝牙设备
+							this.createBLEConnection()
+						} else {
+							this.get_Bluetooth_Bevice == true
+						}
+						this.get_room()
 					},
 					},
 					fail: e => {
 					fail: e => {
 						// console.log('停止搜索蓝牙设备失败,错误码:' + e.errCode);
 						// console.log('停止搜索蓝牙设备失败,错误码:' + e.errCode);
@@ -726,31 +781,101 @@
 			 */
 			 */
 			onBluetoothDeviceFound() {
 			onBluetoothDeviceFound() {
 				uni.onBluetoothDeviceFound((res) => {
 				uni.onBluetoothDeviceFound((res) => {
+					let dname = ''
+					let i = 0
 					res.devices.forEach(device => { // 筛选找到的蓝牙中对名称匹配
 					res.devices.forEach(device => { // 筛选找到的蓝牙中对名称匹配
 						// 过滤掉没有名字的设备
 						// 过滤掉没有名字的设备
 						if (!device.name && !device.localName) {
 						if (!device.name && !device.localName) {
 							return
 							return
 						}
 						}
 
 
+						// 把搜索到的设备存储起来,如有需要可以在页面上展示
+						dname = device.name.substr(1)
+						let d = {
+							did: device.deviceId,
+							dname: dname
+						}
+						if (dname.length == 10 && JSON.stringify(this.devices).indexOf(JSON.stringify(
+								d)) === -1) {
+							this.devices.push(d)
+							i++
+						}
+
 						if (device.name == this.device_code) {
 						if (device.name == this.device_code) {
 							this.process_control(0);
 							this.process_control(0);
 
 
 							//data里面建立一个deviceId、device_code,存储起来
 							//data里面建立一个deviceId、device_code,存储起来
 							// this.device_code = device.name;
 							// this.device_code = device.name;
 							this.deviceId = device.deviceId
 							this.deviceId = device.deviceId
-							// 把搜索到的设备存储起来,如有需要可以在页面上展示
-							if (this.devices.indexOf(res.devices[0].deviceId) == -1) {
-								this.devices.push(res.devices[0].deviceId)
-							}
 
 
 							// 放此位置,苹果手机兼容
 							// 放此位置,苹果手机兼容
 							this.stopBluetoothDevicesDiscovery()
 							this.stopBluetoothDevicesDiscovery()
 
 
 							return
 							return
 						}
 						}
+
+						setTimeout(() => {
+							// 放此位置,苹果手机兼容
+							this.stopBluetoothDevicesDiscovery()
+						}, 2000)
 					})
 					})
 				});
 				});
 			},
 			},
+			// 获取水表对应的宿舍号
+			async get_room() {
+				if (this.devices.length > 0) {
+					let devices_str = []
+
+					for (var i = 0, len = this.devices.length; i < len; i++) {
+						devices_str.push(this.devices[i].dname)
+					}
+
+					const res = await this.$myRequest({
+						host: this.ceshi,
+						url: '/HotWaters/waterqueryDom.action',
+						method: 'POST',
+						header: {
+							'content-type': 'application/x-www-form-urlencoded'
+						},
+						data: {
+							user_id: devices_str.join(',')
+						}
+					});
+
+					// console.log(res);
+					if (res.data.msg == '获取成功') {
+						this.rooms = []
+						// 消费记录
+						let items = res.data.data
+						if (items == 'undefined') {
+							return
+						}
+						for (var i = 0; i < items.length; i++) {
+							let item = {
+								id: items[i].user_id,
+								room: items[i].dom
+							}
+							if (JSON.stringify(this.rooms).indexOf(JSON.stringify(item)) === -1) {
+								this.rooms.push(item); // 进行动态的操作
+							}
+						}
+					} else {
+						if (this.changeDate) {
+							uni.showToast({
+								icon: 'success',
+								title: res.data.mess,
+								success: () => {
+									this.changeDate = false
+								}
+							})
+
+							if (res.data.mess == '本月无消费记录') {
+								this.xiaofei_items = []
+							}
+						}
+					}
+				}
+			},
 
 
 			/**
 			/**
 			 * 555555555555555555555555555555555
 			 * 555555555555555555555555555555555
@@ -863,7 +988,6 @@
 			 * 启用 notify 功能
 			 * 启用 notify 功能
 			 */
 			 */
 			notifyBLECharacteristicValueChange() {
 			notifyBLECharacteristicValueChange() {
-				// console.log(characteristicId, 'characteristicId')
 				uni.notifyBLECharacteristicValueChange({
 				uni.notifyBLECharacteristicValueChange({
 					state: true, // 启用 notify 功能
 					state: true, // 启用 notify 功能
 					deviceId: this.deviceId,
 					deviceId: this.deviceId,
@@ -1179,6 +1303,7 @@
 					} else {
 					} else {
 						this.isChecked = false
 						this.isChecked = false
 						uni.showToast({
 						uni.showToast({
+							icon: 'none',
 							title: res.data.mess,
 							title: res.data.mess,
 							duration: 3000,
 							duration: 3000,
 						})
 						})
@@ -1216,6 +1341,7 @@
 							success: (res1) => {
 							success: (res1) => {
 								this.use_amount = res.data.use_amount.toFixed(2)
 								this.use_amount = res.data.use_amount.toFixed(2)
 								this.amount = (this.amount - this.use_amount).toFixed(2)
 								this.amount = (this.amount - this.use_amount).toFixed(2)
+								this.$store.state.reshui_amount = this.amount
 								// 刷新选定的月份消费记录
 								// 刷新选定的月份消费记录
 								this.request_consumption_records()
 								this.request_consumption_records()
 							}
 							}
@@ -1387,10 +1513,19 @@
 
 
 				.start_bot {
 				.start_bot {
 					display: flex;
 					display: flex;
-					justify-content: flex-end;
+					justify-content: space-between;
 					height: 100rpx;
 					height: 100rpx;
 					align-items: center;
 					align-items: center;
 
 
+					.kongzhonglianjie {
+						margin: 0;
+						height: 60rpx;
+						line-height: 60rpx;
+						font-size: 28rpx;
+						background-color: #1296DB;
+						color: #FFFFFF;
+					}
+
 					.start_bot_txt {
 					.start_bot_txt {
 						margin-left: 20rpx;
 						margin-left: 20rpx;
 						color: #333;
 						color: #333;
@@ -1399,16 +1534,22 @@
 				}
 				}
 			}
 			}
 
 
+			.btn_room {
+				font-size: 28rpx;
+				background-color: #41c560;
+				margin: 10rpx auto;
+			}
+
 			.start_up_process {
 			.start_up_process {
 				padding: 20rpx 0;
 				padding: 20rpx 0;
 				color: #007AFF;
 				color: #007AFF;
 			}
 			}
-			
+
 			.ad {
 			.ad {
 				margin: 0 -40rpx;
 				margin: 0 -40rpx;
 				width: 750rpx;
 				width: 750rpx;
 				height: 216rpx;
 				height: 216rpx;
-				
+
 				.ad_img {
 				.ad_img {
 					height: 100%;
 					height: 100%;
 					width: 100%;
 					width: 100%;

+ 1 - 0
store/index.js

@@ -5,6 +5,7 @@ Vue.use(Vuex)
 const store = new Vuex.Store({
 const store = new Vuex.Store({
 	state: {
 	state: {
 		test: true,  // 控制是否是测试环境
 		test: true,  // 控制是否是测试环境
+		amount: 0.00.toFixed(2),
 		userInfo: {},
 		userInfo: {},
 		payInfo: {
 		payInfo: {
 			from: '',
 			from: '',