item.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { defineComponent, reactive, watch } from 'vue'
  2. import icon from './images/icon.png'
  3. import classes from './index.module.less'
  4. import detaile from './images/detaile.png'
  5. import music from './images/music.png'
  6. import arrow from './images/arrow.png'
  7. import { goodsType } from '@/constant'
  8. import { useRouter } from 'vue-router'
  9. type Props = {
  10. id?: number
  11. addName: string
  12. addUserAvatar: string
  13. musicSheetName: string
  14. subjectNames: string
  15. composer: string
  16. titleImg: string
  17. chargeType: string
  18. }
  19. const chargeTypes = {
  20. CHARGE: '点播',
  21. FREE: '免费',
  22. VIP: 'VIP'
  23. }
  24. export default defineComponent({
  25. name: 'music-item',
  26. props: {
  27. item: {
  28. type: Object as () => Props,
  29. default: () => ({})
  30. },
  31. onClick: {
  32. type: Function,
  33. default: (item: any) => {}
  34. }
  35. },
  36. setup(props: any) {
  37. const state = reactive({
  38. item: props.item
  39. })
  40. const router = useRouter()
  41. watch(
  42. () => props.item,
  43. item => {
  44. state.item = item
  45. }
  46. )
  47. const gotoMusicDetail = () => {
  48. router.push({ path: '/muiscDetial', query: { id: state.item.id } })
  49. }
  50. return () => (
  51. <div
  52. onClick={() => {
  53. props.onClick(state.item)
  54. }}
  55. >
  56. <div class={classes.itemWrap} onClick={() => gotoMusicDetail()}>
  57. <div class={classes.left}>
  58. <div class={classes.imgWrap}>
  59. <img src={state.item.titleImg || music} alt="" />
  60. </div>
  61. <div class={classes.textWrap}>
  62. <p>
  63. {state.item.musicSheetName}
  64. <div
  65. class={[
  66. classes.touchButton,
  67. classes[state.item.chargeType?.toLocaleLowerCase()]
  68. ]}
  69. >
  70. {chargeTypes[state.item.chargeType]
  71. ? chargeTypes[state.item.chargeType]
  72. : '点播'}
  73. </div>
  74. </p>
  75. <div class={classes.authorInfo}>
  76. <span>作曲: {state.item.composer}</span>
  77. {/* <img
  78. class={classes.icon}
  79. src={state.item.addUserAvatar || icon}
  80. alt=""
  81. />
  82. <span class={classes.authorName}>
  83. {state.item.addName ? state.item.addName : '小酷有谱'}
  84. </span>
  85. */}
  86. </div>
  87. <div class={classes.tagList}>
  88. {state.item.subjectNames ? (
  89. <div class={classes.tag}>{state.item.subjectNames}</div>
  90. ) : null}
  91. </div>
  92. </div>
  93. </div>
  94. <div class={classes.right}>
  95. <img class={classes.arrow} src={arrow} alt="" />
  96. </div>
  97. </div>
  98. </div>
  99. )
  100. }
  101. })