shareAir.vue 28 KB

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