index.vue 2.4 KB

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