index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. onLoad() {
  44. this.getLampList();
  45. },
  46. // 触底请求
  47. onReachBottom(e) {
  48. if (this.lampList.length >= this.total) {
  49. return;
  50. }
  51. this.params.page += 1;
  52. this.getLampList();
  53. },
  54. //下拉刷新
  55. onPullDownRefresh() {
  56. this.refreshLampList();
  57. uni.stopPullDownRefresh()
  58. },
  59. methods: {
  60. // 刷新测试灯列表
  61. refreshLampList() {
  62. this.params.page = 1;
  63. this.lampList = [];
  64. this.getLampList();
  65. },
  66. // 获取测试灯列表
  67. async getLampList() {
  68. this.$api.loading('加载中...');
  69. const {
  70. data,
  71. counts
  72. } = await getWormLampList(this.params);
  73. this.$api.hide();
  74. this.lampList = [...this.lampList, ...data];
  75. this.total = counts ?? 0;
  76. },
  77. /**
  78. * 测试灯
  79. * @param {String} val 搜索内容
  80. */
  81. searchLampList(val) {
  82. this.params.device_id = val;
  83. this.refreshLampList();
  84. },
  85. /**
  86. * 打开虫情详情列表
  87. * @param {String} id 设备id
  88. * @param {String} imei 设备号
  89. * @param {Number} uptime 上报时间
  90. */
  91. openLampDetails({
  92. d_id,
  93. imei,
  94. uptime
  95. }) {
  96. uni.navigateTo({
  97. url: `details?id=${d_id}&imei=${imei}&uptime=${uptime}`
  98. })
  99. }
  100. },
  101. }
  102. </script>