shareAir.vue 26 KB

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