import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import styles from './index.module.scss' import A1look from './A1look' import { useDispatch, useSelector } from 'react-redux' import { A1_APIdel, A1_APIgetList } from '@/store/action/A1record' import { RootState } from '@/store' import { MessageFu } from '@/utils/message' import { Button, Checkbox, Input, Table } from 'antd' import MyPopconfirm from '@/components/MyPopconfirm' import { A1ListType, jiGuanFu, LookInfoType } from './data' import A1add from './A1add' import ImageLazy from '@/components/ImageLazy' const baseFromData = { pageNum: 1, pageSize: 10, searchKey: '', display: '' } function A1record() { const dispatch = useDispatch() const [fromData, setFromData] = useState(baseFromData) const getListFu = useCallback(() => { dispatch(A1_APIgetList(fromData)) }, [dispatch, fromData]) useEffect(() => { getListFu() }, [getListFu]) // 作品名称的输入 const timeRef = useRef(-1) const [inputKey, setInputKey] = useState(0) const fromKeyChangeFu = useCallback( (e: React.ChangeEvent, key: 'searchKey') => { clearTimeout(timeRef.current) timeRef.current = window.setTimeout(() => { setFromData({ ...fromData, [key]: e.target.value, pageNum: 1 }) }, 500) }, [fromData] ) const tableInfo = useSelector((state: RootState) => state.A1record.tableInfo) // 点击重置 const resetSelectFu = useCallback(() => { setInputKey(Date.now()) setFromData({ ...baseFromData }) }, []) // 点击查看 const [lookInfo, setLookInfo] = useState({ id: 0, txt: '' }) const delTableFu = useCallback( async (id: number) => { const res = await A1_APIdel(id) if (res.code === 0) { MessageFu.success('删除成功!') getListFu() } }, [getListFu] ) // 表格相关 const columns = useMemo(() => { const arr: any = [ { title: 'ID', dataIndex: 'num', width: 100 }, { title: '封面图', width: 80, render: (item: A1ListType) => (
) }, { title: '姓名', render: (item: A1ListType) => item.name, width: 100 }, { title: '性别', width: 100, render: (item: A1ListType) => (item.gender === 1 ? '男' : '女') }, { title: '民族', width: 100, render: (item: A1ListType) => item.nation || '(空)' }, { title: '番号', render: (item: A1ListType) => item.intro || '(空)' }, { title: '籍贯', render: (item: A1ListType) => jiGuanFu(item) }, { title: '生卒', width: 200, render: (item: A1ListType) => (item.dateStart || '(空)') + ' ~ ' + (item.dateEnd || '(空)') }, { title: '备注', render: (item: A1ListType) => item.remark ? ( item.remark.length >= 50 ? ( {item.remark.substring(0, 50) + '...'} ) : ( item.remark ) ) : ( '(空)' ) }, { title: '编辑时间', width: 150, render: (item: A1ListType) => item.updateTime }, { title: '编辑人', width: 100, render: (item: A1ListType) => item.creatorName }, { title: '操作', fixed: 'right', width: 150, render: (item: A1ListType) => ( <> delTableFu(item.id)} /> ) } ] return arr }, [delTableFu]) return (
烈士档案{lookInfo.txt ? ` - ${lookInfo.txt}` : ''}{' '} {lookInfo.txt === '查看' ? (
setLookInfo({ id: 0, txt: '' })} className='A1LookBack'>
) : null}
{/* 顶部筛选 */}
fromKeyChangeFu(e, 'searchKey')} />
{ const val: any = e.target.checked ? 1 : '' setFromData({ ...fromData, display: val, pageNum: 1 }) }} > 寻亲烈士
{/* 表格主体 */}
setFromData({ ...fromData, pageNum, pageSize }) }} /> {['新增', '编辑'].includes(lookInfo.txt) ? ( setLookInfo({ id: 0, txt: '' })} addTableFu={resetSelectFu} upTableFu={getListFu} /> ) : null} {lookInfo.txt === '查看' ? : null} ) } const MemoA1record = React.memo(A1record) export default MemoA1record