index.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import OEmpty from '@/components/o-empty'
  2. import OSearch from '@/components/o-search'
  3. import OSticky from '@/components/o-sticky'
  4. import request from '@/helpers/request'
  5. import { state } from '@/state'
  6. import dayjs from 'dayjs'
  7. import { Cell, CellGroup, List, Image } from 'vant'
  8. import { defineComponent, onMounted, reactive } from 'vue'
  9. import { useRouter } from 'vue-router'
  10. import styles from './help-center/index.module.less'
  11. export default defineComponent({
  12. name: 'help-center',
  13. setup() {
  14. const router = useRouter()
  15. const form = reactive({
  16. isClick: false,
  17. list: [] as any,
  18. listState: {
  19. dataShow: true, // 判断是否有数据
  20. loading: false,
  21. finished: false
  22. },
  23. params: {
  24. keyword: null,
  25. status: true,
  26. type: 'HOT_CONSULTATION',
  27. page: 1,
  28. rows: 20
  29. }
  30. })
  31. const getList = async () => {
  32. try {
  33. if (form.isClick) return
  34. form.isClick = true
  35. const res = await request.post(state.platformApi + '/sysNewsInformation/page', {
  36. data: {
  37. ...form.params,
  38. catalogType: state.platformType
  39. }
  40. })
  41. form.listState.loading = false
  42. const result = res.data || {}
  43. // 处理重复请求数据
  44. if (form.list.length > 0 && result.current === 1) {
  45. return
  46. }
  47. form.list = form.list.concat(result.rows || [])
  48. form.listState.finished = result.current >= result.pages
  49. form.params.page = result.current + 1
  50. form.listState.dataShow = form.list.length > 0
  51. form.isClick = false
  52. } catch {
  53. form.listState.dataShow = false
  54. form.listState.finished = true
  55. form.isClick = false
  56. }
  57. }
  58. const onSearch = (val: any) => {
  59. form.params.keyword = val
  60. form.params.page = 1
  61. form.list = []
  62. form.listState.dataShow = true // 判断是否有数据
  63. form.listState.loading = false
  64. form.listState.finished = false
  65. getList()
  66. }
  67. const onDetail = (item: any) => {
  68. if (item.linkType === 'OUT') {
  69. window.location.href = item.linkUrl
  70. } else {
  71. router.push({
  72. path: '/information-detail',
  73. query: {
  74. id: item.id
  75. }
  76. })
  77. }
  78. }
  79. onMounted(() => {
  80. getList()
  81. })
  82. return () => (
  83. <div class={styles.helpCenter}>
  84. <OSticky position="top">
  85. <OSearch onSearch={onSearch} />
  86. </OSticky>
  87. {form.listState.dataShow ? (
  88. <List
  89. v-model:loading={form.listState.loading}
  90. finished={form.listState.finished}
  91. finishedText=" "
  92. class={[styles.container, styles.containerInformation]}
  93. onLoad={getList}
  94. immediateCheck={false}
  95. >
  96. {form.list.map((item: any) => (
  97. <Cell
  98. class={styles.cell}
  99. onClick={() => onDetail(item)}
  100. titleStyle={{
  101. display: 'flex',
  102. flexDirection: 'column',
  103. justifyContent: 'space-between'
  104. }}
  105. >
  106. {{
  107. icon: () => <Image src={item.coverImage} class={styles.img} fit="cover" />,
  108. title: () => (
  109. <>
  110. <div class={[styles.title, 'van-ellipsis']}>{item.title}</div>
  111. {/* <div class={[styles.content, 'van-multi-ellipsis--l2']}>{item.memo}</div> */}
  112. <div class={styles.time}>
  113. {item.createTime ? dayjs(item.createTime).format('YYYY年MM月DD日') : ''}
  114. </div>
  115. </>
  116. )
  117. }}
  118. </Cell>
  119. ))}
  120. </List>
  121. ) : (
  122. <OEmpty btnStatus={false} classImgSize="SMALL" tips="暂无数据" />
  123. )}
  124. </div>
  125. )
  126. }
  127. })