system-copyright-react/src/route/Refun/Refun.tsx

457 lines
18 KiB
TypeScript
Raw Normal View History

2024-08-22 16:33:01 +08:00
import './refun.css';
2024-08-23 12:00:55 +08:00
import { useState, useEffect, } from 'react';
2024-08-22 18:28:15 +08:00
import {
Table,
2024-08-22 16:33:01 +08:00
// Pagination,
2024-08-23 11:16:52 +08:00
Modal, Tag, message, Spin
2024-08-22 18:28:15 +08:00
} from 'antd';
2024-08-23 11:16:52 +08:00
import { useSelector, useDispatch } from 'react-redux'
import { get, put, downloadUrl } from '../../util/AjaxUtils'
2024-08-22 16:33:01 +08:00
import type { TableProps } from 'antd';
2024-08-23 12:31:55 +08:00
import { getMenuActive } from '../../util/cache'
import { useNavigate } from "react-router-dom";
2024-08-22 16:33:01 +08:00
interface DataType {
2024-08-22 18:28:15 +08:00
projName: string;
projPayment: string;
refundReason: string;
gmtCreate: string;
2024-08-23 11:16:52 +08:00
refundVoucherFileKVs: any;
2024-08-22 18:28:15 +08:00
projRefundApplyId: string;
gmtReview: string;
applyStatus: string;
reviewReason: string;
2024-08-23 11:16:52 +08:00
projId: string;
2024-08-22 16:33:01 +08:00
}
import revokeImg from '../../static/revoke.png'
import { useLocation } from 'react-router-dom'
export default function Refun() {
const height = window.innerHeight - 180;
const [messageApi, contextHolder] = message.useMessage();
2024-08-23 12:31:55 +08:00
const nav = useNavigate();
2024-08-23 11:16:52 +08:00
const [isLoading, setIsLoading] = useState(false)
2024-08-22 16:33:01 +08:00
const [page, setPage] = useState(1) // 分页
2024-08-23 11:16:52 +08:00
// const [total, setTotal] = useState(0) // 数据总数
// const [data, setData] = useState<any[]>([])
2024-08-22 16:33:01 +08:00
const [revokeModal, setRevokeModal] = useState(false) //撤销弹窗
2024-08-22 18:28:15 +08:00
const [projRefundApplyId, setprojRefundApplyId] = useState('') //要撤销的id
2024-08-22 16:33:01 +08:00
const { state } = useLocation()
2024-08-23 12:31:55 +08:00
const type = state ? state.type : getMenuActive()
2024-08-23 12:00:55 +08:00
// setMenuActive(type)
2024-08-22 16:33:01 +08:00
// {state.type}
2024-08-23 11:16:52 +08:00
const columns: TableProps<DataType>['columns'] =
// 撤销状态
2024-08-23 12:00:55 +08:00
type == 'CANCELED' ? [
2024-08-23 11:16:52 +08:00
{
title: '序号',
dataIndex: 'index',
align: 'center',
width: 80,
2024-08-26 09:10:30 +08:00
render: (_text, _record, index) => (page - 1) * 20 + index + 1, // 显示序号从1开始
2024-08-23 11:16:52 +08:00
},
{
title: '系统名称',
dataIndex: 'projName',
align: 'center',
key: 'projName',
render: (text) => <div className='ellipsis-text' title={text}>{text}</div>,
},
{
title: '金额',
dataIndex: 'projPayment',
key: 'projPayment',
align: 'center',
width: 150,
2024-08-23 12:31:55 +08:00
render: (text) => <div style={{ color: 'red', fontWeight: 700 }}>{text / 100}</div>,
2024-08-23 11:16:52 +08:00
},
{
title: '退款原因',
dataIndex: 'refundReason',
key: 'refundReason',
align: 'center',
render: (text) => <div className='ellipsis-text' title={text}>{text}</div>,
},
{
title: '申请退款时间',
dataIndex: 'gmtCreate',
key: 'gmtCreate',
align: 'center',
width: 200,
},
2024-08-26 18:03:35 +08:00
2024-08-23 11:16:52 +08:00
{
title: '审核状态',
dataIndex: 'applyStatus',
key: 'applyStatus',
align: 'center',
width: 100,
render: (text) => <Tag
color={text == "APPROVED" ? '#87d068' : text == "REJECTED" ? '#f50' : text == "PENDING" ? '#2db7f5' : text == "CANCELED" ? '#108ee9' : ''}
>{text == "APPROVED" ? '已通过' : text == "REJECTED" ? '未通过' : text == "PENDING" ? '待审核' : text == "CANCELED" ? '已取消' : '未知'}</Tag>,
},
2024-08-26 18:03:35 +08:00
2024-08-23 11:16:52 +08:00
{
title: '退款凭证',
dataIndex: 'refundVoucherFileKVs',
key: 'refundVoucherFileKVs',
// width: 100,
align: 'center',
render: (_, record) => (
(record.refundVoucherFileKVs).map((item: any, index: number) => (
2024-08-23 12:31:55 +08:00
2024-08-26 18:03:35 +08:00
<div style={{ cursor: 'pointer', color: 'var(--color-blue)' }}
className='ellipsis-text' title={item.value}
key={index} onClick={() => {
window.open(downloadUrl(item.key, false), '_blank')
}}>{item.value}</div>
2024-08-23 12:31:55 +08:00
2024-08-23 11:16:52 +08:00
))
),
},
]
2024-08-23 12:00:55 +08:00
: type == 'PENDING' ?
2024-08-23 11:16:52 +08:00
// PENDING待审核状态
[
{
title: '序号',
dataIndex: 'index',
align: 'center',
width: 80,
render: (_text, _record, index) => (page - 1) * 10 + index + 1, // 显示序号从1开始
},
{
title: '系统名称',
dataIndex: 'projName',
align: 'center',
key: 'projName',
render: (text) => <div className='ellipsis-text' title={text}>{text}</div>,
},
{
title: '金额',
dataIndex: 'projPayment',
key: 'projPayment',
align: 'center',
width: 150,
2024-08-23 12:31:55 +08:00
render: (text) => <div style={{ color: 'red', fontWeight: 700 }}>{text / 100}</div>,
2024-08-23 11:16:52 +08:00
},
{
title: '退款原因',
dataIndex: 'refundReason',
key: 'refundReason',
align: 'center',
render: (text) => <div className='ellipsis-text' title={text}>{text}</div>,
},
{
title: '申请退款时间',
dataIndex: 'gmtCreate',
key: 'gmtCreate',
align: 'center',
width: 200,
},
{
title: '审核状态',
dataIndex: 'applyStatus',
key: 'applyStatus',
align: 'center',
width: 100,
render: (text) => <Tag
color={text == "APPROVED" ? '#87d068' : text == "REJECTED" ? '#f50' : text == "PENDING" ? '#2db7f5' : text == "CANCELED" ? '#108ee9' : ''}
>{text == "APPROVED" ? '通过' : text == "REJECTED" ? '未通过' : text == "PENDING" ? '待审核' : text == "CANCELED" ? '已取消' : '未知'}</Tag>,
},
{
title: '退款凭证',
dataIndex: 'refundVoucherFileKVs',
key: 'refundVoucherFileKVs',
// width: 100,
align: 'center',
render: (_, record) => (
// {record.name}
// <div className='refunBtn' onClick={() => {
// console.log(record.refundVoucherFileKVs);
// }}> 预览</div>
2024-08-23 12:31:55 +08:00
(record.refundVoucherFileKVs).map((item: any, index: number) => (
2024-08-26 18:03:35 +08:00
<div style={{ cursor: 'pointer', color: 'var(--color-blue)' }}
className='ellipsis-text' title={item.value}
key={index} onClick={() => {
window.open(downloadUrl(item.key, false), '_blank')
}}>{item.value}</div>
2024-08-23 12:31:55 +08:00
2024-08-23 11:16:52 +08:00
))
2024-08-22 16:33:01 +08:00
2024-08-23 11:16:52 +08:00
),
2024-08-22 16:33:01 +08:00
2024-08-23 11:16:52 +08:00
},
{
title: '操作',
align: 'center',
width: 100,
render: (_, record) => (
// {record.name}
<div className='refunBtn' onClick={() => {
2024-08-27 11:35:08 +08:00
// console.log(record.projRefundApplyId);
2024-08-23 11:16:52 +08:00
setRevokeModal(true)
setprojRefundApplyId(record.projRefundApplyId)
}}> </div>
2024-08-22 16:33:01 +08:00
2024-08-23 11:16:52 +08:00
),
},
] :
// 已通过 和未通过 状态
[
{
title: '序号',
dataIndex: 'index',
align: 'center',
width: 80,
render: (_text, _record, index) => (page - 1) * 10 + index + 1, // 显示序号从1开始
},
{
title: '系统名称',
dataIndex: 'projName',
align: 'center',
key: 'projName',
render: (text) => <div className='ellipsis-text' title={text}>{text}</div>,
},
{
title: '金额',
dataIndex: 'projPayment',
key: 'projPayment',
align: 'center',
width: 150,
2024-08-23 12:31:55 +08:00
render: (text) => <div style={{ color: 'red', fontWeight: 700 }}>{text / 100}</div>,
2024-08-23 11:16:52 +08:00
},
{
title: '退款原因',
dataIndex: 'refundReason',
key: 'refundReason',
align: 'center',
render: (text) => <div className='ellipsis-text' title={text}>{text}</div>,
},
{
title: '申请退款时间',
dataIndex: 'gmtCreate',
key: 'gmtCreate',
align: 'center',
width: 200,
},
{
title: '审核时间',
dataIndex: 'gmtReview',
key: 'gmtReview',
align: 'center',
width: 200,
},
{
title: '审核状态',
dataIndex: 'applyStatus',
key: 'applyStatus',
align: 'center',
width: 100,
render: (text) => <Tag
color={text == "APPROVED" ? '#87d068' : text == "REJECTED" ? '#f50' : text == "PENDING" ? '#2db7f5' : text == "CANCELED" ? '#108ee9' : ''}
>{text == "APPROVED" ? '通过' : text == "REJECTED" ? '未通过' : text == "PENDING" ? '待审核' : text == "CANCELED" ? '已取消' : '未知'}</Tag>,
},
{
title: '审核意见',
dataIndex: 'reviewReason',
key: 'reviewReason',
align: 'center',
// width: 150,
2024-08-26 18:03:35 +08:00
render: (text) => <div className='ellipsis-text' title={text}>{text ? text : '—'}</div>,
2024-08-23 11:16:52 +08:00
},
{
title: '退款凭证',
dataIndex: 'refundVoucherFileKVs',
key: 'refundVoucherFileKVs',
// width: 100,
align: 'center',
render: (_, record) => (
2024-08-26 18:03:35 +08:00
2024-08-23 11:16:52 +08:00
(record.refundVoucherFileKVs).map((item: any, index: number) => (
2024-08-23 12:31:55 +08:00
2024-08-26 18:03:35 +08:00
<div className='ellipsis-text' title={item.value} style={{ cursor: 'pointer', color: 'var(--color-blue)' }} key={index} onClick={() => {
2024-08-23 12:31:55 +08:00
window.open(downloadUrl(item.key, false), '_blank')
}}>{item.value}</div>
2024-08-23 11:16:52 +08:00
))
2024-08-22 16:33:01 +08:00
2024-08-23 11:16:52 +08:00
),
},
];
const dispath = useDispatch()
const redxuState: any = useSelector(state => state)
const refunArray = redxuState.refunArray
const total = redxuState.refunTotal
2024-08-22 18:28:15 +08:00
const getData = (page: number) => {
2024-08-22 16:33:01 +08:00
get({
messageApi,
url: `/api/proj/refund/apply/listpage`,
// url: `/api/proj/refund/apply/listpage?applyStatus=${state.type}`,
config: {
params: {
page: page,
2024-08-26 09:10:30 +08:00
rows: 20,
2024-08-23 12:00:55 +08:00
applyStatus: type
2024-08-22 16:33:01 +08:00
}
},
2024-08-23 11:16:52 +08:00
onBefore() {
setIsLoading(true)
},
2024-08-22 18:28:15 +08:00
onSuccess(data: any) {
2024-08-27 11:35:08 +08:00
// console.log(data.data.rows);
2024-08-23 11:16:52 +08:00
// setData(data.data.rows)
dispath({
type: 'upRefunArray',
val: data.data.rows
})
dispath({
type: 'upRefunTotal',
val: data.data.total
})
// setTotal(data.data.total)
},
onFinally() {
setIsLoading(false)
},
2024-08-22 18:28:15 +08:00
})
}
// 撤销退款
const projRefund = () => {
put<any>({
messageApi,
url: `/api/proj/refund/apply/cancel/self/${projRefundApplyId}`,
2024-08-23 11:16:52 +08:00
2024-08-22 18:28:15 +08:00
onBefore() {
2024-08-23 11:16:52 +08:00
2024-08-22 18:28:15 +08:00
},
onSuccess() {
setRevokeModal(false)
messageApi.success('已撤销');
2024-08-23 11:16:52 +08:00
get({
messageApi,
url: `/api/proj/refund/apply/listpage`,
// url: `/api/proj/refund/apply/listpage?applyStatus=${state.type}`,
config: {
params: {
page: page,
2024-08-26 09:10:30 +08:00
rows: 20,
2024-08-23 12:00:55 +08:00
applyStatus: type
2024-08-23 11:16:52 +08:00
}
},
onSuccess(data: any) {
// console.log(data.data.rows);
// setData(data.data.rows)
2024-08-22 18:28:15 +08:00
2024-08-23 11:16:52 +08:00
// setTotal(data.data.total)
2024-08-26 18:03:35 +08:00
if (data.data.rows.length == 0 && page > 1) {
2024-08-23 11:16:52 +08:00
getData(page - 1)
} else {
dispath({
type: 'upRefunArray',
val: data.data.rows
})
dispath({
type: 'upRefunTotal',
val: data.data.total
})
}
}
})
2024-08-22 18:28:15 +08:00
},
onFinally() {
// setIsProjIntroductionLoading(false)
// renderData()
2024-08-22 16:33:01 +08:00
}
})
}
2024-08-23 12:31:55 +08:00
useEffect(() => {
if (!state) {
nav('/home')
}
2024-08-23 12:34:53 +08:00
}, [state])
2024-08-22 18:28:15 +08:00
useEffect(() => {
2024-08-22 16:33:01 +08:00
// getData(1)
setPage(1)
getData(1)
2024-08-27 11:35:08 +08:00
// console.log(type);
2024-08-23 12:31:55 +08:00
2024-08-23 12:00:55 +08:00
}, [type])
2024-08-22 16:33:01 +08:00
return (
<div>
{contextHolder}
2024-08-23 11:16:52 +08:00
2024-08-22 16:33:01 +08:00
<div className='refun' style={{ height: `${height}px`, overflow: 'auto' }}>
{/* {state.type} */}
2024-08-23 11:16:52 +08:00
<Spin tip="加载中..." spinning={isLoading}>
<Table columns={columns} dataSource={refunArray}
style={{
// height: height - 80,
// height: 620,
// background: 'skyblue'
}}
// pagination={false} // 不显示分页
pagination={
{
2024-08-26 09:10:30 +08:00
pageSize: 20,
2024-08-23 11:16:52 +08:00
total: total,
onChange: (currentPage) => {
setPage(currentPage);
getData(currentPage)
},
showSizeChanger: false,
current: page
2024-08-22 16:33:01 +08:00
2024-08-23 11:16:52 +08:00
}
2024-08-22 16:33:01 +08:00
2024-08-23 11:16:52 +08:00
}
2024-08-23 12:31:55 +08:00
scroll={{ y: height - 150 }}
2024-08-23 11:16:52 +08:00
rowKey="projId"
/>
</Spin>
2024-08-23 12:31:55 +08:00
<div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: 15, width: '100%' }}>
2024-08-23 11:16:52 +08:00
{/* <Pagination defaultCurrent={page} total={total} pageSize={10} showSizeChanger={false} onChange={(page) => {
2024-08-22 16:33:01 +08:00
setPage(page)
2024-08-23 11:16:52 +08:00
getData(page)
}} /> */}
</div>
2024-08-22 16:33:01 +08:00
</div>
2024-08-23 11:16:52 +08:00
2024-08-22 16:33:01 +08:00
<Modal
title="确认撤销"
okText="撤销"
cancelText="取消"
destroyOnClose={true}
open={revokeModal}
onOk={() => {
2024-08-22 18:28:15 +08:00
// setRevokeModal(false)
projRefund()
2024-08-22 16:33:01 +08:00
}}
onCancel={() => {
setRevokeModal(false)
}}
okButtonProps={{ style: { background: 'red', color: 'white' } }}
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
height: `${height}px`,
}}>
<div style={{ width: 384, display: 'flex', height: 50, alignItems: 'center' }}>
<img src={revokeImg} alt="" style={{ width: 32, height: 32, marginLeft: 10 }} />
<div style={{ marginLeft: 10, fontSize: 18 }}>
退
</div>
</div>
</Modal>
</div>
)
}