| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- import React, { useCallback, useEffect, useMemo, useState } from 'react'
- import styles from './index.module.scss'
- import { Button, Input, Select } from 'antd'
- import { useDispatch, useSelector } from 'react-redux'
- import { A1EditInfoType } from './data'
- import { A6_APIdel, A6_APIgetList, A6_APIpublish } from '@/store/action/A6exhibition'
- import { RootState } from '@/store'
- import { MessageFu } from '@/utils/message'
- import { A6tableType } from '@/types/api/A6exhibition'
- import MyPopconfirm from '@/components/MyPopconfirm'
- import MyTable from '@/components/MyTable'
- import { A6tableC } from '@/utils/tableData'
- import A6add from './A6add'
- import { handleCopyClick } from '@/utils/copyTxt'
- import { editPreview } from '@/store/action/layout'
- const pageDataBase = {
- pageNum: 1,
- pageSize: 10
- }
- function A6exhibition() {
- const dispatch = useDispatch()
- const [pageData, setPageData] = useState(pageDataBase)
- const [title, setTitle] = useState('')
- const [type, setType] = useState(0)
- const getListFu = useCallback(
- (title?: string) => {
- // status: -1 全部 0 未发布 1 已发布
- dispatch(A6_APIgetList({ ...pageData, status: -1, title, type }))
- },
- [dispatch, pageData, type]
- )
- useEffect(() => {
- getListFu()
- }, [getListFu])
- // 点击重置
- const resetSelectFu = useCallback(() => {
- setPageData({ ...pageDataBase })
- }, [])
- const tableInfo = useSelector((state: RootState) => state.A6exhibition.tableInfo)
- const delTableFu = useCallback(
- async (id: number) => {
- const res = await A6_APIdel(id)
- if (res.code === 0) {
- MessageFu.success('删除成功!')
- getListFu()
- }
- },
- [getListFu]
- )
- const publishFu = useCallback(
- async (id: number) => {
- const res = await A6_APIpublish(id)
- if (res.code === 0) {
- MessageFu.success('发布成功!')
- getListFu()
- }
- },
- [getListFu]
- )
- const tableLastBtn = useMemo(() => {
- return [
- {
- title: '操作',
- render: (item: A6tableType) => (
- <>
- <Button
- size='small'
- type='text'
- onClick={() =>
- handleCopyClick(
- item.status === 1
- ? `https://sit-kelamayi.4dage.com/mini/#/allDetailsShow?id=${item.exhibitId}&type=exhibition&isFrom=weixin`
- : `https://sit-kelamayi.4dage.com/mini/#/allDetailsShow?id=${item.exhibitId}&type=exhibition&preview=1&isFromPage=indexPage/exhibition`
- )
- }
- >
- 复制地址
- </Button>
- {item.status === 0 && (
- <Button
- size='small'
- type='text'
- onClick={() =>
- dispatch(
- editPreview({
- isOpenPreview: true,
- src: `/allDetailsShow?id=${item.exhibitId}&type=exhibition&preview=1&isFromPage=exhibition`
- })
- )
- }
- >
- 预览
- </Button>
- )}
- <Button
- size='small'
- type='text'
- onClick={() => setEditInfo({ id: item.exhibitId, txt: '编辑' })}
- >
- 编辑
- </Button>
- {item.status === 0 && (
- <Button size='small' type='text' onClick={() => publishFu(item.exhibitId)}>
- 发布
- </Button>
- )}
- <MyPopconfirm txtK='删除' onConfirm={() => delTableFu(item.exhibitId)} />
- </>
- )
- }
- ]
- }, [delTableFu, dispatch, publishFu])
- //新增、编辑
- const [editInfo, setEditInfo] = useState<A1EditInfoType>({
- id: 0,
- txt: ''
- })
- return (
- <div className={styles.A6exhibition}>
- <div className='pageTitle'>克博展览 {editInfo.id ? ` - ${editInfo.txt}` : ''}</div>
- {/* 顶部筛选 */}
- <div className='A6top'>
- <div className='A6topLeft'>
- <Input
- style={{ width: 200 }}
- placeholder='请输入标题'
- onChange={e => setTitle(e.target.value)}
- value={title}
- maxLength={10}
- />
- <Button type='primary' onClick={() => getListFu(title)}>
- 搜索
- </Button>
- <Button
- type='primary'
- onClick={() => {
- resetSelectFu()
- setTitle('')
- }}
- >
- 重置
- </Button>
- <div className='rowItem'>
- 展览类型:
- <Select
- style={{ width: 120 }}
- defaultValue={0}
- options={[
- { label: '全部', value: 0 },
- { label: '室内', value: 1 },
- { label: '室外', value: 2 }
- ]}
- onChange={value => setType(value)}
- />
- </div>
- </div>
- <Button type='primary' onClick={() => setEditInfo({ id: -1, txt: '新增' })}>
- 新增
- </Button>
- </div>
- {/* 表格主体 */}
- <div className='A6tableBox'>
- <MyTable
- myKey='exhibitId'
- yHeight={625}
- list={tableInfo.list}
- columnsTemp={A6tableC}
- lastBtn={tableLastBtn}
- pageNum={pageData.pageNum}
- pageSize={pageData.pageSize}
- total={tableInfo.total}
- onChange={(pageNum, pageSize) => setPageData({ ...pageData, pageNum, pageSize })}
- />
- </div>
- {/* 新增 / 编辑 */}
- {editInfo.id ? (
- <A6add
- editInfo={editInfo}
- closeFu={() => setEditInfo({ id: 0, txt: '新增' })}
- addTableFu={resetSelectFu}
- editTableFu={getListFu}
- />
- ) : null}
- </div>
- )
- }
- const MemoA6exhibition = React.memo(A6exhibition)
- export default MemoA6exhibition
|