shareAir.vue 28 KB

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