|
|
@@ -66,10 +66,10 @@
|
|
|
<view class="item-title">{{item.name}}</view>
|
|
|
<view class="item-info">
|
|
|
<text class="item-info-left">{{item.info}}</text>
|
|
|
- <text>启用时长:</text><text>{{item.time}}</text>
|
|
|
+ <text>启动时间:</text><text>{{item.time}}</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
- <view class="item-right" @tap="btn_click(index, item.air_ip, item.name, item.info)">
|
|
|
+ <view class="item-right" @tap="btn_click(index, item.air_ip, item.name, item.info, item.order_num)">
|
|
|
<view class="item-btn">
|
|
|
<image src="../static/images/power-off.png" mode="aspectFit"></image>
|
|
|
<view class="item-txt-off">
|
|
|
@@ -89,10 +89,10 @@
|
|
|
<view class="item-info">
|
|
|
<text class="item-info-left">{{item.info}}</text>
|
|
|
<image src="../static/images/power-off.png" mode="" class="item-info-icon"></image>
|
|
|
- <text>未启用</text>
|
|
|
+ <text>未启动</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
- <view class="item-right" @tap="btn_click(index, item.air_ip, item.name, item.info)"
|
|
|
+ <view class="item-right" @tap="btn_click(index, item.air_ip, item.name, item.info, item.order_num)"
|
|
|
:ref="index">
|
|
|
<view class="item-btn">
|
|
|
<image src="../static/images/power-on.png" mode="aspectFit"></image>
|
|
|
@@ -120,7 +120,6 @@
|
|
|
userinfo: {}, // 用户信息
|
|
|
stu_number: '', // 学号
|
|
|
id_card: '', // 身份证号
|
|
|
- order_num: '', // 订单号
|
|
|
// 滚动横幅的数据
|
|
|
imgUrl: [{
|
|
|
url: this.$code_base_url + '/image/1.png'
|
|
|
@@ -138,15 +137,21 @@
|
|
|
selectAirs: [], // 已经选择的空调列表数据
|
|
|
dotMode: 'round', // 显示控制点样式
|
|
|
isList: false, // 是否显示添加的空调列表
|
|
|
- screenHeight: '' // 屏幕的高度
|
|
|
+ screenHeight: '', // 屏幕的高度
|
|
|
+ options: 0
|
|
|
};
|
|
|
},
|
|
|
onLoad(options) {
|
|
|
- // 选择绑定了的空调
|
|
|
- let airs_selected = uni.getStorageSync('airs_selected')
|
|
|
- if (airs_selected.length > 0) {
|
|
|
- // 使用存储的列表
|
|
|
- this.selectAirs = airs_selected
|
|
|
+ this.options = options
|
|
|
+ try{
|
|
|
+ // 选择绑定了的空调
|
|
|
+ let airs_selected = uni.getStorageSync('airs_selected')
|
|
|
+ if (airs_selected.length > 0) {
|
|
|
+ // 使用存储的列表
|
|
|
+ this.selectAirs = airs_selected
|
|
|
+ }
|
|
|
+ }catch(e){
|
|
|
+ console.log('读取空调相关信息:' + e.message);
|
|
|
}
|
|
|
},
|
|
|
onShow() {
|
|
|
@@ -173,7 +178,8 @@
|
|
|
name: tmpAirs[0] + ' ' + t[0],
|
|
|
info: t[1],
|
|
|
time: '',
|
|
|
- on: false
|
|
|
+ on: false, // true开启了,false关闭了
|
|
|
+ order_num: '' // 订单号
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
@@ -192,11 +198,7 @@
|
|
|
});
|
|
|
|
|
|
// 获取基本信息
|
|
|
- this.get_base_info('options', 'onLoad')
|
|
|
-
|
|
|
- setTimeout(() => {
|
|
|
- uni.hideLoading();
|
|
|
- }, 3000)
|
|
|
+ this.get_base_info(this.options, 'onLoad')
|
|
|
},
|
|
|
methods: {
|
|
|
/**
|
|
|
@@ -229,11 +231,28 @@
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // 按名称排序
|
|
|
- tmpAirs.sort((a, b) => a.name.localeCompare(b.name))
|
|
|
- this.airs = tmpAirs
|
|
|
- // 显示添加的空调列表
|
|
|
- this.isList = true
|
|
|
+ // 不为空
|
|
|
+ if (tmpAirs.length > 0) {
|
|
|
+ // 按名称排序
|
|
|
+ tmpAirs.sort((a, b) => a.name.localeCompare(b.name));
|
|
|
+ let _this = this;
|
|
|
+ // 遍历状态
|
|
|
+ for (var i = 0; i < tmpAirs.length; i++) {
|
|
|
+ // 获取空调状态
|
|
|
+ (function(t, tmpAirs) { // 注意这里是形参
|
|
|
+ setTimeout(function() {
|
|
|
+ _this.readAirsStatus(tmpAirs, t);
|
|
|
+ }, 100 * t); // 还是每秒执行一次,不是累加的
|
|
|
+ })(i, tmpAirs) // 注意这里是实参,这里把要用的参数传进去
|
|
|
+ }
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ if (this.airs.length > 0) {
|
|
|
+ // 显示添加的空调列表
|
|
|
+ _this.isList = true
|
|
|
+ }
|
|
|
+ }, 300)
|
|
|
+ }
|
|
|
} else {
|
|
|
// 隐藏添加的空调列表
|
|
|
this.isList = false
|
|
|
@@ -253,20 +272,56 @@
|
|
|
uni.hideLoading();
|
|
|
},
|
|
|
/**
|
|
|
+ * 获取绑定的空调的状态
|
|
|
+ * @param {Object} tmpAirs
|
|
|
+ * @param {Object} index
|
|
|
+ */
|
|
|
+ async readAirsStatus(tmpAirs, index) {
|
|
|
+ const res = await this.$myRequest({
|
|
|
+ host: this.ceshi,
|
|
|
+ url: '/airManage/consumeStatus.action',
|
|
|
+ method: 'POST',
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/x-www-form-urlencoded'
|
|
|
+ },
|
|
|
+ data: {
|
|
|
+ air_ip: tmpAirs[index].air_ip,
|
|
|
+ sfzh: this.id_card
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // console.log(res.data);
|
|
|
+ if (res.data.code == 200) {
|
|
|
+ let data = res.data;
|
|
|
+ if (data.is_on == 1) {
|
|
|
+ for (var i = 0; i < tmpAirs.length; i++) {
|
|
|
+ if (tmpAirs[i].air_ip == tmpAirs[index].air_ip) {
|
|
|
+ tmpAirs[i].on = true
|
|
|
+ tmpAirs[i].time = data.start_time
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.airs.push(tmpAirs[index])
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
* 获取基本信息
|
|
|
*/
|
|
|
get_base_info(options, param) {
|
|
|
// console.log(options);
|
|
|
uni.showLoading({
|
|
|
- title: '加载中'
|
|
|
+ title: '加载中',
|
|
|
+ mask: true
|
|
|
})
|
|
|
- try {
|
|
|
- // 获取学号
|
|
|
- this.stu_number = this.$store.state.userInfo.card_number
|
|
|
|
|
|
+ // 获取学号
|
|
|
+ this.stu_number = this.$store.state.userInfo.card_number
|
|
|
+
|
|
|
+ try {
|
|
|
if (this.stu_number == '' || typeof(this.stu_number) == 'undefined') { // 学号不存在,可以从存储中拿用户信息
|
|
|
const userinfo = uni.getStorageSync('userinfo_storage_key')
|
|
|
if (userinfo) { // 拿学号
|
|
|
+ this.userinfo = userinfo
|
|
|
this.stu_number = userinfo.card_number
|
|
|
this.id_card = userinfo.id_card
|
|
|
} else { // 还没有需要跳转到首页进行获取
|
|
|
@@ -288,9 +343,13 @@
|
|
|
} catch (e) {
|
|
|
console.log('获取基本信息:' + e.message);
|
|
|
}
|
|
|
-
|
|
|
// 获取code
|
|
|
this.getCode(options, param)
|
|
|
+
|
|
|
+ if (this.id_card !== '') {
|
|
|
+ // 查询绑定的空调
|
|
|
+ this.select_banding_airs()
|
|
|
+ }
|
|
|
},
|
|
|
/**
|
|
|
* 获得code
|
|
|
@@ -319,8 +378,8 @@
|
|
|
* 请求服务器,获得openid
|
|
|
*/
|
|
|
async getOpenId(options, param_code) {
|
|
|
- if (JSON.stringify(this.userinfo) === "{}") {
|
|
|
- return
|
|
|
+ if (typeof this.userinfo === 'object') {
|
|
|
+ this.userinfo = JSON.stringify(this.userinfo)
|
|
|
}
|
|
|
const res = await this.$myRequest({
|
|
|
host: this.ceshi,
|
|
|
@@ -389,8 +448,10 @@
|
|
|
// 余额
|
|
|
this.balance = res.data.data.balance.toFixed(2)
|
|
|
this.id_card = res.data.data.sfzh
|
|
|
- // 查询绑定的空调
|
|
|
- this.select_banding_airs()
|
|
|
+ if (this.isList == false) {
|
|
|
+ // 查询绑定的空调
|
|
|
+ this.select_banding_airs()
|
|
|
+ }
|
|
|
} else {
|
|
|
uni.showToast({
|
|
|
title: res.data.message
|
|
|
@@ -465,8 +526,8 @@
|
|
|
* 单击了启动或关闭按钮
|
|
|
* @param {Object} e
|
|
|
*/
|
|
|
- btn_click(index, air_ip, name, info) {
|
|
|
- // console.log(index, air_ip, name, info);
|
|
|
+ btn_click(index, air_ip, name, info, order_num) {
|
|
|
+ // console.log(index, air_ip, name, info, order_num);
|
|
|
let tmp = name.split('-');
|
|
|
let build = tmp[1],
|
|
|
floors = tmp[2],
|
|
|
@@ -484,7 +545,7 @@
|
|
|
success: (res) => {
|
|
|
if (res.confirm) {
|
|
|
// 【关闭】空调
|
|
|
- this.close_airs(index, air_ip)
|
|
|
+ this.close_airs(index, air_ip, order_num)
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -520,8 +581,8 @@
|
|
|
* @param {Object} index
|
|
|
* @param {Object} air_ip
|
|
|
*/
|
|
|
- async close_airs(index, air_ip) {
|
|
|
- if (this.order_num == '') {
|
|
|
+ async close_airs(index, air_ip, order_num) {
|
|
|
+ if (order_num == '') {
|
|
|
uni.showToast({
|
|
|
title: '未获得单号'
|
|
|
})
|
|
|
@@ -544,22 +605,75 @@
|
|
|
},
|
|
|
data: {
|
|
|
sfzh: this.id_card,
|
|
|
- order_num: this.order_num,
|
|
|
- clientId: air_ip
|
|
|
+ order_num: order_num,
|
|
|
+ air_ip: air_ip
|
|
|
}
|
|
|
})
|
|
|
|
|
|
console.log(res.data);
|
|
|
if (res.data.code == 200) {
|
|
|
+ // 等待1s
|
|
|
+ uni.showLoading({
|
|
|
+ title: '关闭中...',
|
|
|
+ mask: true
|
|
|
+ });
|
|
|
+ // 延时1s看开启状态
|
|
|
+ let _this = this;
|
|
|
+ setTimeout(() => {
|
|
|
+ // 查询是否开启成功
|
|
|
+ _this.selectAirCloseState(index, air_ip, order_num)
|
|
|
+ }, 1000);
|
|
|
+ } else {
|
|
|
uni.showToast({
|
|
|
- title: res.data.message
|
|
|
+ icon: 'none',
|
|
|
+ title: res.data.message,
|
|
|
+ duration: 3000
|
|
|
})
|
|
|
- // 显示已经关闭图标
|
|
|
- this.airs[index].on = false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 查询是否关闭成功
|
|
|
+ * @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
|
|
|
+ uni.showToast({
|
|
|
+ title: '关闭成功!',
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: '关闭失败!',
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ }
|
|
|
+ uni.hideLoading();
|
|
|
} else {
|
|
|
uni.showToast({
|
|
|
- title: res.data.message
|
|
|
- })
|
|
|
+ icon: 'none',
|
|
|
+ title: res.data.message,
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
@@ -593,18 +707,71 @@
|
|
|
|
|
|
console.log(res.data);
|
|
|
if (res.data.code == 200) {
|
|
|
+ // 等待12s
|
|
|
+ uni.showLoading({
|
|
|
+ title: '开启中...',
|
|
|
+ mask: true
|
|
|
+ });
|
|
|
+ // 延时12s看开启状态
|
|
|
+ let _this = this;
|
|
|
+ setTimeout(() => {
|
|
|
+ // 查询是否开启成功
|
|
|
+ _this.selectAirOpenState(index, air_ip)
|
|
|
+ }, 12000);
|
|
|
+ } else {
|
|
|
uni.showToast({
|
|
|
icon: 'none',
|
|
|
- title: res.data.message
|
|
|
+ title: res.data.message,
|
|
|
+ duration: 2000
|
|
|
})
|
|
|
- // 显示已经开启图标
|
|
|
- this.airs[index].on = true
|
|
|
- this.order_num = res.data.order_num
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 查询是否开启成功
|
|
|
+ * @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.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
|
|
|
- })
|
|
|
+ title: res.data.message,
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
}
|
|
|
},
|
|
|
/**
|