list.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import OEmpty from '@/components/o-empty'
  2. import OFullRefresh from '@/components/o-full-refresh'
  3. import OSearch from '@/components/o-search'
  4. import OSticky from '@/components/o-sticky'
  5. import { snedStatus } from '@/constant'
  6. import request from '@/helpers/request'
  7. import { Cell, CellGroup, Icon, List, Sticky } from 'vant'
  8. import { defineComponent, onMounted, reactive } from 'vue'
  9. import { useRouter } from 'vue-router'
  10. import styles from './index.module.less'
  11. export default defineComponent({
  12. name: 'mass-list',
  13. props: {
  14. status: {
  15. type: String,
  16. default: ''
  17. },
  18. height: {
  19. type: Number,
  20. default: 0
  21. }
  22. },
  23. setup(props) {
  24. const router = useRouter()
  25. const state = reactive({
  26. refreshing: false,
  27. height: 0, // 页面头部高度,为了处理下拉刷新用的
  28. list: [],
  29. dataShow: true, // 判断是否有数据
  30. loading: false,
  31. finished: false,
  32. params: {
  33. keyword: null as any,
  34. sendStatus: props.status || 'WAIT',
  35. page: 1,
  36. rows: 10
  37. },
  38. isClick: false
  39. })
  40. const getList = async () => {
  41. try {
  42. if (state.isClick) return
  43. state.isClick = true
  44. const res = await request.post('/api-school/imMessageBatchSending/page', {
  45. data: {
  46. ...state.params
  47. }
  48. })
  49. state.isClick = false
  50. state.loading = false
  51. state.refreshing = false
  52. const result = res.data || {}
  53. // 处理重复请求数据
  54. if (state.list.length > 0 && result.current === 1) {
  55. return
  56. }
  57. state.list = state.list.concat(result.rows || [])
  58. state.finished = result.current >= result.pages
  59. state.params.page = result.current + 1
  60. state.dataShow = state.list.length > 0
  61. } catch {
  62. state.isClick = false
  63. state.dataShow = false
  64. state.refreshing = false
  65. state.finished = true
  66. }
  67. }
  68. // 搜索
  69. const onSearch = () => {
  70. state.params.page = 1
  71. state.list = []
  72. state.dataShow = true // 判断是否有数据
  73. state.loading = false
  74. state.finished = false
  75. getList()
  76. }
  77. // 查看详情
  78. const onDetail = async (item: any) => {
  79. router.push({
  80. path: '/create-message',
  81. query: {
  82. id: item.id
  83. }
  84. })
  85. }
  86. onMounted(() => {
  87. getList()
  88. })
  89. return () => (
  90. <>
  91. {/* var(--van-tab-line-height) */}
  92. <OSearch
  93. background="#f6f8f9"
  94. inputBackground="white"
  95. placeholder="请输入群聊/学员名称/伴学指导名称"
  96. onSearch={(val: string) => {
  97. state.params.keyword = val
  98. onSearch()
  99. }}
  100. />
  101. <div
  102. style={{
  103. height:
  104. 'calc(100vh - var(--van-tabs-line-height) - var(--header-height) - var(--van-search-input-height) - 0.53334rem)',
  105. overflow: 'hidden',
  106. overflowY: 'auto'
  107. }}
  108. >
  109. {state.dataShow ? (
  110. <OFullRefresh
  111. v-model:modelValue={state.refreshing}
  112. onRefresh={onSearch}
  113. style={{
  114. minHeight:
  115. 'calc(100vh - var(--van-tabs-line-height) - var(--header-height) - var(--van-search-input-height) - 0.53334rem)'
  116. }}
  117. >
  118. <List
  119. // v-model:loading={state.loading}
  120. finished={state.finished}
  121. finishedText=" "
  122. class={[styles.liveList]}
  123. onLoad={getList}
  124. immediateCheck={false}
  125. >
  126. {state.list.map((item: any) => (
  127. <CellGroup inset onClick={() => onDetail(item)} style={{ marginBottom: '12px' }}>
  128. <Cell
  129. class={[styles.waitSend, item.sendStatus === 'SEND' && styles.messageSend]}
  130. titleStyle={{ flex: '1 auto' }}
  131. >
  132. {{
  133. title: () => (
  134. <div class={styles.time}>
  135. {item.sendStatus === 'WAIT' && (
  136. <Icon name="clock-o" class={styles.clockO} />
  137. )}
  138. {item.sendTime}
  139. </div>
  140. ),
  141. value: () => <span>{snedStatus[item.sendStatus]}</span>
  142. }}
  143. </Cell>
  144. <Cell valueClass={[styles.messageContent, 'van-multi-ellipsis--l3']}>
  145. {item.textMessage}
  146. </Cell>
  147. </CellGroup>
  148. ))}
  149. </List>
  150. </OFullRefresh>
  151. ) : (
  152. <OEmpty btnStatus={false} tips="暂无群发消息" />
  153. )}
  154. </div>
  155. </>
  156. )
  157. }
  158. })