shareAir.vue 28 KB

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