shareAir.vue 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  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="aspectFill"></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 class="add-bg">
  52. <image src="../static/images/qidong.png" mode="aspectFit"></image>
  53. </view>
  54. </view>
  55. <view class="list-air" v-else>
  56. <scroll-view scroll-y="true" :style="{height: screenHeight}" @scrolltoupper="scroll_to_upper"
  57. @scrolltolower="scroll_to_lower">
  58. <view class="list-items" v-for="(item, index) in airs" :key="index">
  59. <view v-if="item.on === true" class="item-air" @longpress="itemLongPress($event, 1, item.air_ip)">
  60. <view class="item-left">
  61. <view class="item-icon">
  62. <view class="circle1"></view>
  63. <view class="circle2"></view>
  64. <view class="circle3"></view>
  65. </view>
  66. <view class="item-title">{{item.name}}</view>
  67. <view class="item-info">
  68. <text class="item-info-left">{{item.info}}</text>
  69. <text>启动时间:</text><text>{{item.time}}</text>
  70. </view>
  71. </view>
  72. <view class="item-right"
  73. @tap="btn_click(index, item.air_ip, item.name, item.info, item.order_num)">
  74. <view class="item-btn">
  75. <image src="../static/images/power-off.png" mode="aspectFit"></image>
  76. <view class="item-txt-off">
  77. 关闭
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. <view v-else class="item-air" @longpress="itemLongPress($event, 0, item.air_ip)" :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}}</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 v-if="item.time !== ''">{{item.time}}</text>
  94. <text v-else>未启动</text>
  95. </view>
  96. </view>
  97. <view class="item-right" v-if="item.abnormal == 1"
  98. @tap="btn_click(index, item.air_ip, item.name, item.info, item.order_num)" :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. };
  152. },
  153. onLoad(options) {
  154. this.options = options
  155. try {
  156. // 选择绑定了的空调
  157. let airs_selected = uni.getStorageSync('airs_selected')
  158. if (airs_selected.length > 0) {
  159. // 使用存储的列表
  160. this.selectAirs = airs_selected
  161. }
  162. } catch (e) {
  163. console.log('读取空调相关信息:' + e.message);
  164. }
  165. },
  166. onShow() {
  167. // 从新计算高度
  168. this.calc_screen_height()
  169. // 监听全局的自定义事件,事件由 uni.$emit 触发,但仅触发一次,在第一次触发之后移除该监听器。
  170. // 绑定空调
  171. uni.$once('selectAirs', data => {
  172. // console.log(data.airs);
  173. let arrAirs = data.airs.trim().split(',')
  174. for (var i = 0; i < arrAirs.length; i++) {
  175. let tmpAirs = arrAirs[i].split('|')
  176. let t = tmpAirs[1].split('-')
  177. let tf = true
  178. for (var j = 0; j < this.selectAirs.length; j++) {
  179. if (this.selectAirs[j].air_ip == tmpAirs[2]) {
  180. tf = false
  181. }
  182. }
  183. // 存在则不添加到数组和缓存
  184. if (true === tf) {
  185. this.selectAirs.push({
  186. air_ip: tmpAirs[2],
  187. name: tmpAirs[0] + ' ' + t[0],
  188. info: t[1],
  189. time: '',
  190. abnormal: 1,
  191. on: false, // true开启了,false关闭了
  192. order_num: '' // 订单号
  193. })
  194. }
  195. }
  196. // 如果选的空调不为空,则显示添加的空调列表
  197. if (this.selectAirs.length > 0) {
  198. // 去重
  199. const newArr = [...new Set(this.selectAirs.map(e => JSON.stringify(e)))].map(e => JSON.parse(
  200. e));
  201. this.selectAirs = newArr
  202. }
  203. // 存储空调列表
  204. uni.setStorageSync('airs_selected', this.selectAirs)
  205. // 移除全局自定义事件监听器。
  206. uni.$off('selectAirs')
  207. });
  208. // 获取基本信息
  209. this.get_base_info(this.options, 'onShow')
  210. setTimeout(() => {
  211. uni.hideLoading();
  212. }, 3000)
  213. },
  214. methods: {
  215. /**
  216. * 查询绑定的空调
  217. */
  218. async select_banding_airs() {
  219. const res = await this.$myRequest({
  220. host: this.ceshi,
  221. url: '/airManage/usersqueryAir.action',
  222. method: 'POST',
  223. header: {
  224. 'content-type': 'application/x-www-form-urlencoded'
  225. },
  226. data: {
  227. sfzh: this.id_card
  228. }
  229. })
  230. // console.log(res.data);
  231. if (res.data.code == 200) {
  232. let data = res.data.data
  233. if (data.length > 0) {
  234. this.airs = []
  235. let tmpAirs = []
  236. for (var i = 0; i < data.length; i++) {
  237. tmpAirs.push({
  238. air_ip: data[i].air_ip,
  239. name: data[i].school + '-' + data[i].build + '-' + data[i].floors + '-' + data[i].dom +
  240. '-' + data[i].air_name,
  241. info: data[i].air_config,
  242. time: '',
  243. abnormal: data[i].is_normal,
  244. on: data[i].is_on, // true开启了,false关闭了
  245. order_num: '' // 订单号
  246. })
  247. // for (var j = 0; j < this.selectAirs.length; j++) {
  248. // if (this.selectAirs[j].air_ip == data[i].air_ip) {
  249. // tmpAirs.push(this.selectAirs[j])
  250. // break
  251. // }
  252. // }
  253. }
  254. // 不为空
  255. if (tmpAirs.length > 0) {
  256. // 按名称排序
  257. tmpAirs.sort((a, b) => a.name.localeCompare(b.name));
  258. let _this = this;
  259. // 遍历状态
  260. for (var i = 0; i < tmpAirs.length; i++) {
  261. // 获取空调状态
  262. (function(t, tmpAirs) { // 注意这里是形参
  263. setTimeout(function() {
  264. _this.readAirsStatus(tmpAirs, t);
  265. }, 100 * t); // 还是0.1秒执行一次,不是累加的
  266. })(i, tmpAirs) // 注意这里是实参,这里把要用的参数传进去
  267. }
  268. setTimeout(() => {
  269. if (this.airs.length > 0) {
  270. // 显示添加的空调列表
  271. _this.isList = true
  272. }
  273. }, 300)
  274. }
  275. } else {
  276. // 隐藏添加的空调列表
  277. this.isList = false
  278. }
  279. } else if (res.data.code == 205) {
  280. // 隐藏添加的空调列表
  281. this.isList = false
  282. } else {
  283. // 隐藏添加的空调列表
  284. this.isList = false
  285. // 提示返回信息
  286. uni.showToast({
  287. title: res.data.message
  288. })
  289. }
  290. // 隐藏加载
  291. uni.hideLoading();
  292. },
  293. /**
  294. * 获取绑定的空调的状态
  295. * @param {Object} tmpAirs
  296. * @param {Object} index
  297. */
  298. async readAirsStatus(tmpAirs, index) {
  299. const res = await this.$myRequest({
  300. host: this.ceshi,
  301. url: '/airManage/consumeStatus.action',
  302. method: 'POST',
  303. header: {
  304. 'content-type': 'application/x-www-form-urlencoded'
  305. },
  306. data: {
  307. air_ip: tmpAirs[index].air_ip,
  308. sfzh: this.id_card
  309. }
  310. })
  311. // console.log(res.data, tmpAirs[index].air_ip);
  312. if (res.data.code == 200) {
  313. let data = res.data;
  314. if (data.is_on == 1) {
  315. if (typeof data.order_num === 'undefined') {
  316. // 提示返回信息
  317. // uni.showToast({
  318. // icon: 'none',
  319. // title: '其他人员使用中!',
  320. // duration: 3000
  321. // })
  322. tmpAirs[index].time = '未知(其他人员使用中)'
  323. } else {
  324. tmpAirs[index].time = data.start_time
  325. }
  326. tmpAirs[index].on = true
  327. tmpAirs[index].order_num = data.order_num
  328. } else {
  329. tmpAirs[index].on = false
  330. tmpAirs[index].time = ''
  331. tmpAirs[index].order_num = ''
  332. }
  333. // 更新自己绑定的空调列表
  334. this.airs.push(tmpAirs[index])
  335. } else if (res.data.code !== 200) {
  336. tmpAirs[index].time = res.data.message;
  337. // 更新自己绑定的空调列表
  338. this.airs.push(tmpAirs[index])
  339. } else {
  340. // uni.showToast({
  341. // icon: 'none',
  342. // title: tmpAirs[index].air_ip + ' ' + res.data.message,
  343. // duration: 3000
  344. // })
  345. // console.log(tmpAirs[index].air_ip + ' ' + res.data.message);
  346. }
  347. },
  348. /**
  349. * 获取基本信息
  350. */
  351. get_base_info(options, param) {
  352. // console.log(options);
  353. uni.showLoading({
  354. title: '加载中',
  355. mask: true
  356. })
  357. // 获取学号
  358. this.stu_number = this.$store.state.userInfo.card_number
  359. try {
  360. if (this.stu_number == '' || typeof(this.stu_number) == 'undefined') { // 学号不存在,可以从存储中拿用户信息
  361. const userinfo = uni.getStorageSync('userinfo_storage_key')
  362. if (userinfo) { // 拿学号
  363. this.userinfo = userinfo
  364. this.stu_number = userinfo.card_number
  365. this.id_card = userinfo.id_card
  366. } else { // 还没有需要跳转到首页进行获取
  367. uni.navigateTo({
  368. url: '../index/index?from=' + options.from
  369. })
  370. uni.showToast({
  371. icon: 'none',
  372. title: '学号为空,请进行授权',
  373. duration: 3000
  374. });
  375. return
  376. }
  377. } else { // 学号已经存在,可以从存储中拿用户信息
  378. this.userinfo = JSON.stringify(uni.getStorageSync('userinfo_storage_key'))
  379. }
  380. } catch (e) {
  381. console.log('获取基本信息:' + e.message);
  382. }
  383. // 获取code
  384. this.getCode(options, param)
  385. // if (this.id_card !== '') {
  386. // // 查询绑定的空调
  387. // this.select_banding_airs()
  388. // }
  389. },
  390. /**
  391. * 获得code
  392. */
  393. getCode(options, param) {
  394. uni.login({
  395. success: (res) => {
  396. // console.log('getCode', res);
  397. if (res.code) {
  398. if (param == 'get_user_info') {
  399. this.getUserInfo(res.code)
  400. } else {
  401. // 请求服务器,获得openid
  402. this.getOpenId(options, res.code)
  403. }
  404. } else {
  405. uni.showToast({
  406. title: res.errMsg,
  407. icon: 'none'
  408. });
  409. }
  410. }
  411. })
  412. },
  413. /**
  414. * 请求服务器,获得openid
  415. */
  416. async getOpenId(options, param_code) {
  417. if (typeof this.userinfo === 'object') {
  418. this.userinfo = JSON.stringify(this.userinfo)
  419. }
  420. const res = await this.$myRequest({
  421. host: this.ceshi,
  422. url: '/airManage/usersopenid.action',
  423. method: 'POST',
  424. header: {
  425. 'content-type': 'application/x-www-form-urlencoded'
  426. },
  427. data: {
  428. code: param_code,
  429. userinfo: this.userinfo
  430. }
  431. })
  432. // console.log(res.data);
  433. if (res.data.code == 200) {
  434. // 查询用户基本信息
  435. this.getCode(options, 'get_user_info')
  436. // 绑定成功,提示返回信息,但没必要提示
  437. // uni.showToast({
  438. // title: res.data.message
  439. // })
  440. } else if (res.data.code == 205) {
  441. // 查询用户基本信息
  442. this.getCode(options, 'get_user_info')
  443. // 用户已经存在,但没必要提示
  444. // uni.showToast({
  445. // title: res.data.message
  446. // })
  447. } else {
  448. // 提示返回信息
  449. uni.showToast({
  450. title: res.data.message
  451. })
  452. if (options && typeof(options.from) != 'undefined' && typeof(options.from) != '') {
  453. uni.navigateTo({
  454. url: '../index/index?from=' + options.from
  455. })
  456. } else {
  457. uni.redirectTo({
  458. url: '../index/index?from=0'
  459. });
  460. }
  461. }
  462. },
  463. /**
  464. * 获取用户基本信息
  465. * @param {Object} code
  466. */
  467. async getUserInfo(code) {
  468. const res = await this.$myRequest({
  469. host: this.ceshi,
  470. url: '/airManage/usersget_user.action',
  471. method: 'POST',
  472. header: {
  473. 'content-type': 'application/x-www-form-urlencoded'
  474. },
  475. data: {
  476. code: code
  477. }
  478. })
  479. // console.log(res.data);
  480. if (res.data.code == 200) {
  481. // 余额
  482. this.balance = res.data.data.balance.toFixed(2)
  483. this.id_card = res.data.data.sfzh
  484. if (this.isList == false) {
  485. // 查询绑定的空调
  486. this.select_banding_airs()
  487. }
  488. } else {
  489. uni.showToast({
  490. title: res.data.message
  491. })
  492. }
  493. },
  494. /**
  495. * 长按可删除
  496. * @param {Object} e
  497. * @param {Object} val
  498. */
  499. itemLongPress(e, val, air_ip) {
  500. // console.log(e, val, air_ip);
  501. if (val == 0) {
  502. let index = e.currentTarget.dataset.ref
  503. uni.showModal({
  504. title: '提示',
  505. content: '是否删除该空调?',
  506. success: (res) => {
  507. if (res.confirm) {
  508. // 解绑空调
  509. this.unbangding_airs(air_ip, index)
  510. }
  511. }
  512. })
  513. } else {
  514. uni.showToast({
  515. title: '使用中不能删除',
  516. icon: 'error',
  517. duration: 1000
  518. })
  519. }
  520. },
  521. /**
  522. * 解绑空调
  523. * @param {Object} air_ip
  524. * @param {Object} index
  525. */
  526. async unbangding_airs(air_ip, index) {
  527. const res = await this.$myRequest({
  528. host: this.ceshi,
  529. url: '/airManage/usersdelAir.action',
  530. method: 'POST',
  531. header: {
  532. 'content-type': 'application/x-www-form-urlencoded'
  533. },
  534. data: {
  535. sfzh: this.id_card,
  536. air_ip: air_ip
  537. }
  538. })
  539. // console.log(res.data);
  540. if (res.data.code == 200) {
  541. // 删除指定下标的元素
  542. this.airs.splice(index, 1)
  543. if (this.airs.length == 0) {
  544. this.isList = false
  545. }
  546. uni.showToast({
  547. title: res.data.message
  548. })
  549. } else {
  550. uni.showToast({
  551. title: res.data.message
  552. })
  553. }
  554. },
  555. /**
  556. * 单击了启动或关闭按钮
  557. * @param {Object} e
  558. */
  559. btn_click(index, air_ip, name, info, order_num) {
  560. // console.log(index, air_ip, name, info, order_num);
  561. let tmp = name.split('-');
  562. let build = tmp[1],
  563. floors = tmp[2],
  564. dom = tmp[3] + '-' + tmp[4].split(' ')[0];
  565. let air_name = name.split(' ')[1]
  566. // 未获取到索引
  567. if (typeof index === 'undefined') {
  568. return
  569. }
  570. if (this.airs[index].on) {
  571. uni.showModal({
  572. title: '提示',
  573. content: '确认【关闭】空调吗?',
  574. success: (res) => {
  575. if (res.confirm) {
  576. // 【关闭】空调
  577. this.close_airs(index, air_ip, order_num)
  578. }
  579. }
  580. });
  581. } else {
  582. uni.showModal({
  583. title: '提示',
  584. content: '确认【启动】空调吗?',
  585. success: (res) => {
  586. if (res.confirm) {
  587. // 【启动】空调
  588. uni.login({
  589. success: (res) => {
  590. // console.log('getCode', res);
  591. if (res.code) {
  592. // 调用接口,开启空调
  593. this.open_airs(res.code, index, air_ip, build, floors,
  594. dom, info, air_name)
  595. } else {
  596. uni.showToast({
  597. title: res.errMsg,
  598. icon: 'none'
  599. });
  600. }
  601. }
  602. })
  603. }
  604. }
  605. });
  606. }
  607. },
  608. /**
  609. * 关闭空调
  610. * @param {Object} index
  611. * @param {Object} air_ip
  612. */
  613. async close_airs(index, air_ip, order_num) {
  614. if (order_num == '') {
  615. uni.showToast({
  616. title: '未获得单号'
  617. })
  618. return
  619. }
  620. if (this.id_card == '') {
  621. uni.showToast({
  622. title: '未获得身份证号'
  623. })
  624. return
  625. }
  626. const res = await this.$myRequest({
  627. host: this.ceshi,
  628. url: '/airManage/consumeend.action',
  629. method: 'POST',
  630. header: {
  631. 'content-type': 'application/x-www-form-urlencoded'
  632. },
  633. data: {
  634. sfzh: this.id_card,
  635. order_num: order_num,
  636. air_ip: air_ip
  637. }
  638. })
  639. // console.log(res.data)
  640. if (res.data.code == 200) {
  641. // 等待4s
  642. uni.showLoading({
  643. title: '关闭中...',
  644. mask: true
  645. });
  646. // 延时4s看关闭状态
  647. let _this = this;
  648. setTimeout(() => {
  649. // 查询是否关闭成功
  650. _this.selectAirCloseState(index, air_ip, order_num)
  651. }, 4000);
  652. } else {
  653. if (res.data.message == '该订单已结算,请勿重复结算') {
  654. // 显示已经关闭图标
  655. this.airs[index].on = false
  656. }
  657. uni.showToast({
  658. icon: 'none',
  659. title: res.data.message,
  660. duration: 3000
  661. })
  662. }
  663. },
  664. /**
  665. * 查询是否关闭成功
  666. * @param {Object} index
  667. * @param {Object} air_ip
  668. */
  669. async selectAirCloseState(index, air_ip, order_num) {
  670. // console.log(index, air_ip);
  671. const res = await this.$myRequest({
  672. host: this.ceshi,
  673. url: '/airManage/consumeairoffStatus.action',
  674. method: 'POST',
  675. header: {
  676. 'content-type': 'application/x-www-form-urlencoded'
  677. },
  678. data: {
  679. air_ip: air_ip,
  680. order_num: order_num
  681. }
  682. })
  683. // console.log(res.data);
  684. if (res.data.code == 200) {
  685. if (res.data.is_on == 0) {
  686. // 显示已经关闭图标
  687. this.airs[index].on = false
  688. uni.showToast({
  689. title: '关闭成功!',
  690. duration: 2000
  691. });
  692. } else {
  693. uni.showToast({
  694. icon: 'none',
  695. title: '关闭失败!',
  696. duration: 2000
  697. });
  698. }
  699. uni.hideLoading();
  700. } else {
  701. uni.showToast({
  702. icon: 'none',
  703. title: res.data.message,
  704. duration: 2000
  705. });
  706. }
  707. },
  708. /**
  709. * 启动空调
  710. * @param {Object} code
  711. * @param {Object} index
  712. * @param {Object} air_ip
  713. * @param {Object} build
  714. * @param {Object} floors
  715. * @param {Object} dom
  716. * @param {Object} air_config
  717. */
  718. async open_airs(code, index, air_ip, build, floors, dom, air_config, air_name) {
  719. const res = await this.$myRequest({
  720. host: this.ceshi,
  721. url: '/airManage/consumestart.action',
  722. method: 'POST',
  723. header: {
  724. 'content-type': 'application/x-www-form-urlencoded'
  725. },
  726. data: {
  727. code: code,
  728. air_ip: air_ip,
  729. build: build,
  730. floors: floors,
  731. dom: dom,
  732. air_config: air_config,
  733. air_name: air_name
  734. }
  735. })
  736. // console.log(res.data);
  737. if (res.data.code == 200) {
  738. // 等待4s
  739. uni.showLoading({
  740. title: '开启中...',
  741. mask: true
  742. });
  743. let _this = this;
  744. // 获取订单号
  745. this.airs[index].order_num = res.data.order_num
  746. // 延时4s看开启状态
  747. setTimeout(() => {
  748. // 查询是否开启成功
  749. _this.selectAirOpenState(index, air_ip)
  750. }, 4000);
  751. } else {
  752. uni.showToast({
  753. icon: 'none',
  754. title: res.data.message,
  755. duration: 2000
  756. })
  757. }
  758. },
  759. /**
  760. * 查询是否开启成功
  761. * @param {Object} index
  762. * @param {Object} air_ip
  763. */
  764. async selectAirOpenState(index, air_ip) {
  765. // console.log(index, air_ip);
  766. const res = await this.$myRequest({
  767. host: this.ceshi,
  768. url: '/airManage/consumeairStatus.action',
  769. method: 'POST',
  770. header: {
  771. 'content-type': 'application/x-www-form-urlencoded'
  772. },
  773. data: {
  774. air_ip: air_ip,
  775. order_num: this.airs[index].order_num
  776. }
  777. })
  778. // console.log(res.data);
  779. if (res.data.code == 200) {
  780. if (res.data.is_on === '1') {
  781. let _this = this
  782. uni.showToast({
  783. title: '开启成功!',
  784. duration: 2000,
  785. success() {
  786. // 将开启按钮变成关闭按钮
  787. _this.airs[index].on = true;
  788. _this.airs[index].time = res.data.start_time;
  789. }
  790. });
  791. } else {
  792. uni.showToast({
  793. title: '开启失败!',
  794. duration: 2000
  795. });
  796. }
  797. uni.hideLoading();
  798. } else {
  799. uni.showToast({
  800. icon: 'none',
  801. title: res.data.message,
  802. duration: 2000
  803. });
  804. }
  805. },
  806. /**
  807. * 滚动到顶部提示
  808. */
  809. scroll_to_upper() {
  810. uni.showToast({
  811. title: '到顶了!',
  812. icon: 'none',
  813. duration: 500
  814. })
  815. },
  816. /**
  817. * 滚动到底部提示
  818. */
  819. scroll_to_lower() {
  820. uni.showToast({
  821. title: '到底了!',
  822. icon: 'none',
  823. duration: 500
  824. })
  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: #F1F1F1;
  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>