shareAir.vue 26 KB

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