shareAir.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <template>
  2. <view class="container">
  3. <uni-swiper-dot :info="info" :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 info" :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. // 滚动横幅的数据
  118. info: [{
  119. url: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/094a9dc0-50c0-11eb-b680-7980c8a877b8.jpg'
  120. },
  121. {
  122. url: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/094a9dc0-50c0-11eb-b680-7980c8a877b8.jpg'
  123. },
  124. {
  125. url: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/094a9dc0-50c0-11eb-b680-7980c8a877b8.jpg'
  126. }
  127. ],
  128. current: 0, // 开始显示第几个
  129. dotMode: 'round', // 显示控制点样式
  130. balance: 18.88, // 余额
  131. isList: false, // 是否显示添加的空调列表
  132. airs: [], // 已经添加的空调列表数据
  133. screenHeight: '' // 屏幕的高度
  134. };
  135. },
  136. onLoad() {
  137. let airs_selected = uni.getStorageSync('airs_selected')
  138. if (airs_selected.length > 0) {
  139. // 使用存储的列表
  140. this.airs = airs_selected
  141. // 显示添加的空调列表
  142. this.isList = true
  143. }
  144. },
  145. onShow() {
  146. // 从新计算高度
  147. this.calc_screen_height()
  148. // 监听全局的自定义事件,事件由 uni.$emit 触发,但仅触发一次,在第一次触发之后移除该监听器。
  149. uni.$once('selectAirs', data => {
  150. // console.log('监听到事件来自 selectAirs ,携带参数 airs 为:' + data.airs);
  151. // this.airs = []
  152. let arrAirs = data.airs.trim().split(',').sort()
  153. let airs = []
  154. let room = '' // 房间名
  155. let temp = true // 没有同名的空调
  156. for (var i = 0; i < arrAirs.length; i++) {
  157. airs = arrAirs[i].trim().split(' ')
  158. // room = airs[0].replaceAll('-', '')
  159. room = airs[0]
  160. for (var j = 1; j < airs.length; j++) {
  161. if (airs[j].trim().length > 0) {
  162. temp = true
  163. for (var k = 0; k < this.airs.length; k++) {
  164. if (this.airs[k].name == room + ' ' + airs[j]) {
  165. temp = false
  166. break
  167. }
  168. }
  169. // 没有同名的
  170. if (temp) {
  171. this.airs.push({
  172. name: room + ' ' + airs[j],
  173. info: '2P空调',
  174. time: '01:25:21',
  175. on: false
  176. })
  177. }
  178. }
  179. }
  180. }
  181. // 如果选的空调不为空,则显示添加的空调列表
  182. if (this.airs.length > 0) {
  183. // 显示添加的空调列表
  184. this.isList = true
  185. }
  186. // 存储空调列表
  187. uni.setStorageSync('airs_selected', this.airs)
  188. // 移除全局自定义事件监听器。
  189. uni.$off('selectAirs')
  190. })
  191. },
  192. methods: {
  193. // 长按事件
  194. itemLongPress(e, val) {
  195. // console.log(e, val);
  196. if (val == 0) {
  197. let index = e.currentTarget.dataset.ref
  198. uni.showModal({
  199. title: '提示',
  200. content: '是否删除该空调?',
  201. success: (res) => {
  202. if (res.confirm) {
  203. // 删除指定下标的元素
  204. this.airs.splice(index, 1)
  205. // 更新存储
  206. uni.setStorageSync('airs_selected', this.airs)
  207. }
  208. }
  209. })
  210. } else {
  211. uni.showToast({
  212. title: '使用中不能删除',
  213. icon: 'error',
  214. duration: 1000
  215. })
  216. }
  217. },
  218. /**
  219. * 单击了启动或关闭按钮
  220. */
  221. btn_click(e) {
  222. // console.log(e.currentTarget.dataset.ref);
  223. let index_btn = e.currentTarget.dataset.ref
  224. // 未获取到索引
  225. if (typeof index_btn === 'undefined') {
  226. return
  227. }
  228. if (this.airs[index_btn].on) {
  229. uni.showModal({
  230. title: '提示',
  231. content: '确认【关闭】空调吗?',
  232. success: (res) => {
  233. if (res.confirm) {
  234. // 操作【关闭】空调
  235. this.airs[index_btn].on = false
  236. }
  237. }
  238. });
  239. } else {
  240. uni.showModal({
  241. title: '提示',
  242. content: '确认【启动】空调吗?',
  243. success: (res) => {
  244. if (res.confirm) {
  245. // 操作【启动】空调
  246. this.airs[index_btn].on = true
  247. }
  248. }
  249. });
  250. }
  251. },
  252. /**
  253. * 滚动到顶部提示
  254. */
  255. scroll_to_upper() {
  256. uni.showToast({
  257. title: '到顶了!',
  258. icon: 'none',
  259. duration: 500
  260. })
  261. },
  262. /**
  263. * 滚动到底部提示
  264. */
  265. scroll_to_lower() {
  266. uni.showToast({
  267. title: '到底了!',
  268. icon: 'none',
  269. duration: 500
  270. })
  271. },
  272. /**
  273. * 轮播图发生改变
  274. * @param {Object} e
  275. */
  276. swiper_change(e) {
  277. this.current = e.detail.current;
  278. },
  279. /**
  280. * 计算屏幕的高度
  281. */
  282. calc_screen_height() {
  283. uni.getSystemInfo({
  284. success: res => {
  285. let h = 0;
  286. if (this.isList === true) {
  287. h = ((res.screenHeight * (750 / res.windowWidth)) - 640) //将px 转换rpx
  288. } else {
  289. h = ((res.screenHeight * (750 / res.windowWidth)) - 740) //将px 转换rpx
  290. }
  291. this.screenHeight = Math.floor(h) + 'rpx'
  292. }
  293. });
  294. }
  295. }
  296. }
  297. </script>
  298. <style lang="scss" scoped>
  299. .container {
  300. display: flex;
  301. flex-direction: column;
  302. font-size: 28rpx;
  303. font-family: "Microsoft YaHei-3970(82674968)";
  304. width: 730rpx;
  305. padding: 10rpx;
  306. .swiper-box {
  307. height: 150px;
  308. width: 100%;
  309. }
  310. swiper-item {
  311. /* #ifndef APP-NVUE */
  312. display: flex;
  313. /* #endif */
  314. flex-direction: column;
  315. justify-content: center;
  316. align-items: center;
  317. height: 100%;
  318. image {
  319. height: 100%;
  320. width: 100%;
  321. border-radius: 8rpx;
  322. }
  323. }
  324. .line {
  325. height: 20rpx;
  326. }
  327. .nav {
  328. display: flex;
  329. justify-content: space-between;
  330. .btn {
  331. display: flex;
  332. justify-content: space-between;
  333. align-items: center;
  334. width: 338rpx;
  335. height: 100rpx;
  336. padding: 5rpx 10rpx;
  337. border-radius: 8rpx;
  338. background-color: #eaefff;
  339. .btn-icon-tzgl {
  340. display: flex;
  341. align-items: center;
  342. image {
  343. width: 40rpx;
  344. height: 40rpx;
  345. padding: 10rpx;
  346. }
  347. }
  348. .btn-icon {
  349. display: flex;
  350. align-items: center;
  351. image {
  352. width: 60rpx;
  353. height: 60rpx;
  354. }
  355. }
  356. .txt-right {
  357. display: flex;
  358. align-items: center;
  359. }
  360. }
  361. }
  362. .add-air {
  363. border-radius: 8rpx;
  364. padding: 60rpx 10rpx;
  365. background-color: #F1F1F1;
  366. .add-content {
  367. display: flex;
  368. justify-content: space-around;
  369. align-items: center;
  370. margin-bottom: 20rpx;
  371. .add-left {
  372. display: flex;
  373. .add-btn {
  374. display: flex;
  375. flex-direction: column;
  376. justify-content: center;
  377. align-items: center;
  378. margin-right: 20rpx;
  379. width: 120rpx;
  380. height: 120rpx;
  381. border-radius: 20rpx;
  382. background-color: #2979ff;
  383. color: #ffffff;
  384. }
  385. .add-tip {
  386. display: flex;
  387. flex-direction: column;
  388. justify-content: space-around;
  389. .txt-add-air {
  390. font-size: 40rpx;
  391. font-weight: bold;
  392. }
  393. .txt-tip {
  394. font-size: 20rpx;
  395. color: #8f939c;
  396. }
  397. }
  398. }
  399. .add-right {
  400. width: 300rpx;
  401. height: 100rpx;
  402. border-radius: 10rpx;
  403. image {
  404. width: 300rpx;
  405. height: 100rpx;
  406. }
  407. }
  408. }
  409. .add-bg {
  410. display: flex;
  411. justify-content: center;
  412. align-items: center;
  413. padding-top: 90rpx;
  414. image {
  415. width: 400rpx;
  416. height: 400rpx;
  417. }
  418. }
  419. }
  420. .list-air {
  421. border-radius: 8rpx;
  422. padding: 10rpx 10rpx;
  423. background-color: #e9e9eb;
  424. .list-items {
  425. display: flex;
  426. flex-direction: column;
  427. .item-air {
  428. display: flex;
  429. justify-content: space-between;
  430. padding: 30rpx 20rpx;
  431. border-bottom: 1px solid #c3c8d4;
  432. .item-left {
  433. display: flex;
  434. flex-direction: column;
  435. justify-content: space-around;
  436. .item-icon {
  437. display: flex;
  438. align-items: center;
  439. .circle1 {
  440. width: 16rpx;
  441. height: 16rpx;
  442. border-radius: 8rpx;
  443. background-color: #18bc37;
  444. }
  445. .circle2 {
  446. width: 12rpx;
  447. height: 12rpx;
  448. border-radius: 6rpx;
  449. background-color: #18bc37;
  450. margin: 0 10rpx;
  451. }
  452. .circle3 {
  453. display: inline-block;
  454. width: 8rpx;
  455. height: 8rpx;
  456. border-radius: 4rpx;
  457. background-color: #18bc37;
  458. }
  459. }
  460. .item-title {
  461. font-size: 32rpx;
  462. font-weight: bold;
  463. padding-bottom: 12rpx;
  464. }
  465. .item-info {
  466. display: flex;
  467. color: #8f939c;
  468. .item-info-left {
  469. padding-right: 20rpx;
  470. }
  471. .item-info-icon {
  472. width: 40rpx;
  473. height: 40rpx;
  474. margin-right: 8rpx;
  475. }
  476. }
  477. }
  478. .item-right {
  479. .item-btn {
  480. display: flex;
  481. flex-direction: column;
  482. justify-content: center;
  483. align-items: center;
  484. width: 100rpx;
  485. height: 100rpx;
  486. border: 1px solid #d9deeb;
  487. border-radius: 50rpx;
  488. box-shadow: 4rpx 4rpx 5rpx #c8cdd8;
  489. background-image: linear-gradient(-45deg, #F2F4F2, #DFDFDF);
  490. image {
  491. width: 50rpx;
  492. height: 50rpx;
  493. }
  494. .item-txt-on {
  495. font-size: 24rpx;
  496. font-weight: bold;
  497. color: #4B8DFB;
  498. }
  499. .item-txt-off {
  500. font-size: 24rpx;
  501. font-weight: bold;
  502. color: #8A8A8A;
  503. }
  504. }
  505. }
  506. }
  507. }
  508. .add-air-bottom {
  509. display: flex;
  510. justify-content: center;
  511. margin: 20rpx 0;
  512. padding: 20rpx 0;
  513. width: 160rpx;
  514. border-radius: 10rpx;
  515. .add-btn-bottom {
  516. font-size: 40rpx;
  517. color: #4B8DFB;
  518. padding-left: 8rpx;
  519. }
  520. }
  521. }
  522. }
  523. </style>