courseIndex.vue 13 KB

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