shareAir.vue 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. <template>
  2. <view class="container">
  3. <uni-swiper-dot :info="imgUrl" :current="current" field="content" :mode="dotMode">
  4. <swiper class="swiper-box" @change="swiper_change" autoplay :interval="3000" :duration="500">
  5. <swiper-item v-for="(item ,index) in imgUrl" :key="index">
  6. <image :src="item.url" mode="scaleToFill"></image>
  7. </swiper-item>
  8. </swiper>
  9. </uni-swiper-dot>
  10. <view class="line"></view>
  11. <view class="nav">
  12. <navigator class="btn" url="/pagesAir/stdBookMgr/stdBookMgr" hover-class="navigator-hover">
  13. <view class="btn-icon-tzgl">
  14. <image src="../static/images/tzgl.png" mode=""></image>
  15. <text>台账管理</text>
  16. </view>
  17. <view class="txt-right">
  18. <text> </text>
  19. <uni-icons type="forward" color="#c7c9ce" size="26"></uni-icons>
  20. </view>
  21. </navigator>
  22. <navigator class="btn" url="/pagesAir/accountBalance/accountBalance" hover-class="navigator-hover">
  23. <view class="btn-icon">
  24. <image src="../static/images/yhye.png" mode=""></image>
  25. <text>账户余额</text>
  26. </view>
  27. <view class="txt-right">
  28. <text>{{balance}}</text>
  29. <uni-icons type="forward" color="#c7c9ce" size="26"></uni-icons>
  30. </view>
  31. </navigator>
  32. </view>
  33. <view class="line"></view>
  34. <view class="add-air" v-if="isList === false" :style="{height: screenHeight}">
  35. <view class="add-content">
  36. <view class="add-left">
  37. <navigator url="../addAir/addAir" class="add-btn">
  38. <uni-icons type="plus" color="white" size="30"></uni-icons>
  39. <view>添加</view>
  40. </navigator>
  41. <view class="add-tip">
  42. <view class="txt-add-air">添加空调</view>
  43. <view class="txt-tip">点击添加设备</view>
  44. <view class="txt-tip">可添加多个设备</view>
  45. </view>
  46. </view>
  47. <view class="add-right">
  48. <image src="../static/images/air-pic.png" mode="aspectFit"></image>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="list-air" v-else>
  53. <scroll-view scroll-y="true" :style="{height: screenHeight}">
  54. <view class="list-items" v-for="(item, index) in airs" :key="index">
  55. <view v-if="item.on === true" class="item-air"
  56. @longpress="itemLongPress($event, item.time, item.air_ip)">
  57. <view class="item-left">
  58. <view class="item-icon">
  59. <view class="circle1"></view>
  60. <view class="circle2"></view>
  61. <view class="circle3"></view>
  62. </view>
  63. <view class="item-title">{{item.name_show}}</view>
  64. <view class="item-info">
  65. <text class="item-info-left">{{item.info}}</text>
  66. <text>{{item.status}}</text><text>{{item.time}}</text>
  67. </view>
  68. </view>
  69. <view class="item-right"
  70. @tap="btn_click(index, item.air_ip, item.name, item.info, item.order_num, item.time)">
  71. <view class="item-btn">
  72. <image src="../static/images/power-off.png" mode="aspectFit"></image>
  73. <view class="item-txt-off">
  74. 关闭
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. <view v-else class="item-air" @longpress="itemLongPress($event, item.time, item.air_ip)"
  80. :ref="index">
  81. <view class="item-left">
  82. <view class="item-icon">
  83. <view class="circle1"></view>
  84. <view class="circle2"></view>
  85. <view class="circle3"></view>
  86. </view>
  87. <view class="item-title">{{item.name_show}}</view>
  88. <view class="item-info">
  89. <text class="item-info-left">{{item.info}}</text>
  90. <!-- <image src="../static/images/power-off.png" mode="" class="item-info-icon"></image> -->
  91. <text>{{item.status}}</text>
  92. <text v-if="item.time !== ''">{{item.time}}</text>
  93. <text v-else>未启动</text>
  94. </view>
  95. </view>
  96. <view class="item-right" v-if="item.abnormal == 1"
  97. @tap="btn_click(index, item.air_ip, item.name, item.info, item.order_num, item.time)"
  98. :ref="index">
  99. <view class="item-btn">
  100. <image src="../static/images/power-on.png" mode="aspectFit"></image>
  101. <view class="item-txt-on">
  102. 启动
  103. </view>
  104. </view>
  105. </view>
  106. <view class="item-right" v-else :ref="index">
  107. <view class="item-btn">
  108. <image src="../static/images/power-off.png" mode="aspectFit"></image>
  109. <view class="item-txt-off">
  110. 禁用
  111. </view>
  112. </view>
  113. </view>
  114. </view>
  115. </view>
  116. <navigator url="../addAir/addAir" class="add-air-bottom">
  117. <uni-icons type="plus" size="30" color="#4B8DFB"></uni-icons>
  118. <view class="add-btn-bottom">添加</view>
  119. </navigator>
  120. </scroll-view>
  121. </view>
  122. </view>
  123. </template>
  124. <script>
  125. export default {
  126. data() {
  127. return {
  128. ceshi: 'air',
  129. userinfo: {}, // 用户信息
  130. stu_number: '', // 学号
  131. id_card: '', // 身份证号
  132. // 滚动横幅的数据
  133. imgUrl: [{
  134. url: this.$code_base_url + '/image/1.png'
  135. },
  136. {
  137. url: this.$code_base_url + '/image/2.png'
  138. },
  139. {
  140. url: this.$code_base_url + '/image/3.png'
  141. }
  142. ],
  143. current: 0, // 开始显示第几个
  144. balance: 0.0.toFixed(2), // 余额
  145. airs: [], // 已经添加成功的空调列表数据
  146. selectAirs: [], // 已经选择的空调列表数据
  147. dotMode: 'round', // 显示控制点样式
  148. isList: false, // 是否显示添加的空调列表
  149. screenHeight: '', // 屏幕的高度
  150. options: 0,
  151. time_string: '其他人员使用中',
  152. test: this.$store.state.test
  153. };
  154. },
  155. onLoad(options) {
  156. var _this = this;
  157. // 系统正在维护...
  158. if (_this.test == 'weihuzhong') {
  159. uni.redirectTo({
  160. url: '../../pages/index/index'
  161. })
  162. return;
  163. }
  164. _this.options = options
  165. try {
  166. // 选择绑定了的空调
  167. let airs_selected = uni.getStorageSync('airs_selected')
  168. if (airs_selected.length > 0) {
  169. // 使用存储的列表
  170. _this.selectAirs = airs_selected
  171. }
  172. } catch (e) {
  173. console.log('读取空调相关信息:' + e.message);
  174. }
  175. // _this._freshing = false;
  176. // setTimeout(() => {
  177. // _this.triggered = true;
  178. // }, 500);
  179. },
  180. onShow() {
  181. var _this = this;
  182. // 从新计算高度
  183. _this.calc_screen_height();
  184. // 监听全局的自定义事件,事件由 uni.$emit 触发,但仅触发一次,在第一次触发之后移除该监听器。
  185. // 绑定空调
  186. uni.$once('selectAirs', data => {
  187. // console.log(data.sel_airs);
  188. // 拆分数组元素
  189. let tf = true;
  190. let arrAirs = data.sel_airs.trim().split(',');
  191. for (var i = 0; i < arrAirs.length; i++) {
  192. let tmpAirs = arrAirs[i].split('|');
  193. let t = tmpAirs[1].split('-');
  194. tf = true;
  195. for (var j = 0; j < _this.selectAirs.length; j++) {
  196. if (_this.selectAirs[j].air_ip == tmpAirs[2]) {
  197. tf = false;
  198. }
  199. }
  200. // 存在则不添加到数组和缓存
  201. if (true === tf) {
  202. _this.selectAirs.push({
  203. air_ip: tmpAirs[2],
  204. name: tmpAirs[0] + ' ' + t[0],
  205. info: t[1],
  206. time: '',
  207. abnormal: 1,
  208. on: false, // true开启了,false关闭了
  209. order_num: '' // 订单号
  210. });
  211. }
  212. }
  213. // 如果选的空调不为空,则显示添加的空调列表
  214. if (_this.selectAirs.length > 0) {
  215. // 去重
  216. var newArr = [...new Set(_this.selectAirs.map(e => JSON.stringify(e)))].map(e => JSON.parse(
  217. e));
  218. _this.selectAirs = newArr;
  219. }
  220. // 存储空调列表
  221. uni.setStorageSync('airs_selected', _this.selectAirs);
  222. // 移除全局自定义事件监听器。
  223. // uni.$off('selectAirs')
  224. });
  225. // 获取基本信息
  226. _this.get_base_info(_this.options, 'onShow');
  227. setTimeout(() => {
  228. uni.hideLoading();
  229. }, 3000);
  230. },
  231. // 下拉刷新
  232. onPullDownRefresh() {
  233. var _this = this;
  234. // 获取基本信息
  235. _this.get_base_info(_this.options, 'onShow');
  236. // 查询绑定的空调(更新列表)
  237. _this.select_banding_airs();
  238. // 停止刷新
  239. uni.stopPullDownRefresh();
  240. },
  241. methods: {
  242. /**
  243. * 查询绑定的空调
  244. */
  245. async select_banding_airs() {
  246. uni.showLoading({
  247. title: '加载绑定的空调'
  248. });
  249. var _this = this;
  250. const res = await this.$myRequest({
  251. host: _this.ceshi,
  252. url: '/airManage/usersqueryAir.action',
  253. method: 'POST',
  254. header: {
  255. 'content-type': 'application/x-www-form-urlencoded'
  256. },
  257. data: {
  258. sfzh: _this.id_card
  259. }
  260. })
  261. // console.log(res.data);
  262. if (res.data.code == 200) {
  263. let data = res.data.data
  264. if (data.length > 0) {
  265. _this.airs = []
  266. let tmpAirs = []
  267. for (var i = 0; i < data.length; i++) {
  268. tmpAirs.push({
  269. air_ip: data[i].air_ip,
  270. name: data[i].school + '-' + data[i].build + '-' + data[i].floors + '-' + data[
  271. i].dom + '-' + data[i].air_name,
  272. name_show: data[i].school + '-' + data[i].dom + '-' + data[i].air_name,
  273. info: data[i].air_config,
  274. time: '',
  275. abnormal: data[i].is_normal,
  276. on: data[i].is_on, // true开启了,false关闭了
  277. order_num: '' // 订单号
  278. })
  279. // for (var j = 0; j < _this.selectAirs.length; j++) {
  280. // if (_this.selectAirs[j].air_ip == data[i].air_ip) {
  281. // tmpAirs.push(_this.selectAirs[j])
  282. // break
  283. // }
  284. // }
  285. }
  286. // 不为空
  287. if (tmpAirs.length > 0) {
  288. // 遍历状态
  289. for (var i = 0; i < tmpAirs.length; i++) {
  290. // 获取空调状态
  291. (function(t, tmpAirs) { // 注意这里是形参
  292. setTimeout(function() {
  293. _this.readAirsStatus(tmpAirs, t);
  294. }, 100 * t); // 还是0.1秒执行一次,不是累加的
  295. })(i, tmpAirs) // 注意这里是实参,这里把要用的参数传进去
  296. }
  297. setTimeout(() => {
  298. if (_this.airs.length > 0) {
  299. // 显示添加的空调列表
  300. _this.isList = true;
  301. uni.hideLoading();
  302. }
  303. }, 500);
  304. }
  305. } else {
  306. // 隐藏添加的空调列表
  307. _this.isList = false
  308. }
  309. } else if (res.data.code == 205) {
  310. // 隐藏添加的空调列表
  311. _this.isList = false
  312. } else {
  313. // 隐藏添加的空调列表
  314. _this.isList = false
  315. // 提示返回信息
  316. uni.showToast({
  317. title: res.data.message
  318. })
  319. }
  320. // 隐藏加载
  321. uni.hideLoading();
  322. },
  323. /**
  324. * 获取绑定的空调的状态
  325. * @param {Object} tmpAirs
  326. * @param {Object} index
  327. */
  328. async readAirsStatus(tmpAirs, index) {
  329. var _this = this;
  330. const res = await _this.$myRequest({
  331. host: _this.ceshi,
  332. url: '/airManage/consumeStatus.action',
  333. method: 'POST',
  334. header: {
  335. 'content-type': 'application/x-www-form-urlencoded'
  336. },
  337. data: {
  338. air_ip: tmpAirs[index].air_ip,
  339. sfzh: _this.id_card
  340. }
  341. })
  342. // console.log(res.data, tmpAirs[index].air_ip);
  343. if (res.data.code == 200) {
  344. let data = res.data;
  345. if (data.is_on == 1) {
  346. if (typeof data.order_num === 'undefined') {
  347. tmpAirs[index].status = '状态:';
  348. tmpAirs[index].time = _this.time_string;
  349. } else {
  350. tmpAirs[index].status = '启动时间:';
  351. tmpAirs[index].time = data.start_time
  352. }
  353. tmpAirs[index].on = true
  354. tmpAirs[index].order_num = data.order_num
  355. } else {
  356. tmpAirs[index].status = '状态:';
  357. tmpAirs[index].on = false
  358. tmpAirs[index].time = ''
  359. tmpAirs[index].order_num = ''
  360. }
  361. // 更新自己绑定的空调列表
  362. _this.airs.push(tmpAirs[index])
  363. } else {
  364. tmpAirs[index].status = '状态:';
  365. tmpAirs[index].time = res.data.message;
  366. // 更新自己绑定的空调列表
  367. _this.airs.push(tmpAirs[index])
  368. }
  369. // 按名称排序
  370. _this.airs.sort((a, b) => a.name.localeCompare(b.name));
  371. },
  372. /**
  373. * 获取基本信息
  374. */
  375. get_base_info(options, param) {
  376. // console.log(options);
  377. uni.showLoading({
  378. title: '加载中',
  379. mask: true
  380. })
  381. // 获取学号
  382. this.stu_number = this.$store.state.userInfo.card_number
  383. try {
  384. if (this.stu_number == '' || typeof(this.stu_number) == 'undefined') { // 学号不存在,可以从存储中拿用户信息
  385. const userinfo = uni.getStorageSync('userinfo_storage_key')
  386. if (userinfo) { // 拿学号
  387. this.userinfo = userinfo
  388. this.stu_number = userinfo.card_number
  389. this.id_card = userinfo.id_card
  390. } else { // 还没有需要跳转到首页进行获取
  391. uni.navigateTo({
  392. url: '../../pages/index/index?from=' + options.from
  393. })
  394. uni.showToast({
  395. icon: 'none',
  396. title: '学号为空,请进行授权',
  397. duration: 3000
  398. });
  399. return
  400. }
  401. } else { // 学号已经存在,可以从存储中拿用户信息
  402. this.userinfo = JSON.stringify(uni.getStorageSync('userinfo_storage_key'))
  403. }
  404. } catch (e) {
  405. console.log('获取基本信息:' + e.message);
  406. }
  407. // 获取code
  408. this.getCode(options, param)
  409. // if (this.id_card !== '') {
  410. // // 查询绑定的空调
  411. // this.select_banding_airs()
  412. // }
  413. },
  414. /**
  415. * 获得code
  416. */
  417. getCode(options, param) {
  418. var _this = this;
  419. uni.login({
  420. success: (res) => {
  421. // console.log('getCode', res);
  422. if (res.code) {
  423. if (param == 'get_user_info') {
  424. _this.getUserInfo(res.code)
  425. } else {
  426. // 请求服务器,获得openid
  427. _this.getOpenId(options, res.code)
  428. }
  429. } else {
  430. uni.showToast({
  431. title: res.errMsg,
  432. icon: 'none'
  433. });
  434. }
  435. }
  436. })
  437. },
  438. /**
  439. * 请求服务器,获得openid
  440. */
  441. async getOpenId(options, param_code) {
  442. var _this = this;
  443. if (typeof _this.userinfo === 'object') {
  444. _this.userinfo = JSON.stringify(_this.userinfo)
  445. }
  446. const res = await _this.$myRequest({
  447. host: _this.ceshi,
  448. url: '/airManage/usersopenid.action',
  449. method: 'POST',
  450. header: {
  451. 'content-type': 'application/x-www-form-urlencoded'
  452. },
  453. data: {
  454. code: param_code,
  455. userinfo: _this.userinfo
  456. }
  457. })
  458. // console.log(res.data);
  459. if (res.data.code == 200) {
  460. // 查询用户基本信息
  461. _this.getCode(options, 'get_user_info')
  462. // 绑定成功,提示返回信息,但没必要提示
  463. // uni.showToast({
  464. // title: res.data.message
  465. // })
  466. } else if (res.data.code == 205) {
  467. // 查询用户基本信息
  468. _this.getCode(options, 'get_user_info')
  469. // 用户已经存在,但没必要提示
  470. // uni.showToast({
  471. // title: res.data.message
  472. // })
  473. } else {
  474. // 提示返回信息
  475. uni.showToast({
  476. title: res.data.message
  477. })
  478. if (options && typeof(options.from) != 'undefined' && typeof(options.from) != '') {
  479. uni.navigateTo({
  480. url: '../../pages/index/index?from=' + options.from
  481. })
  482. } else {
  483. uni.redirectTo({
  484. url: '../../pages/index/index?from=0'
  485. });
  486. }
  487. }
  488. },
  489. /**
  490. * 获取用户基本信息
  491. * @param {Object} code
  492. */
  493. async getUserInfo(code) {
  494. var _this = this;
  495. const res = await _this.$myRequest({
  496. host: _this.ceshi,
  497. url: '/airManage/usersget_user.action',
  498. method: 'POST',
  499. header: {
  500. 'content-type': 'application/x-www-form-urlencoded'
  501. },
  502. data: {
  503. code: code
  504. }
  505. });
  506. // console.log(res.data);
  507. if (res.data.code == 200) {
  508. // 余额
  509. _this.balance = res.data.data.balance.toFixed(2);
  510. _this.id_card = res.data.data.sfzh;
  511. // 查询绑定的空调(更新列表)
  512. _this.select_banding_airs();
  513. } else {
  514. uni.showToast({
  515. title: res.data.message
  516. });
  517. }
  518. },
  519. /**
  520. * 长按可解绑
  521. * @param {Object} e
  522. * @param {Object} time
  523. * @param {Object} air_ip
  524. */
  525. itemLongPress(e, time, air_ip) {
  526. // console.log(e, time, air_ip);
  527. var _this = this;
  528. var reg =
  529. /^[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$/;
  530. var regExp = new RegExp(reg);
  531. // if (regExp.test(time) || time == this.time_string) {
  532. if (regExp.test(time)) {
  533. uni.showToast({
  534. title: '使用中不能解绑',
  535. icon: 'error',
  536. duration: 1000
  537. })
  538. } else {
  539. let index = e.currentTarget.dataset.ref
  540. uni.showModal({
  541. title: '提示',
  542. content: '是否解绑该空调?',
  543. success: (res) => {
  544. if (res.confirm) {
  545. // 解绑空调
  546. _this.unbangding_airs(air_ip, index)
  547. }
  548. }
  549. });
  550. }
  551. },
  552. /**
  553. * 解绑空调
  554. * @param {Object} air_ip
  555. * @param {Object} index
  556. */
  557. async unbangding_airs(air_ip, index) {
  558. var _this = this;
  559. const res = await _this.$myRequest({
  560. host: _this.ceshi,
  561. url: '/airManage/usersdelAir.action',
  562. method: 'POST',
  563. header: {
  564. 'content-type': 'application/x-www-form-urlencoded'
  565. },
  566. data: {
  567. sfzh: _this.id_card,
  568. air_ip: air_ip
  569. }
  570. });
  571. // console.log(res.data);
  572. if (res.data.code == 200) {
  573. // 删除指定下标的元素
  574. _this.airs.splice(index, 1);
  575. uni.setStorageSync('airs_selected', _this.airs);
  576. if (_this.airs.length == 0) {
  577. _this.isList = false;
  578. }
  579. uni.showToast({
  580. title: res.data.message
  581. })
  582. } else {
  583. uni.showToast({
  584. title: res.data.message
  585. });
  586. }
  587. },
  588. /**
  589. * 单击了启动或关闭按钮
  590. * @param {Object} e
  591. */
  592. btn_click(index, air_ip, name, info, order_num, time) {
  593. // console.log(index, air_ip, name, info, order_num, time);
  594. var _this = this;
  595. let tmp = name.split('-');
  596. let build = tmp[1],
  597. floors = tmp[2],
  598. dom = tmp[3] + '-' + tmp[4].split(' ')[0];
  599. let air_name = tmp[tmp.length - 1];
  600. // console.log(air_name);
  601. // 未获取到索引
  602. if (typeof index === 'undefined') {
  603. uni.showToast({
  604. title: '索引为空!',
  605. icon: 'none'
  606. });
  607. return;
  608. }
  609. // 获取空调名称
  610. if (typeof air_name === 'undefined') {
  611. uni.showToast({
  612. title: '空调名称为空!',
  613. icon: 'none'
  614. });
  615. return;
  616. }
  617. if (_this.airs[index].on) {
  618. uni.showModal({
  619. title: '提示',
  620. content: '确认【关闭】空调吗?',
  621. success: (res) => {
  622. if (res.confirm) {
  623. // 【关闭】空调
  624. _this.close_airs(index, air_ip, order_num)
  625. }
  626. }
  627. });
  628. } else {
  629. uni.showModal({
  630. title: '提示',
  631. content: '确认【启动】空调吗?',
  632. success: (res) => {
  633. if (res.confirm) {
  634. // 【启动】空调
  635. uni.login({
  636. success: (res) => {
  637. // console.log('getCode', res);
  638. if (res.code) {
  639. // 调用接口,开启空调
  640. _this.open_airs(res.code, index, air_ip, build, floors,
  641. dom, info, air_name)
  642. } else {
  643. uni.showToast({
  644. title: res.errMsg,
  645. icon: 'none'
  646. });
  647. }
  648. }
  649. })
  650. }
  651. }
  652. });
  653. }
  654. },
  655. /**
  656. * 关闭空调
  657. * @param {Object} index
  658. * @param {Object} air_ip
  659. */
  660. async close_airs(index, air_ip, order_num) {
  661. // console.log(index, air_ip, order_num);
  662. if (order_num == '') {
  663. uni.showToast({
  664. title: '未获得单号'
  665. })
  666. return
  667. }
  668. if (this.id_card == '') {
  669. uni.showToast({
  670. title: '未获得身份证号'
  671. })
  672. return
  673. }
  674. uni.showLoading({
  675. title: '关闭中...',
  676. mask: true
  677. });
  678. var _this = this;
  679. const res = await this.$myRequest({
  680. host: _this.ceshi,
  681. url: '/airManage/consumeend.action',
  682. method: 'POST',
  683. header: {
  684. 'content-type': 'application/x-www-form-urlencoded'
  685. },
  686. data: {
  687. sfzh: _this.id_card,
  688. order_num: order_num,
  689. air_ip: air_ip
  690. }
  691. })
  692. if (typeof(res.data) === 'undefined') {
  693. uni.showToast({
  694. title: '请求超时!',
  695. duration: 3000,
  696. success() {
  697. setTimeout(() => {
  698. uni.hideLoading();
  699. }, 1000);
  700. }
  701. });
  702. } else {
  703. // console.log(res.data)
  704. if (res.data.code == 200) {
  705. // 显示已经关闭图标
  706. _this.airs[index].status = '状态:';
  707. _this.airs[index].on = false;
  708. _this.airs[index].time = '未启动';
  709. uni.showToast({
  710. title: '关闭成功!',
  711. duration: 2000,
  712. success() {
  713. // 获取基本信息
  714. _this.get_base_info(_this.options, 'onShow');
  715. setTimeout(() => {
  716. uni.hideLoading();
  717. }, 1000);
  718. }
  719. });
  720. } else {
  721. if (res.data.message.indexOf('已结算') != -1 || res.data.message.indexOf('结算成功') != -1) {
  722. // 显示已经关闭图标
  723. _this.airs[index].status = '状态:';
  724. _this.airs[index].time = '设备已结算';
  725. setTimeout(() => {
  726. uni.hideLoading();
  727. }, 1000);
  728. } else {
  729. // "该空调开启时长超过5天,请联系管理员关闭"
  730. uni.showToast({
  731. icon: 'none',
  732. title: res.data.message,
  733. duration: 3000,
  734. success() {
  735. _this.airs[index].status = '状态:';
  736. _this.airs[index].time = _this.time_string;
  737. setTimeout(() => {
  738. uni.hideLoading();
  739. }, 1000);
  740. }
  741. });
  742. }
  743. }
  744. }
  745. },
  746. /**
  747. * 启动空调
  748. * @param {Object} code
  749. * @param {Object} index
  750. * @param {Object} air_ip
  751. * @param {Object} build
  752. * @param {Object} floors
  753. * @param {Object} dom
  754. * @param {Object} air_config
  755. */
  756. async open_airs(code, index, air_ip, build, floors, dom, air_config, air_name) {
  757. // console.log(code, index, air_ip, build, floors, dom, air_config, air_name);
  758. uni.showLoading({
  759. title: '开启中...',
  760. mask: true
  761. });
  762. var _this = this;
  763. const res = await this.$myRequest({
  764. host: _this.ceshi,
  765. url: '/airManage/consumestart.action',
  766. method: 'POST',
  767. header: {
  768. 'content-type': 'application/x-www-form-urlencoded'
  769. },
  770. data: {
  771. code: code,
  772. air_ip: air_ip,
  773. build: build,
  774. floors: floors,
  775. dom: dom,
  776. air_config: air_config,
  777. air_name: air_name
  778. }
  779. })
  780. if (typeof(res.data) === 'undefined') {
  781. uni.showToast({
  782. title: '请求超时!',
  783. duration: 3000,
  784. success() {
  785. setTimeout(() => {
  786. uni.hideLoading();
  787. }, 1000);
  788. }
  789. });
  790. } else {
  791. // console.log(res.data);
  792. if (res.data.code == 200) {
  793. // 获取订单号
  794. _this.airs[index].order_num = res.data.order_num
  795. uni.showToast({
  796. title: '开启成功!',
  797. duration: 2000,
  798. success() {
  799. // 将开启按钮变成关闭按钮
  800. _this.airs[index].status = '启动时间:';
  801. _this.airs[index].on = true;
  802. _this.airs[index].time = res.data.start_time;
  803. setTimeout(() => {
  804. uni.hideLoading();
  805. }, 1000);
  806. }
  807. });
  808. } else {
  809. // "设备已被其他人使用"
  810. if (res.data.message.indexOf('已被其他人使用') != -1 || res.data.message.indexOf('请勿重复开启' != -1)) {
  811. // 显示已经关闭图标
  812. _this.airs[index].status = '状态:';
  813. _this.airs[index].time = _this.time_string;
  814. setTimeout(() => {
  815. uni.hideLoading();
  816. }, 1000);
  817. } else {
  818. uni.showToast({
  819. icon: 'none',
  820. title: res.data.message,
  821. duration: 2000,
  822. success() {
  823. _this.airs[index].status = '状态:';
  824. _this.airs[index].time = res.data.message;
  825. setTimeout(() => {
  826. uni.hideLoading();
  827. }, 1000);
  828. }
  829. });
  830. }
  831. }
  832. }
  833. },
  834. onRestore() {
  835. this.triggered = true; // 需要重置
  836. },
  837. /**
  838. * 轮播图发生改变
  839. * @param {Object} e
  840. */
  841. swiper_change(e) {
  842. // console.log(e.detail.current);
  843. this.current = e.detail.current;
  844. },
  845. /**
  846. * 计算屏幕的高度, 适配屏幕的高度
  847. */
  848. calc_screen_height() {
  849. uni.getSystemInfo({
  850. success: res => {
  851. let h = 0;
  852. if (this.isList === true) {
  853. h = ((res.screenHeight * (750 / res.windowWidth)) - 640) //将px 转换rpx
  854. } else {
  855. h = ((res.screenHeight * (750 / res.windowWidth)) - 740) //将px 转换rpx
  856. }
  857. this.screenHeight = Math.floor(h) + 'rpx'
  858. }
  859. });
  860. }
  861. }
  862. }
  863. </script>
  864. <style lang="scss" scoped>
  865. .container {
  866. display: flex;
  867. flex-direction: column;
  868. font-size: 28rpx;
  869. font-family: "Microsoft YaHei-3970(82674968)";
  870. width: 730rpx;
  871. padding: 10rpx;
  872. .swiper-box {
  873. height: 150px;
  874. width: 100%;
  875. }
  876. swiper-item {
  877. /* #ifndef APP-NVUE */
  878. display: flex;
  879. /* #endif */
  880. flex-direction: column;
  881. justify-content: center;
  882. align-items: center;
  883. height: 100%;
  884. image {
  885. height: 100%;
  886. width: 100%;
  887. border-radius: 8rpx;
  888. }
  889. }
  890. .line {
  891. height: 20rpx;
  892. }
  893. .nav {
  894. display: flex;
  895. justify-content: space-between;
  896. .btn {
  897. display: flex;
  898. justify-content: space-between;
  899. align-items: center;
  900. width: 338rpx;
  901. height: 100rpx;
  902. padding: 5rpx 10rpx;
  903. border-radius: 8rpx;
  904. background-color: #eaefff;
  905. .btn-icon-tzgl {
  906. display: flex;
  907. align-items: center;
  908. image {
  909. width: 40rpx;
  910. height: 40rpx;
  911. padding: 10rpx;
  912. }
  913. }
  914. .btn-icon {
  915. display: flex;
  916. align-items: center;
  917. image {
  918. width: 60rpx;
  919. height: 60rpx;
  920. }
  921. }
  922. .txt-right {
  923. display: flex;
  924. align-items: center;
  925. }
  926. }
  927. }
  928. .add-air {
  929. border-radius: 8rpx;
  930. padding: 60rpx 10rpx;
  931. background-color: #ffffff;
  932. .add-content {
  933. display: flex;
  934. justify-content: space-around;
  935. align-items: center;
  936. margin-bottom: 20rpx;
  937. .add-left {
  938. display: flex;
  939. .add-btn {
  940. display: flex;
  941. flex-direction: column;
  942. justify-content: center;
  943. align-items: center;
  944. margin-right: 20rpx;
  945. width: 120rpx;
  946. height: 120rpx;
  947. border-radius: 20rpx;
  948. background-color: #2979ff;
  949. color: #ffffff;
  950. }
  951. .add-tip {
  952. display: flex;
  953. flex-direction: column;
  954. justify-content: space-around;
  955. .txt-add-air {
  956. font-size: 40rpx;
  957. font-weight: bold;
  958. }
  959. .txt-tip {
  960. font-size: 20rpx;
  961. color: #8f939c;
  962. }
  963. }
  964. }
  965. .add-right {
  966. width: 300rpx;
  967. height: 100rpx;
  968. border-radius: 10rpx;
  969. image {
  970. width: 300rpx;
  971. height: 100rpx;
  972. }
  973. }
  974. }
  975. .add-bg {
  976. display: flex;
  977. justify-content: center;
  978. align-items: center;
  979. padding-top: 90rpx;
  980. image {
  981. width: 400rpx;
  982. height: 400rpx;
  983. }
  984. }
  985. }
  986. .list-air {
  987. border-radius: 8rpx;
  988. padding: 10rpx 10rpx;
  989. background-color: #e9e9eb;
  990. .list-items {
  991. display: flex;
  992. flex-direction: column;
  993. .item-air {
  994. display: flex;
  995. justify-content: space-between;
  996. padding: 30rpx 20rpx;
  997. border-bottom: 1px solid #c3c8d4;
  998. .item-left {
  999. display: flex;
  1000. flex-direction: column;
  1001. justify-content: space-around;
  1002. .item-icon {
  1003. display: flex;
  1004. align-items: center;
  1005. .circle1 {
  1006. width: 16rpx;
  1007. height: 16rpx;
  1008. border-radius: 8rpx;
  1009. background-color: #18bc37;
  1010. }
  1011. .circle2 {
  1012. width: 12rpx;
  1013. height: 12rpx;
  1014. border-radius: 6rpx;
  1015. background-color: #18bc37;
  1016. margin: 0 10rpx;
  1017. }
  1018. .circle3 {
  1019. display: inline-block;
  1020. width: 8rpx;
  1021. height: 8rpx;
  1022. border-radius: 4rpx;
  1023. background-color: #18bc37;
  1024. }
  1025. }
  1026. .item-title {
  1027. font-size: 32rpx;
  1028. font-weight: bold;
  1029. padding-bottom: 12rpx;
  1030. }
  1031. .item-info {
  1032. display: flex;
  1033. color: #8f939c;
  1034. .item-info-left {
  1035. padding-right: 20rpx;
  1036. }
  1037. .item-info-icon {
  1038. width: 40rpx;
  1039. height: 40rpx;
  1040. margin-right: 8rpx;
  1041. }
  1042. }
  1043. }
  1044. .item-right {
  1045. .item-btn {
  1046. display: flex;
  1047. flex-direction: column;
  1048. justify-content: center;
  1049. align-items: center;
  1050. margin-left: 20rpx;
  1051. width: 100rpx;
  1052. height: 100rpx;
  1053. border: 1px solid #d9deeb;
  1054. border-radius: 50rpx;
  1055. box-shadow: 4rpx 4rpx 5rpx #c8cdd8;
  1056. background-image: linear-gradient(-45deg, #F2F4F2, #DFDFDF);
  1057. image {
  1058. width: 50rpx;
  1059. height: 50rpx;
  1060. }
  1061. .item-txt-on {
  1062. font-size: 24rpx;
  1063. font-weight: bold;
  1064. color: #4B8DFB;
  1065. }
  1066. .item-txt-off {
  1067. font-size: 24rpx;
  1068. font-weight: bold;
  1069. color: #8A8A8A;
  1070. }
  1071. }
  1072. }
  1073. }
  1074. }
  1075. .add-air-bottom {
  1076. display: flex;
  1077. justify-content: center;
  1078. margin: 20rpx 0;
  1079. padding: 20rpx 0;
  1080. width: 160rpx;
  1081. border-radius: 10rpx;
  1082. .add-btn-bottom {
  1083. font-size: 40rpx;
  1084. color: #4B8DFB;
  1085. padding-left: 8rpx;
  1086. }
  1087. }
  1088. }
  1089. }
  1090. </style>