collect.vue 6.1 KB

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