index.tsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. import { computed, defineComponent, onMounted, reactive, ref, watch } from 'vue'
  2. import {
  3. Image,
  4. Tabs,
  5. Tab,
  6. List,
  7. Button,
  8. Popup,
  9. Dialog,
  10. Sticky,
  11. Swipe,
  12. SwipeItem
  13. } from 'vant'
  14. import styles from './index.module.less'
  15. import TheSticky from '@/components/the-sticky'
  16. import ColHeader from '@/components/col-header'
  17. import { useWindowScroll, useEventListener } from '@vueuse/core'
  18. import request from '@/helpers/request'
  19. import iconMenu from './images/icon-menu.png'
  20. import iconRightTop from './images/icon-right-top.png'
  21. import iconAlbumCover from '../../images/icon-album-cover.png'
  22. import iconTimer from './images/icon-timer.png'
  23. import { state as baseState, setLogout } from '@/state'
  24. import Song from '../component/song'
  25. import { useRoute, useRouter } from 'vue-router'
  26. import ColResult from '@/components/col-result'
  27. import { moneyFormat } from '@/helpers/utils'
  28. import { orderStatus } from '@/views/order-detail/orderStatus'
  29. import { postMessage } from '@/helpers/native-message'
  30. import { browser } from '@/helpers/utils'
  31. // Import Swiper Vue.js components
  32. // import Swiper core and required modules
  33. import { Pagination } from 'swiper/modules'
  34. import { Swiper, SwiperSlide } from 'swiper/vue'
  35. // Import Swiper styles
  36. import 'swiper/css'
  37. import 'swiper/css/pagination'
  38. import CourseItem from '../lessonCourseware/component/CourseItem'
  39. export default defineComponent({
  40. name: 'train-tool',
  41. setup() {
  42. const subjectType = sessionStorage.getItem('tool-subject-type')
  43. sessionStorage.removeItem('tool-subject-type')
  44. const route = useRoute()
  45. const router = useRouter()
  46. const background = ref<string>('rgba(55, 205, 177, 0)')
  47. const color = ref<string>('#fff')
  48. const state = reactive({
  49. details: {} as any,
  50. buy: route.query.buy as any,
  51. albumId: route.query.albumId || null,
  52. activeTab: route.query.subjectType || 'SUBJECT',
  53. loadingAlbum: false,
  54. loading: false,
  55. finished: false,
  56. isError: false,
  57. list: [] as any,
  58. popupStatus: false,
  59. selectMember: {} as any, // 购买的月份
  60. ensembleCounts: false,
  61. musicCounts: false,
  62. subjectCounts: false,
  63. coursewareCounts: false,
  64. tenantAlbumStatus: 0 as any,
  65. ablumStatus: false,
  66. heightV: 0,
  67. hasBuyStatus: true, // 是否能继续购买
  68. albumList: [] as any // 专辑列表
  69. })
  70. const params = reactive({
  71. page: 1,
  72. rows: 20
  73. })
  74. const apiSuffix = ref(
  75. baseState.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
  76. )
  77. const isSingleAlbum = computed(() => {
  78. const query = route.query
  79. if (query.taId || query.albumId) {
  80. return true
  81. } else {
  82. return false
  83. }
  84. })
  85. const getDetails = async () => {
  86. state.loadingAlbum = true
  87. try {
  88. // tenantGroupAlbum/buyAlbumInfo
  89. if (state.albumId) {
  90. let url = apiSuffix.value + '/userTenantAlbumRecord/detail'
  91. if (state.albumId) {
  92. url = url + '?albumId=' + state.albumId
  93. }
  94. const { data } = await request.post(url)
  95. state.albumList = [data || {}]
  96. state.details = data || {}
  97. } else {
  98. const url =
  99. apiSuffix.value +
  100. '/tenantGroupAlbum/buyAlbumInfo?tenantGroupAlbumId=' +
  101. (route.query.taId || '')
  102. // if (state.albumId) {
  103. // url = url + '?albumId=' + state.albumId
  104. // }
  105. const { data } = await request.get(url)
  106. state.albumList = data || []
  107. if (state.albumList.length > 0) {
  108. state.details = state.albumList[0]
  109. } else {
  110. // state.albumList
  111. if (!browser().isApp) {
  112. Dialog.alert({
  113. title: '提示',
  114. message: '该专辑不可购买',
  115. confirmButtonText: '确定',
  116. confirmButtonColor: '#2dc7aa'
  117. }).then(() => {
  118. if (browser().isApp) {
  119. postMessage({ api: 'back' })
  120. } else {
  121. setLogout()
  122. router.replace({
  123. path: '/login' as any,
  124. query: {
  125. returnUrl: '/train-tool',
  126. ...route.query
  127. }
  128. })
  129. }
  130. })
  131. }
  132. }
  133. }
  134. } catch {
  135. //
  136. }
  137. state.loadingAlbum = false
  138. }
  139. watch(
  140. () => state.details,
  141. () => {
  142. state.ensembleCounts = state.details?.ensembleCounts <= 0 ? false : true
  143. state.subjectCounts = state.details?.subjectCounts <= 0 ? false : true
  144. state.musicCounts = state.details?.musicCounts <= 0 ? false : true
  145. state.coursewareCounts =
  146. state.details?.coursewareCounts <= 0 ? false : true
  147. if (state.subjectCounts) {
  148. state.activeTab = 'SUBJECT'
  149. } else if (state.musicCounts) {
  150. state.activeTab = 'MUSIC'
  151. } else if (state.ensembleCounts) {
  152. state.activeTab = 'ENSEMBLE'
  153. } else if (state.coursewareCounts) {
  154. state.activeTab = 'COURSEWARE'
  155. }
  156. // 带的参数
  157. if (route.query.subjectType == 'SUBJECT' && state.subjectCounts) {
  158. state.activeTab = 'SUBJECT'
  159. } else if (route.query.subjectType == 'MUSIC' && state.musicCounts) {
  160. state.activeTab = 'MUSIC'
  161. } else if (
  162. route.query.subjectType == 'ENSEMBLE' &&
  163. state.ensembleCounts
  164. ) {
  165. state.activeTab = 'ENSEMBLE'
  166. } else if (
  167. route.query.subjectType == 'COURSEWARE' &&
  168. state.coursewareCounts
  169. ) {
  170. state.activeTab = 'COURSEWARE'
  171. }
  172. // subjectType 缓存
  173. if (subjectType == 'SUBJECT' && state.subjectCounts) {
  174. state.activeTab = 'SUBJECT'
  175. } else if (subjectType == 'MUSIC' && state.musicCounts) {
  176. state.activeTab = 'MUSIC'
  177. } else if (subjectType == 'ENSEMBLE' && state.ensembleCounts) {
  178. state.activeTab = 'ENSEMBLE'
  179. } else if (subjectType == 'COURSEWARE' && state.coursewareCounts) {
  180. state.activeTab = 'COURSEWARE'
  181. }
  182. if (state.details.buyTimesFlag) {
  183. if (state.details.buyedTimes >= state.details.buyTimes) {
  184. state.hasBuyStatus = false
  185. } else {
  186. state.hasBuyStatus = true
  187. }
  188. } else {
  189. state.hasBuyStatus = true
  190. }
  191. }
  192. )
  193. const FetchList = async (hideLoading = false) => {
  194. if (state.loading) {
  195. return
  196. }
  197. state.loading = true
  198. state.isError = false
  199. const tempParams = {
  200. albumId: state.details.id || null,
  201. subjectType: state.activeTab,
  202. ...params
  203. }
  204. try {
  205. const { data } = await request.post(
  206. `${apiSuffix.value}/tenantAlbumMusic/page`,
  207. {
  208. hideLoading,
  209. data: tempParams
  210. }
  211. )
  212. if (state.list.length > 0 && data.pageNo === 1) {
  213. return
  214. }
  215. state.list = state.list.concat(data.rows || [])
  216. params.page = data.pageNo + 1
  217. // showContact.value = state.list.length > 0
  218. state.loading = false
  219. state.finished = data.pageNo >= data.totalPage
  220. params.page = data.pageNo + 1
  221. } catch (error) {
  222. state.isError = true
  223. }
  224. state.loading = false
  225. }
  226. onMounted(async () => {
  227. useEventListener(document, 'scroll', evt => {
  228. const { y } = useWindowScroll()
  229. if (y.value > 20) {
  230. background.value = `rgba(255, 255, 255)`
  231. } else {
  232. background.value = 'transparent'
  233. }
  234. })
  235. state.loading = true
  236. state.loadingAlbum = true
  237. await getDetails()
  238. await FetchList()
  239. state.loadingAlbum = false
  240. state.loading = false
  241. // 为了处理 swiper 会不显示的问题
  242. document.body.scrollIntoView()
  243. window.scrollTo(1, 0)
  244. })
  245. const onSubmit = async () => {
  246. const album = state.details
  247. const details = state.details
  248. orderStatus.orderObject.orderType = 'TENANT_ALBUM'
  249. orderStatus.orderObject.orderName = details.name
  250. orderStatus.orderObject.orderDesc = details.name
  251. orderStatus.orderObject.actualPrice = album.actualPrice
  252. // orderStatus.orderObject.recomUserId = route.query.recomUserId || 0
  253. // orderStatus.orderObject.activityId = route.query.activityId || 0
  254. orderStatus.orderObject.orderNo = ''
  255. orderStatus.orderObject.orderList = [
  256. {
  257. orderType: 'TENANT_ALBUM',
  258. goodsName: details.name,
  259. actualPrice: album.actualPrice,
  260. price: album.actualPrice,
  261. ...details,
  262. ...album
  263. }
  264. ]
  265. const res = await request.post('/api-student/userOrder/getPendingOrder', {
  266. data: {
  267. goodType: 'TENANT_ALBUM',
  268. bizId: details.id
  269. }
  270. })
  271. const result = res.data
  272. console.log(details, album)
  273. if (result) {
  274. state.popupStatus = false
  275. Dialog.confirm({
  276. title: '提示',
  277. message: '您有一个未支付的订单,是否继续支付?',
  278. theme: 'round-button',
  279. className: 'confirm-button-group',
  280. cancelButtonText: '取消订单',
  281. confirmButtonText: '继续支付'
  282. })
  283. .then(async () => {
  284. orderStatus.orderObject.orderNo = result.orderNo
  285. orderStatus.orderObject.actualPrice = result.actualPrice
  286. orderStatus.orderObject.discountPrice = result.discountPrice
  287. orderStatus.orderObject.paymentConfig = {
  288. ...result.paymentConfig,
  289. paymentVendor: result.paymentVendor,
  290. paymentVersion: result.paymentVersion
  291. }
  292. routerTo()
  293. })
  294. .catch(() => {
  295. Dialog.close()
  296. // 只用取消订单,不用做其它处理
  297. cancelPayment(result.orderNo)
  298. })
  299. } else {
  300. routerTo()
  301. }
  302. }
  303. const routerTo = () => {
  304. const album = state.details
  305. router.push({
  306. path: '/orderDetail',
  307. query: {
  308. orderType: 'ALBUM',
  309. album: album.id
  310. }
  311. })
  312. }
  313. const cancelPayment = async (orderNo: string) => {
  314. try {
  315. await request.post('/api-student/userOrder/orderCancel/v2', {
  316. data: {
  317. orderNo
  318. }
  319. })
  320. } catch {
  321. //
  322. }
  323. }
  324. return () => (
  325. <div class={styles.trainTool}>
  326. {!state.loading && !state.details.id && state.buy != '1' ? (
  327. <>
  328. <TheSticky
  329. position="top"
  330. onBarHeight={(height: any) => {
  331. console.log(height, 'height', height)
  332. state.heightV = height
  333. }}
  334. >
  335. <ColHeader border={false} isFixed={false} />
  336. </TheSticky>
  337. {!state.loading && (
  338. <div
  339. style={{
  340. height: 'calc(100vh - var(--header-height))',
  341. display: 'flex',
  342. alignItems: 'center'
  343. }}
  344. >
  345. <ColResult
  346. tips="暂无专辑"
  347. classImgSize="SMALL"
  348. btnStatus={false}
  349. />
  350. </div>
  351. )}
  352. </>
  353. ) : (
  354. !state.loadingAlbum && (
  355. <>
  356. <TheSticky
  357. position="top"
  358. onBarHeight={(height: any) => {
  359. state.heightV = height
  360. }}
  361. >
  362. <ColHeader
  363. background={background.value}
  364. border={false}
  365. isFixed={false}
  366. hideHeader={route.query.taId ? true : false}
  367. // color={color.value}
  368. // backIconColor="white"
  369. />
  370. </TheSticky>
  371. {/* <img class={styles.bgImg} src={state.details?.coverImg} /> */}
  372. <div class={styles.musicContent}></div>
  373. <div class={styles.bg}>
  374. <div class={styles.alumWrap}>
  375. {isSingleAlbum.value ? (
  376. <div class={styles.singleAlbum}>
  377. <div class={styles.img}>
  378. {state.details?.buyTimesFlag && (
  379. <span class={styles.quota}>
  380. 限购:{state.details?.buyedTimes}/
  381. {state.details?.buyTimes}次
  382. </span>
  383. )}
  384. <Image
  385. class={styles.image}
  386. width="100%"
  387. height="100%"
  388. fit="cover"
  389. src={state.details?.coverImg || iconAlbumCover}
  390. errorIcon={iconAlbumCover}
  391. />
  392. <div class={styles.iconPian}></div>
  393. </div>
  394. </div>
  395. ) : (
  396. state.albumList &&
  397. state.albumList.length > 0 && (
  398. <Swiper
  399. watchSlidesProgress={true}
  400. slidesPerView={'auto'}
  401. centeredSlides={true}
  402. modules={[Pagination]}
  403. pagination={{ clickable: true }}
  404. // onSlideChange={(swiper: any) => {}}
  405. onTransitionEnd={(swiper: any) => {
  406. state.details = state.albumList[swiper.activeIndex]
  407. state.ensembleCounts =
  408. state.details?.ensembleCounts <= 0 ? false : true
  409. state.subjectCounts =
  410. state.details?.subjectCounts <= 0 ? false : true
  411. state.musicCounts =
  412. state.details?.musicCounts <= 0 ? false : true
  413. state.coursewareCounts =
  414. state.details?.coursewareCounts <= 0 ? false : true
  415. if (state.subjectCounts) {
  416. state.activeTab = 'SUBJECT'
  417. } else if (state.musicCounts) {
  418. state.activeTab = 'MUSIC'
  419. } else if (state.ensembleCounts) {
  420. state.activeTab = 'ENSEMBLE'
  421. } else if (state.coursewareCounts) {
  422. state.activeTab = 'COURSEWARE'
  423. }
  424. params.page = 1
  425. state.list = []
  426. FetchList(true)
  427. }}
  428. >
  429. {state.albumList.map((album: any) => (
  430. <SwiperSlide>
  431. <div class={styles.img}>
  432. {album.buyTimesFlag && (
  433. <span class={styles.quota}>
  434. 限购{album.buyedTimes}/{album.buyTimes}次
  435. </span>
  436. )}
  437. <Image
  438. class={styles.image}
  439. width="100%"
  440. height="100%"
  441. fit="cover"
  442. src={album?.coverImg || iconAlbumCover}
  443. errorIcon={iconAlbumCover}
  444. />
  445. <div class={styles.iconPian}></div>
  446. </div>
  447. </SwiperSlide>
  448. ))}
  449. </Swiper>
  450. )
  451. )}
  452. <div class={styles.alumDes}>
  453. <div class={[styles.alumTitle, 'van-ellipsis']}>
  454. {state.details?.name}
  455. </div>
  456. <div
  457. class={[styles.des, 'van-multi-ellipsis--l2']}
  458. style={{
  459. height: '32px',
  460. lineHeight: '16px'
  461. }}
  462. >
  463. {state.details?.describe}
  464. </div>
  465. </div>
  466. {state.buy != '1' && baseState.platformType === 'STUDENT' && (
  467. <div class={styles.albumPriceGroup}>
  468. <div class={styles.albumTimer}>
  469. <img src={iconTimer} class={styles.iconTimer} />
  470. <span>有效期:{state.details?.purchaseNum || 0}天</span>
  471. </div>
  472. <div class={styles.albumPriceList}>
  473. {(state.details?.originalPrice || 0) >
  474. (state.details?.actualPrice || 0) && (
  475. <del class={styles.originPrice}>
  476. 原价:¥
  477. {moneyFormat(state.details?.originalPrice || 0)}
  478. </del>
  479. )}
  480. <span class={styles.currentPrice}>
  481. <span>
  482. ¥{moneyFormat(state.details?.actualPrice || 0)}
  483. </span>
  484. </span>
  485. </div>
  486. </div>
  487. )}
  488. </div>
  489. </div>
  490. <div class={styles.musicList}>
  491. <Sticky position="top" offsetTop={state.heightV}>
  492. <Tabs
  493. color="var(--van-primary)"
  494. background="transparent"
  495. lineWidth={20}
  496. shrink
  497. v-model:active={state.activeTab}
  498. onChange={val => {
  499. state.activeTab = val
  500. params.page = 1
  501. state.list = []
  502. FetchList()
  503. }}
  504. >
  505. {state.subjectCounts && (
  506. <Tab title="声部练习" name="SUBJECT"></Tab>
  507. )}
  508. {state.musicCounts && (
  509. <Tab title="独奏曲目" name="MUSIC"></Tab>
  510. )}
  511. {state.ensembleCounts && (
  512. <Tab title="合奏练习" name="ENSEMBLE"></Tab>
  513. )}
  514. {state.coursewareCounts && (
  515. <Tab title="云教程" name="COURSEWARE"></Tab>
  516. )}
  517. </Tabs>
  518. </Sticky>
  519. <div class={styles.alumnList}>
  520. <List
  521. loading={state.loading}
  522. finished={state.finished}
  523. finished-text={' '}
  524. onLoad={FetchList}
  525. immediateCheck={false}
  526. error={state.isError}
  527. >
  528. {state.list && state.list.length ? (
  529. state.activeTab === 'COURSEWARE' ? (
  530. <CourseItem
  531. list={state.list.map(item => {
  532. return {
  533. name: item.musicSheetName,
  534. coverImg: item.titleImg,
  535. id: item.id
  536. }
  537. })}
  538. onItemClick={row => {
  539. router.push({
  540. path: '/courseList',
  541. query: {
  542. id: row.id,
  543. albumId: state.details.id
  544. }
  545. })
  546. }}
  547. />
  548. ) : (
  549. <Song
  550. showNumber
  551. list={state.list}
  552. onDetail={(item: any) => {
  553. sessionStorage.setItem(
  554. 'tool-subject-type',
  555. state.activeTab as any
  556. )
  557. router.push({
  558. path: '/music-detail',
  559. query: {
  560. id: item.id,
  561. tenantAlbumId: item.tenantAlbumId
  562. // albumId: route.params.id
  563. }
  564. })
  565. }}
  566. />
  567. )
  568. ) : (
  569. !state.loading && (
  570. <ColResult
  571. tips="暂无曲目" //暂无教程
  572. classImgSize="SMALL"
  573. btnStatus={false}
  574. />
  575. )
  576. )}
  577. </List>
  578. </div>
  579. </div>
  580. {baseState.platformType === 'STUDENT' && state.buy != '1' && (
  581. <TheSticky position="bottom">
  582. <div class={styles.btnGroup}>
  583. <Button
  584. round
  585. block
  586. disabled={
  587. state.details?.musicNum <= 0 || !state.hasBuyStatus
  588. }
  589. color="linear-gradient(270deg, #FF204B 0%, #FE5B71 100%)"
  590. onClick={onSubmit}
  591. >
  592. 开通训练教程
  593. </Button>
  594. </div>
  595. </TheSticky>
  596. )}
  597. </>
  598. )
  599. )}
  600. </div>
  601. )
  602. }
  603. })