index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <!--虫情监测列表 -->
  3. <view>
  4. <!-- 搜索框 -->
  5. <ui-search placeholder="请输入设备ID" @confirm="searchLampList"></ui-search>
  6. <!-- 搜索框end -->
  7. <!-- 监测列表 -->
  8. <block v-for="(item,index) in lampList" :key="index">
  9. <view class="ui-card forecast-item" @click="openLampDetails(item)">
  10. <view class="flex-1 info">
  11. <view class="font-16 title" :class="item.is_online?'on':'off'">
  12. {{item.device_name?item.device_name:'测报灯'}}</view>
  13. <view class="text">设备ID:{{item.imei}}</view>
  14. <view class="text text-ellipsis">地址:{{item.address}}</view>
  15. <view class="text">最新上报时间:{{ item.uptime | timeFrom}}</view>
  16. </view>
  17. <ui-state :state="item.is_online"></ui-state>
  18. </view>
  19. </block>
  20. <!-- 监测列表end -->
  21. <ui-empty v-if="lampList.length==0"></ui-empty>
  22. </view>
  23. </template>
  24. <script>
  25. import {
  26. getWormLampList
  27. } from '@/api/worm.js'
  28. export default {
  29. data() {
  30. return {
  31. // 列表搜索条件
  32. params: {
  33. device_type_id: 3, //3虫情测报灯 7孢子仪
  34. device_id: '', // 搜索项,设备号、设备名称搜索
  35. page: 1,
  36. page_size: 10,
  37. // device_status: // 筛选项 1在线 0离线
  38. },
  39. total: 0, // 设备总数
  40. lampList: [], // 测报灯列表
  41. };
  42. },
  43. async onLoad() {
  44. await this.$onLaunched;
  45. this.getLampList();
  46. },
  47. // 触底请求
  48. onReachBottom(e) {
  49. if (this.lampList.length >= this.total) {
  50. return;
  51. }
  52. this.params.page += 1;
  53. this.getLampList();
  54. },
  55. //下拉刷新
  56. onPullDownRefresh() {
  57. this.refreshLampList();
  58. uni.stopPullDownRefresh()
  59. },
  60. methods: {
  61. // 刷新测试灯列表
  62. refreshLampList() {
  63. this.params.page = 1;
  64. this.lampList = [];
  65. this.getLampList();
  66. },
  67. // 获取测试灯列表
  68. async getLampList() {
  69. this.$api.loading('加载中...');
  70. const {
  71. data,
  72. counts
  73. } = await getWormLampList(this.params);
  74. this.$api.hide();
  75. this.lampList = [...this.lampList, ...data];
  76. this.total = counts ?? 0;
  77. },
  78. /**
  79. * 测试灯
  80. * @param {String} val 搜索内容
  81. */
  82. searchLampList(val) {
  83. this.params.device_id = val;
  84. this.refreshLampList();
  85. },
  86. /**
  87. * 打开虫情详情列表
  88. * @param {String} id 设备id
  89. * @param {String} imei 设备号
  90. * @param {Number} uptime 上报时间
  91. */
  92. openLampDetails({
  93. d_id,
  94. imei,
  95. uptime
  96. }) {
  97. uni.navigateTo({
  98. url: `details?id=${d_id}&imei=${imei}&uptime=${uptime}`
  99. })
  100. }
  101. },
  102. }
  103. </script>