index.vue 2.1 KB

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