index.vue 2.4 KB

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