程志平 3 years ago
parent
commit
b97c410c34

+ 36 - 31
pages/recharge/recharge.vue

@@ -72,7 +72,8 @@
 						// console.log('recharge', res);
 						if (res.code) {
 							// 组合地址,发起支付
-							this.jsapi(param_ip, res.code)
+							// this.jsapi(param_ip, res.code)
+							this.jsapi(res.code)
 						} else {
 							uni.showToast({
 								title: res.errMsg,
@@ -85,37 +86,37 @@
 			/**
 			 * 获取IP
 			 */
-			async getIP() {
-				const res = await this.$myRequest({
-					host: 'ip',
-					url: '?ie=utf-8',
-					// url: '/json',
-					method: 'POST'
-				})
-
-				if (res.data) {
-					// console.log(res);
-					const reg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
-					let ip = reg.exec(res.data);
-
-					// 获取code
-					this.getCode(ip[0])
-				} else {
-					uni.showToast({
-						title: 未获得IP地址,
-						icon: 'none',
-						duration: 2000
-					})
-				}
-			},
+			// async getIP() {
+			// 	const res = await this.$myRequest({
+			// 		host: 'ip',
+			// 		url: '?ie=utf-8',
+			// 		// url: '/json',
+			// 		method: 'POST'
+			// 	})
+
+			// 	if (res.data) {
+			// 		// console.log(res);
+			// 		const reg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
+			// 		let ip = reg.exec(res.data);
+
+			// 		// 获取code
+			// 		this.getCode(ip[0])
+			// 	} else {
+			// 		uni.showToast({
+			// 			title: 未获得IP地址,
+			// 			icon: 'none',
+			// 			duration: 2000
+			// 		})
+			// 	}
+			// },
 			/**
 			 * 请求服务器,获取支付参数,并支付
 			 */
-			async jsapi(param_ip, param_code) {
-				if (param_code == '' || this.amount == '' || param_ip == '') {
+			async jsapi(param_code) {
+				if (param_code == '' || this.amount == '') {
 					uni.showToast({
 						icon: 'none',
-						title: 'code、充值金额或IP为空'
+						title: 'code或充值金额为空'
 					});
 					return
 				}
@@ -128,9 +129,9 @@
 						'content-type': 'application/x-www-form-urlencoded'
 					},
 					data: {
+						// ip: param_ip,
 						code: param_code,
-						num: this.amount,
-						ip: param_ip
+						num: this.amount
 					}
 				})
 
@@ -317,7 +318,9 @@
 						success: (res) => {
 							if (res.confirm) {
 								// 获取IP
-								_this.getIP()
+								// _this.getIP()
+								// 获取code
+								this.getCode()
 							} else if (res.cancel) {
 								return
 							}
@@ -344,7 +347,9 @@
 					success: (res) => {
 						if (res.confirm) {
 							// 获取IP
-							_this.getIP()
+							// _this.getIP()
+							// 获取code
+							this.getCode()
 						} else if (res.cancel) {
 							return
 						}

+ 6 - 5
pagesAir/addAir/addAir.vue

@@ -77,13 +77,14 @@
 								<view v-for="(item4, index4) in item3.children" :key="index4"
 									:style="{display: item3.isShow ? '' : 'none'}">
 									<view class="item-kongtiao" v-if="item4.isUsering">
-										<view :style="{color: item4.isUsering ? '#747578' : '#2979ff'}">
+										<view :style="{color: item4.isUsering ? '#dc0000' : '#2979ff'}">
 											{{item4.label}}(使用中)
 										</view>
-										<checkbox :id="item4.id" :checked="true" :disabled="true" />
+										<checkbox :value="index4" :id="item4.id" :checked="item4.isChecked"
+											@tap="handle_kongtiao" />
 									</view>
 									<view class="item-kongtiao" v-else>
-										<view :style="{color: item4.isUsering ? '#747578' : '#2979ff'}">
+										<view :style="{color: item4.isUsering ? '#dc0000' : '#2979ff'}">
 											{{item4.label}}
 										</view>
 										<checkbox :value="index4" :id="item4.id" :checked="item4.isChecked"
@@ -572,12 +573,12 @@
 						(function(t, air_ip) {
 							setTimeout(function() {
 								_this.bangding_airs(air_ip);
-							}, 300 * t);
+							}, 100 * t);
 						})(i, tmpAirs[2])
 					}
 
 					uni.$emit('selectAirs', {
-						airs: this.return_selected_airs
+						sel_airs: this.return_selected_airs
 					})
 				}
 

+ 99 - 59
pagesAir/shareAir/shareAir.vue

@@ -3,7 +3,7 @@
 		<uni-swiper-dot :info="imgUrl" :current="current" field="content" :mode="dotMode">
 			<swiper class="swiper-box" @change="swiper_change" autoplay :interval="3000" :duration="500">
 				<swiper-item v-for="(item ,index) in imgUrl" :key="index">
-					<image :src="item.url" mode="aspectFill"></image>
+					<image :src="item.url" mode="scaleToFill"></image>
 				</swiper-item>
 			</swiper>
 		</uni-swiper-dot>
@@ -48,15 +48,13 @@
 					<image src="../static/images/air-pic.png" mode="aspectFit"></image>
 				</view>
 			</view>
-			<view class="add-bg">
-				<image src="../static/images/qidong.png" mode="aspectFit"></image>
-			</view>
 		</view>
 		<view class="list-air" v-else>
 			<scroll-view scroll-y="true" :style="{height: screenHeight}" @scrolltoupper="scroll_to_upper"
 				@scrolltolower="scroll_to_lower">
 				<view class="list-items" v-for="(item, index) in airs" :key="index">
-					<view v-if="item.on === true" class="item-air" @longpress="itemLongPress($event, 1, item.air_ip)">
+					<view v-if="item.on === true" class="item-air"
+						@longpress="itemLongPress($event, item.time, item.air_ip)">
 						<view class="item-left">
 							<view class="item-icon">
 								<view class="circle1"></view>
@@ -70,7 +68,7 @@
 							</view>
 						</view>
 						<view class="item-right"
-							@tap="btn_click(index, item.air_ip, item.name, item.info, item.order_num)">
+							@tap="btn_click(index, item.air_ip, item.name, item.info, item.order_num, item.time)">
 							<view class="item-btn">
 								<image src="../static/images/power-off.png" mode="aspectFit"></image>
 								<view class="item-txt-off">
@@ -79,7 +77,8 @@
 							</view>
 						</view>
 					</view>
-					<view v-else class="item-air" @longpress="itemLongPress($event, 0, item.air_ip)" :ref="index">
+					<view v-else class="item-air" @longpress="itemLongPress($event, item.time, item.air_ip)"
+						:ref="index">
 						<view class="item-left">
 							<view class="item-icon">
 								<view class="circle1"></view>
@@ -94,8 +93,9 @@
 								<text v-else>未启动</text>
 							</view>
 						</view>
-						<view class="item-right" v-if="item.abnormal == 1" 
-							@tap="btn_click(index, item.air_ip, item.name, item.info, item.order_num)" :ref="index">
+						<view class="item-right" v-if="item.abnormal == 1"
+							@tap="btn_click(index, item.air_ip, item.name, item.info, item.order_num, item.time)"
+							:ref="index">
 							<view class="item-btn">
 								<image src="../static/images/power-on.png" mode="aspectFit"></image>
 								<view class="item-txt-on">
@@ -149,6 +149,7 @@
 				isList: false, // 是否显示添加的空调列表
 				screenHeight: '', // 屏幕的高度
 				options: 0,
+				time_string: '未知(其他人员使用中)',
 				test: this.$store.state.test
 			};
 		},
@@ -158,10 +159,10 @@
 				uni.redirectTo({
 					url: '../../pages/index/index'
 				})
-			
+
 				return;
 			}
-			
+
 			this.options = options
 			try {
 				// 选择绑定了的空调
@@ -176,24 +177,27 @@
 		},
 		onShow() {
 			// 从新计算高度
-			this.calc_screen_height()
+			this.calc_screen_height();
 			// 监听全局的自定义事件,事件由 uni.$emit 触发,但仅触发一次,在第一次触发之后移除该监听器。
 			// 绑定空调
+			var _this = this;
 			uni.$once('selectAirs', data => {
-				// console.log(data.airs);
-				let arrAirs = data.airs.trim().split(',')
+				// console.log(data.sel_airs);
+				// 拆分数组元素
+				let tf = true;
+				let arrAirs = data.sel_airs.trim().split(',');
 				for (var i = 0; i < arrAirs.length; i++) {
-					let tmpAirs = arrAirs[i].split('|')
-					let t = tmpAirs[1].split('-')
-					let tf = true
-					for (var j = 0; j < this.selectAirs.length; j++) {
-						if (this.selectAirs[j].air_ip == tmpAirs[2]) {
-							tf = false
+					let tmpAirs = arrAirs[i].split('|');
+					let t = tmpAirs[1].split('-');
+					tf = true;
+					for (var j = 0; j < _this.selectAirs.length; j++) {
+						if (_this.selectAirs[j].air_ip == tmpAirs[2]) {
+							tf = false;
 						}
 					}
 					// 存在则不添加到数组和缓存
 					if (true === tf) {
-						this.selectAirs.push({
+						_this.selectAirs.push({
 							air_ip: tmpAirs[2],
 							name: tmpAirs[0] + ' ' + t[0],
 							info: t[1],
@@ -201,19 +205,19 @@
 							abnormal: 1,
 							on: false, // true开启了,false关闭了
 							order_num: '' // 订单号
-						})
+						});
 					}
 				}
 				// 如果选的空调不为空,则显示添加的空调列表
-				if (this.selectAirs.length > 0) {
+				if (_this.selectAirs.length > 0) {
 					// 去重
-					const newArr = [...new Set(this.selectAirs.map(e => JSON.stringify(e)))].map(e => JSON.parse(
+					var newArr = [...new Set(_this.selectAirs.map(e => JSON.stringify(e)))].map(e => JSON.parse(
 						e));
 
-					this.selectAirs = newArr
+					_this.selectAirs = newArr
 				}
 				// 存储空调列表
-				uni.setStorageSync('airs_selected', this.selectAirs)
+				uni.setStorageSync('airs_selected', _this.selectAirs)
 				// 移除全局自定义事件监听器。
 				// uni.$off('selectAirs')
 			});
@@ -251,7 +255,8 @@
 						for (var i = 0; i < data.length; i++) {
 							tmpAirs.push({
 								air_ip: data[i].air_ip,
-								name: data[i].school + '-' + data[i].build + '-' + data[i].floors + '-' + data[i].dom +
+								name: data[i].school + '-' + data[i].build + '-' + data[i].floors + '-' + data[
+										i].dom +
 									'-' + data[i].air_name,
 								info: data[i].air_config,
 								time: '',
@@ -336,7 +341,7 @@
 							// 	title: '其他人员使用中!',
 							// 	duration: 3000
 							// })
-							tmpAirs[index].time = '未知(其他人员使用中)'
+							tmpAirs[index].time = this.time_string;
 						} else {
 							tmpAirs[index].time = data.start_time
 						}
@@ -413,15 +418,16 @@
 			 * 获得code
 			 */
 			getCode(options, param) {
+				var _this = this;
 				uni.login({
 					success: (res) => {
 						// console.log('getCode', res);
 						if (res.code) {
 							if (param == 'get_user_info') {
-								this.getUserInfo(res.code)
+								_this.getUserInfo(res.code)
 							} else {
 								// 请求服务器,获得openid
-								this.getOpenId(options, res.code)
+								_this.getOpenId(options, res.code)
 							}
 						} else {
 							uni.showToast({
@@ -506,10 +512,9 @@
 					// 余额
 					this.balance = res.data.data.balance.toFixed(2)
 					this.id_card = res.data.data.sfzh
-					if (this.isList == false) {
-						// 查询绑定的空调
-						this.select_banding_airs()
-					}
+
+					// 查询绑定的空调(更新列表)
+					this.select_banding_airs()
 				} else {
 					uni.showToast({
 						title: res.data.message
@@ -517,30 +522,35 @@
 				}
 			},
 			/**
-			 * 长按可删除
+			 * 长按可解绑
 			 * @param {Object} e
-			 * @param {Object} val
+			 * @param {Object} time
+			 * @param {Object} air_ip
 			 */
-			itemLongPress(e, val, air_ip) {
-				// console.log(e, val, air_ip);
-				if (val == 0) {
+			itemLongPress(e, time, air_ip) {
+				// console.log(e, time, air_ip);
+				var _this = this;
+				var reg =
+					/^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$/;
+				var regExp = new RegExp(reg);
+				if (regExp.test(time) || time == this.time_string) {
+					uni.showToast({
+						title: '使用中不能解绑',
+						icon: 'error',
+						duration: 1000
+					})
+				} else {
 					let index = e.currentTarget.dataset.ref
 					uni.showModal({
 						title: '提示',
-						content: '是否删除该空调?',
+						content: '是否解绑该空调?',
 						success: (res) => {
 							if (res.confirm) {
 								// 解绑空调
-								this.unbangding_airs(air_ip, index)
+								_this.unbangding_airs(air_ip, index)
 							}
 						}
-					})
-				} else {
-					uni.showToast({
-						title: '使用中不能删除',
-						icon: 'error',
-						duration: 1000
-					})
+					});
 				}
 			},
 			/**
@@ -560,15 +570,16 @@
 						sfzh: this.id_card,
 						air_ip: air_ip
 					}
-				})
+				});
 
 				// console.log(res.data);
 				if (res.data.code == 200) {
 					// 删除指定下标的元素
-					this.airs.splice(index, 1)
+					this.airs.splice(index, 1);
+					uni.setStorageSync('airs_selected', this.airs);
 
 					if (this.airs.length == 0) {
-						this.isList = false
+						this.isList = false;
 					}
 
 					uni.showToast({
@@ -577,23 +588,49 @@
 				} else {
 					uni.showToast({
 						title: res.data.message
-					})
+					});
 				}
 			},
 			/**
 			 * 单击了启动或关闭按钮
 			 * @param {Object} e
 			 */
-			btn_click(index, air_ip, name, info, order_num) {
-				// console.log(index, air_ip, name, info, order_num);
+			btn_click(index, air_ip, name, info, order_num, time) {
+				// console.log(index, air_ip, name, info, order_num, time);
+				var _this = this;
+				if (time === this.time_string) {
+					uni.showModal({
+						title: '提示',
+						content: '其他人员使用中,你不能关闭!',
+						confirmText: '好的',
+						showCancel: false
+					})
+					return;
+				}
+
 				let tmp = name.split('-');
 				let build = tmp[1],
 					floors = tmp[2],
 					dom = tmp[3] + '-' + tmp[4].split(' ')[0];
-				let air_name = name.split(' ')[1]
+				let air_name = tmp[tmp.length - 1];
+				// console.log(air_name);
 				// 未获取到索引
 				if (typeof index === 'undefined') {
-					return
+					uni.showToast({
+						title: '索引为空!',
+						icon: 'none'
+					});
+					
+					return;
+				}
+				// 获取空调名称
+				if (typeof air_name === 'undefined') {
+					uni.showToast({
+						title: '空调名称为空!',
+						icon: 'none'
+					});
+					
+					return;
 				}
 
 				if (this.airs[index].on) {
@@ -603,7 +640,7 @@
 						success: (res) => {
 							if (res.confirm) {
 								// 【关闭】空调
-								this.close_airs(index, air_ip, order_num)
+								_this.close_airs(index, air_ip, order_num)
 							}
 						}
 					});
@@ -619,7 +656,7 @@
 										// console.log('getCode', res);
 										if (res.code) {
 											// 调用接口,开启空调
-											this.open_airs(res.code, index, air_ip, build, floors,
+											_this.open_airs(res.code, index, air_ip, build, floors,
 												dom, info, air_name)
 										} else {
 											uni.showToast({
@@ -640,6 +677,7 @@
 			 * @param {Object} air_ip
 			 */
 			async close_airs(index, air_ip, order_num) {
+				// console.log(index, air_ip, order_num);
 				if (order_num == '') {
 					uni.showToast({
 						title: '未获得单号'
@@ -718,6 +756,7 @@
 					if (res.data.is_on == 0) {
 						// 显示已经关闭图标
 						this.airs[index].on = false
+						this.airs[index].time = '未启动'
 						uni.showToast({
 							title: '关闭成功!',
 							duration: 2000
@@ -749,6 +788,7 @@
 			 * @param {Object} air_config
 			 */
 			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);
 				const res = await this.$myRequest({
 					host: this.ceshi,
 					url: '/airManage/consumestart.action',
@@ -965,7 +1005,7 @@
 		.add-air {
 			border-radius: 8rpx;
 			padding: 60rpx 10rpx;
-			background-color: #F1F1F1;
+			background-color: #ffffff;
 
 			.add-content {
 				display: flex;

BIN
pagesAir/static/images/qidong.png