device.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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">
  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, DtEmpty
  23. },
  24. data() {
  25. return {
  26. deviceList: [],
  27. }
  28. },
  29. onLoad() {
  30. },
  31. methods: {
  32. //订阅消息通知
  33. subscribeMessage() {
  34. this.$util.subscribe(["nSBYQTAe7wtQFPyHLXkacYF3IxwkYKjzWxsiVMzx-xM"]);
  35. },
  36. downCallback(mescroll) {
  37. setTimeout(() => {
  38. this.mescroll.resetUpScroll()
  39. }, 1500)
  40. },
  41. upCallback(mescroll) {
  42. let that = this;
  43. let params = {
  44. memberId: app.globalData.member.id,
  45. residentialId: uni.getStorageSync("residentialId")
  46. };
  47. let operation = 'device/list';
  48. try {
  49. app.globalData.postRequest(params, operation, function (res) {
  50. if (res.data.code == 500) {
  51. mescroll.endErr()
  52. return
  53. }
  54. let data = res.data.smartDevices;
  55. // let total = res.data.carPage.total;
  56. // mescroll.endBySize(data.length, total);
  57. mescroll.endSuccess(data.length);
  58. if (mescroll.num == 1) {
  59. that.deviceList = []; //如果是第一页需手动制空列表
  60. }
  61. that.deviceList = that.deviceList.concat(data); //追加新数据
  62. });
  63. } catch (e) {
  64. mescroll.endErr()
  65. }
  66. }
  67. }
  68. }
  69. </script>
  70. <style lang="scss" scoped>
  71. </style>