shareAir.vue 26 KB

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