accompanimentModal.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <div class="accompanimentModal">
  3. <van-sticky :offset-top="isHead ? '.46rem' : 0">
  4. <van-dropdown-menu class="cateDropDown" active-color="#01C1B5">
  5. <van-dropdown-item v-model="levelId" :options="levelOptions" @change="levelChange" />
  6. <van-dropdown-item v-model="subjectId" :options="subjectOptions" @change="subjectChange" />
  7. </van-dropdown-menu>
  8. <van-search
  9. v-model="search"
  10. show-action
  11. placeholder="请输入搜索关键词"
  12. shape="round"
  13. >
  14. <template #label>
  15. <van-dropdown-menu class="headDropDown" active-color="#01C1B5">
  16. <van-dropdown-item v-model="typeId" :options="typeOptions" @change="typeChange" />
  17. </van-dropdown-menu>
  18. </template>
  19. <template #action>
  20. <div @click="onSearch">搜索</div>
  21. </template>
  22. </van-search>
  23. </van-sticky>
  24. <van-list
  25. v-model="loading"
  26. v-if="show"
  27. key="data"
  28. :finished="finished"
  29. finished-text="没有更多数据了"
  30. :immediate-check="false"
  31. @load="FetchList"
  32. >
  33. <van-cell-group>
  34. <van-cell
  35. v-for="(item, index) in list"
  36. :key="index"
  37. class="input-cell"
  38. clickable
  39. @click="onSelect(item)"
  40. :center="true"
  41. >
  42. <template slot="icon">
  43. <van-icon class="iconMusic" :name="MusicIcon" />
  44. <div class='icon' v-if="item.rankIds">
  45. <img src='./icons/vip_icon.png' />
  46. </div>
  47. </template>
  48. <template slot="title">
  49. <!-- {{ item.examSongName }} -->
  50. <van-notice-bar
  51. background="none"
  52. :style="{ paddingLeft: (item.rankIds ? '.04rem' : '.15rem') + '!important' }"
  53. color="#444"
  54. :scrollable="false"
  55. :text="item.examSongName"
  56. />
  57. </template>
  58. </van-cell>
  59. </van-cell-group>
  60. </van-list>
  61. <m-empty class="empty" v-else key="data" />
  62. </div>
  63. </template>
  64. <script>
  65. import { find } from 'lodash'
  66. import { sysMusicScoreCategoriesTree, queryPageLimit, querySubjectIds } from './api'
  67. import MusicIcon from './icons/music.png'
  68. export default {
  69. props: {
  70. isHead: {
  71. type: Boolean,
  72. default() {
  73. return false
  74. }
  75. },
  76. searchSubjectId: {
  77. type: [Number, String],
  78. default: 0
  79. }
  80. },
  81. data() {
  82. return {
  83. MusicIcon,
  84. levelId: 0,
  85. tempSubjectId: 0,
  86. levelOptions: [
  87. // { text: '全部等级', value: 0 },
  88. ],
  89. subjectOptions: [
  90. { text: '全部声部', value: 0 }
  91. ],
  92. typeId: 0,
  93. typeOptions: [],
  94. search: null,
  95. loading: false,
  96. finished: false,
  97. show: true,
  98. params: {
  99. page: 1,
  100. rows: 20,
  101. },
  102. list: [],
  103. }
  104. },
  105. computed: {
  106. subjectId() {
  107. return this.tempSubjectId || Number(this.searchSubjectId)
  108. }
  109. },
  110. async mounted() {
  111. await this.FetchLevel()
  112. await this.FetchList()
  113. },
  114. methods: {
  115. async FetchLevel() {
  116. try {
  117. const res = await sysMusicScoreCategoriesTree({ parentId: 1 })
  118. // console.log(res)
  119. this.levelOptions = [...res.data.map((item) => ({value: item.id, text: item.name, childs: item.sysMusicScoreCategoriesList}))]
  120. if (this.levelOptions.length && !this.levelId) {
  121. // console.log(this.levelOptions)
  122. this.levelId = this.levelOptions[0].value
  123. const active = find(this.levelOptions, {value: this.levelId})
  124. if (active) {
  125. if (active.childs) {
  126. this.typeOptions = [{value: 0, text: '全部练习'}, ...active.childs.map((item) => ({value: item.id, text: item.name}))]
  127. } else {
  128. this.typeOptions = null
  129. }
  130. }
  131. }
  132. } catch(error) {
  133. //
  134. }
  135. },
  136. async FetchCats() {
  137. try {
  138. const res = await querySubjectIds()
  139. this.subjectOptions = [...this.subjectOptions, ...res.data.filter((item) => !!item).map((item) => ({value: item.id, text: item.name}))]
  140. } catch (error) {
  141. //
  142. }
  143. },
  144. async FetchList() {
  145. if (this.subjectOptions.length === 1) {
  146. await this.FetchCats()
  147. }
  148. try {
  149. let params = this.params
  150. const res = await queryPageLimit({
  151. ...params,
  152. clientType: 'SMART_PRACTICE',
  153. subjectId: this.subjectId === 0 ? undefined : this.subjectId,
  154. categoriesId: (this.levelId || this.typeId) === 0 ? undefined : this.typeId || this.levelId,
  155. search: this.search
  156. })
  157. this.loading = false;
  158. const { data } = res
  159. this.list = [...this.list, ...data.rows]
  160. if(params.page >= Math.ceil(data.totalPage)) {
  161. this.finished = true
  162. // Toast('列表加载完成')
  163. }
  164. this.params.page = data.nextPage
  165. if(this.list.length <= 0) {
  166. this.show = false
  167. }
  168. } catch {
  169. //
  170. }
  171. },
  172. levelChange(val) {
  173. this.levelId = val
  174. this.typeId = 0
  175. const active = find(this.levelOptions, {value: val})
  176. if (active) {
  177. if (active.childs) {
  178. this.typeOptions = [{value: 0, text: '全部练习'}, ...active.childs.map((item) => ({value: item.id, text: item.name}))]
  179. } else {
  180. this.typeOptions = null
  181. }
  182. }
  183. this.onSearch()
  184. },
  185. subjectChange(val) {
  186. this.tempSubjectId = val
  187. this.onSearch()
  188. },
  189. typeChange(val) {
  190. this.typeId = val
  191. this.onSearch()
  192. },
  193. onSearch() {
  194. this.params.page = 1
  195. this.list = []
  196. this.show = true
  197. this.finished = false
  198. this.FetchList()
  199. },
  200. onSelect(item) {
  201. this.$emit('onSelectMusic', item)
  202. }
  203. }
  204. }
  205. </script>
  206. <style lang="less" scoped>
  207. .accompanimentModal {
  208. background-color: #f5f5f5;
  209. min-height: 100vh;
  210. /deep/.van-search {
  211. .van-cell {
  212. font-size: 0.14rem;
  213. padding: 0.05rem 0.08rem;
  214. line-height: 0.24rem;
  215. }
  216. .van-dropdown-menu__bar {
  217. height: .36rem;
  218. background: transparent;
  219. box-shadow: none;
  220. }
  221. }
  222. .headDropDown {
  223. height: .36rem;
  224. background: transparent;
  225. /deep/.van-dropdown-menu__title {
  226. font-size: .14rem;
  227. }
  228. }
  229. /deep/.van-field__control {
  230. font-size: .14rem;
  231. }
  232. /deep/.van-dropdown-item .van-cell {
  233. padding: 0.12rem 0.16rem;
  234. }
  235. .iconMusic {
  236. /deep/.van-icon__image {
  237. width: .38rem;
  238. height: .38rem;
  239. margin: auto;
  240. vertical-align: middle;
  241. // padding-right: .1rem;
  242. }
  243. }
  244. .icon{
  245. display: flex;
  246. align-items: center;
  247. margin-left: .15rem;
  248. img{
  249. width: .4rem;
  250. // margin-top: -.02rem;
  251. }
  252. }
  253. }
  254. </style>