oneButton.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view :class="$isEmpty(device_list)?'empty-wrap':''">
  3. <view class="openButton_contain" v-if="device_list.length>0">
  4. <view class="padding-30" v-for="(item, index) in device_list" :key="index" style="border-bottom: 1rpx solid #EEEEEE;display: flex;justify-content: space-between;">
  5. <text style="margin: 8rpx 0 0 6rpx;">{{item.name}}</text>
  6. <view :data-device_id="item.id" @tap="openDoor" class="cu-btn bg-red sm round " >
  7. 立即开门
  8. </view>
  9. </view>
  10. <!-- <view v-for="(item, index) in device_list" :key="index" class="openButton_list">
  11. <view class="info">{{item.name}}</view>
  12. <view class="cu-btn round sm bg-red">
  13. 立即开门
  14. </view>
  15. <view class="button" :data-device_id="item.id" @tap="openDoor">立即开门</view>
  16. </view> -->
  17. </view>
  18. <view class="default" v-if="$isEmpty(device_list)">
  19. <image src="/static/common/empty.png" mode="heightFix"></image>
  20. <view>
  21. <text>没有获取到设备信息</text>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. //获取app实例
  28. var app = getApp();
  29. export default {
  30. data() {
  31. return {
  32. isFirst:true,
  33. device_list: null
  34. };
  35. },
  36. components: {},
  37. props: {},
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad: function (options) {
  42. // let device_list = app.device_list;
  43. // if (device_list){
  44. // this.setData({
  45. // device_list: device_list
  46. // })
  47. // }else{
  48. // 如果设备列表为空--则去拉取一次
  49. // }
  50. this.isFirst=false
  51. this.getAuthDevice();
  52. },
  53. onShow() {
  54. if(!this.isFirst){
  55. this.getAuthDevice();
  56. }
  57. },
  58. methods: {
  59. //立即开门
  60. openDoor: function (event) {
  61. let device_id = event.currentTarget.dataset.device_id;
  62. let that = this;
  63. let params = {};
  64. params['member_id'] = app.globalData.member.id;
  65. params['device_id'] = device_id;
  66. let operation = 'member/openDoor';
  67. app.globalData.postRequest(params, operation, function (res) {
  68. app.globalData.oneFailHint(res.data.result_msg);
  69. });
  70. },
  71. //获取用户的授权设备列表
  72. getAuthDevice: function () {
  73. let that = this;
  74. let params = {};
  75. params['member_id'] = app.globalData.member.id;
  76. let operation = 'member/getAuthDeviceByMemberId';
  77. app.globalData.postRequest(params, operation, function (res) {
  78. console.info("查询结果:" + res.data.result_msg); //获取成功
  79. if (res.data.result_code == 1) {
  80. // let list = res.data.list;
  81. // console.log(list)
  82. // that.setData({
  83. // device_list: list
  84. // })
  85. // app.device_list = list;
  86. let list = [];
  87. if (uni.getStorageSync('plotName')) {
  88. res.data.list.map(item => {
  89. if (item.name.indexOf(uni.getStorageSync('plotName')) >= 0) {
  90. list.push(item);
  91. }
  92. });
  93. } else {
  94. list = res.data.list;
  95. }
  96. that.setData({
  97. device_list: list
  98. });
  99. app.globalData.device_list = list;
  100. }
  101. });
  102. }
  103. }
  104. };
  105. </script>
  106. <style lang="scss">
  107. view,
  108. button
  109. {
  110. box-sizing: border-box;
  111. }
  112. .cu-btn.sm {
  113. padding: 0 26rpx;
  114. font-size: 24rpx;
  115. height: 54rpx;
  116. }
  117. page {
  118. overflow-y: scroll;
  119. background-color: #FFFFFF;
  120. height: 100vh;
  121. }
  122. .openButton_contain {
  123. padding-top: 30rpx;
  124. }
  125. .openButton_list {
  126. width: 100%;
  127. padding: 0 20rpx;
  128. border-bottom: 1px solid #eee;
  129. height: 120rpx;
  130. line-height: 120rpx;
  131. background: #fff;
  132. position: relative;
  133. box-sizing: border-box;
  134. }
  135. .openButton_list .button {
  136. position: absolute;
  137. right: 20rpx;
  138. top: 50%;
  139. transform: translate(0, -50%);
  140. border: 1px solid $base;
  141. height: 60rpx;
  142. line-height: 60rpx;
  143. padding: 0 20rpx;
  144. border-radius: 6rpx;
  145. color: #fff;
  146. background: $base;
  147. }
  148. .default { text-align: center; position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%);}.default text{ color: #AAAAAA;}.default image { height: 250rpx; display: inline-block;}.empty-wrap{ background-color: #FFFFFF; min-height: 100vh;}
  149. </style>