index.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import OEmpty from '@/components/o-empty'
  2. import { List, Image, Cell } from 'vant'
  3. import { defineComponent, onMounted, reactive } from 'vue'
  4. import styles from './index.module.less'
  5. import request from '@/helpers/request'
  6. import i1 from './images/1.png'
  7. import i2 from './images/2.png'
  8. import i3 from './images/3.png'
  9. export default defineComponent({
  10. name: 'my-instrument',
  11. setup() {
  12. const state = reactive({
  13. isLoading: false,
  14. list: [] as any,
  15. listState: {
  16. dataShow: true, // 判断是否有数据
  17. loading: false,
  18. finished: false
  19. },
  20. params: {
  21. page: 1,
  22. rows: 20
  23. }
  24. })
  25. // 班级列表
  26. const getList = async () => {
  27. try {
  28. if (state.isLoading) return
  29. state.isLoading = true
  30. const res = await request.post('/api-student/userPaymentOrder/instrumentPage', {
  31. data: {
  32. ...state.params
  33. }
  34. })
  35. state.listState.loading = false
  36. const result = res.data || {}
  37. // 处理重复请求数据
  38. if (state.list.length > 0 && result.current === 1) {
  39. return
  40. }
  41. const rows = result.rows || []
  42. state.list = state.list.concat(rows)
  43. state.listState.finished = result.current >= result.pages
  44. state.params.page = result.current + 1
  45. state.listState.dataShow = state.list.length > 0
  46. state.isLoading = false
  47. } catch {
  48. state.listState.dataShow = false
  49. state.listState.finished = true
  50. state.isLoading = false
  51. }
  52. }
  53. onMounted(async () => {
  54. await getList()
  55. })
  56. return () => (
  57. <div class={styles.myInstrument}>
  58. {state.listState.dataShow ? (
  59. <List
  60. // v-model:loading={state.listState.loading}
  61. finished={state.listState.finished}
  62. finishedText=" "
  63. onLoad={getList}
  64. immediateCheck={false}
  65. >
  66. {state.list.map((item: any) => (
  67. <Cell>
  68. {{
  69. icon: () => <img src={item.instrumentUrl} class={styles.goodsImg} />,
  70. title: () => (
  71. <div class={styles.goodsInfo}>
  72. <h2>{item.instrumentName}</h2>
  73. <p class={styles.times}>购买时间:{item.buyTime}</p>
  74. {/* NOT_OPEN:未开通 NOT_ACTIVATED:未激活 ACTIVATED:已激活 INVALID:已失效 */}
  75. {item.instrumentStatus === 'ACTIVATED' && (
  76. <div class={[styles.type, styles[item.instrumentStatus]]}>
  77. {item.instrumentStatus === 'ACTIVATED' && <img src={i2} />}
  78. 乐器保障服务中
  79. </div>
  80. )}
  81. {item.instrumentStatus === 'INVALID' && (
  82. <div class={[styles.type, styles[item.instrumentStatus]]}>
  83. {item.instrumentStatus === 'INVALID' && <img src={i3} />}
  84. 乐器保障服务已失效
  85. </div>
  86. )}
  87. {item.instrumentStatus === 'NOT_OPEN' && (
  88. <div class={[styles.type, styles[item.instrumentStatus]]}>
  89. {item.instrumentStatus === 'NOT_OPEN' && <img src={i3} />}
  90. 该乐器未开通乐器保障服务
  91. </div>
  92. )}
  93. {item.instrumentStatus === 'NOT_ACTIVATED' && (
  94. <div class={[styles.type, styles[item.instrumentStatus]]}>
  95. {item.instrumentStatus === 'NOT_ACTIVATED' && <img src={i1} />}
  96. 乐器保障服务尚未激活
  97. </div>
  98. )}
  99. </div>
  100. )
  101. }}
  102. </Cell>
  103. ))}
  104. </List>
  105. ) : (
  106. <OEmpty btnStatus={false} tips="暂无乐器检查" />
  107. )}
  108. </div>
  109. )
  110. }
  111. })