shareAir.vue 30 KB

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