collect.vue 6.0 KB

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