courseIndex.vue 12 KB

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