index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <div class="home-container">
  3. <head-bar :isBack="false">
  4. <template #title>
  5. <div style="width: 90%">
  6. <div class="rightSearch">
  7. <div class="searchImg" @click="search(undefined)">
  8. <img src="../../assets/images/home/search.png" alt="" />
  9. </div>
  10. <el-input
  11. v-model="courseName"
  12. auto-complete="off"
  13. placeholder="搜索课程..."
  14. @input="search(undefined)"
  15. ></el-input>
  16. </div>
  17. </div>
  18. <div class="exit" @click="exitLogin">退出</div>
  19. </template>
  20. </head-bar>
  21. <div class="home-box">
  22. <class-filter @getAll="search" :zoneClass.sync="zoneClass"> </class-filter>
  23. <van-pull-refresh v-model="isLoading" @refresh="onRefresh" class="rheight">
  24. <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad" class="vheight">
  25. <!-- <course-all :courseList="zoneClass"></course-all> -->
  26. <van-empty description="暂无课程" v-if="!zoneClass.length" />
  27. <course-item v-for="(c, cIndex) in zoneClass" :key="cIndex" class="courseItem" :c="c"></course-item>
  28. </van-list>
  29. </van-pull-refresh>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import { selectTypeCourse2 } from '@/api/home'
  35. import { loginOut } from '@/api/user'
  36. import { mapGetters } from 'vuex'
  37. import headBar from '@/components/headBar.vue'
  38. import classFilter from './components/classFilter.vue'
  39. import courseItem from './components/courseItem.vue'
  40. // import courseAll from './components/courseAll.vue'
  41. export default {
  42. components: {
  43. headBar,
  44. classFilter,
  45. courseItem
  46. },
  47. data() {
  48. return {
  49. courseName: '',
  50. zoneClass: [],
  51. typea: '',
  52. typeb: '',
  53. typec: '',
  54. page: 1,
  55. isLoading: false,
  56. loading: false,
  57. finished: false
  58. }
  59. },
  60. computed: {
  61. ...mapGetters(['userinfo'])
  62. },
  63. methods: {
  64. search(tList) {
  65. this.page = 1
  66. if (tList !== undefined) {
  67. var typeList = Object.values(tList)
  68. this.typea = typeList[0]
  69. this.typeb = typeList[2]
  70. this.typec = typeList[1]
  71. }
  72. this.selectAll(true)
  73. },
  74. onRefresh() {
  75. this.page = 1
  76. this.finished = false
  77. this.selectAll(true)
  78. },
  79. onLoad() {
  80. this.page++
  81. this.selectAll()
  82. },
  83. async selectAll(isRefresh) {
  84. const params = {
  85. uid: this.userinfo.userid,
  86. oid: this.userinfo.organizeid,
  87. typea: this.typea !== undefined ? this.typea : '',
  88. typeb: this.typeb !== undefined ? this.typeb : '',
  89. typec: '',
  90. typed: this.typec !== undefined ? this.typec : '',
  91. typeE: '',
  92. cu: '',
  93. cn: this.courseName,
  94. classid: this.userinfo.classid,
  95. org: this.userinfo.org,
  96. page: this.page,
  97. pageSize: 10
  98. }
  99. const res = await selectTypeCourse2(params)
  100. if (isRefresh) {
  101. this.isLoading = false
  102. // 下拉刷新
  103. this.zoneClass = res[0]
  104. } else {
  105. this.loading = false
  106. // 上拉加载
  107. this.zoneClass = [...this.zoneClass, ...res[0]]
  108. }
  109. this.$emit('update:list', this.zoneClass)
  110. if (res[0].length === 0) {
  111. // 证明没有下一页数据了
  112. this.finished = true
  113. }
  114. },
  115. exitLogin() {
  116. this.$dialog({
  117. message: '是否退出' + this.userinfo.username + '账号',
  118. showCancelButton: true,
  119. beforeClose: (action, done) => {
  120. if (action === 'confirm') {
  121. loginOut()
  122. .then(res => {
  123. this.$toast({
  124. message: '退出成功',
  125. type: 'success'
  126. })
  127. this.$store.dispatch('user/logout')
  128. window.location.reload()
  129. done()
  130. })
  131. .catch(err => {
  132. console.error(err)
  133. done()
  134. })
  135. } else {
  136. // 拦截取消操作
  137. done()
  138. }
  139. }
  140. })
  141. }
  142. },
  143. mounted() {
  144. this.selectAll()
  145. }
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. .home-container {
  150. height: 100%;
  151. overflow: hidden;
  152. .home-box {
  153. height: calc(100% - 55px);
  154. margin-top: 55px;
  155. overflow: hidden;
  156. }
  157. .rheight {
  158. height: calc(100% - 40px);
  159. overflow: auto;
  160. background: #e8ebf2;
  161. /deep/.van-pull-refresh__track {
  162. height: 100%;
  163. }
  164. }
  165. .vheight {
  166. padding: 10px 0;
  167. // height: 100%;
  168. // overflow: auto;
  169. }
  170. // .courseBox {
  171. // background: #e8ebf2;
  172. // padding: 15px 0;
  173. .courseItem {
  174. background: #fff;
  175. width: 90%;
  176. margin: 0 auto 15px;
  177. border-radius: 10px;
  178. box-shadow: 0 0 10px 1px #dcdfe6;
  179. padding: 10px;
  180. }
  181. .exit {
  182. color: #fff;
  183. margin-left: 10px;
  184. font-size: 15px;
  185. min-width: 40px;
  186. }
  187. // }
  188. }
  189. /deep/.rightSearch {
  190. display: flex;
  191. flex-direction: row;
  192. width: 100%;
  193. height: 30px;
  194. position: relative;
  195. .searchImg {
  196. width: 20px;
  197. height: 20px;
  198. position: absolute;
  199. z-index: 9;
  200. top: 5px;
  201. left: 5px;
  202. > img {
  203. width: 100%;
  204. height: 100%;
  205. }
  206. }
  207. .el-input__inner {
  208. width: 100%;
  209. height: 30px;
  210. text-indent: 15px;
  211. line-height: 30px;
  212. }
  213. }
  214. </style>