homePageSearch.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <template>
  2. <view class="container">
  3. <!-- 顶部导航 Tab -->
  4. <view class="top-nav">
  5. <view class="search-cont">
  6. <view class="inner">
  7. <image class="icon-search"
  8. src="https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/search.png" mode="">
  9. </image>
  10. <input type="text" @confirm="goSearch" v-model="keywordValue" placeholder="请输入关键字搜索内容"
  11. placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
  12. <u-icon v-if="keywordValue != ''" name="close-circle" color="#00000073" size="20"
  13. @tap="deleteKeywordMethods"></u-icon>
  14. </view>
  15. <view class="searchBtnViewClass" @tap="goSearch">搜索</view>
  16. </view>
  17. <view v-if="false" class="nav-row">
  18. <view class="nav-all" :class="{ active: activeId === 'all' }" @tap.stop="onSelectAll">
  19. <text>全部</text>
  20. </view>
  21. <scroll-view scroll-x class="nav-scroll" :show-scrollbar="false">
  22. <view class="nav-inner">
  23. <view v-for="(item, index) in navList" :key="index"
  24. :class="['nav-item', { active: item.id === activeId }]"
  25. @tap.stop="onSelectByIndex(item.id)">
  26. <text>{{ item.categoryName }}</text>
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. </view>
  32. <scroll-view scroll-y class="scroll-wrap" :show-scrollbar="false" :scroll-top="scrollTop"
  33. @scrolltolower="isSearch ? getPageSearchCoursesData() : getPageRecommendCoursesData()">
  34. <!-- 没有搜索词-推荐课程 -->
  35. <template v-if="!isSearch">
  36. <view style="height: 300rpx;width: 100%;"> </view>
  37. <view class="recommend-section">
  38. <text class="recommend-title">大家都在学习</text>
  39. <view v-if="recommendList.length > 0" class="course-grid" style="padding: 0;">
  40. <view v-for="(course, idx) in recommendList" :key="idx" class="course-card"
  41. @click="onCourseClick(course)">
  42. <view class="card-cover">
  43. <image :src="course.imgUrl || '/static/logo.jpg'" mode="aspectFill" class="cover-img">
  44. </image>
  45. </view>
  46. <view class="card-footer">
  47. <text class="card-title">{{ course.courseName }}</text>
  48. <view class="x-end" style="justify-content: space-between;">
  49. <view class="course-meta">
  50. <image src="@/static/images/new/renshu.png"></image>
  51. <text class="meta-count">{{ course.watchUserCount }}</text>
  52. </view>
  53. <view class="btn-watch" @click.stop="onCourseClick(course)">立即观看</view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. <view v-else class="empty-state">
  59. <image class="empty-icon" src="@/static/images/new/nodata.png"></image>
  60. <text class="empty-text">暂无课程</text>
  61. </view>
  62. </view>
  63. </template>
  64. <!-- 搜索后的课程列表 内容 -->
  65. <template v-else>
  66. <view v-if="courseList.length > 0" class="course-grid">
  67. <view v-for="(course, idx) in courseList" :key="idx" class="course-card"
  68. @click="onCourseClick(course)">
  69. <view class="card-cover">
  70. <image :src="course.imgUrl || '/static/logo.jpg'" mode="aspectFill" class="cover-img">
  71. </image>
  72. </view>
  73. <view class="course-info">
  74. <text class="card-title">{{ course.courseName }}</text>
  75. <view class="x-end" style="justify-content: space-between;">
  76. <view class="course-meta">
  77. <image src="@/static/images/new/renshu.png"></image>
  78. <text class="meta-count">{{ course.watchUserCount }}</text>
  79. </view>
  80. <view class="btn-watch" @click.stop="onCourseClick(course)">立即观看</view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. <view v-if="isSearch && courseList.length == 0" class="empty-state">
  86. <image class="empty-icon" src="@/static/images/new/nodata.png"></image>
  87. <text class="empty-text">没有搜索任何内容,换个词试试</text>
  88. </view>
  89. </template>
  90. <view class="bottom-placeholder"></view>
  91. </scroll-view>
  92. </view>
  93. </template>
  94. <script>
  95. import {
  96. courseListDataApi
  97. } from '@/api/home'
  98. export default {
  99. data() {
  100. return {
  101. keywordValue: '',
  102. statusBarHeight: uni.getSystemInfoSync().statusBarHeight + 'px',
  103. activeId: 'all',
  104. courseList: [],
  105. isSearch: false,
  106. scrollTop: 0,
  107. searchPage: {
  108. pageNum: 1,
  109. pageSize: 10,
  110. total: 0,
  111. },
  112. navList: [{
  113. id: 37,
  114. categoryName: "健康食品"
  115. },
  116. {
  117. id: 35,
  118. categoryName: "绿色有机"
  119. },
  120. {
  121. id: 36,
  122. categoryName: "膳食营养"
  123. },
  124. {
  125. id: 33,
  126. categoryName: "太极养生"
  127. }
  128. ],
  129. recommendList: [],
  130. recommendPage: {
  131. pageNum: 1,
  132. pageSize: 10,
  133. total: 0,
  134. },
  135. }
  136. },
  137. onLoad() {
  138. this.getRecommendData()
  139. },
  140. methods: {
  141. deleteKeywordMethods() {
  142. this.keywordValue = ''
  143. this.isSearch = false
  144. this.courseList = []
  145. this.scrollTop = 0
  146. },
  147. goSearch() {
  148. if (this.keywordValue == '') {
  149. this.isSearch = false
  150. this.searchPage.pageNum = 1;
  151. this.searchPage.total = 0;
  152. this.courseList = [];
  153. } else {
  154. this.resetSearchDataList()
  155. }
  156. },
  157. onSelectAll() {
  158. this.activeId = 'all'
  159. },
  160. onCourseClick(course) {
  161. uni.navigateTo({
  162. url: `/pages/course/info?courseId=${course.courseId}`
  163. })
  164. },
  165. onSelectByIndex(id) {
  166. this.activeId = id
  167. },
  168. // 搜索课程列表
  169. async searchCourseList() {
  170. let params = {
  171. pageNum: this.searchPage.pageNum,
  172. pageSize: this.searchPage.pageSize,
  173. keyword: this.keywordValue,
  174. };
  175. uni.showLoading({
  176. title: "加载中...",
  177. mask: true,
  178. })
  179. const res = await courseListDataApi(params);
  180. this.isSearch = true
  181. uni.hideLoading()
  182. if (res.code === 200 && res.data.list.length > 0) {
  183. this.searchPage.total = res.data.total;
  184. this.courseList = [...this.courseList, ...res.data.list];
  185. }
  186. },
  187. // 分页获取搜索课程列表
  188. getPageSearchCoursesData() {
  189. if (this.searchPage.total <= this.courseList.length) {
  190. return;
  191. }
  192. this.searchPage.pageNum++;
  193. this.searchCourseList();
  194. },
  195. // 搜索课程列表重置方法
  196. resetSearchDataList() {
  197. this.searchPage.pageNum = 1;
  198. this.searchPage.total = 0;
  199. this.courseList = [];
  200. this.scrollTop = 0;
  201. this.searchCourseList();
  202. },
  203. // 获取推荐课程列表
  204. async getRecommendData() {
  205. let params = {
  206. pageNum: this.recommendPage.pageNum,
  207. pageSize: this.recommendPage.pageSize,
  208. };
  209. const res = await courseListDataApi(params);
  210. if (res.code === 200 && res.data.list.length > 0) {
  211. this.recommendPage.total = res.data.total;
  212. this.recommendList = [...this.recommendList, ...res.data.list];
  213. }
  214. },
  215. // 分页获取推荐课程列表
  216. getPageRecommendCoursesData() {
  217. if (this.recommendPage.total <= this.recommendList.length) {
  218. return;
  219. }
  220. this.recommendPage.pageNum++;
  221. this.getRecommendData();
  222. },
  223. // 推荐课程列表重置方法
  224. resetRecommendDataList() {
  225. this.recommendPage.pageNum = 1;
  226. this.recommendPage.total = 0;
  227. this.recommendList = [];
  228. this.getRecommendData();
  229. },
  230. }
  231. }
  232. </script>
  233. <style lang="scss" scoped>
  234. /* 图片箭头旋转类(展开时向上) */
  235. .rotate-arrow {
  236. transform: rotate(180deg);
  237. }
  238. .container {
  239. // min-height: 100vh;
  240. background: #F5F5F5;
  241. display: flex;
  242. flex-direction: column;
  243. }
  244. /* 顶部 Tab */
  245. .top-nav {
  246. display: flex;
  247. flex-direction: column;
  248. background: #fff;
  249. }
  250. .search-cont {
  251. padding: 24rpx 24rpx 20rpx;
  252. background-color: #FFFFFF;
  253. display: flex;
  254. align-items: center;
  255. justify-content: space-between;
  256. .inner {
  257. box-sizing: border-box;
  258. width: calc(100vw - 135rpx);
  259. height: 72rpx;
  260. background: #F7F7F7;
  261. border-radius: 38rpx;
  262. display: flex;
  263. align-items: center;
  264. padding: 0 20rpx;
  265. .icon-search {
  266. width: 28upx;
  267. height: 28upx;
  268. margin-right: 20upx;
  269. }
  270. input {
  271. height: 65rpx;
  272. line-height: 65rpx;
  273. flex: 1;
  274. font-size: 32rpx;
  275. padding-right: 15rpx;
  276. }
  277. }
  278. .searchBtnViewClass {
  279. font-weight: 400;
  280. font-size: 36rpx;
  281. color: #222222;
  282. }
  283. .icon-search {
  284. margin-left: 10upx;
  285. width: 40upx;
  286. height: 40upx;
  287. image {
  288. width: 40upx;
  289. height: 40upx;
  290. }
  291. }
  292. }
  293. .nav-row {
  294. display: flex;
  295. align-items: center;
  296. padding: 0 24rpx 24rpx;
  297. gap: 30rpx;
  298. }
  299. .nav-all {
  300. flex-shrink: 0;
  301. font-family: PingFangSC, PingFang SC;
  302. font-weight: 400;
  303. font-size: 40rpx;
  304. color: rgba(0, 0, 0, 0.85);
  305. line-height: 56rpx;
  306. }
  307. .nav-all.active {
  308. color: #FF233C;
  309. font-weight: 600;
  310. }
  311. .nav-scroll {
  312. flex: 1;
  313. }
  314. .nav-inner {
  315. display: inline-flex;
  316. padding: 0;
  317. gap: 30rpx;
  318. }
  319. .nav-item {
  320. flex-shrink: 0;
  321. font-family: PingFangSC, PingFang SC;
  322. font-weight: 400;
  323. font-size: 40rpx;
  324. color: rgba(0, 0, 0, 0.85);
  325. line-height: 56rpx;
  326. }
  327. .nav-item.active {
  328. color: #FF233C;
  329. font-weight: 600;
  330. }
  331. /* 滚动区 */
  332. .scroll-wrap {
  333. flex: 1;
  334. height: 0;
  335. }
  336. /* 课程网格 */
  337. .course-grid {
  338. display: flex;
  339. flex-wrap: wrap;
  340. padding: 24rpx;
  341. gap: 24rpx 20rpx;
  342. flex-direction: column;
  343. }
  344. .course-card {
  345. display: flex;
  346. background: #fff;
  347. border-radius: 20rpx;
  348. overflow: hidden;
  349. padding: 20rpx;
  350. }
  351. .course-tag {
  352. position: absolute;
  353. left: 0;
  354. bottom: 0;
  355. right: 0;
  356. padding: 8rpx 12rpx;
  357. background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
  358. font-size: 22rpx;
  359. color: #fff;
  360. }
  361. .course-info {
  362. flex: 1;
  363. padding-left: 24rpx;
  364. /* padding: 20rpx 24rpx; */
  365. display: flex;
  366. flex-direction: column;
  367. justify-content: space-between;
  368. min-width: 0;
  369. }
  370. .course-meta {
  371. display: flex;
  372. align-items: center;
  373. image {
  374. width: 30rpx;
  375. height: 30rpx;
  376. }
  377. }
  378. .meta-icon {
  379. font-size: 24rpx;
  380. margin-right: 6rpx;
  381. color: #999;
  382. }
  383. .meta-count {
  384. margin-left: 10rpx;
  385. font-family: PingFangSC, PingFang SC;
  386. font-weight: 400;
  387. font-size: 32rpx;
  388. color: #666666;
  389. }
  390. .card-cover {
  391. position: relative;
  392. width: 296rpx;
  393. height: 222rpx;
  394. border-radius: 20rpx;
  395. overflow: hidden;
  396. flex-shrink: 0;
  397. }
  398. .cover-img {
  399. width: 100%;
  400. height: 100%;
  401. background: #BB6D6D;
  402. }
  403. .card-title {
  404. font-family: PingFangSC, PingFang SC;
  405. font-weight: 600;
  406. font-size: 36rpx;
  407. color: #222222;
  408. line-height: 50rpx;
  409. text-align: justify;
  410. overflow: hidden;
  411. text-overflow: ellipsis;
  412. display: -webkit-box;
  413. -webkit-line-clamp: 2;
  414. -webkit-box-orient: vertical;
  415. }
  416. .card-footer {
  417. flex: 1;
  418. padding-left: 24rpx;
  419. /* padding: 20rpx 24rpx; */
  420. display: flex;
  421. flex-direction: column;
  422. justify-content: space-between;
  423. min-width: 0;
  424. }
  425. .card-views {
  426. font-family: PingFangSC, PingFang SC;
  427. font-weight: 400;
  428. font-size: 32rpx;
  429. color: #666666;
  430. line-height: 44rpx;
  431. }
  432. .btn-watch {
  433. width: 168rpx;
  434. height: 64rpx;
  435. line-height: 60rpx;
  436. text-align: center;
  437. background: linear-gradient(135deg, #FF5267 0%, #FF233C 100%);
  438. border-radius: 32rpx;
  439. font-family: PingFangSC, PingFang SC;
  440. font-weight: 600;
  441. font-size: 32rpx;
  442. color: #FFFFFF;
  443. }
  444. /* 最近学习 - 按日期分组 */
  445. .recent-group {
  446. padding: 24rpx 24rpx 0;
  447. }
  448. .group-date {
  449. display: flex;
  450. align-items: center;
  451. margin-bottom: 24rpx;
  452. }
  453. .date-icon {
  454. width: 32rpx;
  455. height: 32rpx;
  456. margin-right: 8rpx;
  457. }
  458. .date-text {
  459. font-family: PingFangSC, PingFang SC;
  460. font-weight: 600;
  461. font-size: 40rpx;
  462. line-height: 56rpx;
  463. color: #222222;
  464. }
  465. .recent-card {
  466. display: flex;
  467. background: #fff;
  468. border-radius: 20rpx;
  469. overflow: hidden;
  470. padding: 20rpx;
  471. margin-bottom: 24rpx;
  472. }
  473. .recent-card:last-child {
  474. margin-bottom: 0;
  475. }
  476. .recent-thumb {
  477. position: relative;
  478. width: 296rpx;
  479. height: 222rpx;
  480. border-radius: 20rpx;
  481. overflow: hidden;
  482. flex-shrink: 0;
  483. }
  484. .thumb-img {
  485. width: 100%;
  486. height: 100%;
  487. background: #BB6D6D;
  488. }
  489. .recent-info {
  490. flex: 1;
  491. padding-left: 24rpx;
  492. /* padding: 20rpx 24rpx; */
  493. display: flex;
  494. flex-direction: column;
  495. justify-content: space-between;
  496. min-width: 0;
  497. }
  498. .recent-title {
  499. font-family: PingFangSC, PingFang SC;
  500. font-weight: 600;
  501. font-size: 36rpx;
  502. color: #222222;
  503. line-height: 50rpx;
  504. text-align: justify;
  505. overflow: hidden;
  506. text-overflow: ellipsis;
  507. display: -webkit-box;
  508. -webkit-line-clamp: 2;
  509. -webkit-box-orient: vertical;
  510. }
  511. .recent-progress {
  512. font-family: PingFangSC, PingFang SC;
  513. font-weight: 400;
  514. font-size: 32rpx;
  515. color: rgba(0, 0, 0, 0.65);
  516. line-height: 44rpx;
  517. }
  518. /* 空态 */
  519. .empty-state {
  520. display: flex;
  521. flex-direction: column;
  522. align-items: center;
  523. justify-content: center;
  524. padding: 80rpx 0 48rpx;
  525. /* background: linear-gradient(180deg, #fff5f5 0%, #fff 100%); */
  526. }
  527. .empty-icon {
  528. width: 310rpx;
  529. height: 260rpx;
  530. margin-bottom: 30rpx;
  531. }
  532. .empty-text {
  533. font-family: PingFangSC, PingFang SC;
  534. font-weight: 400;
  535. font-size: 36rpx;
  536. color: rgba(0, 0, 0, 0.25);
  537. line-height: 50rpx;
  538. }
  539. /* 为您精选 */
  540. .recommend-section {
  541. padding: 0 24rpx 32rpx;
  542. }
  543. .recommend-title {
  544. display: block;
  545. font-family: PingFangSC, PingFang SC;
  546. font-weight: 600;
  547. font-size: 40rpx;
  548. color: #222222;
  549. line-height: 56rpx;
  550. padding-bottom: 24rpx;
  551. }
  552. .bottom-placeholder {
  553. height: 120rpx;
  554. }
  555. </style>