index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <!-- 病虫害百科 -->
  3. <view>
  4. <ui-sticky>
  5. <ui-search placeholder="请输入害虫名字" @confirm="searchPestList"></ui-search>
  6. <ui-tabs :list="tabs" :active="params.code" @clickTab="clickPestTab"></ui-tabs>
  7. </ui-sticky>
  8. <!-- 病虫害百科列表 -->
  9. <view class="page-panel pest-panel">
  10. <block v-for="(item,index) in pestList" :key="index">
  11. <view class="pest-item" @click="openPestsInfo(item)">
  12. <image class="pic" mode="aspectFill" :src="item.img_urls"></image>
  13. <view class="row-center p-10">
  14. <text class="text">{{item.name}}</text>
  15. </view>
  16. </view>
  17. </block>
  18. <ui-empty v-if="pestList.length==0"></ui-empty>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import {
  24. loadPestList
  25. } from '@/api/pest.js'
  26. export default {
  27. data() {
  28. return {
  29. // 病虫害百科列表
  30. pestList: [],
  31. // 搜索条件列表
  32. params: {
  33. code: 2,
  34. page: 1,
  35. page_size: 10,
  36. pest_name: ''
  37. },
  38. total: 0, // 设备总数
  39. // tabs列表
  40. tabs: [{
  41. text: '虫害库',
  42. value: 2
  43. }, {
  44. text: '病害库',
  45. value: 1
  46. }]
  47. };
  48. },
  49. onLoad() {
  50. this.getPestList();
  51. },
  52. // 触底请求
  53. onReachBottom(e) {
  54. if (this.pestList.length >= this.total) {
  55. return;
  56. }
  57. this.params.page += 1;
  58. this.getPestList();
  59. },
  60. methods: {
  61. clickPestTab(value) {
  62. this.params.code = value;
  63. this.refreshPestList();
  64. },
  65. // 刷新虫害百科列表
  66. refreshPestList() {
  67. this.params.page = 1;
  68. this.pestList = [];
  69. this.getPestList();
  70. },
  71. // 获取虫害or病害 列表
  72. async getPestList() {
  73. const {
  74. disease_nums,
  75. pest_nums,
  76. data
  77. } = await loadPestList(this.params);
  78. this.pestList = [...this.pestList, ...(data ?? [])];
  79. this.total = this.params.code == 2 ? pest_nums : disease_nums;
  80. },
  81. /**
  82. * 搜索病虫害
  83. * @param {String} val 搜索内容
  84. */
  85. searchPestList(val) {
  86. this.params.pest_name = val;
  87. this.refreshPestList();
  88. },
  89. // 打开病虫害
  90. openPestsInfo(item){
  91. uni.navigateTo({
  92. url:`details?params=${JSON.stringify(item)}`
  93. })
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss">
  99. // 病虫害百科面板
  100. .pest-panel {
  101. display: flex;
  102. flex-wrap: wrap;
  103. padding: 24rpx;
  104. }
  105. // 病虫害百科列表项
  106. .pest-item {
  107. width: 336rpx;
  108. margin-right: 28rpx;
  109. margin-bottom: 24rpx;
  110. border-radius: 12rpx;
  111. border: 1rpx solid #F1F1F1;
  112. &:nth-child(2n) {
  113. margin-right: 0;
  114. }
  115. .pic {
  116. display: block;
  117. width: 336rpx;
  118. height: 255rpx;
  119. border-radius: 4rpx;
  120. }
  121. .text {
  122. font-size: 20rpx;
  123. color: #666666;
  124. }
  125. .tips {
  126. width: 24rpx;
  127. height: 24rpx;
  128. background: #07F546;
  129. border-radius: 100%;
  130. }
  131. }
  132. </style>