courseIndex.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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"
  12. @refresherrefresh="pullDownRefreshs" :refresher-triggered="triggereds"
  13. refresher-background="rgba(0,0,0,0)" @refresherrestore="triggereds = false" :upper-threshold="100"
  14. :lower-threshold="100" @refresherabort="triggereds = false" @scrolltolower="reachBottoms">
  15. <view class="justify-between align-center mb20 mlr20 ">
  16. <u-search placeholder="搜索课程" v-model="keyword" :showAction="false" height="30px"
  17. style="width:100%" @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" :class="courserIndex == index ? 'boxnav-active':''"
  23. @click="handleCourse(item,index)">{{item.periodName}}</view>
  24. </view>
  25. </view>
  26. </view>
  27. <u-loadmore :status="status" />
  28. </scroll-view>
  29. </dropdownPanel>
  30. </view>
  31. <view class="justify-between align-center mb20 mlr20 mt20 ">
  32. <u-search placeholder="请输入课程名称" v-model="keywordlist" :showAction="false" height="30px" style="width:100%"
  33. @search='searchKeywordlist' bgColor='#fff'></u-search>
  34. </view>
  35. <view class="container-right">
  36. <scroll-view style="height:100%" :scroll-y="true" :refresher-enabled="isEnableds"
  37. :refresher-triggered="triggered" refresher-background="rgba(0,0,0,0)"
  38. @refresherrefresh="pullDownRefresh" :scroll-top='scrollTop' @refresherrestore="triggered = false"
  39. :upper-threshold="100" :lower-threshold="100" @refresherabort="triggered = false"
  40. @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. 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://zkzh-2025.oss-cn-beijing.aliyuncs.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.getters.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. onChildDataUpdate(data) {
  153. this.childdata = data
  154. this.showShare = this.childdata.onshow
  155. console.log(this.childdata);
  156. console.log('父组件', this.childdata.path + "?course=" + JSON.stringify(this.childdata.params))
  157. },
  158. reflashtime() {
  159. this.keywordlist = ''
  160. this.params.pageNum = 1
  161. this.dataList = []
  162. this.gettodaylist()
  163. this.getFsCourseList('refresh')
  164. },
  165. gettodaylist() {
  166. const data = {
  167. pageNum: this.params.pageNum,
  168. pageSize: this.params.pageSize,
  169. }
  170. getTodayCourse(data).then(res => {
  171. if (res.code == 200) {
  172. this.viewload = false
  173. if (this.params.pageNum == 1) this.dataList = []
  174. this.dataList = [...this.dataList, ...res.data.list]
  175. if (res.data.isLastPage) {
  176. this.loadStatus = 'nomore'
  177. } else {
  178. this.loadStatus = 'loadmore'
  179. }
  180. } else {
  181. uni.showToast({
  182. icon: 'none',
  183. title: res.msg,
  184. });
  185. }
  186. })
  187. },
  188. selindex(e) {
  189. this.seltoday = e.value
  190. if (e.value == 0) {
  191. this.params.pageNum = 1
  192. this.gettodaylist()
  193. } else {
  194. this.params.pageNum = 1
  195. this.keywordlist = ''
  196. this.getFsCourseList('refresh')
  197. }
  198. },
  199. handleShare(config) {
  200. // 保存分享配置到父页面数据
  201. this.shareConfig = config;
  202. this.$emit('child-data-update', this.shareConfig);
  203. // 调起分享面板(微信小程序需主动调用)
  204. // #ifdef MP-WEIXIN
  205. uni.showShareMenu();
  206. // #endif
  207. },
  208. scroll: function(e) {
  209. this.old.scrollTop = e.detail.scrollTop
  210. },
  211. onChange(index) {
  212. this.searchbarNav = index
  213. },
  214. reset() {
  215. this.courseId = ''
  216. this.keyword = ''
  217. this.courseList = []
  218. this.getFsCourseList()
  219. },
  220. handleCourse(item, index) {
  221. console.log(index)
  222. this.courserIndex = index
  223. this.titleName = item.periodName
  224. this.actid = item.periodId
  225. },
  226. confirm() {
  227. if (this.actid == '') {
  228. uni.showToast({
  229. icon: 'none',
  230. title: '请选择课程',
  231. });
  232. return
  233. }
  234. this.courseId = this.actid
  235. this.filterData[1].name = this.titleName
  236. console.log(this.filterData[1].name)
  237. this.params.pageNum = 1
  238. // this.getListInit()
  239. this.getListData('refresh')
  240. },
  241. searchKeyword(value) {
  242. this.courseList = []
  243. this.keyword = value
  244. this.params.pageNum = 1
  245. this.getFsCourseList('refresh')
  246. },
  247. searchKeywordlist(value) {
  248. this.dataList = []
  249. this.keywordlist = value
  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. // uni.showLoading({
  320. // title: "加载中..."
  321. // })
  322. this.loadStatus = 'loading'
  323. const result = await getCourseVdieoList({
  324. periodId: this.courseId,
  325. keyword: this.keywordlist,
  326. ...this.params
  327. })
  328. if (result) {
  329. const {
  330. isLastPage,
  331. total,
  332. list,
  333. } = result.data
  334. if (type == 'refresh') {
  335. this.dataList = list
  336. } else {
  337. this.dataList = [...this.dataList, ...list]
  338. }
  339. if (isLastPage) {
  340. this.loadStatus = 'nomore';
  341. } else {
  342. this.loadStatus = 'loadmore';
  343. }
  344. // 当页数为1时,重置滚动位置
  345. if (this.params.pageNum === 1) {
  346. console.log(this.scrollTop)
  347. this.scrollTop = this.old.scrollTop
  348. this.$nextTick(function() {
  349. this.scrollTop = 0
  350. });
  351. }
  352. uni.hideLoading()
  353. } else {
  354. uni.showToast({
  355. icon: 'none',
  356. title: "请求失败",
  357. });
  358. this.dataList = []
  359. }
  360. },
  361. /**
  362. * 触底添加下一页
  363. */
  364. reachBottom(options) {
  365. if (this.loadStatus === 'loadmore') {
  366. this.loadStatus = 'loading'
  367. uni.showNavigationBarLoading()
  368. setTimeout(() => {
  369. this.params.pageNum += 1;
  370. if (this.seltoday == 0) {
  371. this.gettodaylist()
  372. } else {
  373. this.getListData('more')
  374. }
  375. uni.hideNavigationBarLoading()
  376. }, 500);
  377. }
  378. },
  379. /**
  380. * 下拉列表页
  381. */
  382. pullDownRefresh(options) {
  383. this.triggered = true;
  384. setTimeout(() => {
  385. this.triggered = false;
  386. uni.stopPullDownRefresh()
  387. this.params.pageNum = 1;
  388. if (this.seltoday == 0) {
  389. this.gettodaylist()
  390. } else {
  391. this.getListData('refresh')
  392. }
  393. }, 500)
  394. }
  395. }
  396. }
  397. </script>
  398. <style lang="scss">
  399. .container {
  400. font-family: PingFang SC, PingFang SC;
  401. font-weight: 400;
  402. font-size: 14px;
  403. color: #222;
  404. display: flex;
  405. flex-direction: column;
  406. /* #ifdef MP-WEIXIN */
  407. height: 100vh;
  408. /* #endif */
  409. }
  410. .boxnav {
  411. flex-wrap: wrap;
  412. padding: 0 0 0 10px;
  413. &-item {
  414. width: 50%;
  415. overflow: hidden;
  416. }
  417. &-item-info {
  418. border: 1px solid #f5f5f5;
  419. text-align: center;
  420. color: #222;
  421. background-color: #f5f5f5;
  422. border-radius: 3px;
  423. padding: 5px;
  424. margin: 0 10px 10px 0;
  425. }
  426. &-active {
  427. border: 1px solid #1677ff !important;
  428. color: #1677ff !important;
  429. background-color: #e7f1fe !important;
  430. }
  431. }
  432. .headbox {
  433. background-color: #fff;
  434. }
  435. .headnav {
  436. padding: 15px 12px;
  437. margin: 0 -10px -10px 0;
  438. box-sizing: border-box;
  439. image {
  440. height: 60px;
  441. width: 50px;
  442. position: absolute;
  443. z-index: 0;
  444. bottom: 0;
  445. right: 0;
  446. display: none;
  447. }
  448. &-item {
  449. flex: 1;
  450. font-size: 16px;
  451. padding: 10px;
  452. border-radius: 10px;
  453. background: #f5f5f5;
  454. margin: 0 10px 10px 0;
  455. position: relative;
  456. z-index: 1;
  457. overflow: hidden;
  458. color: #555;
  459. }
  460. &-active {
  461. background-color: rgb(231, 241, 255) !important;
  462. .headnav-num {
  463. color: #1677ff !important;
  464. }
  465. image {
  466. display: block !important;
  467. }
  468. }
  469. &-num {
  470. font-family: DIN, DIN;
  471. font-weight: bold;
  472. font-size: 25px;
  473. margin: 5px 0;
  474. }
  475. }
  476. .searchbar {
  477. flex: 1;
  478. padding-bottom: 10px;
  479. .arrow-down {
  480. margin-left: 5px;
  481. }
  482. &-active {
  483. color: #1677ff !important;
  484. .arrow-down {
  485. transform: rotate(180deg);
  486. }
  487. }
  488. }
  489. .container-right {
  490. flex: 1;
  491. height: calc(100% - 80rpx);
  492. overflow-y: scroll;
  493. // padding-bottom: 80rpx;
  494. .list {
  495. padding: 10px;
  496. box-sizing: border-box;
  497. width: 100%;
  498. }
  499. }
  500. </style>