index.vue 2.6 KB

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