search.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="report-search-page">
  3. <van-sticky style="background: #fff">
  4. <view style="padding:30rpx 34rpx">
  5. <searchBox
  6. :focus="focus"
  7. placeholder="请输入报告标题或关键字"
  8. @change="onChange"
  9. @search="onSearch"
  10. ></searchBox>
  11. </view>
  12. </van-sticky>
  13. <view class="empty-box" v-if="finished&&list.length==0">
  14. <image :src="globalImgUrls.chartEmpty" mode="widthFix" />
  15. <view>找不到对应报告,试试别的搜索词吧</view>
  16. </view>
  17. <view class="list-wrap" v-else>
  18. <view class="item" v-for="(item,index) in list" :key="index" @click="goReportDetail(item)">
  19. <view class="title" v-html="item.title"></view>
  20. <view class="desc" v-html="item.content_sub"></view>
  21. <view class="flex bot">
  22. <view class="tags">
  23. <text v-if="item.classify_name_first">#{{item.classify_name_first}}</text>
  24. <text v-if="item.classify_name_second">#{{item.classify_name_second}}</text>
  25. </view>
  26. <view class="time">{{getReportListTime(item.publish_time)}}</view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. const dayjs=require('@/utils/dayjs.min')
  34. dayjs.locale('zh-cn')
  35. import searchBox from './components/searchBox.vue'
  36. import {apiReportSearch} from '@/api/report'
  37. export default {
  38. components: {
  39. searchBox
  40. },
  41. data () {
  42. return {
  43. searchVal:'',
  44. focus:true,
  45. list:[],
  46. finished:false,
  47. page:1,
  48. }
  49. },
  50. onReachBottom() {
  51. if(this.finished) return
  52. this.page++
  53. this.getList()
  54. },
  55. methods: {
  56. onChange(e){
  57. this.searchVal=e
  58. },
  59. async getList(){
  60. const res=await apiReportSearch({
  61. key_word:this.searchVal,
  62. current_index:this.page,
  63. page_size:20,
  64. })
  65. if(res.code===200){
  66. if(res.data.paging.is_end){
  67. this.finished=true
  68. }
  69. let arr=res.data.list||[]
  70. this.list=[...this.list,...arr]
  71. }
  72. },
  73. async onSearch(){
  74. this.finished=false
  75. this.page=1
  76. this.list=[]
  77. if(!this.searchVal){
  78. this.finished=true
  79. return
  80. }
  81. this.getList()
  82. },
  83. goReportDetail(item){
  84. if(['晨报','周报'].includes(item.classify_name_first)){
  85. uni.navigateTo({url: `/pages-report/chapterDetail?chapterId=${item.report_chapter_id}&fromPage=search`})
  86. }else{
  87. uni.navigateTo({url:'/pages-report/reportDetail?reportId='+item.report_id})
  88. }
  89. },
  90. getReportListTime(e){
  91. return dayjs(e).format('YYYY年MM月DD日 HH:mm')
  92. }
  93. }
  94. }
  95. </script>
  96. <style>
  97. .van-sticky-wrap--fixed{
  98. background-color: #fff;
  99. }
  100. page{
  101. padding-bottom: 0;
  102. }
  103. </style>
  104. <style lang="scss" scoped>
  105. .empty-box{
  106. text-align: center;
  107. font-size: 32rpx;
  108. color: #999;
  109. padding-top: 150rpx;
  110. image{
  111. width: 346rpx;
  112. margin-bottom: 57rpx;
  113. }
  114. }
  115. .list-wrap{
  116. padding: 34rpx;
  117. .item{
  118. padding: 30rpx;
  119. background: #FFFFFF;
  120. box-shadow: 3rpx 3rpx 12rpx 1rpx rgba(184, 184, 184, 0.16);
  121. border-radius: 16rpx;
  122. border: 1px solid #E5E5E5;
  123. margin-bottom: 20rpx;
  124. .title{
  125. font-size: 32rpx;
  126. font-weight: bold;
  127. }
  128. .desc{
  129. color: #666666;
  130. line-height: 1.5;
  131. margin: 10rpx 0 20rpx 0;
  132. }
  133. .bot{
  134. justify-content: space-between;
  135. align-items: flex-end;
  136. .time{
  137. flex-shrink: 0;
  138. color: #999999;
  139. font-size: 24rpx;
  140. }
  141. .tags{
  142. font-size: 28rpx;
  143. color: #E3B377;
  144. text{
  145. display: inline-block;
  146. margin-right: 30rpx;
  147. }
  148. }
  149. }
  150. }
  151. }
  152. </style>