orchestra-information.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import OEmpty from '@/components/o-empty'
  2. import OFullRefresh from '@/components/o-full-refresh'
  3. import OPopup from '@/components/o-popup'
  4. import OSticky from '@/components/o-sticky'
  5. import request from '@/helpers/request'
  6. import { router } from '@/router/routes-common'
  7. import dayjs from 'dayjs'
  8. import { ActionSheet, Button, Cell, Icon, Image, List, showConfirmDialog, showToast } from 'vant'
  9. import { defineComponent, onMounted, reactive } from 'vue'
  10. import { useRoute, useRouter } from 'vue-router'
  11. import AddInformation from './modal/add-information'
  12. import styles from './orchestra-information.module.less'
  13. export default defineComponent({
  14. name: 'orchestra-information',
  15. setup() {
  16. const route = useRoute()
  17. const router = useRouter()
  18. const state = reactive({
  19. addStatus: false,
  20. isLoading: false,
  21. list: [] as any,
  22. listState: {
  23. dataShow: true, // 判断是否有数据
  24. loading: false,
  25. finished: false,
  26. refreshing: false,
  27. height: 0 // 页面头部高度,为了处理下拉刷新用的
  28. },
  29. params: {
  30. type: 'HOT_CONSULTATION',
  31. clientType: 'SCHOOL',
  32. page: 1,
  33. rows: 20
  34. },
  35. oPopover: false,
  36. selectItem: {} as any,
  37. selectType: 'add'
  38. })
  39. const getList = async () => {
  40. try {
  41. if (state.isLoading) return
  42. state.isLoading = true
  43. const res = await request.post('/api-school/sysNewsInformation/page', {
  44. data: {
  45. ...state.params,
  46. orchestraPhotoAlbumId: route.query.photoId
  47. }
  48. })
  49. state.listState.loading = false
  50. state.listState.refreshing = false
  51. const result = res.data || {}
  52. // 处理重复请求数据
  53. if (state.list.length > 0 && result.current === 1) {
  54. return
  55. }
  56. const rows = result.rows || []
  57. state.list = state.list.concat(rows)
  58. state.listState.finished = result.current >= result.pages
  59. state.params.page = result.current + 1
  60. state.listState.dataShow = state.list.length > 0
  61. state.isLoading = false
  62. } catch {
  63. state.listState.dataShow = false
  64. state.listState.finished = true
  65. state.listState.refreshing = false
  66. state.isLoading = false
  67. }
  68. }
  69. const onSearch = () => {
  70. state.params.page = 1
  71. state.list = []
  72. state.listState.dataShow = true // 判断是否有数据
  73. state.listState.loading = false
  74. state.listState.finished = false
  75. getList()
  76. }
  77. const onDetail = (item: any) => {
  78. try {
  79. console.log(item, 'item')
  80. if (item.linkUrl) {
  81. window.location.href = item.linkUrl
  82. } else {
  83. router.push({
  84. path: '/information-detail',
  85. query: {
  86. id: item.id
  87. }
  88. })
  89. }
  90. } catch {
  91. //
  92. }
  93. }
  94. const onUpdate = async () => {
  95. state.selectType = 'update'
  96. state.addStatus = true
  97. }
  98. const onRemove = async () => {
  99. showConfirmDialog({
  100. message: '您确认删除该资讯吗?'
  101. }).then(async () => {
  102. try {
  103. await request.post('/api-school/sysNewsInformation/remove', {
  104. requestType: 'form',
  105. data: {
  106. id: state.selectItem.id
  107. }
  108. })
  109. setTimeout(() => {
  110. showToast('删除成功')
  111. }, 100)
  112. setTimeout(() => {
  113. onSearch()
  114. }, 1100)
  115. } catch {
  116. //
  117. }
  118. })
  119. }
  120. onMounted(() => {
  121. getList()
  122. })
  123. return () => (
  124. <div class={styles.information}>
  125. <OSticky
  126. position="top"
  127. onGetHeight={(height: any) => {
  128. state.listState.height = height
  129. }}
  130. >
  131. <div style="background: #f6f8f9; overflow: hidden;">
  132. <Button
  133. icon="plus"
  134. block
  135. class={styles.addPhone}
  136. onClick={() => {
  137. state.selectType = 'add'
  138. state.addStatus = true
  139. }}
  140. >
  141. 添加资讯
  142. </Button>
  143. </div>
  144. </OSticky>
  145. {state.listState.dataShow ? (
  146. <OFullRefresh
  147. v-model:modelValue={state.listState.refreshing}
  148. onRefresh={onSearch}
  149. style={{
  150. minHeight: `calc(100vh - ${state.listState.height}px)`
  151. }}
  152. >
  153. <List
  154. v-model:loading={state.listState.loading}
  155. finished={state.listState.finished}
  156. finishedText=" "
  157. onLoad={getList}
  158. immediateCheck={false}
  159. class={styles.informationGroup}
  160. >
  161. {state.list.map((item: any, index: number) => (
  162. <Cell center class={styles.cell} onClick={() => onDetail(item)}>
  163. {{
  164. icon: () => <Image src={item.coverImage} class={styles.img} />,
  165. title: () => (
  166. <div>
  167. <div class={[styles.title, 'van-ellipsis']}>{item.title}</div>
  168. <div class={[styles.content, 'van-multi-ellipsis--l2']}>{item.memo}</div>
  169. <div
  170. style={{
  171. display: 'flex',
  172. alignItems: 'center',
  173. justifyContent: 'space-between'
  174. }}
  175. >
  176. <div class={styles.time}>
  177. {item.createTime ? dayjs(item.createTime).format('YYYY年MM月DD日') : ''}
  178. </div>
  179. <Icon
  180. name="ellipsis"
  181. size={23}
  182. color="#777777"
  183. style={{ fontWeight: 'bold' }}
  184. onClick={(e: any) => {
  185. e.stopPropagation()
  186. state.selectItem = item
  187. state.oPopover = true
  188. }}
  189. />
  190. </div>
  191. </div>
  192. )
  193. }}
  194. </Cell>
  195. ))}
  196. </List>
  197. </OFullRefresh>
  198. ) : (
  199. <OEmpty btnStatus={false} tips="暂无资讯" />
  200. )}
  201. <OPopup v-model:modelValue={state.addStatus} style={{ background: '#f8f8f8' }} destroy>
  202. <AddInformation
  203. selectType={state.selectType}
  204. selectItem={state.selectItem}
  205. onClose={() => (state.addStatus = false)}
  206. onGetList={onSearch}
  207. />
  208. </OPopup>
  209. <ActionSheet
  210. cancelText="取消"
  211. v-model:show={state.oPopover}
  212. closeOnClickAction
  213. actions={[
  214. { name: '修改', callback: () => onUpdate() },
  215. { name: '删除', color: '#F44541', callback: () => onRemove() }
  216. ]}
  217. />
  218. </div>
  219. )
  220. }
  221. })