device.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view :class="$isEmpty(deviceList) ? 'bg-white':''">
  3. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
  4. :up="upOption">
  5. <device-card :list="deviceList"></device-card>
  6. </mescroll-body>
  7. <view class="footer-fixed" v-if="$isNotEmpty(deviceList)">
  8. <view class="margin">
  9. <u-button type="primary" shape="circle" @click="subscribeMessage">订阅设备告警通知</u-button>
  10. </view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. var app = getApp();
  16. import MescrollMixin from "@/comps/mescroll-body/mescroll-mixins.js";
  17. import DeviceCard from "@/comps/device-card.vue";
  18. import DtEmpty from '@/comps/dt_empty.vue';
  19. export default {
  20. mixins: [MescrollMixin], // 使用mixin
  21. components: {
  22. DeviceCard,
  23. DtEmpty
  24. },
  25. data() {
  26. return {
  27. deviceList: [],
  28. }
  29. },
  30. onLoad() {
  31. },
  32. methods: {
  33. //订阅消息通知
  34. subscribeMessage() {
  35. this.$util.subscribe(["nSBYQTAe7wtQFPyHLXkacYF3IxwkYKjzWxsiVMzx-xM"]);
  36. },
  37. downCallback(mescroll) {
  38. setTimeout(() => {
  39. this.mescroll.resetUpScroll()
  40. }, 200)
  41. },
  42. upCallback(mescroll) {
  43. let residentialId=uni.getStorageSync("residentialId")
  44. if (this.$isEmpty(this.vuex_member)||this.$isEmpty(residentialId)) {
  45. this.mescroll.endErr()
  46. return
  47. }
  48. let that = this;
  49. let params = {
  50. memberId: this.vuex_member.id,
  51. residentialId
  52. }
  53. try {
  54. that.$http.iotDeviceList(params).then(res => {
  55. let data = res.data.iotDevices;
  56. mescroll.endSuccess(data.length);
  57. if (mescroll.num == 1) {
  58. that.deviceList = []; //如果是第一页需手动制空列表
  59. }
  60. that.deviceList = that.deviceList.concat(data); //追加新数据
  61. });
  62. } catch (e) {
  63. this.mescroll.endErr()
  64. }
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. </style>