index.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { defineComponent, reactive, watch } from 'vue'
  2. import icon from '../videoDetailItem/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. chargeType: String
  17. }
  18. const chargeTypes = {
  19. CHARGE: '点播',
  20. FREE: '免费',
  21. VIP: 'VIP'
  22. }
  23. export default defineComponent({
  24. name: 'musicLIstItem',
  25. props: {
  26. item: {
  27. type: Object as () => Props,
  28. default: () => ({})
  29. },
  30. onClick: {
  31. type: Function,
  32. default: (item: any) => {}
  33. }
  34. },
  35. setup(props: any) {
  36. const state = reactive({
  37. item:props.item
  38. })
  39. const router = useRouter()
  40. watch(
  41. () => props.item,
  42. item => {
  43. state.item = item
  44. }
  45. )
  46. const gotoMusicDetail = () => {
  47. router.push({path:'/muiscDetial',query:{id:state.item.id}})
  48. }
  49. return () => (
  50. <div
  51. onClick={() => {
  52. props.onClick(state.item)
  53. }}
  54. >
  55. <div class={classes.itemWrap} onClick={() => gotoMusicDetail()}>
  56. <div class={classes.left}>
  57. <div class={classes.imgWrap}>
  58. <img src={music} alt="" />
  59. </div>
  60. <div class={classes.textWrap}>
  61. <p>
  62. {state.item.musicSheetName}
  63. <span>作曲: {state.item.composer}</span>
  64. </p>
  65. <div class={classes.authorInfo}>
  66. <img
  67. class={classes.icon}
  68. src={state.item.addUserAvatar || icon}
  69. alt=""
  70. />
  71. <span class={classes.authorName}>{state.item.addName}</span>
  72. <div class={classes.tagList}>
  73. <div class={classes.tag}>{state.item.subjectNames}</div>
  74. {/* <div class={classes.tag}>圆号</div> */}
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. <div class={classes.right}>
  80. <div
  81. class={[
  82. classes.touchButton,
  83. classes[state.item.chargeType?.toLocaleLowerCase()]
  84. ]}
  85. >
  86. {chargeTypes[state.item.chargeType]
  87. ? chargeTypes[state.item.chargeType]
  88. : '点播'}
  89. </div>
  90. <img class={classes.arrow} src={arrow} alt="" />
  91. </div>
  92. </div>
  93. </div>
  94. )
  95. }
  96. })