open.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view class="page">
  3. <view class="" v-if="!loading">
  4. <view class="" v-if="$isNotEmpty(device_list)">
  5. <view class="cu-list menu text-left">
  6. <view class="cu-item" @click="activedIndex=index" v-for="(item,index) in device_list" :key="index">
  7. <label class="flex justify-between align-center flex-sub">
  8. <view class="flex-sub margin-left-sm">{{item.deviceName}}</view>
  9. <u-icon size="36" name="checkmark-circle-fill" color="#2f7ff5" v-if="activedIndex==index">
  10. </u-icon>
  11. </label>
  12. </view>
  13. </view>
  14. <view class="bottom">
  15. <button @click="openDoor" class="cu-btn cuIcon round bg-white shadow1"
  16. style="height: 150rpx;width: 150rpx;margin-bottom: 160rpx;border: 1rpx solid #c6c6c6;">
  17. <text v-if="!isOpen" class="cuIcon-lock" style="font-size: 50rpx;color: #989898;"></text>
  18. <u-loading mode="flower" size="40" v-else></u-loading>
  19. </button>
  20. </view>
  21. </view>
  22. <empty v-else></empty>
  23. </view>
  24. <loading v-else></loading>
  25. </view>
  26. </template>
  27. <script>
  28. import empty from "@/comps/empty.vue"
  29. import loading from "@/comps/loading.vue"
  30. var app = getApp()
  31. var that;
  32. export default {
  33. components:{
  34. empty,
  35. loading
  36. },
  37. data() {
  38. return {
  39. activedIndex: 0,
  40. device_list: [],
  41. loading: true,
  42. isOpen: false,
  43. };
  44. },
  45. onShow() {
  46. that = this
  47. this.getAuthDevice()
  48. },
  49. methods: {
  50. /**
  51. * 立即开门
  52. */
  53. openDoor() {
  54. let item = this.device_list[this.activedIndex]
  55. if (this.$isEmpty(item)) {
  56. this.$dialog.showModal('设备不存在')
  57. return
  58. }
  59. let params = {
  60. memberId: this.vuex_member.id,
  61. serialNum: item.deviceSerialNum,
  62. deviceFactory: item.deviceFactory,
  63. residentialId: item.residentialId,
  64. userType: 'ZH_'
  65. }
  66. this.isOpen = true
  67. this.$http.openDoor(params).then(res => {
  68. this.isOpen = false
  69. if (res.data.success) {
  70. this.$u.toast('开门成功')
  71. } else {
  72. this.$u.toast('开门失败')
  73. }
  74. }).catch(err => {
  75. this.isOpen = false
  76. })
  77. },
  78. /**
  79. * 获取设备列表
  80. */
  81. getAuthDevice: function() {
  82. let memberId = this.vuex_member ? this.vuex_member.id : ''
  83. let residentialId = uni.getStorageSync("residentialId")
  84. if (!memberId || !residentialId) {
  85. this.loading=false
  86. return
  87. }
  88. let params = {
  89. id: memberId,
  90. residentialId
  91. }
  92. this.$http.getAuthDeviceByMemberId(params).then(res => {
  93. this.loading=false
  94. if (res.data.success) {
  95. this.device_list = res.data.data
  96. }
  97. });
  98. },
  99. }
  100. };
  101. </script>
  102. <style lang="scss" scoped>
  103. .bottom {
  104. position: fixed;
  105. bottom: 0;
  106. left: 40%;
  107. }
  108. .shadow1 {
  109. box-shadow: 0 0 20rpx #cbcbcb
  110. }
  111. button:active {
  112. box-shadow: 0 0 10rpx rgba(203, 203, 203, 0.2);
  113. position: relative;
  114. top: 2px;
  115. }
  116. </style>