list.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import ColResult from '@/components/col-result'
  2. import { useList } from '@/helpers/hooks'
  3. import request from '@/helpers/request'
  4. import { state } from '@/state'
  5. import { List } from 'vant'
  6. import { defineComponent, PropType } from 'vue'
  7. import styles from './index.module.less'
  8. import Item from './item'
  9. // 使用状态: EXPIRED(已失效) USABLE(可使用) USED(已使用)
  10. export default defineComponent({
  11. name: 'coupon-list',
  12. props: {
  13. useState: {
  14. type: String as PropType<'USABLE' | 'USED' | 'EXPIRED'>,
  15. default: 'USABLE'
  16. }
  17. },
  18. data() {
  19. return {
  20. list: [] as any,
  21. listState: {
  22. dataShow: true, // 判断是否有数据
  23. loading: false,
  24. finished: false
  25. },
  26. params: {
  27. useState: this.useState,
  28. page: 1,
  29. rows: 20
  30. }
  31. }
  32. },
  33. mounted() {
  34. this.getList()
  35. },
  36. methods: {
  37. async getList() {
  38. try {
  39. const result = await useList(`${state.platformApi}/couponInfo/page`, {
  40. params: this.params,
  41. list: this.list,
  42. ...this.listState
  43. })
  44. const { params, list, ...res } = result
  45. this.params = params
  46. this.list = list
  47. this.listState = res
  48. } catch {
  49. //
  50. }
  51. }
  52. },
  53. render() {
  54. return (
  55. <>
  56. {this.listState.dataShow ? (
  57. <List
  58. v-model:loading={this.listState.loading}
  59. finished={this.listState.finished}
  60. finishedText=" "
  61. // 为了处理体验问题
  62. class={[this.list.length > 0 && styles.list]}
  63. onLoad={this.getList}
  64. immediateCheck={false}
  65. >
  66. {this.list.map((item: any) => (
  67. <Item item={item} />
  68. ))}
  69. </List>
  70. ) : (
  71. <ColResult btnStatus={false} classImgSize="SMALL" tips="暂无优惠券" />
  72. )}
  73. </>
  74. )
  75. }
  76. })