courseIndex.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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. console.log(this.dataList);
  184. if ( res.data.isLastPage) {
  185. this.loadStatus = 'nomore'
  186. } else {
  187. this.loadStatus = 'loadmore'
  188. }
  189. }else{
  190. uni.showToast({
  191. icon: 'none',
  192. title: res.msg,
  193. });
  194. }
  195. })
  196. },
  197. selindex(e){
  198. this.seltoday=e.value
  199. if(e.value==0){
  200. this.params.pageNum = 1
  201. this.gettodaylist('refresh')
  202. }else{
  203. this.params.pageNum = 1
  204. this.keywordlist=''
  205. this.getFsCourseList('refresh')
  206. }
  207. console.log(e)
  208. },
  209. handleShare(config) {
  210. // 保存分享配置到父页面数据
  211. this.shareConfig = config;
  212. this.$emit('child-data-update', this.shareConfig);
  213. // 调起分享面板(微信小程序需主动调用)
  214. // #ifdef MP-WEIXIN
  215. uni.showShareMenu();
  216. // #endif
  217. },
  218. scroll: function(e) {
  219. this.old.scrollTop = e.detail.scrollTop
  220. },
  221. onChange(index) {
  222. this.searchbarNav = index
  223. },
  224. reset() {
  225. this.courseId = ''
  226. this.keyword =''
  227. this.courseList=[]
  228. this.getFsCourseList()
  229. },
  230. handleCourse(item,index) {
  231. console.log(index)
  232. this.courserIndex = index
  233. this.titleName=item.periodName
  234. this.actid=item.periodId
  235. },
  236. confirm() {
  237. if(this.actid==''){
  238. uni.showToast({
  239. icon: 'none',
  240. title: '请选择课程',
  241. });
  242. return
  243. }
  244. this.courseId = this.actid
  245. this.filterData[1].name=this.titleName
  246. console.log(this.filterData[1].name)
  247. this.params.pageNum=1
  248. // this.getListInit()
  249. this.getListData('refresh')
  250. },
  251. searchKeyword(value){
  252. this.courseList=[]
  253. this.keyword = value
  254. this.params.pageNum=1
  255. this.getFsCourseList('refresh')
  256. },
  257. searchKeywordlist(value){
  258. this.dataList = []
  259. this.keywordlist = value
  260. if(this.seltoday==0){
  261. this.gettodaylist()
  262. }else{
  263. this.getListData()
  264. }
  265. },
  266. pullDownRefreshs() {
  267. // 下拉
  268. this.triggereds = true; //下拉了状态为true
  269. setTimeout(() => {
  270. this.triggereds = false;
  271. uni.stopPullDownRefresh()
  272. this.pageNum = 1;
  273. this.getFsCourseList('refresh') //触底 不穿执行else
  274. // 请求接口里面需要判断是不是最后一页 是最后一页 status赋值为‘loadmore’没有更多了
  275. // 请求接口
  276. }, 1000)
  277. },
  278. reachBottoms() {
  279. // status这个是加载状态
  280. if (this.status === 'loadmore') {
  281. this.status = 'loading'
  282. uni.showNavigationBarLoading()
  283. setTimeout(() => {
  284. this.pageNum++
  285. this.getFsCourseList() //触底 不穿执行else
  286. uni.hideNavigationBarLoading()
  287. }, 1000);
  288. }
  289. },
  290. // 训练营
  291. getFsCourseList(type) {
  292. const day = uni.$u.timeFormat(new Date(), 'yyyy-mm-dd')
  293. const param = {
  294. pageNum:this.pageNum,
  295. pageSize:this.pageSize,
  296. keyword:this.keyword
  297. }
  298. getFsCourseList(param).then(res => {
  299. if (res.code == 200) {
  300. if (type == 'refresh') {
  301. this.courseList = res.data.list
  302. } else {
  303. // 加载更多 当前页和下一页合并
  304. this.courseList = [...this.courseList, ...res.data.list]
  305. }
  306. if ( res.data.isLastPage) {
  307. this.status = 'nomore'
  308. } else {
  309. this.status = 'loadmore'
  310. }
  311. // this.courseId=this.courseList[0].periodId
  312. // this.filterData[1].name=this.courseList[0].periodName
  313. // this.getListInit()
  314. } else {
  315. uni.showToast({
  316. icon: 'none',
  317. title: res.msg,
  318. });
  319. }
  320. })
  321. },
  322. handleNav(type) {
  323. this.activeTab = type
  324. },
  325. clickSearchbar(type) {
  326. this.searchbarNav = type == this.searchbarNav ? 'colse' : type
  327. },
  328. getListInit() {
  329. this.params.pageNum = 1
  330. this.getListData('refresh')
  331. },
  332. async getListData(type) {
  333. console.log(type)
  334. uni.showLoading({
  335. title: "加载中..."
  336. })
  337. this.loadStatus = 'loading'
  338. const result = await getCourseVdieoList({
  339. periodId: this.courseId,
  340. keyword:this.keywordlist,
  341. ...this.params
  342. })
  343. if (result) {
  344. const {
  345. isLastPage,
  346. total,
  347. list,
  348. } = result.data
  349. if (type == 'refresh') {
  350. this.dataList = list
  351. } else {
  352. this.dataList = [...this.dataList, ...list]
  353. }
  354. if (isLastPage) {
  355. this.loadStatus = 'nomore';
  356. } else {
  357. this.loadStatus = 'loadmore';
  358. }
  359. // 当页数为1时,重置滚动位置
  360. if (this.params.pageNum === 1) {
  361. console.log(this.scrollTop)
  362. this.scrollTop = this.old.scrollTop
  363. this.$nextTick(function() {
  364. this.scrollTop = 0
  365. });
  366. }
  367. uni.hideLoading()
  368. } else {
  369. uni.showToast({
  370. icon: 'none',
  371. title: "请求失败",
  372. });
  373. this.dataList = []
  374. }
  375. },
  376. /**
  377. * 触底添加下一页
  378. */
  379. reachBottom(options) {
  380. if (this.loadStatus === 'loadmore') {
  381. this.loadStatus = 'loading'
  382. uni.showNavigationBarLoading()
  383. setTimeout(() => {
  384. this.params.pageNum += 1;
  385. // this.getListData('more')
  386. if(this.seltoday==0){
  387. this.gettodaylist('more')
  388. }else{
  389. this.getListData('more')
  390. }
  391. uni.hideNavigationBarLoading()
  392. }, 500);
  393. }
  394. },
  395. /**
  396. * 下拉列表页
  397. */
  398. pullDownRefresh(options) {
  399. this.triggered = true;
  400. setTimeout(() => {
  401. this.triggered = false;
  402. uni.stopPullDownRefresh()
  403. this.params.pageNum = 1;
  404. if(this.seltoday==0){
  405. this.gettodaylist('refresh')
  406. }else{
  407. this.getListData('refresh')
  408. }
  409. }, 500)
  410. }
  411. }
  412. }
  413. </script>
  414. <style lang="scss">
  415. .container {
  416. font-family: PingFang SC, PingFang SC;
  417. font-weight: 400;
  418. font-size: 14px;
  419. color: #222;
  420. display: flex;
  421. flex-direction: column;
  422. /* #ifdef MP-WEIXIN */
  423. height: 100vh;
  424. /* #endif */
  425. }
  426. .boxnav {
  427. flex-wrap: wrap;
  428. padding: 0 0 0 10px;
  429. &-item {
  430. width: 50%;
  431. overflow: hidden;
  432. }
  433. &-item-info {
  434. border: 1px solid #f5f5f5;
  435. text-align: center;
  436. color: #222;
  437. background-color: #f5f5f5;
  438. border-radius: 3px;
  439. padding: 5px;
  440. margin: 0 10px 10px 0;
  441. }
  442. &-active {
  443. border: 1px solid #1677ff !important;
  444. color: #1677ff !important;
  445. background-color: #e7f1fe !important;
  446. }
  447. }
  448. .headbox {
  449. background-color: #fff;
  450. }
  451. .headnav {
  452. padding: 15px 12px;
  453. margin: 0 -10px -10px 0;
  454. box-sizing: border-box;
  455. image {
  456. height: 60px;
  457. width: 50px;
  458. position: absolute;
  459. z-index: 0;
  460. bottom: 0;
  461. right: 0;
  462. display: none;
  463. }
  464. &-item {
  465. flex: 1;
  466. font-size: 16px;
  467. padding: 10px;
  468. border-radius: 10px;
  469. background: #f5f5f5;
  470. margin: 0 10px 10px 0;
  471. position: relative;
  472. z-index: 1;
  473. overflow: hidden;
  474. color: #555;
  475. }
  476. &-active {
  477. background-color: rgb(231, 241, 255) !important;
  478. .headnav-num {
  479. color: #1677ff !important;
  480. }
  481. image {
  482. display: block !important;
  483. }
  484. }
  485. &-num {
  486. font-family: DIN, DIN;
  487. font-weight: bold;
  488. font-size: 25px;
  489. margin: 5px 0;
  490. }
  491. }
  492. .searchbar {
  493. flex: 1;
  494. padding-bottom: 10px;
  495. .arrow-down {
  496. margin-left: 5px;
  497. }
  498. &-active {
  499. color: #1677ff !important;
  500. .arrow-down {
  501. transform: rotate(180deg);
  502. }
  503. }
  504. }
  505. .container-right {
  506. flex: 1;
  507. height: calc(100% - 80rpx);
  508. overflow-y: scroll;
  509. // padding-bottom: 80rpx;
  510. .list {
  511. padding: 10px;
  512. box-sizing: border-box;
  513. width: 100%;
  514. }
  515. }
  516. </style>