orchestra-information.tsx 4.0 KB

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