shareAir.vue 27 KB

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