shareAir.vue 28 KB

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