index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view>
  3. <view>
  4. <!--#ifdef APP-PLUS-->
  5. <view class="lz-status_bar">
  6. <view class="lz-top_view"></view>
  7. </view>
  8. <!--#endif-->
  9. <!-- #ifndef MP-WEIXIN -->
  10. <view class="kaoshi-head">
  11. <view class="kaoshi-head-top">
  12. <view class="kaoshi-head-left">
  13. <view class="iconfont icon-zuojiantou" @tap="$navigateBack"></view>
  14. </view>
  15. <view class="kaoshi-head-m">选择科目</view>
  16. <view class="kaoshi-head-right"></view>
  17. </view>
  18. </view>
  19. <!--#endif-->
  20. </view>
  21. <view class="kaoshi-subject">
  22. <view class="classifybox">
  23. <view class="classify" v-for="(item,index) in list" :key="index"
  24. :class="classifytype == index ? 'active' : ''" @tap="changeclassify(index,item.id)">
  25. <view class="classifytext">{{item.subject_name}}</view>
  26. </view>
  27. </view>
  28. <view class="liebiaobox">
  29. <view class="class" v-for="(item,index) in classlist" :key="index">
  30. <view :class="Subject_id == item.id ? 'active' : ''" class="classtext"
  31. @tap="tap_handle_choice_subject(item)">{{item.subject_name}}</view>
  32. <view v-if="Subject_id == item.id" class="iconfont icon-dui1"></view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import {
  40. mapState
  41. } from 'vuex'
  42. export default {
  43. data() {
  44. return {
  45. list: [], //科目列表
  46. Subject_id: 0, //已选的科目id
  47. classifytype: 0,
  48. classlist: [], //科目2级列表
  49. }
  50. },
  51. onShow() {
  52. // 获取科目列表
  53. this.getSub()
  54. this.Subject_id = this.subject.id
  55. },
  56. computed: {
  57. ...mapState(['subject', 'userinfo', 'subjectVip'])
  58. },
  59. methods: {
  60. async getSub() {
  61. let res = await this.$myHttp.post({
  62. url: this.$myHttp.urlMap.subjectList,
  63. data: {
  64. page: 1,
  65. limit: 0
  66. },
  67. needLogin: false
  68. })
  69. if (res.code === 1) {
  70. this.list = res.data
  71. this.classlist = this.list[0].childlist
  72. }
  73. },
  74. async tap_handle_choice_subject(item) {
  75. this.$store.commit('setSubject', {
  76. subject: {
  77. id: item.id,
  78. subject_name: item.subject_name
  79. }
  80. })
  81. if (this.userinfo.user_id !== undefined) {
  82. await this.$myUserLogin.getSubvip(this.subject.id)
  83. }
  84. this.$myUtils.$router.switchTab({
  85. url: '/pages/index/index'
  86. })
  87. },
  88. changeclassify(index, id) {
  89. this.classifytype = index
  90. this.classlist = this.list[index].childlist
  91. }
  92. }
  93. }
  94. </script>
  95. <style>
  96. page {
  97. background: #fff
  98. }
  99. .kaoshi-subject {
  100. display: flex;
  101. align-items: flex-start;
  102. background: #fff;
  103. height: 100vh;
  104. }
  105. .classifybox {
  106. width: 40%;
  107. background-color: #f6f9fc;
  108. height: 100vh;
  109. }
  110. .classify,
  111. .class {
  112. display: flex;
  113. align-items: center;
  114. height: 50px;
  115. }
  116. .classifytext {
  117. margin-left: 15px;
  118. padding-left: 10px;
  119. font-size: 15px;
  120. line-height: 18px;
  121. border-left: 3px solid transparent;
  122. }
  123. .classify.active {
  124. background-color: #fff;
  125. }
  126. .classify.active .classifytext {
  127. border-left: 3px solid #3a79f7;
  128. }
  129. .liebiaobox {
  130. width: 60%;
  131. height: 100vh;
  132. }
  133. .class {
  134. display: flex;
  135. justify-content: space-between;
  136. align-items: center;
  137. padding: 0 15px;
  138. font-size: 14px;
  139. }
  140. .classtext.active {
  141. font-weight: bold;
  142. }
  143. .icon-dui1 {
  144. color: #0ec380;
  145. }
  146. </style>