orchestra-information.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import OEmpty from '@/components/o-empty'
  2. import OPopup from '@/components/o-popup'
  3. import request from '@/helpers/request'
  4. import dayjs from 'dayjs'
  5. import { Button, Cell, Image, List } from 'vant'
  6. import { defineComponent, onMounted, reactive } from 'vue'
  7. import { useRoute } from 'vue-router'
  8. import AddInformation from './modal/add-information'
  9. import styles from './orchestra-information.module.less'
  10. export default defineComponent({
  11. name: 'orchestra-information',
  12. setup() {
  13. const route = useRoute()
  14. const state = reactive({
  15. addStatus: false,
  16. isLoading: false,
  17. list: [] as any,
  18. listState: {
  19. dataShow: true, // 判断是否有数据
  20. loading: false,
  21. finished: false
  22. },
  23. params: {
  24. type: 'HOT_CONSULTATION',
  25. clientType: 'SCHOOL',
  26. page: 1,
  27. rows: 20
  28. }
  29. })
  30. const getList = async () => {
  31. try {
  32. if (state.isLoading) return
  33. state.isLoading = true
  34. const res = await request.post('/api-school/sysNewsInformation/page', {
  35. data: {
  36. ...state.params,
  37. orchestraPhotoAlbumId: route.query.photoId
  38. }
  39. })
  40. state.listState.loading = false
  41. const result = res.data || {}
  42. // 处理重复请求数据
  43. if (state.list.length > 0 && result.pageNo === 1) {
  44. return
  45. }
  46. const rows = result.rows || []
  47. state.list = state.list.concat(rows)
  48. state.listState.finished = result.current >= result.pages
  49. state.params.page = result.current + 1
  50. state.listState.dataShow = state.list.length > 0
  51. state.isLoading = false
  52. } catch {
  53. state.listState.dataShow = false
  54. state.listState.finished = true
  55. state.isLoading = false
  56. }
  57. }
  58. onMounted(() => {
  59. getList()
  60. })
  61. return () => (
  62. <div class={styles.information}>
  63. <Button icon="plus" block class={styles.addPhone} onClick={() => (state.addStatus = true)}>
  64. 添加资讯
  65. </Button>
  66. {state.listState.dataShow ? (
  67. <List
  68. v-model:loading={state.listState.loading}
  69. finished={state.listState.finished}
  70. finishedText=" "
  71. onLoad={getList}
  72. immediateCheck={false}
  73. >
  74. {state.list.map((item: any, index: number) => (
  75. <Cell center class={styles.cell}>
  76. {{
  77. icon: () => <Image src={item.coverImage} class={styles.img} />,
  78. title: () => (
  79. <div>
  80. <div class={[styles.title, 'van-ellipsis']}>{item.title}</div>
  81. <div class={[styles.content, 'van-multi-ellipsis--l2']}>{item.memo}</div>
  82. <div class={styles.time}>{dayjs(item.createBy).format('YYYY年MM月DD日')}</div>
  83. </div>
  84. )
  85. }}
  86. </Cell>
  87. ))}
  88. </List>
  89. ) : (
  90. <OEmpty btnStatus={false} classImgSize="SMALL" tips="暂无资讯" />
  91. )}
  92. <OPopup v-model:modelValue={state.addStatus} style={{ background: '#f8f8f8' }}>
  93. <AddInformation onClose={() => (state.addStatus = false)} />
  94. </OPopup>
  95. </div>
  96. )
  97. }
  98. })