shareAir.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  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. uni.showToast({
  524. title: '使用中不能解绑',
  525. icon: 'error',
  526. duration: 1000
  527. })
  528. } else {
  529. let index = e.currentTarget.dataset.ref
  530. uni.showModal({
  531. title: '提示',
  532. content: '是否解绑该空调?',
  533. success: (res) => {
  534. if (res.confirm) {
  535. // 解绑空调
  536. _this.unbangding_airs(air_ip, index)
  537. }
  538. }
  539. });
  540. }
  541. },
  542. /**
  543. * 解绑空调
  544. * @param {Object} air_ip
  545. * @param {Object} index
  546. */
  547. async unbangding_airs(air_ip, index) {
  548. const res = await this.$myRequest({
  549. host: this.ceshi,
  550. url: '/airManage/usersdelAir.action',
  551. method: 'POST',
  552. header: {
  553. 'content-type': 'application/x-www-form-urlencoded'
  554. },
  555. data: {
  556. sfzh: this.id_card,
  557. air_ip: air_ip
  558. }
  559. });
  560. // console.log(res.data);
  561. if (res.data.code == 200) {
  562. // 删除指定下标的元素
  563. this.airs.splice(index, 1);
  564. uni.setStorageSync('airs_selected', this.airs);
  565. if (this.airs.length == 0) {
  566. this.isList = false;
  567. }
  568. uni.showToast({
  569. title: res.data.message
  570. })
  571. } else {
  572. uni.showToast({
  573. title: res.data.message
  574. });
  575. }
  576. },
  577. /**
  578. * 单击了启动或关闭按钮
  579. * @param {Object} e
  580. */
  581. btn_click(index, air_ip, name, info, order_num, time) {
  582. // console.log(index, air_ip, name, info, order_num, time);
  583. var _this = this;
  584. // if (time === this.time_string) {
  585. // uni.showModal({
  586. // title: '提示',
  587. // content: '其他人员使用中,你不能关闭!',
  588. // confirmText: '好的',
  589. // showCancel: false
  590. // })
  591. // return;
  592. // }
  593. let tmp = name.split('-');
  594. let build = tmp[1],
  595. floors = tmp[2],
  596. dom = tmp[3] + '-' + tmp[4].split(' ')[0];
  597. let air_name = tmp[tmp.length - 1];
  598. // console.log(air_name);
  599. // 未获取到索引
  600. if (typeof index === 'undefined') {
  601. uni.showToast({
  602. title: '索引为空!',
  603. icon: 'none'
  604. });
  605. return;
  606. }
  607. // 获取空调名称
  608. if (typeof air_name === 'undefined') {
  609. uni.showToast({
  610. title: '空调名称为空!',
  611. icon: 'none'
  612. });
  613. return;
  614. }
  615. if (this.airs[index].on) {
  616. uni.showModal({
  617. title: '提示',
  618. content: '确认【关闭】空调吗?',
  619. success: (res) => {
  620. if (res.confirm) {
  621. // 【关闭】空调
  622. _this.close_airs(index, air_ip, order_num)
  623. }
  624. }
  625. });
  626. } else {
  627. uni.showModal({
  628. title: '提示',
  629. content: '确认【启动】空调吗?',
  630. success: (res) => {
  631. if (res.confirm) {
  632. // 【启动】空调
  633. uni.login({
  634. success: (res) => {
  635. // console.log('getCode', res);
  636. if (res.code) {
  637. // 调用接口,开启空调
  638. _this.open_airs(res.code, index, air_ip, build, floors,
  639. dom, info, air_name)
  640. } else {
  641. uni.showToast({
  642. title: res.errMsg,
  643. icon: 'none'
  644. });
  645. }
  646. }
  647. })
  648. }
  649. }
  650. });
  651. }
  652. },
  653. /**
  654. * 关闭空调
  655. * @param {Object} index
  656. * @param {Object} air_ip
  657. */
  658. async close_airs(index, air_ip, order_num) {
  659. // console.log(index, air_ip, order_num);
  660. if (order_num == '') {
  661. uni.showToast({
  662. title: '未获得单号'
  663. })
  664. return
  665. }
  666. if (this.id_card == '') {
  667. uni.showToast({
  668. title: '未获得身份证号'
  669. })
  670. return
  671. }
  672. uni.showLoading({
  673. title: '关闭中...',
  674. mask: true
  675. });
  676. const res = await this.$myRequest({
  677. host: this.ceshi,
  678. url: '/airManage/consumeend.action',
  679. method: 'POST',
  680. header: {
  681. 'content-type': 'application/x-www-form-urlencoded'
  682. },
  683. data: {
  684. sfzh: this.id_card,
  685. order_num: order_num,
  686. air_ip: air_ip
  687. }
  688. })
  689. if (typeof(res.data) === 'undefined') {
  690. uni.showToast({
  691. title: '请求超时!',
  692. duration: 3000,
  693. success() {
  694. setTimeout(() => {
  695. uni.hideLoading();
  696. }, 1000);
  697. }
  698. });
  699. } else {
  700. // console.log(res.data)
  701. if (res.data.code == 200) {
  702. // 显示已经关闭图标
  703. this.airs[index].on = false
  704. this.airs[index].time = '未启动'
  705. uni.showToast({
  706. title: '关闭成功!',
  707. duration: 2000,
  708. success() {
  709. setTimeout(() => {
  710. uni.hideLoading();
  711. }, 1000);
  712. }
  713. });
  714. } else {
  715. if (res.data.message == '该订单已结算,请勿重复结算') {
  716. // 显示已经关闭图标
  717. this.airs[index].on = false
  718. }
  719. uni.showToast({
  720. icon: 'none',
  721. title: res.data.message,
  722. duration: 3000,
  723. success() {
  724. setTimeout(() => {
  725. uni.hideLoading();
  726. }, 1000);
  727. }
  728. })
  729. }
  730. }
  731. },
  732. /**
  733. * 启动空调
  734. * @param {Object} code
  735. * @param {Object} index
  736. * @param {Object} air_ip
  737. * @param {Object} build
  738. * @param {Object} floors
  739. * @param {Object} dom
  740. * @param {Object} air_config
  741. */
  742. async open_airs(code, index, air_ip, build, floors, dom, air_config, air_name) {
  743. // console.log(code, index, air_ip, build, floors, dom, air_config, air_name);
  744. uni.showLoading({
  745. title: '开启中...',
  746. mask: true
  747. });
  748. const res = await this.$myRequest({
  749. host: this.ceshi,
  750. url: '/airManage/consumestart.action',
  751. method: 'POST',
  752. header: {
  753. 'content-type': 'application/x-www-form-urlencoded'
  754. },
  755. data: {
  756. code: code,
  757. air_ip: air_ip,
  758. build: build,
  759. floors: floors,
  760. dom: dom,
  761. air_config: air_config,
  762. air_name: air_name
  763. }
  764. })
  765. if (typeof(res.data) === 'undefined') {
  766. uni.showToast({
  767. title: '请求超时!',
  768. duration: 3000,
  769. success() {
  770. setTimeout(() => {
  771. uni.hideLoading();
  772. }, 1000);
  773. }
  774. });
  775. } else {
  776. // console.log(res.data);
  777. if (res.data.code == 200) {
  778. let _this = this;
  779. // 获取订单号
  780. this.airs[index].order_num = res.data.order_num
  781. uni.showToast({
  782. title: '开启成功!',
  783. duration: 2000,
  784. success() {
  785. // 将开启按钮变成关闭按钮
  786. _this.airs[index].on = true;
  787. _this.airs[index].time = res.data.start_time;
  788. setTimeout(() => {
  789. uni.hideLoading();
  790. }, 1000);
  791. }
  792. });
  793. } else {
  794. uni.showToast({
  795. icon: 'none',
  796. title: res.data.message,
  797. duration: 2000,
  798. success() {
  799. setTimeout(() => {
  800. uni.hideLoading();
  801. }, 1000);
  802. }
  803. })
  804. }
  805. }
  806. },
  807. /**
  808. * 滚动到顶部提示
  809. */
  810. scroll_to_upper() {
  811. uni.showToast({
  812. title: '到顶了!',
  813. icon: 'none',
  814. duration: 500
  815. })
  816. },
  817. /**
  818. * 滚动到底部提示
  819. */
  820. scroll_to_lower() {
  821. uni.showToast({
  822. title: '到底了!',
  823. icon: 'none',
  824. duration: 500
  825. })
  826. },
  827. /**
  828. * 轮播图发生改变
  829. * @param {Object} e
  830. */
  831. swiper_change(e) {
  832. // console.log(e.detail.current);
  833. this.current = e.detail.current;
  834. },
  835. /**
  836. * 计算屏幕的高度, 适配屏幕的高度
  837. */
  838. calc_screen_height() {
  839. uni.getSystemInfo({
  840. success: res => {
  841. let h = 0;
  842. if (this.isList === true) {
  843. h = ((res.screenHeight * (750 / res.windowWidth)) - 640) //将px 转换rpx
  844. } else {
  845. h = ((res.screenHeight * (750 / res.windowWidth)) - 740) //将px 转换rpx
  846. }
  847. this.screenHeight = Math.floor(h) + 'rpx'
  848. }
  849. });
  850. }
  851. }
  852. }
  853. </script>
  854. <style lang="scss" scoped>
  855. .container {
  856. display: flex;
  857. flex-direction: column;
  858. font-size: 28rpx;
  859. font-family: "Microsoft YaHei-3970(82674968)";
  860. width: 730rpx;
  861. padding: 10rpx;
  862. .swiper-box {
  863. height: 150px;
  864. width: 100%;
  865. }
  866. swiper-item {
  867. /* #ifndef APP-NVUE */
  868. display: flex;
  869. /* #endif */
  870. flex-direction: column;
  871. justify-content: center;
  872. align-items: center;
  873. height: 100%;
  874. image {
  875. height: 100%;
  876. width: 100%;
  877. border-radius: 8rpx;
  878. }
  879. }
  880. .line {
  881. height: 20rpx;
  882. }
  883. .nav {
  884. display: flex;
  885. justify-content: space-between;
  886. .btn {
  887. display: flex;
  888. justify-content: space-between;
  889. align-items: center;
  890. width: 338rpx;
  891. height: 100rpx;
  892. padding: 5rpx 10rpx;
  893. border-radius: 8rpx;
  894. background-color: #eaefff;
  895. .btn-icon-tzgl {
  896. display: flex;
  897. align-items: center;
  898. image {
  899. width: 40rpx;
  900. height: 40rpx;
  901. padding: 10rpx;
  902. }
  903. }
  904. .btn-icon {
  905. display: flex;
  906. align-items: center;
  907. image {
  908. width: 60rpx;
  909. height: 60rpx;
  910. }
  911. }
  912. .txt-right {
  913. display: flex;
  914. align-items: center;
  915. }
  916. }
  917. }
  918. .add-air {
  919. border-radius: 8rpx;
  920. padding: 60rpx 10rpx;
  921. background-color: #ffffff;
  922. .add-content {
  923. display: flex;
  924. justify-content: space-around;
  925. align-items: center;
  926. margin-bottom: 20rpx;
  927. .add-left {
  928. display: flex;
  929. .add-btn {
  930. display: flex;
  931. flex-direction: column;
  932. justify-content: center;
  933. align-items: center;
  934. margin-right: 20rpx;
  935. width: 120rpx;
  936. height: 120rpx;
  937. border-radius: 20rpx;
  938. background-color: #2979ff;
  939. color: #ffffff;
  940. }
  941. .add-tip {
  942. display: flex;
  943. flex-direction: column;
  944. justify-content: space-around;
  945. .txt-add-air {
  946. font-size: 40rpx;
  947. font-weight: bold;
  948. }
  949. .txt-tip {
  950. font-size: 20rpx;
  951. color: #8f939c;
  952. }
  953. }
  954. }
  955. .add-right {
  956. width: 300rpx;
  957. height: 100rpx;
  958. border-radius: 10rpx;
  959. image {
  960. width: 300rpx;
  961. height: 100rpx;
  962. }
  963. }
  964. }
  965. .add-bg {
  966. display: flex;
  967. justify-content: center;
  968. align-items: center;
  969. padding-top: 90rpx;
  970. image {
  971. width: 400rpx;
  972. height: 400rpx;
  973. }
  974. }
  975. }
  976. .list-air {
  977. border-radius: 8rpx;
  978. padding: 10rpx 10rpx;
  979. background-color: #e9e9eb;
  980. .list-items {
  981. display: flex;
  982. flex-direction: column;
  983. .item-air {
  984. display: flex;
  985. justify-content: space-between;
  986. padding: 30rpx 20rpx;
  987. border-bottom: 1px solid #c3c8d4;
  988. .item-left {
  989. display: flex;
  990. flex-direction: column;
  991. justify-content: space-around;
  992. .item-icon {
  993. display: flex;
  994. align-items: center;
  995. .circle1 {
  996. width: 16rpx;
  997. height: 16rpx;
  998. border-radius: 8rpx;
  999. background-color: #18bc37;
  1000. }
  1001. .circle2 {
  1002. width: 12rpx;
  1003. height: 12rpx;
  1004. border-radius: 6rpx;
  1005. background-color: #18bc37;
  1006. margin: 0 10rpx;
  1007. }
  1008. .circle3 {
  1009. display: inline-block;
  1010. width: 8rpx;
  1011. height: 8rpx;
  1012. border-radius: 4rpx;
  1013. background-color: #18bc37;
  1014. }
  1015. }
  1016. .item-title {
  1017. font-size: 32rpx;
  1018. font-weight: bold;
  1019. padding-bottom: 12rpx;
  1020. }
  1021. .item-info {
  1022. display: flex;
  1023. color: #8f939c;
  1024. .item-info-left {
  1025. padding-right: 20rpx;
  1026. }
  1027. .item-info-icon {
  1028. width: 40rpx;
  1029. height: 40rpx;
  1030. margin-right: 8rpx;
  1031. }
  1032. }
  1033. }
  1034. .item-right {
  1035. .item-btn {
  1036. display: flex;
  1037. flex-direction: column;
  1038. justify-content: center;
  1039. align-items: center;
  1040. margin-left: 20rpx;
  1041. width: 100rpx;
  1042. height: 100rpx;
  1043. border: 1px solid #d9deeb;
  1044. border-radius: 50rpx;
  1045. box-shadow: 4rpx 4rpx 5rpx #c8cdd8;
  1046. background-image: linear-gradient(-45deg, #F2F4F2, #DFDFDF);
  1047. image {
  1048. width: 50rpx;
  1049. height: 50rpx;
  1050. }
  1051. .item-txt-on {
  1052. font-size: 24rpx;
  1053. font-weight: bold;
  1054. color: #4B8DFB;
  1055. }
  1056. .item-txt-off {
  1057. font-size: 24rpx;
  1058. font-weight: bold;
  1059. color: #8A8A8A;
  1060. }
  1061. }
  1062. }
  1063. }
  1064. }
  1065. .add-air-bottom {
  1066. display: flex;
  1067. justify-content: center;
  1068. margin: 20rpx 0;
  1069. padding: 20rpx 0;
  1070. width: 160rpx;
  1071. border-radius: 10rpx;
  1072. .add-btn-bottom {
  1073. font-size: 40rpx;
  1074. color: #4B8DFB;
  1075. padding-left: 8rpx;
  1076. }
  1077. }
  1078. }
  1079. }
  1080. </style>