liveCourse.vue 12 KB

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