index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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: true
  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. } else {
  114. this.finished = false
  115. }
  116. },
  117. exitLogin() {
  118. this.$dialog({
  119. message: '是否退出' + this.userinfo.username + '账号',
  120. showCancelButton: true,
  121. beforeClose: (action, done) => {
  122. if (action === 'confirm') {
  123. loginOut()
  124. .then(res => {
  125. this.$toast({
  126. message: '退出成功',
  127. type: 'success'
  128. })
  129. this.$store.dispatch('user/logout')
  130. window.location.reload()
  131. done()
  132. })
  133. .catch(err => {
  134. console.error(err)
  135. done()
  136. })
  137. } else {
  138. // 拦截取消操作
  139. done()
  140. }
  141. }
  142. })
  143. }
  144. },
  145. mounted() {
  146. this.selectAll()
  147. }
  148. }
  149. </script>
  150. <style lang="scss" scoped>
  151. .home-container {
  152. height: 100%;
  153. overflow: hidden;
  154. .home-box {
  155. height: calc(100% - 55px);
  156. margin-top: 55px;
  157. overflow: hidden;
  158. }
  159. .rheight {
  160. height: calc(100% - 40px);
  161. overflow: auto;
  162. background: #e8ebf2;
  163. /deep/.van-pull-refresh__track {
  164. height: 100%;
  165. }
  166. }
  167. .vheight {
  168. padding: 10px 0;
  169. // height: 100%;
  170. // overflow: auto;
  171. }
  172. // .courseBox {
  173. // background: #e8ebf2;
  174. // padding: 15px 0;
  175. .courseItem {
  176. background: #fff;
  177. width: 90%;
  178. margin: 0 auto 15px;
  179. border-radius: 10px;
  180. box-shadow: 0 0 10px 1px #dcdfe6;
  181. padding: 10px;
  182. }
  183. .exit {
  184. color: #fff;
  185. margin-left: 10px;
  186. font-size: 15px;
  187. min-width: 40px;
  188. }
  189. // }
  190. }
  191. /deep/.rightSearch {
  192. display: flex;
  193. flex-direction: row;
  194. width: 100%;
  195. height: 30px;
  196. position: relative;
  197. .searchImg {
  198. width: 20px;
  199. height: 20px;
  200. position: absolute;
  201. z-index: 9;
  202. top: 5px;
  203. left: 5px;
  204. > img {
  205. width: 100%;
  206. height: 100%;
  207. }
  208. }
  209. .el-input__inner {
  210. width: 100%;
  211. height: 30px;
  212. text-indent: 15px;
  213. line-height: 30px;
  214. }
  215. }
  216. </style>