accompanimentModal.vue 8.2 KB

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