shareAir.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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="aspectFill"></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 class="add-bg">
  52. <image src="../static/images/qidong.png" mode="aspectFit"></image>
  53. </view>
  54. </view>
  55. <view class="list-air" v-else>
  56. <scroll-view scroll-y="true" :style="{height: screenHeight}" @scrolltoupper="scroll_to_upper"
  57. @scrolltolower="scroll_to_lower">
  58. <view class="list-items" v-for="(item, index) in airs" :key="index">
  59. <view v-if="item.on" class="item-air" @longpress="itemLongPress($event, 1)">
  60. <view class="item-left">
  61. <view class="item-icon">
  62. <view class="circle1"></view>
  63. <view class="circle2"></view>
  64. <view class="circle3"></view>
  65. </view>
  66. <view class="item-title">{{item.name}}</view>
  67. <view class="item-info">
  68. <text class="item-info-left">{{item.info}}</text>
  69. <text>启用时长:</text><text>{{item.time}}</text>
  70. </view>
  71. </view>
  72. <view class="item-right" @tap="btn_click" :ref="index">
  73. <view class="item-btn">
  74. <image src="../static/images/power-off.png" mode="aspectFit"></image>
  75. <view class="item-txt-off">
  76. 关闭
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. <view v-else class="item-air" @longpress="itemLongPress($event, 0)" :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>未启用</text>
  93. </view>
  94. </view>
  95. <view class="item-right" @tap="btn_click" :ref="index">
  96. <view class="item-btn">
  97. <image src="../static/images/power-on.png" mode="aspectFit"></image>
  98. <view class="item-txt-on">
  99. 启动
  100. </view>
  101. </view>
  102. </view>
  103. </view>
  104. </view>
  105. <navigator 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: 'dev',
  118. stu_number: '',
  119. userinfo: {},
  120. // 滚动横幅的数据
  121. imgUrl: [{
  122. url: this.$code_base_url + '/image/1.png'
  123. },
  124. {
  125. url: this.$code_base_url + '/image/2.png'
  126. },
  127. {
  128. url: this.$code_base_url + '/image/3.png'
  129. }
  130. ],
  131. balance: 0.0.toFixed(2), // 余额
  132. airs: [], // 已经添加的空调列表数据
  133. dotMode: 'round', // 显示控制点样式
  134. current: 0, // 开始显示第几个
  135. isList: false, // 是否显示添加的空调列表
  136. screenHeight: '' // 屏幕的高度
  137. };
  138. },
  139. onLoad(options) {
  140. // 选择绑定了的空调
  141. let airs_selected = uni.getStorageSync('airs_selected')
  142. if (airs_selected.length > 0) {
  143. // 使用存储的列表
  144. this.airs = airs_selected
  145. // 显示添加的空调列表
  146. this.isList = true
  147. }
  148. // 获取基本信息
  149. this.get_base_info(options, 'onLoad')
  150. },
  151. onShow() {
  152. // 从新计算高度
  153. this.calc_screen_height()
  154. // 监听全局的自定义事件,事件由 uni.$emit 触发,但仅触发一次,在第一次触发之后移除该监听器。
  155. // 绑定空调
  156. uni.$once('selectAirs', data => {
  157. // console.log('监听到事件来自 selectAirs ,携带参数 airs 为:' + data.airs);
  158. // this.airs = []
  159. let arrAirs = data.airs.trim().split(',').sort()
  160. let airs = []
  161. let room = '' // 房间名
  162. let temp = true // 没有同名的空调
  163. for (var i = 0; i < arrAirs.length; i++) {
  164. airs = arrAirs[i].trim().split(' ')
  165. // room = airs[0].replaceAll('-', '')
  166. room = airs[0]
  167. for (var j = 1; j < airs.length; j++) {
  168. if (airs[j].trim().length > 0) {
  169. temp = true
  170. for (var k = 0; k < this.airs.length; k++) {
  171. if (this.airs[k].name == room + ' ' + airs[j]) {
  172. temp = false
  173. break
  174. }
  175. }
  176. // 没有同名的
  177. if (temp) {
  178. this.airs.push({
  179. name: room + ' ' + airs[j],
  180. info: '2P空调',
  181. time: '01:25:21',
  182. on: false
  183. })
  184. }
  185. }
  186. }
  187. }
  188. // 如果选的空调不为空,则显示添加的空调列表
  189. if (this.airs.length > 0) {
  190. // 显示添加的空调列表
  191. this.isList = true
  192. }
  193. // 存储空调列表
  194. uni.setStorageSync('airs_selected', this.airs)
  195. // 移除全局自定义事件监听器。
  196. uni.$off('selectAirs')
  197. })
  198. },
  199. methods: {
  200. /**
  201. * 获取基本信息
  202. */
  203. get_base_info(options, param) {
  204. // console.log(options);
  205. try {
  206. // 获取学号
  207. this.stu_number = this.$store.state.userInfo.card_number
  208. if (this.stu_number == '' || typeof(this.stu_number) == 'undefined') { // 学号不存在,可以从存储中拿用户信息
  209. const userinfo = uni.getStorageSync('userinfo_storage_key')
  210. if (userinfo) { // 拿学号
  211. this.stu_number = userinfo.card_number
  212. } else { // 还没有需要跳转到首页进行获取
  213. uni.navigateTo({
  214. url: '../index/index?from=' + options.from
  215. })
  216. uni.showToast({
  217. icon: 'none',
  218. title: '学号为空,请进行授权',
  219. duration: 3000
  220. });
  221. return
  222. }
  223. } else { // 学号已经存在,可以从存储中拿用户信息
  224. this.userinfo = JSON.stringify(uni.getStorageSync('userinfo_storage_key'))
  225. }
  226. } catch (e) {
  227. console.log('获取基本信息:' + e.message);
  228. }
  229. // 获取code
  230. this.getCode(options, param)
  231. },
  232. /**
  233. * 获得code
  234. */
  235. getCode(options, param) {
  236. uni.login({
  237. success: (res) => {
  238. // console.log('getCode', res);
  239. if (res.code) {
  240. if (param == 'get_user_info') {
  241. this.getUserInfo(res.code)
  242. } else {
  243. // 请求服务器,获得openid
  244. this.getOpenId(options, res.code)
  245. }
  246. } else {
  247. uni.showToast({
  248. title: res.errMsg,
  249. icon: 'none'
  250. });
  251. }
  252. }
  253. })
  254. },
  255. /**
  256. * 请求服务器,获得openid
  257. */
  258. async getOpenId(options, param_code) {
  259. const res = await this.$myRequest({
  260. host: this.ceshi,
  261. url: '/airManage/usersopenid.action',
  262. method: 'POST',
  263. header: {
  264. 'content-type': 'application/x-www-form-urlencoded'
  265. },
  266. data: {
  267. code: param_code,
  268. userinfo: this.userinfo
  269. }
  270. })
  271. // console.log(res.data);
  272. if (res.data.code == 200) {
  273. // 查询用户基本信息
  274. this.getCode(options, 'get_user_info')
  275. // 绑定成功,提示返回信息,但没必要提示
  276. // uni.showToast({
  277. // title: res.data.message
  278. // })
  279. } else if (res.data.code == 205) {
  280. // 查询用户基本信息
  281. this.getCode(options, 'get_user_info')
  282. // 用户已经存在,但没必要提示
  283. // uni.showToast({
  284. // title: res.data.message
  285. // })
  286. } else {
  287. // 提示返回信息
  288. uni.showToast({
  289. title: res.data.message
  290. })
  291. if (options && typeof(options.from) != 'undefined' && typeof(options.from) != '') {
  292. uni.navigateTo({
  293. url: '../index/index?from=' + options.from
  294. })
  295. } else {
  296. uni.redirectTo({
  297. url: '../index/index?from=0'
  298. });
  299. }
  300. }
  301. },
  302. /**
  303. * 获取用户基本信息
  304. * @param {Object} code
  305. */
  306. async getUserInfo(code) {
  307. const res = await this.$myRequest({
  308. host: this.ceshi,
  309. url: '/airManage/usersget_user.action',
  310. method: 'POST',
  311. header: {
  312. 'content-type': 'application/x-www-form-urlencoded'
  313. },
  314. data: {
  315. code: code
  316. }
  317. })
  318. // console.log(res.data);
  319. if (res.data.code == 200) {
  320. // 余额
  321. this.balance = res.data.data.balance.toFixed(2)
  322. } else {
  323. uni.showToast({
  324. title: res.data.message
  325. })
  326. }
  327. },
  328. /**
  329. * 长按可删除
  330. * @param {Object} e
  331. * @param {Object} val
  332. */
  333. itemLongPress(e, val) {
  334. // console.log(e, val);
  335. if (val == 0) {
  336. let index = e.currentTarget.dataset.ref
  337. uni.showModal({
  338. title: '提示',
  339. content: '是否删除该空调?',
  340. success: (res) => {
  341. if (res.confirm) {
  342. // 删除指定下标的元素
  343. this.airs.splice(index, 1)
  344. // 更新存储
  345. uni.setStorageSync('airs_selected', this.airs)
  346. }
  347. }
  348. })
  349. } else {
  350. uni.showToast({
  351. title: '使用中不能删除',
  352. icon: 'error',
  353. duration: 1000
  354. })
  355. }
  356. },
  357. /**
  358. * 单击了启动或关闭按钮
  359. * @param {Object} e
  360. */
  361. btn_click(e) {
  362. // console.log(e.currentTarget.dataset.ref);
  363. let index_btn = e.currentTarget.dataset.ref
  364. // 未获取到索引
  365. if (typeof index_btn === 'undefined') {
  366. return
  367. }
  368. if (this.airs[index_btn].on) {
  369. uni.showModal({
  370. title: '提示',
  371. content: '确认【关闭】空调吗?',
  372. success: (res) => {
  373. if (res.confirm) {
  374. // 操作【关闭】空调
  375. this.airs[index_btn].on = false
  376. }
  377. }
  378. });
  379. } else {
  380. uni.showModal({
  381. title: '提示',
  382. content: '确认【启动】空调吗?',
  383. success: (res) => {
  384. if (res.confirm) {
  385. // 操作【启动】空调
  386. this.airs[index_btn].on = true
  387. }
  388. }
  389. });
  390. }
  391. },
  392. /**
  393. * 滚动到顶部提示
  394. */
  395. scroll_to_upper() {
  396. uni.showToast({
  397. title: '到顶了!',
  398. icon: 'none',
  399. duration: 500
  400. })
  401. },
  402. /**
  403. * 滚动到底部提示
  404. */
  405. scroll_to_lower() {
  406. uni.showToast({
  407. title: '到底了!',
  408. icon: 'none',
  409. duration: 500
  410. })
  411. },
  412. /**
  413. * 轮播图发生改变
  414. * @param {Object} e
  415. */
  416. swiper_change(e) {
  417. // console.log(e.detail.current);
  418. this.current = e.detail.current;
  419. },
  420. /**
  421. * 计算屏幕的高度, 适配屏幕的高度
  422. */
  423. calc_screen_height() {
  424. uni.getSystemInfo({
  425. success: res => {
  426. let h = 0;
  427. if (this.isList === true) {
  428. h = ((res.screenHeight * (750 / res.windowWidth)) - 640) //将px 转换rpx
  429. } else {
  430. h = ((res.screenHeight * (750 / res.windowWidth)) - 740) //将px 转换rpx
  431. }
  432. this.screenHeight = Math.floor(h) + 'rpx'
  433. }
  434. });
  435. }
  436. }
  437. }
  438. </script>
  439. <style lang="scss" scoped>
  440. .container {
  441. display: flex;
  442. flex-direction: column;
  443. font-size: 28rpx;
  444. font-family: "Microsoft YaHei-3970(82674968)";
  445. width: 730rpx;
  446. padding: 10rpx;
  447. .swiper-box {
  448. height: 150px;
  449. width: 100%;
  450. }
  451. swiper-item {
  452. /* #ifndef APP-NVUE */
  453. display: flex;
  454. /* #endif */
  455. flex-direction: column;
  456. justify-content: center;
  457. align-items: center;
  458. height: 100%;
  459. image {
  460. height: 100%;
  461. width: 100%;
  462. border-radius: 8rpx;
  463. }
  464. }
  465. .line {
  466. height: 20rpx;
  467. }
  468. .nav {
  469. display: flex;
  470. justify-content: space-between;
  471. .btn {
  472. display: flex;
  473. justify-content: space-between;
  474. align-items: center;
  475. width: 338rpx;
  476. height: 100rpx;
  477. padding: 5rpx 10rpx;
  478. border-radius: 8rpx;
  479. background-color: #eaefff;
  480. .btn-icon-tzgl {
  481. display: flex;
  482. align-items: center;
  483. image {
  484. width: 40rpx;
  485. height: 40rpx;
  486. padding: 10rpx;
  487. }
  488. }
  489. .btn-icon {
  490. display: flex;
  491. align-items: center;
  492. image {
  493. width: 60rpx;
  494. height: 60rpx;
  495. }
  496. }
  497. .txt-right {
  498. display: flex;
  499. align-items: center;
  500. }
  501. }
  502. }
  503. .add-air {
  504. border-radius: 8rpx;
  505. padding: 60rpx 10rpx;
  506. background-color: #F1F1F1;
  507. .add-content {
  508. display: flex;
  509. justify-content: space-around;
  510. align-items: center;
  511. margin-bottom: 20rpx;
  512. .add-left {
  513. display: flex;
  514. .add-btn {
  515. display: flex;
  516. flex-direction: column;
  517. justify-content: center;
  518. align-items: center;
  519. margin-right: 20rpx;
  520. width: 120rpx;
  521. height: 120rpx;
  522. border-radius: 20rpx;
  523. background-color: #2979ff;
  524. color: #ffffff;
  525. }
  526. .add-tip {
  527. display: flex;
  528. flex-direction: column;
  529. justify-content: space-around;
  530. .txt-add-air {
  531. font-size: 40rpx;
  532. font-weight: bold;
  533. }
  534. .txt-tip {
  535. font-size: 20rpx;
  536. color: #8f939c;
  537. }
  538. }
  539. }
  540. .add-right {
  541. width: 300rpx;
  542. height: 100rpx;
  543. border-radius: 10rpx;
  544. image {
  545. width: 300rpx;
  546. height: 100rpx;
  547. }
  548. }
  549. }
  550. .add-bg {
  551. display: flex;
  552. justify-content: center;
  553. align-items: center;
  554. padding-top: 90rpx;
  555. image {
  556. width: 400rpx;
  557. height: 400rpx;
  558. }
  559. }
  560. }
  561. .list-air {
  562. border-radius: 8rpx;
  563. padding: 10rpx 10rpx;
  564. background-color: #e9e9eb;
  565. .list-items {
  566. display: flex;
  567. flex-direction: column;
  568. .item-air {
  569. display: flex;
  570. justify-content: space-between;
  571. padding: 30rpx 20rpx;
  572. border-bottom: 1px solid #c3c8d4;
  573. .item-left {
  574. display: flex;
  575. flex-direction: column;
  576. justify-content: space-around;
  577. .item-icon {
  578. display: flex;
  579. align-items: center;
  580. .circle1 {
  581. width: 16rpx;
  582. height: 16rpx;
  583. border-radius: 8rpx;
  584. background-color: #18bc37;
  585. }
  586. .circle2 {
  587. width: 12rpx;
  588. height: 12rpx;
  589. border-radius: 6rpx;
  590. background-color: #18bc37;
  591. margin: 0 10rpx;
  592. }
  593. .circle3 {
  594. display: inline-block;
  595. width: 8rpx;
  596. height: 8rpx;
  597. border-radius: 4rpx;
  598. background-color: #18bc37;
  599. }
  600. }
  601. .item-title {
  602. font-size: 32rpx;
  603. font-weight: bold;
  604. padding-bottom: 12rpx;
  605. }
  606. .item-info {
  607. display: flex;
  608. color: #8f939c;
  609. .item-info-left {
  610. padding-right: 20rpx;
  611. }
  612. .item-info-icon {
  613. width: 40rpx;
  614. height: 40rpx;
  615. margin-right: 8rpx;
  616. }
  617. }
  618. }
  619. .item-right {
  620. .item-btn {
  621. display: flex;
  622. flex-direction: column;
  623. justify-content: center;
  624. align-items: center;
  625. width: 100rpx;
  626. height: 100rpx;
  627. border: 1px solid #d9deeb;
  628. border-radius: 50rpx;
  629. box-shadow: 4rpx 4rpx 5rpx #c8cdd8;
  630. background-image: linear-gradient(-45deg, #F2F4F2, #DFDFDF);
  631. image {
  632. width: 50rpx;
  633. height: 50rpx;
  634. }
  635. .item-txt-on {
  636. font-size: 24rpx;
  637. font-weight: bold;
  638. color: #4B8DFB;
  639. }
  640. .item-txt-off {
  641. font-size: 24rpx;
  642. font-weight: bold;
  643. color: #8A8A8A;
  644. }
  645. }
  646. }
  647. }
  648. }
  649. .add-air-bottom {
  650. display: flex;
  651. justify-content: center;
  652. margin: 20rpx 0;
  653. padding: 20rpx 0;
  654. width: 160rpx;
  655. border-radius: 10rpx;
  656. .add-btn-bottom {
  657. font-size: 40rpx;
  658. color: #4B8DFB;
  659. padding-left: 8rpx;
  660. }
  661. }
  662. }
  663. }
  664. </style>