guide.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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="true"
  20. v-model="searchForm.codeCurrent"
  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="onGuideClick(item)">
  41. <view class="main-box">
  42. <view class="icon-box">
  43. <view class="iconfont icon-banshizhiyin"></view>
  44. <!-- <cover-image class="icon"
  45. :src="`${FILE_URL}/notice/icon-1.jpg`"></cover-image> -->
  46. </view>
  47. <view class="content-box">
  48. <view class="title">
  49. {{item.title}}
  50. </view>
  51. <!-- <view class="text">
  52. {{item.desc}}
  53. </view> -->
  54. </view>
  55. <!-- <view class="other-box">
  56. <view class="date">
  57. {{item.date}}
  58. </view>
  59. </view> -->
  60. </view>
  61. <view class="line-box"></view>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script setup>
  67. import { ref } from 'vue'
  68. import { onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app'
  69. import { getGuideList as query, getGuideType } from '@/api/notice.js'
  70. import configService from '@/utils/baseurl.js'
  71. const FILE_URL = configService.FILE_URL;
  72. const uToast = ref()
  73. const searchInputStyle = {
  74. backgroundColor: '#E5E5E5'
  75. }
  76. const searchType = ref([
  77. {
  78. label: '全部',
  79. value: null
  80. }
  81. ])
  82. const pageNum = ref(1)
  83. const pageSize = ref(10)
  84. const visualLoadMore = ref(false)
  85. const loadMoreStatus = ref('more')
  86. const searchForm = ref({
  87. keyword: '',
  88. code: null,
  89. codeCurrent: 0,
  90. pageNumber: 1,
  91. pageSize: 10
  92. })
  93. const list = ref([
  94. ])
  95. function onSearchConfirm() {
  96. searchForm.value.pageNumber = 1
  97. pageNum.value = 1
  98. onSearch()
  99. }
  100. function onSearchClear() {
  101. searchForm.value.keyword = null
  102. searchForm.value.pageNumber = 1
  103. pageNum.value = 1
  104. onSearch()
  105. }
  106. function onSearch() {
  107. loadMoreStatus.value = 'more'
  108. query(searchForm.value).then(res => {
  109. if (res && res.code === 0) {
  110. list.value = res.data
  111. if (res.count === 0) {
  112. visualLoadMore.value = false
  113. }
  114. }
  115. })
  116. }
  117. function onSearchTypeChange(val) {
  118. searchForm.value.code = searchType.value[val].value
  119. onSearchConfirm()
  120. }
  121. onPullDownRefresh((e) => {
  122. searchForm.value.pageNumber = 1
  123. loadMoreStatus.value = 'more'
  124. query(searchForm.value).then(res => {
  125. if (res && res.code === 0) {
  126. list.value = res.data
  127. if (res.count === 0) {
  128. visualLoadMore.value = false
  129. }
  130. uni.showToast({
  131. title: '刷新成功',
  132. icon: 'success',
  133. duration: 2000
  134. })
  135. }
  136. uni.stopPullDownRefresh()
  137. })
  138. })
  139. onReachBottom(async () => {
  140. if (loadMoreStatus.value === 'noMore') {
  141. uni.showToast({
  142. title: '没有更多啦>﹏<',
  143. icon: 'none'
  144. })
  145. return
  146. }
  147. visualLoadMore.value = true
  148. loadMoreStatus.value = 'loading'
  149. searchForm.value.pageNumber++
  150. query(searchForm.value).then(res => {
  151. if (res && res.code === 0) {
  152. if (res.data) {
  153. if (res.count >= list.value.length) {
  154. if (list.value.length === res.count) {
  155. loadMoreStatus.value = 'noMore'
  156. visualLoadMore.value = true
  157. } else {
  158. list.value.push(...res.data)
  159. loadMoreStatus.value = 'more'
  160. visualLoadMore.value = false
  161. }
  162. } else {
  163. loadMoreStatus.value = 'noMore'
  164. visualLoadMore.value = true
  165. }
  166. } else {
  167. loadMoreStatus.value = 'noMore'
  168. visualLoadMore.value = true
  169. }
  170. }
  171. })
  172. })
  173. onLoad(()=>{
  174. getGuideType().then(res => {
  175. if (res && res.code === 0) {
  176. let data = res.data.map(item => {
  177. return {
  178. label: item.name,
  179. value: item.code
  180. }
  181. })
  182. searchType.value.push(...data)
  183. }
  184. })
  185. onSearch()
  186. })
  187. function onGuideClick(guide) {
  188. uni.navigateTo({
  189. url: `/pages/guide/guideDetail/guideDetail?id=${guide.id}&title=${guide.title}`
  190. })
  191. }
  192. </script>
  193. <style lang="scss" scoped>
  194. .container {
  195. height: 100vh;
  196. width: 100vw;
  197. background-color: #FFFFFF;
  198. padding: 0 20rpx env(safe-area-inset-bottom, 0);
  199. .header-box {
  200. background-color: $uni-text-color-inverse;
  201. @include topMagnet();
  202. }
  203. .search-box {
  204. margin-bottom: 20rpx;
  205. ::v-deep(.u-search) {
  206. background-color: #e5e5e5;
  207. border-radius: 50rpx;
  208. .u-action {
  209. width: 18%;
  210. background-color: $uni-color-primary;
  211. border-radius: 50rpx;
  212. color: $uni-text-color-inverse;
  213. margin-right: 8rpx;
  214. font-size: 28rpx;
  215. line-height: 50rpx;
  216. letter-spacing: 3rpx;
  217. text-align: center;
  218. }
  219. }
  220. }
  221. .list-box {
  222. padding: 0 20rpx;
  223. .list-item-box {
  224. .main-box {
  225. display: flex;
  226. // justify-content: space-between;
  227. align-items: center;
  228. padding: 30rpx 0;
  229. &:active {
  230. background-color: $uni-bg-color-hover;
  231. }
  232. .icon-box {
  233. width: 15%;
  234. display: flex;
  235. justify-content: center;
  236. align-items: center;
  237. .icon {
  238. width: 70rpx;
  239. height: 70rpx;
  240. }
  241. .iconfont{
  242. font-size: 60rpx;
  243. color: #0069f6;
  244. }
  245. }
  246. .content-box {
  247. // width: 67%;
  248. display: flex;
  249. flex-direction: column;
  250. justify-content: space-around;
  251. gap: 10rpx;
  252. .title {
  253. height: calc(70% - 5rpx);
  254. font-size: $uni-title-font-size-2;
  255. font-weight: bold;
  256. }
  257. .text {
  258. height: calc(30% - 5rpx);
  259. font-size: $uni-font-size-3;
  260. color: $uni-text-color-grey;
  261. @include text-overflow();
  262. }
  263. }
  264. .other-box {
  265. width: 18%;
  266. display: flex;
  267. flex-direction: column;
  268. justify-content: space-around;
  269. align-items: center;
  270. gap: 10rpx;
  271. .date {
  272. font-size: $uni-font-size-3;
  273. color: $uni-text-color-grey;
  274. }
  275. .tag {
  276. font-size: $uni-font-size-3;
  277. width: 42rpx;
  278. background-color: $uni-color-error;
  279. color: $uni-text-color-inverse;
  280. border-radius: 20rpx;
  281. text-align: center;
  282. }
  283. }
  284. }
  285. .line-box {
  286. height: 1rpx;
  287. width: 80%;
  288. background-color: #E5E5E5;
  289. margin: 0 auto;
  290. }
  291. }
  292. }
  293. }
  294. </style>