orchestra-information-list.tsx 8.3 KB

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