oneButton.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. that.$http.openDoor(params).then(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. params['residential_id'] = uni.getStorageSync("residentialId");
  77. // let operation = 'member/getAuthDeviceByMemberId';
  78. that.$http.getAuthDeviceByMemberId(params).then (res=>{
  79. console.info("查询结果:" + res.data.result_msg); //获取成功
  80. if (res.data.result_code == 1) {
  81. // let list = res.data.list;
  82. // console.log(list)
  83. // that.setData({
  84. // device_list: list
  85. // })
  86. // app.device_list = list;
  87. let list = [];
  88. if (uni.getStorageSync('plotName')) {
  89. res.data.list.map(item => {
  90. if (item.name.indexOf(uni.getStorageSync('plotName')) >= 0) {
  91. list.push(item);
  92. }
  93. });
  94. } else {
  95. list = res.data.list;
  96. }
  97. that.setData({
  98. device_list: list
  99. });
  100. app.globalData.device_list = list;
  101. }
  102. });
  103. }
  104. }
  105. };
  106. </script>
  107. <style lang="scss">
  108. view,
  109. button
  110. {
  111. box-sizing: border-box;
  112. }
  113. .cu-btn.sm {
  114. padding: 0 26rpx;
  115. font-size: 24rpx;
  116. height: 54rpx;
  117. }
  118. page {
  119. overflow-y: scroll;
  120. background-color: #FFFFFF;
  121. height: 100vh;
  122. }
  123. .openButton_contain {
  124. padding-top: 30rpx;
  125. }
  126. .openButton_list {
  127. width: 100%;
  128. padding: 0 20rpx;
  129. border-bottom: 1px solid #eee;
  130. height: 120rpx;
  131. line-height: 120rpx;
  132. background: #fff;
  133. position: relative;
  134. box-sizing: border-box;
  135. }
  136. .openButton_list .button {
  137. position: absolute;
  138. right: 20rpx;
  139. top: 50%;
  140. transform: translate(0, -50%);
  141. border: 1px solid $base;
  142. height: 60rpx;
  143. line-height: 60rpx;
  144. padding: 0 20rpx;
  145. border-radius: 6rpx;
  146. color: #fff;
  147. background: $base;
  148. }
  149. .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;}
  150. </style>