list.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <!-- 故障上报设备列表 -->
  3. <view>
  4. <!-- 搜索框 -->
  5. <ui-search placeholder="请输入设备ID" @confirm="searchDevice"></ui-search>
  6. <!-- 搜索框end -->
  7. <ui-tabs :list="deviceTabs" :active="deviceTab" @clickTab="clickDeviceTabs"></ui-tabs>
  8. <!-- 设备列表 -->
  9. <block v-for="(item,index) in deviceList" :key="index">
  10. <!-- 气象站 墒情站 -->
  11. <view class="ui-card forecast-item" @click="openDeviceDetails(item.equip_id,item.equip_name)" v-if="deviceTab==1 || deviceTab==3">
  12. <view class="flex-1 info">
  13. <view class="font-16 title" :class="item.is_online==1?'on':'off'">设备名称:{{item.equip_name}}</view>
  14. <view class="text">设备ID:{{item.equip_id}}</view>
  15. <view class="text text-ellipsis">地址:{{item.address}}</view>
  16. <view class="text">最新上报时间:{{item.uptime | timeFrom}}</view>
  17. </view>
  18. <view class="aftersale-tips">故障上报</view>
  19. </view>
  20. <!-- 测报灯 -->
  21. <view class="ui-card forecast-item" @click="openDeviceDetails(item.imei,item.device_name)" v-if="deviceTab==4">
  22. <view class="flex-1 info">
  23. <view class="font-16 title" :class="item.is_online==1?'on':'off'">设备名称:{{item.device_name?item.device_name:'测报灯'}}</view>
  24. <view class="text">设备ID:{{item.imei}}</view>
  25. <view class="text text-ellipsis">地址:{{item.address}}</view>
  26. <view class="text">最新上报时间:{{ item.uptime | timeFrom}}</view>
  27. </view>
  28. <view class="aftersale-tips">故障上报</view>
  29. </view>
  30. <!-- 监控 -->
  31. <view class="ui-card forecast-item" @click="openDeviceDetails(item.device_id,item.device_name)" v-if="deviceTab==2">
  32. <view class="flex-1 info">
  33. <view class="font-16 title" :class="item.status==1?'on':'off'">设备名称:{{item.device_name}}</view>
  34. <view class="text">设备ID:{{item.device_id}}</view>
  35. </view>
  36. <view class="aftersale-tips">故障上报</view>
  37. </view>
  38. </block>
  39. <!-- 气象列表end -->
  40. <ui-empty v-if="deviceList.length==0"></ui-empty>
  41. </view>
  42. </template>
  43. <script>
  44. import {
  45. getWeatherDeviceList
  46. } from '@/api/weather.js' // 气象列表
  47. import {
  48. getCameraList
  49. } from '@/api/camera.js' // 监控列表
  50. import {
  51. getWormLampList
  52. } from '@/api/worm.js' // 孢子仪 测报灯列表
  53. export default {
  54. data() {
  55. return {
  56. // 列表搜索条件
  57. params: {
  58. device_id: '', //筛选项 设备号、设备名称
  59. page: 1,
  60. page_size: 10,
  61. // device_type: 5, // 5气象站 8墒情站
  62. // device_type_id:3 3虫情测报灯 7孢子仪
  63. },
  64. deviceList: [], // 设备列表
  65. total: 0, // 设备总数
  66. deviceTab: 1, //当前设备类型
  67. deviceTabs: [{
  68. text: '气象站',
  69. value: 1
  70. }, {
  71. text: '监控',
  72. value: 2
  73. },
  74. {
  75. text: '墒情站',
  76. value: 3
  77. }, {
  78. text: '测报灯',
  79. value: 4
  80. }
  81. ]
  82. };
  83. },
  84. async onLoad() {
  85. await this.$onLaunched
  86. this.getDeviceList();
  87. },
  88. // 触底请求
  89. onReachBottom(e) {
  90. if (this.deviceList.length >= this.total) {
  91. return;
  92. }
  93. this.params.page += 1;
  94. this.getDeviceList();
  95. },
  96. methods: {
  97. // 刷新设备列表
  98. refreshDeviceList() {
  99. this.params.page = 1;
  100. this.deviceList = [];
  101. this.getDeviceList();
  102. },
  103. // 切换设备类型
  104. clickDeviceTabs(val) {
  105. this.deviceTab = val;
  106. this.refreshDeviceList();
  107. },
  108. /**
  109. * 打开设备故障上报
  110. * @param {Object} deviceId 设备号
  111. */
  112. openDeviceDetails(deviceId,deviceName) {
  113. uni.navigateTo({
  114. url: `index?deviceId=${deviceId}&name=${deviceName}`
  115. })
  116. },
  117. // 获取设备列表
  118. async getDeviceList() {
  119. let params = {};
  120. if (this.deviceTab == 1 || this.deviceTab == 3) {
  121. params.device_type = this.deviceTab == 1 ? 5 : 8;
  122. }
  123. if (this.deviceTab == 4) {
  124. params.device_type_id = 3;
  125. }
  126. const {
  127. data,
  128. counts
  129. } = await this.requestDeviceList({
  130. ...this.params,
  131. ...params
  132. });
  133. this.deviceList = [...this.deviceList, ...data];
  134. this.total = counts ?? 0;
  135. },
  136. // 请求设备列表
  137. async requestDeviceList(params) {
  138. const handleList = {
  139. 1: getWeatherDeviceList, // 气象
  140. 2: getCameraList, // 监控
  141. 3: getWeatherDeviceList, // 墒情
  142. 4: getWormLampList,
  143. }
  144. let res = await handleList[this.deviceTab](params);
  145. // 气象 墒情
  146. if (this.deviceTab == 1 || this.deviceTab == 3) {
  147. return {
  148. data: res.ids,
  149. counts: res.nums,
  150. }
  151. }
  152. return {
  153. data: res.data,
  154. counts: res.counts,
  155. }
  156. },
  157. /**
  158. * 搜索设备
  159. * @param {String} val 搜索内容
  160. */
  161. searchDevice(val) {
  162. this.params.device_id = val;
  163. this.refreshDeviceList();
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang="scss">
  169. .aftersale-tips {
  170. color: #E93F27;
  171. font-size: 20rpx;
  172. }
  173. </style>