shareAir.vue 27 KB

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