collect.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. searchForm.value.type = searchType[val].value
  124. onSearchConfirm()
  125. }
  126. function onClickReport(report) {
  127. uni.navigateTo({
  128. url: `/pages/reportDetail/reportDetail?id=${report.id}&title=${report.title}`
  129. })
  130. }
  131. onPullDownRefresh((e) => {
  132. searchForm.value.pageNumber = 1
  133. loadMoreStatus.value = 'more'
  134. query(searchForm.value).then(res => {
  135. if (res && res.message === 'success') {
  136. list.value = res.data
  137. if (res.count === 0) {
  138. visualLoadMore.value = false
  139. }
  140. uni.showToast({
  141. title: '刷新成功',
  142. icon: 'success',
  143. duration: 2000
  144. })
  145. }
  146. uni.stopPullDownRefresh()
  147. })
  148. })
  149. onReachBottom(async () => {
  150. if (loadMoreStatus.value === 'noMore') {
  151. uni.showToast({
  152. title: '没有更多啦>﹏<',
  153. icon: 'none'
  154. })
  155. return
  156. }
  157. visualLoadMore.value = true
  158. loadMoreStatus.value = 'loading'
  159. searchForm.value.pageNum++
  160. query(searchForm.value).then(res => {
  161. if (res && res.message === 'success') {
  162. if (res.data) {
  163. if (res.count >= list.value.length) {
  164. if (list.value.length === res.count) {
  165. loadMoreStatus.value = 'noMore'
  166. visualLoadMore.value = true
  167. } else {
  168. list.value.push(...res.data)
  169. loadMoreStatus.value = 'more'
  170. visualLoadMore.value = false
  171. }
  172. } else {
  173. loadMoreStatus.value = 'noMore'
  174. visualLoadMore.value = true
  175. }
  176. } else {
  177. loadMoreStatus.value = 'noMore'
  178. visualLoadMore.value = true
  179. }
  180. }
  181. })
  182. })
  183. onLoad(() => {
  184. onSearch()
  185. })
  186. </script>
  187. <style lang="scss" scoped>
  188. .container {
  189. height: 100vh;
  190. width: 100vw;
  191. background-color: $uni-text-color-inverse;
  192. padding: 0 20rpx;
  193. .header-box {
  194. background-color: $uni-text-color-inverse;
  195. @include topMagnet();
  196. }
  197. .search-box {
  198. margin-bottom: 20rpx;
  199. ::v-deep(.u-search) {
  200. background-color: #e5e5e5;
  201. border-radius: 50rpx;
  202. .u-action {
  203. width: 18%;
  204. background-color: $uni-color-primary;
  205. border-radius: 50rpx;
  206. color: $uni-text-color-inverse;
  207. margin-right: 8rpx;
  208. font-size: 28rpx;
  209. line-height: 50rpx;
  210. letter-spacing: 3rpx;
  211. text-align: center;
  212. }
  213. }
  214. }
  215. .list-box {
  216. .list-item-box {
  217. padding: 20rpx 10rpx;
  218. border-bottom: 5rpx solid #E6E6E6;
  219. display: flex;
  220. &:active {
  221. background-color: $uni-bg-color-hover;
  222. }
  223. .icon-box {
  224. width: 3%;
  225. padding-top: 10rpx;
  226. .icon {
  227. width: 10rpx;
  228. height: 10rpx;
  229. background-color: $uni-color-primary;
  230. border-radius: 50%;
  231. }
  232. }
  233. .info-box {
  234. width: 82%;
  235. .title {
  236. font-size: $uni-title-font-size-2;
  237. font-weight: bold;
  238. margin-bottom: 5rpx;
  239. @include text-overflow()
  240. }
  241. .text {
  242. line-height: 40rpx;
  243. font-size: $uni-font-size-2;
  244. font-weight: bold;
  245. }
  246. }
  247. .suffix-box {
  248. width: 15%;
  249. display: flex;
  250. align-items: center;
  251. justify-content: center;
  252. .button {
  253. color: $uni-text-color-inverse;
  254. padding: 5rpx 18rpx;
  255. border-radius: $uni-card-border-radius;
  256. background-color: $uni-color-primary;
  257. font-size: $uni-font-size-3;
  258. letter-spacing: 3rpx;
  259. }
  260. }
  261. }
  262. }
  263. }
  264. </style>