courseIndex.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. <template>
  2. <view class="container">
  3. <view class="headbox">
  4. <dropdownPanel :filterData='filterData' @onChange="onChange" @confirm="confirm" @reset="reset"
  5. @onClick="selindex">
  6. <!-- <view class="justify-center align-center">
  7. <view class="u-border ptb4 plr20 radius50 fs24 base-color-6">上一页</view>
  8. <view class="mlr20">1</view>
  9. <view class="u-border ptb4 plr20 radius50 fs24 base-color-6">下一页</view>
  10. </view> -->
  11. <scroll-view scroll-y="true" class="hb" :refresher-enabled="isEnableds" @refresherrefresh="pullDownRefreshs"
  12. :refresher-triggered="triggereds" refresher-background="rgba(0,0,0,0)" @refresherrestore="triggereds = false"
  13. :upper-threshold="100" :lower-threshold="100" @refresherabort="triggereds = false"
  14. @scrolltolower="reachBottoms">
  15. <view class="justify-between align-center mb20 mlr20 ">
  16. <u-search placeholder="搜索课程" v-model="keyword" :showAction="false" height="30px"
  17. @search='searchKeyword'></u-search>
  18. </view>
  19. <view v-if="searchbarNav == 1">
  20. <view class="boxnav x-bc">
  21. <view class="boxnav-item" v-for="(item,index) in courseList" :key="index">
  22. <view class="boxnav-item-info one-t x-bc"
  23. :class="courserIndex == index ? 'boxnav-active':''"
  24. @click="handleCourse(item,index)">{{item.periodName}}
  25. <u-icon v-if="item.isFavorite==0" name="star" color="#999" size="24" @click="doFavorite(item)"></u-icon>
  26. <u-icon v-else name="star-fill" color="#FFE469" size="24" @click="doFavorite(item)"></u-icon>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <u-loadmore :status="status" />
  32. </scroll-view>
  33. </dropdownPanel>
  34. </view>
  35. <view class="justify-between align-center mb20 mlr20 mt20 ">
  36. <u-search placeholder="请输入课程名称" v-model="keywordlist" :showAction="false" height="30px"
  37. @search='searchKeywordlist' bgColor='#fff'></u-search>
  38. </view>
  39. <view class="container-right" >
  40. <scroll-view style="height:100%" :scroll-y="true" :refresher-enabled="isEnableds" :refresher-triggered="triggered"
  41. refresher-background="rgba(0,0,0,0)" @refresherrefresh="pullDownRefresh" :scroll-top='scrollTop'
  42. @refresherrestore="triggered = false" :upper-threshold="100" :lower-threshold="100"
  43. @refresherabort="triggered = false" @scrolltolower="reachBottom" @scroll="scroll">
  44. <view class="list">
  45. <courseItem :from="'course'" :activeTab="1" v-for="(item,index) in dataList" :key="index"
  46. :info="item" @trigger-share="handleShare" :parent-method="parentMethod" @retime='reflashtime'/>
  47. <u-loadmore :status="loadStatus" />
  48. <view class="h120"></view>
  49. </view>
  50. </scroll-view>
  51. </view>
  52. <u-loading-page :loading="viewload" iconSize="32" loadingColor="#3c9cff" fontSize="24"
  53. :loading-text="loadingtext"></u-loading-page>
  54. </view>
  55. </template>
  56. <script>
  57. import {
  58. getFsCourseList,
  59. getCourseVdieoList,
  60. getTodayCourse,
  61. courseFavorite
  62. } from "@/api/manageCompany.js"
  63. import dropdownPanel from "../components/dropdownPanel.vue"
  64. import courseItem from "../components/courseItem.vue"
  65. export default {
  66. name:"liveCourse",
  67. components: {
  68. courseItem,
  69. dropdownPanel
  70. },
  71. props: ['parentMethod'],
  72. data() {
  73. return {
  74. viewload:true,
  75. loadingtext:"数据加载中...",
  76. user: {},
  77. filterData: [{
  78. name: '今日课程',
  79. value: 0,
  80. type: 'click',
  81. },{
  82. name: ' 我的课程',
  83. value: 1,
  84. },
  85. ],
  86. contentH: 0,
  87. activeTab: 1,
  88. courseList: [],
  89. courseId: '',
  90. searchbarNav: 0,
  91. courserIndex: null,
  92. searchbar: [{
  93. name: '我的课程'
  94. },
  95. {
  96. name: '课程状态'
  97. }
  98. ],
  99. mescroll: null,
  100. downOption: {
  101. use: true,
  102. auto: false
  103. },
  104. upOption: {
  105. onScroll: false,
  106. use: true, // 是否启用上拉加载; 默认true
  107. auto: true,
  108. page: {
  109. pae: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  110. size: 10 // 每页数据的数量,默认10
  111. },
  112. noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  113. textNoMore: "已经到底了",
  114. empty: {
  115. icon: 'https://cos.his.cdwjyyh.com/fs/20240423/cf4a86b913a04341bb44e34bb4d37aa2.png',
  116. tip: '暂无数据'
  117. }
  118. },
  119. dataList: [],
  120. params: {
  121. pageNum: 1,
  122. pageSize: 10
  123. },
  124. triggered: false,
  125. loadStatus: 'loadmore',
  126. //课程选择列表
  127. pageNum:1,
  128. pageSize: 10,
  129. triggereds: false,
  130. status: 'loadmore',
  131. keyword:'',
  132. isEnableds:true,
  133. keywordlist:'',
  134. actid:'',
  135. scrollTop: 0,
  136. old: {
  137. scrollTop: 0
  138. },
  139. shareConfig:'',
  140. titleName:'',
  141. seltoday:0,
  142. isFavorite:false
  143. }
  144. },
  145. computed: {
  146. imgPath() {
  147. return this.$store.state.imgpath
  148. }
  149. },
  150. mounted() {
  151. const windowHeight = uni.getSystemInfoSync().windowHeight
  152. this.contentH = `calc(${windowHeight}px - 132px - 56px)`
  153. this.user = uni.getStorageSync("companyUserInfo") ? JSON.parse(uni.getStorageSync("companyUserInfo")) : {}
  154. this.gettodaylist()
  155. console.log(this.courserIndex)
  156. },
  157. methods: {
  158. onChildDataUpdate(data) {
  159. this.childdata = data
  160. this.showShare = this.childdata.onshow
  161. console.log(this.childdata);
  162. console.log('父组件', this.childdata.path + "?course=" +JSON.stringify(this.childdata.params) )
  163. },
  164. reflashtime(){
  165. this.keywordlist=''
  166. this.params.pageNum=1
  167. this.dataList=[]
  168. this.gettodaylist()
  169. this.getFsCourseList('refresh')
  170. },
  171. doFavorite(item) {
  172. // 调用接口(自动切换收藏/取消)
  173. courseFavorite(item.periodId).then(res => {
  174. if (res.code === 200) {
  175. // 接口返回最新状态:true=已收藏,false=未收藏
  176. const favoriteStatus = res.data.favorited;
  177. // 同步更新列表里的 item 状态(控制星星图标)
  178. item.isFavorite = favoriteStatus ? 1 : 0;
  179. this.getFsCourseList('refresh')
  180. if(this.searchbarNav==0){
  181. this.gettodaylist('refresh')
  182. }else{
  183. this.getListInit()
  184. }
  185. setTimeout(() => {
  186. // 提示文字
  187. uni.showToast({
  188. icon: 'none',
  189. title: favoriteStatus ? '收藏成功' : '取消收藏'
  190. });
  191. }, 500);
  192. } else {
  193. // 失败提示
  194. uni.showToast({
  195. icon: 'none',
  196. title: res.msg || '操作失败'
  197. });
  198. }
  199. });
  200. },
  201. gettodaylist(type){
  202. const data={
  203. pageNum:this.params.pageNum,
  204. pageSize:this.params.pageSize,
  205. keyword:this.keywordlist,
  206. }
  207. getTodayCourse(data).then(res=>{
  208. console.log(res)
  209. if(res.code==200){
  210. this.viewload=false
  211. const list=res.data.list
  212. // this.dataList=res.data.list
  213. if (type == 'refresh') {
  214. this.dataList = list
  215. } else {
  216. this.dataList = [...this.dataList, ...list]
  217. }
  218. if ( res.data.isLastPage) {
  219. this.loadStatus = 'nomore'
  220. } else {
  221. this.loadStatus = 'loadmore'
  222. }
  223. }else{
  224. uni.showToast({
  225. icon: 'none',
  226. title: res.msg,
  227. });
  228. }
  229. })
  230. },
  231. selindex(e){
  232. this.seltoday=e.value
  233. if(e.value==0){
  234. this.params.pageNum = 1
  235. this.gettodaylist('refresh')
  236. }else{
  237. this.params.pageNum = 1
  238. this.keywordlist=''
  239. this.getFsCourseList('refresh')
  240. }
  241. console.log(e)
  242. },
  243. handleShare(config) {
  244. // 保存分享配置到父页面数据
  245. this.shareConfig = config;
  246. this.$emit('child-data-update', this.shareConfig);
  247. // 调起分享面板(微信小程序需主动调用)
  248. // #ifdef MP-WEIXIN
  249. uni.showShareMenu();
  250. // #endif
  251. },
  252. scroll: function(e) {
  253. this.old.scrollTop = e.detail.scrollTop
  254. },
  255. onChange(index) {
  256. this.searchbarNav = index
  257. },
  258. reset() {
  259. this.courseId = ''
  260. this.actid=''
  261. this.keyword =''
  262. this.courseList=[]
  263. this.courserIndex=null
  264. this.pageNum=1
  265. this.getFsCourseList('refresh')
  266. if(this.searchbarNav==0){
  267. this.filterData[0].name='今日课程'
  268. this.gettodaylist('refresh')
  269. }else{
  270. this.filterData[1].name='我的课程'
  271. this.getListInit()
  272. }
  273. },
  274. handleCourse(item,index) {
  275. console.log(index)
  276. this.courserIndex = index
  277. this.titleName=item.periodName
  278. this.actid=item.periodId
  279. },
  280. confirm() {
  281. if(this.actid==''){
  282. uni.showToast({
  283. icon: 'none',
  284. title: '请选择课程',
  285. });
  286. return
  287. }
  288. this.courseId = this.actid
  289. this.filterData[1].name=this.titleName
  290. console.log(this.filterData[1].name)
  291. this.params.pageNum=1
  292. // this.getListInit()
  293. this.getListData('refresh')
  294. },
  295. searchKeyword(value){
  296. this.courseList=[]
  297. this.keyword = value
  298. this.params.pageNum=1
  299. this.getFsCourseList('refresh')
  300. },
  301. searchKeywordlist(value){
  302. this.dataList = []
  303. this.keywordlist = value
  304. if(this.seltoday==0){
  305. this.gettodaylist()
  306. }else{
  307. this.getListData()
  308. }
  309. },
  310. pullDownRefreshs() {
  311. // 下拉
  312. this.triggereds = true; //下拉了状态为true
  313. setTimeout(() => {
  314. this.triggereds = false;
  315. uni.stopPullDownRefresh()
  316. this.pageNum = 1;
  317. this.getFsCourseList('refresh') //触底 不穿执行else
  318. // 请求接口里面需要判断是不是最后一页 是最后一页 status赋值为‘loadmore’没有更多了
  319. // 请求接口
  320. }, 1000)
  321. },
  322. reachBottoms() {
  323. // status这个是加载状态
  324. if (this.status === 'loadmore') {
  325. this.status = 'loading'
  326. uni.showNavigationBarLoading()
  327. setTimeout(() => {
  328. this.pageNum++
  329. this.getFsCourseList() //触底 不穿执行else
  330. uni.hideNavigationBarLoading()
  331. }, 1000);
  332. }
  333. },
  334. // 训练营
  335. getFsCourseList(type) {
  336. const day = uni.$u.timeFormat(new Date(), 'yyyy-mm-dd')
  337. const param = {
  338. pageNum:this.pageNum,
  339. pageSize:this.pageSize,
  340. keyword:this.keyword
  341. }
  342. getFsCourseList(param).then(res => {
  343. if (res.code == 200) {
  344. if (type == 'refresh') {
  345. this.courseList = res.data.list
  346. } else {
  347. // 加载更多 当前页和下一页合并
  348. this.courseList = [...this.courseList, ...res.data.list]
  349. }
  350. if ( res.data.isLastPage) {
  351. this.status = 'nomore'
  352. } else {
  353. this.status = 'loadmore'
  354. }
  355. // this.courseId=this.courseList[0].periodId
  356. // this.filterData[1].name=this.courseList[0].periodName
  357. // this.getListInit()
  358. } else {
  359. uni.showToast({
  360. icon: 'none',
  361. title: res.msg,
  362. });
  363. }
  364. })
  365. },
  366. handleNav(type) {
  367. this.activeTab = type
  368. },
  369. clickSearchbar(type) {
  370. this.searchbarNav = type == this.searchbarNav ? 'colse' : type
  371. },
  372. getListInit() {
  373. this.params.pageNum = 1
  374. this.getListData('refresh')
  375. },
  376. async getListData(type) {
  377. console.log(type)
  378. uni.showLoading({
  379. title: "加载中..."
  380. })
  381. this.loadStatus = 'loading'
  382. const result = await getCourseVdieoList({
  383. periodId: this.courseId,
  384. keyword:this.keywordlist,
  385. ...this.params
  386. })
  387. if (result) {
  388. const {
  389. isLastPage,
  390. total,
  391. list,
  392. } = result.data
  393. if (type == 'refresh') {
  394. this.dataList = list
  395. } else {
  396. this.dataList = [...this.dataList, ...list]
  397. }
  398. if (isLastPage) {
  399. this.loadStatus = 'nomore';
  400. } else {
  401. this.loadStatus = 'loadmore';
  402. }
  403. // 当页数为1时,重置滚动位置
  404. if (this.params.pageNum === 1) {
  405. console.log(this.scrollTop)
  406. this.scrollTop = this.old.scrollTop
  407. this.$nextTick(function() {
  408. this.scrollTop = 0
  409. });
  410. }
  411. uni.hideLoading()
  412. } else {
  413. uni.showToast({
  414. icon: 'none',
  415. title: "请求失败",
  416. });
  417. this.dataList = []
  418. }
  419. },
  420. /**
  421. * 触底添加下一页
  422. */
  423. reachBottom(options) {
  424. if (this.loadStatus === 'loadmore') {
  425. this.loadStatus = 'loading'
  426. uni.showNavigationBarLoading()
  427. setTimeout(() => {
  428. this.params.pageNum += 1;
  429. // this.getListData('more')
  430. if(this.seltoday==0){
  431. this.gettodaylist('more')
  432. }else{
  433. this.getListData('more')
  434. }
  435. uni.hideNavigationBarLoading()
  436. }, 500);
  437. }
  438. },
  439. /**
  440. * 下拉列表页
  441. */
  442. pullDownRefresh(options) {
  443. this.triggered = true;
  444. setTimeout(() => {
  445. this.triggered = false;
  446. uni.stopPullDownRefresh()
  447. this.params.pageNum = 1;
  448. if(this.seltoday==0){
  449. this.gettodaylist('refresh')
  450. }else{
  451. this.getListData('refresh')
  452. }
  453. }, 500)
  454. }
  455. }
  456. }
  457. </script>
  458. <style lang="scss">
  459. .container {
  460. font-family: PingFang SC, PingFang SC;
  461. font-weight: 400;
  462. font-size: 14px;
  463. color: #222;
  464. display: flex;
  465. flex-direction: column;
  466. /* #ifdef MP-WEIXIN */
  467. height: 100vh;
  468. /* #endif */
  469. }
  470. .boxnav {
  471. flex-wrap: wrap;
  472. padding: 0 0 0 10px;
  473. &-item {
  474. width: 50%;
  475. overflow: hidden;
  476. }
  477. &-item-info {
  478. border: 1px solid #f5f5f5;
  479. text-align: center;
  480. color: #222;
  481. background-color: #f5f5f5;
  482. border-radius: 3px;
  483. padding: 5px;
  484. margin: 0 10px 10px 0;
  485. }
  486. &-active {
  487. border: 1px solid #1677ff !important;
  488. color: #1677ff !important;
  489. background-color: #e7f1fe !important;
  490. }
  491. }
  492. .headbox {
  493. background-color: #fff;
  494. }
  495. .headnav {
  496. padding: 15px 12px;
  497. margin: 0 -10px -10px 0;
  498. box-sizing: border-box;
  499. image {
  500. height: 60px;
  501. width: 50px;
  502. position: absolute;
  503. z-index: 0;
  504. bottom: 0;
  505. right: 0;
  506. display: none;
  507. }
  508. &-item {
  509. flex: 1;
  510. font-size: 16px;
  511. padding: 10px;
  512. border-radius: 10px;
  513. background: #f5f5f5;
  514. margin: 0 10px 10px 0;
  515. position: relative;
  516. z-index: 1;
  517. overflow: hidden;
  518. color: #555;
  519. }
  520. &-active {
  521. background-color: rgb(231, 241, 255) !important;
  522. .headnav-num {
  523. color: #1677ff !important;
  524. }
  525. image {
  526. display: block !important;
  527. }
  528. }
  529. &-num {
  530. font-family: DIN, DIN;
  531. font-weight: bold;
  532. font-size: 25px;
  533. margin: 5px 0;
  534. }
  535. }
  536. .searchbar {
  537. flex: 1;
  538. padding-bottom: 10px;
  539. .arrow-down {
  540. margin-left: 5px;
  541. }
  542. &-active {
  543. color: #1677ff !important;
  544. .arrow-down {
  545. transform: rotate(180deg);
  546. }
  547. }
  548. }
  549. .container-right {
  550. flex: 1;
  551. height: calc(100% - 80rpx);
  552. overflow-y: scroll;
  553. // padding-bottom: 80rpx;
  554. .list {
  555. padding: 10px;
  556. box-sizing: border-box;
  557. width: 100%;
  558. }
  559. }
  560. </style>