index.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. import {
  2. computed,
  3. defineComponent,
  4. nextTick,
  5. onMounted,
  6. reactive,
  7. ref
  8. } from 'vue'
  9. import {
  10. List,
  11. DropdownMenu,
  12. DropdownItem,
  13. Tag,
  14. Image,
  15. Button,
  16. Cell,
  17. Radio,
  18. RadioGroup
  19. } from 'vant'
  20. import Search from '@/components/col-search'
  21. import request from '@/helpers/request'
  22. import { useRoute, useRouter } from 'vue-router'
  23. import ColResult from '@/components/col-result'
  24. import styles from './index.module.less'
  25. import { getRandomKey } from '../music'
  26. import { openDefaultWebView, state as baseState, state } from '@/state'
  27. import { SubjectEnum, useSubjectId } from '@/helpers/hooks'
  28. import Song from '../component/song'
  29. import ColHeader from '@/components/col-header'
  30. import bgImg from '../../images/bg-image.png'
  31. import TheSticky from '@/components/the-sticky'
  32. import dayjs from 'dayjs'
  33. const noop = () => {
  34. //
  35. }
  36. export default defineComponent({
  37. name: 'MusicList',
  38. props: {
  39. teacherId: {
  40. type: String || Number,
  41. default: ''
  42. },
  43. myself: {
  44. type: Boolean,
  45. default: false
  46. }
  47. },
  48. setup({ onItemClick }, { expose }) {
  49. localStorage.setItem('behaviorId', getRandomKey())
  50. const route = useRoute()
  51. const router = useRouter()
  52. //
  53. const subjectType = route.query.subjectType || ''
  54. let title = ''
  55. if (subjectType === 'SUBJECT') {
  56. title = '声部练习'
  57. } else if (subjectType === 'MUSIC') {
  58. title = '独奏曲目'
  59. } else if (subjectType === 'ENSEMBLE') {
  60. title = '合奏练习'
  61. }
  62. const params = reactive({
  63. keyword: (route.query.search as string) || '',
  64. subjectType: subjectType,
  65. page: 1,
  66. subjectId: null,
  67. albumId: null,
  68. albumName: '',
  69. level: '',
  70. type: '',
  71. title: title
  72. })
  73. const data = ref<any>(null)
  74. const loading = ref(false)
  75. const finished = ref(false)
  76. const isError = ref(false)
  77. const searchObj = ref<any>({})
  78. const searchRef = ref()
  79. const albumRef = ref()
  80. const albumRecord = ref<any>([])
  81. const apiSuffix = ref(
  82. baseState.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
  83. )
  84. const onSearch = (value: string) => {
  85. params.page = 1
  86. params.keyword = value
  87. data.value = null
  88. FetchList()
  89. }
  90. const FetchList = async () => {
  91. loading.value = true
  92. isError.value = false
  93. const tempParams = {
  94. ...params
  95. }
  96. try {
  97. const res = await request.post(
  98. `${apiSuffix.value}/tenantAlbumMusic/page`,
  99. {
  100. data: tempParams
  101. }
  102. )
  103. if (data.value?.rows?.length > 0 && res.data.pageNo === 1) {
  104. return
  105. }
  106. if (data.value) {
  107. const result = (data.value?.rows || []).concat(res.data.rows || [])
  108. data.value.rows = result
  109. }
  110. data.value = data.value || res.data
  111. params.page = res.data.pageNo + 1
  112. finished.value = res.data.pageNo >= res.data.totalPage
  113. } catch (error) {
  114. isError.value = true
  115. }
  116. loading.value = false
  117. }
  118. const getSelectCondition = async () => {
  119. const { data } = await request.post(
  120. `${apiSuffix.value}/tenantAlbumMusic/selectCondition`,
  121. {
  122. data: {
  123. subjectType: params.subjectType,
  124. tenantAlbumId: params.albumId
  125. }
  126. }
  127. )
  128. searchObj.value = data || {}
  129. }
  130. const getAlbumRecordPage = async () => {
  131. isError.value = false
  132. try {
  133. const { data } = await request.post('/userTenantAlbumRecord/list', {
  134. prefix:
  135. state.platformType === 'TEACHER' ? '/api-teacher' : '/api-student',
  136. data: {
  137. page: 1,
  138. rows: 999
  139. }
  140. })
  141. albumRecord.value = data || []
  142. if (albumRecord.value.length > 0) {
  143. const albumCatchType = localStorage.getItem(
  144. 'albumCatch' + subjectType
  145. )
  146. if (albumCatchType) {
  147. const item = albumRecord.value.find(
  148. (item: any) => item.tenantAlbumId == albumCatchType
  149. )
  150. if (item) {
  151. params.albumId = item.tenantAlbumId
  152. params.albumName = item.tenantAlbumName
  153. } else {
  154. params.albumId = albumRecord.value[0].tenantAlbumId
  155. params.albumName = albumRecord.value[0].tenantAlbumName
  156. }
  157. } else {
  158. params.albumId = albumRecord.value[0].tenantAlbumId
  159. params.albumName = albumRecord.value[0].tenantAlbumName
  160. }
  161. }
  162. } catch (error) {
  163. isError.value = true
  164. }
  165. }
  166. const isSearchStatus = computed(() => {
  167. const obj = searchObj.value
  168. let status = false
  169. if (obj.subjects && obj.subjects.length > 0) {
  170. status = true
  171. }
  172. if (obj.levelList && obj.levelList.length > 0) {
  173. status = true
  174. }
  175. if (obj.typeList && obj.typeList.length > 0) {
  176. status = true
  177. }
  178. return status
  179. })
  180. onMounted(async () => {
  181. // SUBJECT: '声部练习',
  182. // MUSIC: '独奏曲目',
  183. // ENSEMBLE: '合奏练习'
  184. loading.value = true
  185. await getAlbumRecordPage()
  186. await getSelectCondition()
  187. if (params.albumId) {
  188. await FetchList()
  189. } else {
  190. loading.value = false
  191. }
  192. })
  193. return () => {
  194. return (
  195. <>
  196. <div class={styles.sticky}>
  197. <TheSticky>
  198. <ColHeader
  199. hideHeader={false}
  200. background="transparent"
  201. isFixed={false}
  202. border={false}
  203. title={title}
  204. color="#131415"
  205. >
  206. {{
  207. right: () =>
  208. albumRecord.value.length > 1 &&
  209. params.albumId && (
  210. <DropdownMenu class={styles.albumSearchSection}>
  211. <DropdownItem
  212. titleClass={styles.albumSearchTitle}
  213. title={params.albumName}
  214. ref={albumRef}
  215. >
  216. <div
  217. class={styles.albumSearchResult}
  218. style={{ maxHeight: '45vh', overflowY: 'auto' }}
  219. >
  220. {albumRecord.value.map((item: any) => (
  221. <Cell
  222. border={false}
  223. class={[
  224. styles.albumSearchCell,
  225. item.tenantAlbumId === params.albumId &&
  226. styles.albumSearchCellActive
  227. ]}
  228. center
  229. onClick={async () => {
  230. localStorage.setItem(
  231. 'albumCatch' + subjectType,
  232. item.tenantAlbumId
  233. )
  234. params.albumId = item.tenantAlbumId
  235. params.albumName = item.tenantAlbumName
  236. params.subjectId = null
  237. params.level = ''
  238. params.type = ''
  239. await getSelectCondition()
  240. params.page = 1
  241. data.value = null
  242. await FetchList()
  243. albumRef.value?.toggle()
  244. }}
  245. >
  246. {{
  247. icon: () => (
  248. <Image
  249. src={item.tenantAlbumCoverImg}
  250. class={styles.albumLogo}
  251. />
  252. ),
  253. title: () => (
  254. <div class={styles.albumContent}>
  255. <h2>{item.tenantAlbumName}</h2>
  256. <p>
  257. 到期时间:
  258. {dayjs(item.endTime).format(
  259. 'YYYY-MM-DD'
  260. )}
  261. </p>
  262. </div>
  263. ),
  264. 'right-icon': () => (
  265. <div class={styles.iconSelect}></div>
  266. )
  267. }}
  268. </Cell>
  269. ))}
  270. </div>
  271. </DropdownItem>
  272. </DropdownMenu>
  273. )
  274. }}
  275. </ColHeader>
  276. <Search
  277. onSearch={onSearch}
  278. type="tenant"
  279. background="transparent"
  280. inputBackground="transparent"
  281. // leftIcon={iconSearch}
  282. v-slots={{
  283. left: () => (
  284. <DropdownMenu>
  285. <DropdownItem
  286. disabled={!isSearchStatus.value}
  287. titleClass={
  288. params.subjectId || params.type || params.level
  289. ? styles.titleActive
  290. : ''
  291. }
  292. title="筛选"
  293. ref={searchRef}
  294. >
  295. <div
  296. class={styles.searchResult}
  297. style={{ maxHeight: '45vh', overflowY: 'auto' }}
  298. >
  299. {searchObj.value.subjects &&
  300. searchObj.value.subjects.length > 0 && (
  301. <>
  302. <div class={styles.searchTitle}>声部</div>
  303. <div
  304. class={[
  305. styles['radio-group'],
  306. styles.radio,
  307. styles['organ-radio']
  308. ]}
  309. >
  310. {searchObj.value.subjects.map(
  311. (subject: any) => {
  312. const isActive =
  313. subject.id === params.subjectId
  314. const type = isActive
  315. ? 'primary'
  316. : 'default'
  317. return (
  318. <Tag
  319. size="large"
  320. plain={isActive}
  321. type={type}
  322. round
  323. onClick={() => {
  324. params.subjectId = subject.id
  325. }}
  326. >
  327. {subject.name}
  328. </Tag>
  329. )
  330. }
  331. )}
  332. </div>
  333. </>
  334. )}
  335. {searchObj.value.levelList &&
  336. searchObj.value.levelList.length > 0 && (
  337. <>
  338. <div class={styles.searchTitle}>级别</div>
  339. <div
  340. class={[
  341. styles['radio-group'],
  342. styles.radio,
  343. styles['organ-radio']
  344. ]}
  345. >
  346. {searchObj.value.levelList.map(
  347. (subject: any) => {
  348. const isActive =
  349. subject.id === params.level
  350. const type = isActive
  351. ? 'primary'
  352. : 'default'
  353. return (
  354. <Tag
  355. size="large"
  356. plain={isActive}
  357. type={type}
  358. round
  359. onClick={() => {
  360. params.level = subject.id
  361. }}
  362. >
  363. {subject.value}
  364. </Tag>
  365. )
  366. }
  367. )}
  368. </div>
  369. </>
  370. )}
  371. {searchObj.value.typeList &&
  372. searchObj.value.typeList.length > 0 && (
  373. <>
  374. <div class={styles.searchTitle}>类型</div>
  375. <div
  376. class={[
  377. styles['radio-group'],
  378. styles.radio,
  379. styles['organ-radio']
  380. ]}
  381. >
  382. {searchObj.value.typeList.map(
  383. (subject: any) => {
  384. const isActive =
  385. subject.id === params.type
  386. const type = isActive
  387. ? 'primary'
  388. : 'default'
  389. return (
  390. <Tag
  391. size="large"
  392. plain={isActive}
  393. type={type}
  394. round
  395. onClick={() => {
  396. params.type = subject.id
  397. }}
  398. >
  399. {subject.value}
  400. </Tag>
  401. )
  402. }
  403. )}
  404. </div>
  405. </>
  406. )}
  407. </div>
  408. <div class={['btnGroup', 'btnMore']}>
  409. <Button
  410. type="primary"
  411. plain
  412. round
  413. onClick={() => {
  414. params.subjectId = null
  415. params.level = ''
  416. params.type = ''
  417. }}
  418. >
  419. 重 置
  420. </Button>
  421. <Button
  422. type="primary"
  423. round
  424. block
  425. onClick={() => {
  426. onSearch('')
  427. searchRef.value?.toggle()
  428. }}
  429. >
  430. 确 认
  431. </Button>
  432. </div>
  433. </DropdownItem>
  434. </DropdownMenu>
  435. )
  436. }}
  437. />
  438. </TheSticky>
  439. <img class={styles.bgImg} src={bgImg} />
  440. </div>
  441. <div class={styles.alumnList}>
  442. <List
  443. // loading={loading.value}
  444. finished={finished.value}
  445. finished-text={data.value && data.value.rows.length ? '' : ''}
  446. onLoad={FetchList}
  447. error={isError.value}
  448. immediateCheck={false}
  449. >
  450. {data.value && data.value.rows.length ? (
  451. <Song
  452. showTitleImg
  453. list={data.value.rows}
  454. onDetail={(item: any) => {
  455. router.push({
  456. path: '/music-detail',
  457. query: {
  458. subjectType,
  459. id: item.id,
  460. tenantAlbumId: item.tenantAlbumId
  461. }
  462. })
  463. }}
  464. />
  465. ) : (
  466. !loading.value && (
  467. <ColResult
  468. tips="暂无曲目"
  469. classImgSize="SMALL"
  470. btnStatus={false}
  471. />
  472. )
  473. )}
  474. </List>
  475. </div>
  476. </>
  477. )
  478. }
  479. }
  480. })