home.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div class="homePage">
  3. <div class="homeContent">
  4. <scroller
  5. :isInitRefresh="false"
  6. ref="recordScroller"
  7. :list="courseList"
  8. noDataText="没有更多..."
  9. :on-refresh='resetList'
  10. :on-infinite="getMoreList">
  11. <div class="tit" style="margin-top: .3rem;" v-if="freeCourseList.length>0">
  12. <span>今日更新</span>
  13. </div>
  14. <div class="freeContent" v-if="freeCourseList.length>0">
  15. <div class="freeLi" v-for="(item,index) in freeCourseList" :key="index" @click="toUrl(item)">
  16. <div class="liIcon">
  17. <van-icon name="play-circle-o" />
  18. </div>
  19. <div class="freeR">
  20. <p>{{ item.name }}</p>
  21. <span>{{ Math.floor(Math.random()*100) }}人浏览</span>
  22. </div>
  23. </div>
  24. </div>
  25. <div class="tit">
  26. <span>课程推荐</span>
  27. </div>
  28. <courseList :dataList="courseList" :showNum="4"></courseList>
  29. </scroller>
  30. <van-tabbar v-model="active" @change="activeChange">
  31. <van-tabbar-item icon="home-o">首页</van-tabbar-item>
  32. <van-tabbar-item icon="friends-o">我的</van-tabbar-item>
  33. </van-tabbar>
  34. </div>
  35. </div>
  36. </template>
  37. <script>
  38. import { getUserAllCourseList ,getFreeCourseList} from "./api";
  39. import courseList from "./components/courseList.vue";
  40. import {setDocumentTitle} from '../../components/vueHashCalendar/utils/util'
  41. import {setWxConfig} from './utils'
  42. import wx from 'weixin-js-sdk'
  43. export default {
  44. name: "courseHome",
  45. components: {
  46. courseList
  47. },
  48. data() {
  49. return {
  50. active:0,
  51. canReq: true,
  52. noDate: false,
  53. logo:require('../../../static/images/logo.png'),
  54. page: {
  55. cur: 1,
  56. size: 10,
  57. total: 0
  58. },
  59. courseList: [],
  60. freeCourseList:[]
  61. };
  62. },
  63. created() {
  64. setDocumentTitle('首页')
  65. this.init();
  66. if(this.$isWx){
  67. let info = {
  68. title:'公道云课程',// 分享标题
  69. desc:'公道云',// 分享描述
  70. link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  71. imgUrl: this.logo, // 分享图标
  72. }
  73. setWxConfig(info);
  74. }
  75. },
  76. methods: {
  77. //跳转免费课程
  78. toUrl(item){
  79. this.$router.push({
  80. path:`/freeCourse`,
  81. query:item
  82. })
  83. },
  84. // 触底加载
  85. getMoreList(done) {
  86. if (!this.noDate) {
  87. setTimeout(() => {
  88. this.getList(done);
  89. }, 300);
  90. } else {
  91. this.$refs.recordScroller.finishInfinite(true);
  92. }
  93. },
  94. //上拉刷新
  95. resetList(done){
  96. this.page.cur = 1;
  97. this.getList(done,1)
  98. },
  99. //底部导航变化
  100. activeChange(){
  101. if(this.active != 0){
  102. this.$router.push('/courseUser')
  103. this.active = 0
  104. }
  105. },
  106. // 初始化
  107. init() {
  108. this.getList();
  109. this.getFreeList();
  110. },
  111. // 获取免费课程列表
  112. getFreeList(){
  113. getFreeCourseList().then(res=>{
  114. this.freeCourseList = res.sections
  115. })
  116. },
  117. // 获取所有课程列表
  118. getList(done,type) {
  119. let data = {
  120. page: this.page.cur,
  121. pageSize: this.page.size,
  122. enable: 1
  123. };
  124. getUserAllCourseList(data).then(res => {
  125. let list = []
  126. res.list.forEach(item => {
  127. let data = {
  128. subjectName: item.name,
  129. subjectId: item.id,
  130. subjectPrice: item.price,
  131. subjectThumb: item.thumb,
  132. subjectEnable: item.enable,
  133. sectionsNum: item.sectionsNum,
  134. clickNum:Number(item.baseClick) + Number(item.clickNum)
  135. };
  136. list.push(data);
  137. });
  138. if(type == 1){
  139. this.courseList = list;
  140. }else{
  141. this.courseList = this.courseList.concat(list);
  142. }
  143. this.page.total = res.total;
  144. this.page.cur = res.current;
  145. if (res.pages == res.current || res.pages == 0) {
  146. if (done) done(true);
  147. this.noDate = true;
  148. } else {
  149. if (done) done();
  150. this.page.cur++; //下拉一次页数+1
  151. this.noDate = false;
  152. }
  153. });
  154. },
  155. }
  156. };
  157. </script>
  158. <style scoped lang="scss">
  159. *{
  160. margin: 0;
  161. padding: 0;
  162. }
  163. .homePage {
  164. background: #f3f2ee;
  165. background: linear-gradient(90deg, #f3f2ee, #e7eff9);
  166. .homeContent {
  167. height: calc(100vh - 1rem);
  168. margin: 0 .2rem;
  169. box-sizing: border-box;
  170. position: relative;
  171. .tit{
  172. display: flex;
  173. span{
  174. font-size: .32rem;
  175. color: #000;
  176. font-weight: 600;
  177. line-height: .6rem;
  178. }
  179. }
  180. .freeContent{
  181. margin-bottom: .3rem;
  182. .freeLi{
  183. background-color: #FFF;
  184. display: flex;
  185. justify-content: space-between;
  186. align-items: center;
  187. border-radius: 0.1rem;
  188. margin-bottom: 0.1rem;
  189. padding: 0.15rem;
  190. .liIcon{
  191. background: #DBECFE;
  192. width: .8rem;
  193. height: .8rem;
  194. display: flex;
  195. justify-content: center;
  196. align-items: center;
  197. border-radius: .1rem;
  198. i{
  199. font-size: .62rem;
  200. color:#609DFF;
  201. }
  202. }
  203. .freeR{
  204. flex: 1;
  205. margin-left: .2rem;
  206. width: calc(100% - 1.2rem);
  207. p{
  208. font-size: .3rem;
  209. color: #333;
  210. line-height: .35rem;
  211. text-overflow: ellipsis;
  212. overflow: hidden;
  213. word-break: break-all;
  214. white-space: nowrap;
  215. }
  216. span{
  217. font-size: .22rem;
  218. color: #999;
  219. line-height: .3rem;
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. </style>