index.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import OEmpty from '@/components/o-empty'
  2. import OFullRefresh from '@/components/o-full-refresh'
  3. import OHeader from '@/components/o-header'
  4. import OSearch from '@/components/o-search'
  5. import OSticky from '@/components/o-sticky'
  6. import { snedStatus } from '@/constant'
  7. import request from '@/helpers/request'
  8. import item from '@/student/coupons/item'
  9. import { Cell, CellGroup, Icon, Swipe, SwipeItem, Tab, Tabs } from 'vant'
  10. import { defineComponent, onMounted, reactive } from 'vue'
  11. import { useRouter } from 'vue-router'
  12. import List from './list'
  13. import styles from './index.module.less'
  14. export default defineComponent({
  15. name: 'mass-message',
  16. setup() {
  17. const router = useRouter()
  18. const status = sessionStorage.getItem('mass-message-send')
  19. const state = reactive({
  20. refreshing: false,
  21. height: 0, // 页面头部高度,为了处理下拉刷新用的
  22. list: [],
  23. dataShow: true, // 判断是否有数据
  24. loading: false,
  25. finished: false,
  26. tabValue: status || 'WAIT',
  27. params: {
  28. keyword: null as any,
  29. sendStatus: status || 'WAIT',
  30. page: 1,
  31. rows: 10
  32. },
  33. isClick: false
  34. })
  35. const getList = async () => {
  36. try {
  37. if (state.isClick) return
  38. state.isClick = true
  39. const res = await request.post('/api-school/imMessageBatchSending/page', {
  40. data: {
  41. ...state.params
  42. }
  43. })
  44. state.isClick = false
  45. state.loading = false
  46. state.refreshing = false
  47. const result = res.data || {}
  48. // 处理重复请求数据
  49. if (state.list.length > 0 && result.current === 1) {
  50. return
  51. }
  52. state.list = state.list.concat(result.rows || [])
  53. state.finished = result.current >= result.pages
  54. state.params.page = result.current + 1
  55. state.dataShow = state.list.length > 0
  56. } catch {
  57. state.isClick = false
  58. state.dataShow = false
  59. state.refreshing = false
  60. state.finished = true
  61. }
  62. }
  63. // 搜索
  64. const onSearch = () => {
  65. state.params.page = 1
  66. state.list = []
  67. state.dataShow = true // 判断是否有数据
  68. state.loading = false
  69. state.finished = false
  70. getList()
  71. }
  72. // 查看详情
  73. const onDetail = async (item: any) => {
  74. router.push({
  75. path: '/create-message',
  76. query: {
  77. id: item.id
  78. }
  79. })
  80. }
  81. onMounted(() => {
  82. getList()
  83. })
  84. return () => (
  85. <div class={[styles.massMessage]}>
  86. <OSticky
  87. position="top"
  88. onGetHeight={(height: any) => {
  89. state.height = height
  90. document.documentElement.style.setProperty('--header-height', height + 'px')
  91. }}
  92. >
  93. <OHeader border={false}>
  94. {{
  95. right: () => (
  96. <span
  97. style="color: var(--van-primary-color)"
  98. onClick={() => {
  99. router.push('/create-message')
  100. }}
  101. >
  102. 消息群发
  103. </span>
  104. )
  105. }}
  106. </OHeader>
  107. </OSticky>
  108. <Tabs
  109. lineWidth={18}
  110. v-model:active={state.tabValue}
  111. sticky
  112. animated
  113. swipeable
  114. offsetTop={state.height}
  115. onChange={(val: string) => {
  116. state.params.sendStatus = val
  117. onSearch()
  118. sessionStorage.setItem('mass-message-send', val)
  119. }}
  120. >
  121. <Tab title="待发送" name="WAIT">
  122. <List status="WAIT" height={state.height} />
  123. </Tab>
  124. <Tab title="已发送" name="SEND">
  125. <List status="SEND" height={state.height} />
  126. </Tab>
  127. </Tabs>
  128. {/* <Swipe
  129. showIndicators={false}
  130. style={{
  131. height: 'calc(100vh - var(--header-height))',
  132. overflowY: 'auto'
  133. }}
  134. >
  135. <SwipeItem>
  136. <List status="WAIT" height={state.height} />
  137. </SwipeItem>
  138. <SwipeItem>
  139. <List status="SEND" height={state.height} />
  140. </SwipeItem>
  141. </Swipe> */}
  142. </div>
  143. )
  144. }
  145. })