index.vue 2.6 KB

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