Pārlūkot izejas kodu

开启、关闭设备

程志平 3 gadi atpakaļ
vecāks
revīzija
82885635e1
1 mainītis faili ar 147 papildinājumiem un 112 dzēšanām
  1. 147 112
      pagesAir/shareAir/shareAir.vue

+ 147 - 112
pagesAir/shareAir/shareAir.vue

@@ -620,7 +620,7 @@
 						title: '索引为空!',
 						icon: 'none'
 					});
-					
+
 					return;
 				}
 				// 获取空调名称
@@ -629,7 +629,7 @@
 						title: '空调名称为空!',
 						icon: 'none'
 					});
-					
+
 					return;
 				}
 
@@ -692,6 +692,11 @@
 					return
 				}
 
+				uni.showLoading({
+					title: '关闭中...',
+					mask: true
+				});
+
 				const res = await this.$myRequest({
 					host: this.ceshi,
 					url: '/airManage/consumeend.action',
@@ -706,54 +711,15 @@
 					}
 				})
 
-				// console.log(res.data)
-				if (res.data.code == 200) {
-					// 等待4s
-					uni.showLoading({
-						title: '关闭中...',
-						mask: true
-					});
-					// 延时4s看关闭状态
-					let _this = this;
-					setTimeout(() => {
-						// 查询是否关闭成功
-						_this.selectAirCloseState(index, air_ip, order_num)
-					}, 4000);
-				} else {
-					if (res.data.message == '该订单已结算,请勿重复结算') {
-						// 显示已经关闭图标
-						this.airs[index].on = false
-					}
+				if (typeof(res.data) === 'undefined') {
 					uni.showToast({
-						icon: 'none',
-						title: res.data.message,
+						title: '请求超时!',
 						duration: 3000
-					})
-				}
-			},
-			/**
-			 * 查询是否关闭成功
-			 * @param {Object} index
-			 * @param {Object} air_ip
-			 */
-			async selectAirCloseState(index, air_ip, order_num) {
-				// console.log(index, air_ip);
-				const res = await this.$myRequest({
-					host: this.ceshi,
-					url: '/airManage/consumeairoffStatus.action',
-					method: 'POST',
-					header: {
-						'content-type': 'application/x-www-form-urlencoded'
-					},
-					data: {
-						air_ip: air_ip,
-						order_num: order_num
-					}
-				})
-
-				// console.log(res.data);
-				if (res.data.code == 200) {
-					if (res.data.is_on == 0) {
+					});
+					uni.hideLoading();
+				} else {
+					// console.log(res.data)
+					if (res.data.code == 200) {
 						// 显示已经关闭图标
 						this.airs[index].on = false
 						this.airs[index].time = '未启动'
@@ -761,23 +727,74 @@
 							title: '关闭成功!',
 							duration: 2000
 						});
+						uni.hideLoading();
+						// 延时15s看关闭状态
+						// let _this = this;
+						// setTimeout(() => {
+						// 	// 查询是否关闭成功
+						// 	_this.selectAirCloseState(index, air_ip, order_num)
+						// }, 15000);
 					} else {
+						if (res.data.message == '该订单已结算,请勿重复结算') {
+							// 显示已经关闭图标
+							this.airs[index].on = false
+						}
 						uni.showToast({
 							icon: 'none',
-							title: '关闭失败!',
-							duration: 2000
-						});
+							title: res.data.message,
+							duration: 3000
+						})
+						uni.hideLoading();
 					}
-					uni.hideLoading();
-				} else {
-					uni.showToast({
-						icon: 'none',
-						title: res.data.message,
-						duration: 2000
-					});
 				}
 			},
 			/**
+			 * 查询是否关闭成功
+			 * @param {Object} index
+			 * @param {Object} air_ip
+			 */
+			// async selectAirCloseState(index, air_ip, order_num) {
+			// 	// console.log(index, air_ip);
+			// 	const res = await this.$myRequest({
+			// 		host: this.ceshi,
+			// 		url: '/airManage/consumeairoffStatus.action',
+			// 		method: 'POST',
+			// 		header: {
+			// 			'content-type': 'application/x-www-form-urlencoded'
+			// 		},
+			// 		data: {
+			// 			air_ip: air_ip,
+			// 			order_num: order_num
+			// 		}
+			// 	})
+
+			// 	// console.log(res.data);
+			// 	if (res.data.code == 200) {
+			// 		if (res.data.is_on == 0) {
+			// 			// 显示已经关闭图标
+			// 			this.airs[index].on = false
+			// 			this.airs[index].time = '未启动'
+			// 			uni.showToast({
+			// 				title: '关闭成功!',
+			// 				duration: 2000
+			// 			});
+			// 		} else {
+			// 			uni.showToast({
+			// 				icon: 'none',
+			// 				title: '关闭失败!',
+			// 				duration: 2000
+			// 			});
+			// 		}
+			// 		uni.hideLoading();
+			// 	} else {
+			// 		uni.showToast({
+			// 			icon: 'none',
+			// 			title: res.data.message,
+			// 			duration: 2000
+			// 		});
+			// 	}
+			// },
+			/**
 			 * 启动空调
 			 * @param {Object} code
 			 * @param {Object} index
@@ -789,6 +806,10 @@
 			 */
 			async open_airs(code, index, air_ip, build, floors, dom, air_config, air_name) {
 				// console.log(code, index, air_ip, build, floors, dom, air_config, air_name);
+				uni.showLoading({
+					title: '开启中...',
+					mask: true
+				});
 				const res = await this.$myRequest({
 					host: this.ceshi,
 					url: '/airManage/consumestart.action',
@@ -807,53 +828,18 @@
 					}
 				})
 
-				// console.log(res.data);
-				if (res.data.code == 200) {
-					// 等待4s
-					uni.showLoading({
-						title: '开启中...',
-						mask: true
+				if (typeof(res.data) === 'undefined') {
+					uni.showToast({
+						title: '请求超时!',
+						duration: 3000
 					});
-					let _this = this;
-					// 获取订单号
-					this.airs[index].order_num = res.data.order_num
-					// 延时4s看开启状态
-					setTimeout(() => {
-						// 查询是否开启成功
-						_this.selectAirOpenState(index, air_ip)
-					}, 4000);
+					uni.hideLoading();
 				} else {
-					uni.showToast({
-						icon: 'none',
-						title: res.data.message,
-						duration: 2000
-					})
-				}
-			},
-			/**
-			 * 查询是否开启成功
-			 * @param {Object} index
-			 * @param {Object} air_ip
-			 */
-			async selectAirOpenState(index, air_ip) {
-				// console.log(index, air_ip);
-				const res = await this.$myRequest({
-					host: this.ceshi,
-					url: '/airManage/consumeairStatus.action',
-					method: 'POST',
-					header: {
-						'content-type': 'application/x-www-form-urlencoded'
-					},
-					data: {
-						air_ip: air_ip,
-						order_num: this.airs[index].order_num
-					}
-				})
-
-				// console.log(res.data);
-				if (res.data.code == 200) {
-					if (res.data.is_on === '1') {
-						let _this = this
+					// console.log(res.data);
+					if (res.data.code == 200) {
+						let _this = this;
+						// 获取订单号
+						this.airs[index].order_num = res.data.order_num
 						uni.showToast({
 							title: '开启成功!',
 							duration: 2000,
@@ -863,22 +849,71 @@
 								_this.airs[index].time = res.data.start_time;
 							}
 						});
+						uni.hideLoading();
+						// 延时15s看开启状态
+						// setTimeout(() => {
+						// 	// 查询是否开启成功
+						// 	_this.selectAirOpenState(index, air_ip)
+						// }, 150000);
 					} else {
 						uni.showToast({
-							title: '开启失败!',
+							icon: 'none',
+							title: res.data.message,
 							duration: 2000
-						});
+						})
+						uni.hideLoading();
 					}
-					uni.hideLoading();
-				} else {
-					uni.showToast({
-						icon: 'none',
-						title: res.data.message,
-						duration: 2000
-					});
 				}
 			},
 			/**
+			 * 查询是否开启成功
+			 * @param {Object} index
+			 * @param {Object} air_ip
+			 */
+			// async selectAirOpenState(index, air_ip) {
+			// 	// console.log(index, air_ip);
+			// 	const res = await this.$myRequest({
+			// 		host: this.ceshi,
+			// 		url: '/airManage/consumeairStatus.action',
+			// 		method: 'POST',
+			// 		header: {
+			// 			'content-type': 'application/x-www-form-urlencoded'
+			// 		},
+			// 		data: {
+			// 			air_ip: air_ip,
+			// 			order_num: this.airs[index].order_num
+			// 		}
+			// 	})
+
+			// 	// console.log(res.data);
+			// 	if (res.data.code == 200) {
+			// 		if (res.data.is_on === '1') {
+			// 			let _this = this
+			// 			uni.showToast({
+			// 				title: '开启成功!',
+			// 				duration: 2000,
+			// 				success() {
+			// 					// 将开启按钮变成关闭按钮
+			// 					_this.airs[index].on = true;
+			// 					_this.airs[index].time = res.data.start_time;
+			// 				}
+			// 			});
+			// 		} else {
+			// 			uni.showToast({
+			// 				title: '开启失败!',
+			// 				duration: 2000
+			// 			});
+			// 		}
+			// 		uni.hideLoading();
+			// 	} else {
+			// 		uni.showToast({
+			// 			icon: 'none',
+			// 			title: res.data.message,
+			// 			duration: 2000
+			// 		});
+			// 	}
+			// },
+			/**
 			 * 滚动到顶部提示
 			 */
 			scroll_to_upper() {