index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. let {
  71. disease_nums,
  72. pest_nums,
  73. data
  74. } = await loadPestList(this.params);
  75. this.pestList = [...this.pestList, ...(data ?? [])];
  76. this.total = this.params.code == 2 ? pest_nums : disease_nums;
  77. },
  78. /**
  79. * 搜索病虫害
  80. * @param {String} val 搜索内容
  81. */
  82. searchPestList(val) {
  83. this.params.pest_name = val;
  84. this.refreshPestList();
  85. },
  86. // 打开病虫害
  87. openPestsInfo(item){
  88. uni.navigateTo({
  89. url:`details?params=${JSON.stringify(item)}`
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss">
  96. // 病虫害百科面板
  97. .pest-panel {
  98. display: flex;
  99. flex-wrap: wrap;
  100. padding: 24rpx;
  101. }
  102. // 病虫害百科列表项
  103. .pest-item {
  104. width: 336rpx;
  105. margin-right: 28rpx;
  106. margin-bottom: 24rpx;
  107. border-radius: 12rpx;
  108. border: 1rpx solid #F1F1F1;
  109. &:nth-child(2n) {
  110. margin-right: 0;
  111. }
  112. .pic {
  113. display: block;
  114. width: 336rpx;
  115. height: 255rpx;
  116. border-radius: 4rpx;
  117. }
  118. .text {
  119. font-size: 20rpx;
  120. color: #666666;
  121. }
  122. .tips {
  123. width: 24rpx;
  124. height: 24rpx;
  125. background: #07F546;
  126. border-radius: 100%;
  127. }
  128. }
  129. </style>