courseIndex.vue 12 KB

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