orchestra-information.tsx 8.2 KB

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