collect.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <view class="container">
  3. <view class="header-box">
  4. <view class="search-box">
  5. <u-search
  6. v-model="searchForm.keyword"
  7. :clearabled="true"
  8. bg-color="#E5E5E5"
  9. :input-style="searchInputStyle"
  10. placeholder="搜索您想要的内容"
  11. ></u-search>
  12. </view>
  13. <view class="tab-box">
  14. <u-tabs
  15. name="label"
  16. :list="searchType"
  17. :is-scroll="false"
  18. v-model="searchForm.type"
  19. @change="onSearchTypeChange"
  20. font-size="24"
  21. :bold="false"
  22. inactive-color="#000000"
  23. active-color="#000000"
  24. :bar-style="{'background-color': '#2979ff'}"
  25. height="50"
  26. ></u-tabs>
  27. </view>
  28. </view>
  29. <u-empty
  30. mode="data"
  31. v-if="list.length === 0"
  32. iconSize="120"
  33. textSize="58"
  34. text="暂无数据"
  35. >
  36. </u-empty>
  37. <view class="list-box">
  38. <view class="list-item-box" v-for="item in list" :key="item.id" @click="onClickReport(item)">
  39. <view class="icon-box">
  40. <view class="icon" v-if="item.isNew"></view>
  41. </view>
  42. <view class="info-box">
  43. <view class="title">
  44. {{item.title}}
  45. </view>
  46. <view class="text">
  47. 【{{item.typeName}}】
  48. </view>
  49. </view>
  50. <view class="suffix-box">
  51. <view class="button">
  52. 查看
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <uni-load-more v-show="visualLoadMore" :status="loadMoreStatus"></uni-load-more>
  58. </view>
  59. </template>
  60. <script setup>
  61. import { ref } from 'vue'
  62. import { onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app'
  63. import { query } from '@/api/collect.js'
  64. const searchInputStyle = {
  65. backgroundColor: '#E5E5E5'
  66. }
  67. const searchType = [
  68. {
  69. label: '全部',
  70. value: 0
  71. },
  72. {
  73. label: '研究报告',
  74. value: 1
  75. },
  76. {
  77. label: '继续教育',
  78. value: 2
  79. },
  80. ]
  81. const pageNum = ref(1)
  82. const pageSize = ref(10)
  83. const visualLoadMore = ref(false)
  84. const loadMoreStatus = ref('more')
  85. const searchForm = ref({
  86. keyword: '',
  87. type: 0,
  88. pageNumber: 1,
  89. pageSize: 10
  90. })
  91. const list = ref([
  92. {
  93. id: '01',
  94. title: '2024年11月关注是中介促成二手住宅市场交易简报',
  95. type: 1,
  96. typeName: '月度成交简报',
  97. isNew: true
  98. },
  99. ])
  100. function onSearchConfirm() {
  101. searchForm.value.pageNumber = 1
  102. pageNum.value = 1
  103. onSearch()
  104. }
  105. function onSearchClear() {
  106. searchForm.value.keyword = null
  107. searchForm.value.pageNumber = 1
  108. pageNum.value = 1
  109. onSearch()
  110. }
  111. function onSearch() {
  112. loadMoreStatus.value = 'more'
  113. query(searchForm.value).then(res => {
  114. if (res && res.message === 'success') {
  115. list.value = res.data
  116. if (res.count === 0) {
  117. visualLoadMore.value = false
  118. }
  119. }
  120. })
  121. }
  122. function onSearchTypeChange(val) {}
  123. function onClickReport(report) {
  124. uni.navigateTo({
  125. url: `/pages/reportDetail/reportDetail?id=${report.id}&title=${report.title}`
  126. })
  127. }
  128. onPullDownRefresh((e) => {
  129. searchForm.value.pageNumber = 1
  130. loadMoreStatus.value = 'more'
  131. query(searchForm.value).then(res => {
  132. if (res && res.message === 'success') {
  133. list.value = res.data
  134. if (res.count === 0) {
  135. visualLoadMore.value = false
  136. }
  137. uni.showToast({
  138. title: '刷新成功',
  139. icon: 'success',
  140. duration: 2000
  141. })
  142. }
  143. uni.stopPullDownRefresh()
  144. })
  145. })
  146. onReachBottom(async () => {
  147. if (loadMoreStatus.value === 'noMore') {
  148. uni.showToast({
  149. title: '没有更多啦>﹏<',
  150. icon: 'none'
  151. })
  152. return
  153. }
  154. visualLoadMore.value = true
  155. loadMoreStatus.value = 'loading'
  156. searchForm.value.pageNum++
  157. query(searchForm.value).then(res => {
  158. if (res && res.message === 'success') {
  159. if (res.data) {
  160. if (res.count >= list.value.length) {
  161. if (list.value.length === res.count) {
  162. loadMoreStatus.value = 'noMore'
  163. visualLoadMore.value = true
  164. } else {
  165. list.value.push(...res.data)
  166. loadMoreStatus.value = 'more'
  167. visualLoadMore.value = false
  168. }
  169. } else {
  170. loadMoreStatus.value = 'noMore'
  171. visualLoadMore.value = true
  172. }
  173. } else {
  174. loadMoreStatus.value = 'noMore'
  175. visualLoadMore.value = true
  176. }
  177. }
  178. })
  179. })
  180. onLoad(() => {
  181. onSearch()
  182. })
  183. </script>
  184. <style lang="scss" scoped>
  185. .container {
  186. height: 100vh;
  187. width: 100vw;
  188. background-color: $uni-text-color-inverse;
  189. padding: 0 20rpx;
  190. .header-box {
  191. background-color: $uni-text-color-inverse;
  192. @include topMagnet();
  193. }
  194. .search-box {
  195. margin-bottom: 20rpx;
  196. ::v-deep(.u-search) {
  197. background-color: #e5e5e5;
  198. border-radius: 50rpx;
  199. .u-action {
  200. width: 18%;
  201. background-color: $uni-color-primary;
  202. border-radius: 50rpx;
  203. color: $uni-text-color-inverse;
  204. margin-right: 8rpx;
  205. font-size: 28rpx;
  206. line-height: 50rpx;
  207. letter-spacing: 3rpx;
  208. text-align: center;
  209. }
  210. }
  211. }
  212. .list-box {
  213. .list-item-box {
  214. padding: 20rpx 10rpx;
  215. border-bottom: 5rpx solid #E6E6E6;
  216. display: flex;
  217. &:active {
  218. background-color: $uni-bg-color-hover;
  219. }
  220. .icon-box {
  221. width: 3%;
  222. padding-top: 10rpx;
  223. .icon {
  224. width: 10rpx;
  225. height: 10rpx;
  226. background-color: $uni-color-primary;
  227. border-radius: 50%;
  228. }
  229. }
  230. .info-box {
  231. width: 82%;
  232. .title {
  233. font-size: $uni-title-font-size-2;
  234. font-weight: bold;
  235. margin-bottom: 5rpx;
  236. @include text-overflow()
  237. }
  238. .text {
  239. line-height: 40rpx;
  240. font-size: $uni-font-size-2;
  241. font-weight: bold;
  242. }
  243. }
  244. .suffix-box {
  245. width: 15%;
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. .button {
  250. color: $uni-text-color-inverse;
  251. padding: 5rpx 18rpx;
  252. border-radius: $uni-card-border-radius;
  253. background-color: $uni-color-primary;
  254. font-size: $uni-font-size-3;
  255. letter-spacing: 3rpx;
  256. }
  257. }
  258. }
  259. }
  260. }
  261. </style>