system-copyright-react/src/components/RefunModal/RefunModal.tsx

388 lines
13 KiB
TypeScript
Raw Normal View History

2024-09-04 15:52:35 +08:00
import { useState, useEffect } from 'react'
2024-08-22 16:33:01 +08:00
import './RefunModal.css'
2024-09-04 15:52:35 +08:00
import { Form, Button, Upload, message, Input, Modal, Table, Empty } from 'antd';
import type { TableColumnsType } from 'antd';
2024-08-22 16:33:01 +08:00
import { UploadOutlined } from '@ant-design/icons';
2024-09-11 15:04:59 +08:00
import { DevUserId, get, post,uploadFileUrl } from "../../util/AjaxUtils.ts";
2024-09-04 15:52:35 +08:00
// import { getMenuActive } from '../../util/cache.ts'
2024-08-23 11:16:52 +08:00
import { useDispatch } from 'react-redux'
2024-09-04 15:52:35 +08:00
const { Search } = Input;
2024-08-22 16:33:01 +08:00
const { TextArea } = Input;
2024-09-04 15:52:35 +08:00
interface DataType {
key: React.Key;
projName: string;
projContext: string;
gmtCreate: string;
2024-09-11 15:04:59 +08:00
projId: string,
applyContactName: string;
2024-09-04 15:52:35 +08:00
}
2024-08-22 16:33:01 +08:00
2024-08-22 18:28:15 +08:00
export default function RefunModal(props: any) {
2024-09-04 15:52:35 +08:00
const columns: TableColumnsType<DataType> = [
{
title: '序号',
dataIndex: 'index',
align: 'center',
width: 80,
render: (_text, _record, index) => (page - 1) * 20 + index + 1, // 显示序号从1开始
},
{
title: '项目名称',
dataIndex: 'projName',
align: 'center',
render: (text: string) => <>{text}</>,
},
2024-09-11 15:04:59 +08:00
{
title: '所属者名称',
dataIndex: 'applyContactName',
align: 'center',
render: (text: string) => <>{text}</>,
},
2024-09-04 15:52:35 +08:00
{
title: '编号',
dataIndex: 'projContext',
align: 'center',
},
{
title: '创建时间',
dataIndex: 'gmtCreate',
align: 'center',
},
];
2024-08-22 16:33:01 +08:00
const [messageApi, contextHolder] = message.useMessage();
// 上传附件
const [refunArray, setRefunArray] = useState<string[]>([]);
2024-08-23 11:16:52 +08:00
// const [selectedReason, setSelectedReason] = useState(''); //选择原因
2024-08-22 16:33:01 +08:00
2024-08-23 11:16:52 +08:00
// const handleReasonChange = (value: any) => {
// setSelectedReason(value);
// };
// 获取当前选择类型
2024-09-04 15:52:35 +08:00
// const type = getMenuActive()
2024-08-23 11:16:52 +08:00
const dispath = useDispatch()
2024-09-04 15:52:35 +08:00
// 选择项目得临时name
const [newprojName, setnewprojName] = useState('')
// 选择项目得name
const [projName, setProjName] = useState('')
// 选择得项目临时id
const [newprojId, setnewProjId] = useState('')
// 选择 项目的id
const [projId, setProjId] = useState('')
//默认选择得项目
const [selectedRowKeys, setselectedRowKeys] = useState<string[]>([])
// 分页
const [page, setPage] = useState(1)
const [total, setTotal] = useState(0)
// 搜索关键字
const [keywords, setKeywords] = useState('')
const [refunDataArray, setRefunDataArray] = useState<any[]>([]) //未退款项目数组
// 选择项目弹窗
const [projModal, setProjModal] = useState(false)
const [isDisabled, setIsDisabled] = useState(false) //提交按钮是否禁用
const [form] = Form.useForm<any>();
// 关键字搜索
const handleSearch = (value: string) => {
setKeywords(value)
}
const handleChange = (e: any) => {
if (e.target.value == '') {
setKeywords('')
}
}
2024-08-22 16:33:01 +08:00
// 提交表单
const onFinish = (values: any) => {
2024-08-23 11:16:52 +08:00
// console.log('Form values:', values);
2024-08-22 18:28:15 +08:00
post<any>({
messageApi,
url: `/api/proj/refund/apply/save`,
body: {
2024-09-04 15:52:35 +08:00
projId: projId,
2024-08-22 18:28:15 +08:00
refundReason: values.other,
2024-08-23 11:29:57 +08:00
refundVoucher: refunArray.join(',')
2024-08-22 18:28:15 +08:00
},
onBefore() {
2024-08-26 18:03:35 +08:00
setIsDisabled(true)
2024-08-22 18:28:15 +08:00
},
onSuccess() {
messageApi.success('提交成功')
2024-08-26 18:03:35 +08:00
setIsDisabled(true)
2024-08-23 11:16:52 +08:00
setTimeout(() => {
props.closeModal()
2024-08-26 18:03:35 +08:00
}, 500)
2024-08-23 11:16:52 +08:00
2024-09-04 15:52:35 +08:00
getData()
2024-08-23 11:16:52 +08:00
2024-08-22 18:28:15 +08:00
},
onFinally() {
2024-08-26 18:03:35 +08:00
setIsDisabled(false)
2024-08-22 18:28:15 +08:00
}
})
2024-08-22 16:33:01 +08:00
};
2024-08-23 11:16:52 +08:00
const getData = () => {
get({
messageApi,
2024-09-06 17:26:09 +08:00
url: `/api/proj/refund/apply/listpage/self`,
2024-08-23 11:16:52 +08:00
config: {
params: {
page: 1,
2024-08-26 09:10:30 +08:00
rows: 20,
2024-09-04 15:52:35 +08:00
applyStatus: ''
2024-08-23 11:16:52 +08:00
}
},
onSuccess(data: any) {
dispath({
type: 'upRefunArray',
val: data.data.rows
})
dispath({
type: 'upRefunTotal',
val: data.data.total
})
}
})
}
2024-08-22 16:33:01 +08:00
// 获取未退款项目
const getRefunData = () => {
get({
messageApi,
2024-09-04 15:52:35 +08:00
url: `/api/proj/refund/apply/listpage-proj-unapply/self`,
config: {
params: {
page: 1,
rows: 20,
keywords
}
},
2024-08-22 18:28:15 +08:00
onBefore() {
},
onSuccess(data: any) {
2024-09-04 15:52:35 +08:00
setRefunDataArray(data.data.rows)
setTotal(data.data.total)
2024-08-22 18:28:15 +08:00
},
onFinally() {
},
2024-08-22 16:33:01 +08:00
})
}
2024-08-22 18:28:15 +08:00
useEffect(() => {
2024-08-22 16:33:01 +08:00
getRefunData()
2024-09-04 15:52:35 +08:00
}, [page, keywords])
2024-08-22 16:33:01 +08:00
return (
<div className='refunModal'>
{contextHolder}
<Form
name="Form"
2024-09-04 15:52:35 +08:00
form={form}
2024-08-22 16:33:01 +08:00
onFinish={onFinish}
initialValues={{ softWare: '' }}
style={{ maxWidth: 600 }}
>
<div className='refunModal-item'>
<div className='refunModal-title'>
退<span className='refunModal-red'>*</span>
</div>
2024-09-04 15:52:35 +08:00
<div className='refunInput'>
<Form.Item
name="title"
rules={[{ required: true, message: '请选择一个软著!' }]}
>
<Input style={{
2024-08-22 16:33:01 +08:00
width: 405,
height: 46,
2024-09-04 15:52:35 +08:00
background: '#FFF',
color: 'black'
2024-08-22 16:33:01 +08:00
}}
2024-09-04 15:52:35 +08:00
placeholder="选择需要退款的软著"
disabled
>
</Input>
2024-08-22 16:33:01 +08:00
</Form.Item>
2024-09-04 15:52:35 +08:00
<div className='refunInput-button' onClick={() => {
setProjModal(true)
setKeywords('')
setPage(1)
getRefunData()
}}>
</div>
2024-08-22 16:33:01 +08:00
</div>
2024-09-04 15:52:35 +08:00
</div>
2024-08-22 18:28:15 +08:00
<div className='refunModal-item'>
<div className='refunModal-title'>
退<span className='refunModal-red'>*</span>
</div>
<Form.Item
name="other"
rules={[{ required: true, message: '请输入退款原因' }]}
>
<TextArea
placeholder="输入退款原因"
style={{ height: 120, resize: 'none', width: 405 }}
/>
</Form.Item>
</div>
2024-08-22 16:33:01 +08:00
<div className='refunModal-item'>
<div className='refunModal-title'>
退<span className='refunModal-red'>*</span>
</div>
<div style={{ width: 405, }}>
<Form.Item
name="img"
// label="退款软著"
valuePropName="fileList"
getValueFromEvent={(e: any) => {
if (e.file.status === 'done') {
2024-09-11 15:04:59 +08:00
// console.log(e);
2024-08-22 16:33:01 +08:00
refunArray.push(e.file.response.data.fileId);
setRefunArray(refunArray);
2024-09-11 15:04:59 +08:00
2024-08-22 16:33:01 +08:00
}
if (e.file.status === 'removed') {
const idArray = refunArray.filter(item => item != e.file.response.data.fileId);
setRefunArray(idArray);
}
return e.fileList;
}}
2024-09-04 15:52:35 +08:00
rules={[{ required: true, message: '请上传补正通知书' }]}
2024-08-22 16:33:01 +08:00
>
<Upload
2024-09-11 15:04:59 +08:00
name="file"
action={uploadFileUrl()}
2024-08-22 16:33:01 +08:00
headers={{ 'X-USER-ID': DevUserId }}
beforeUpload={(file) => {
2024-09-11 15:04:59 +08:00
const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png' ||file.type === 'application/pdf';
// const isPng = file.type == 'application/pdf'
if (!isJpgOrPng ) {
message.error('只能上传 JPG/PNG/PDF 格式文件!');
2024-08-22 16:33:01 +08:00
return Upload.LIST_IGNORE; // 不允许上传非
}
return isJpgOrPng;
}}
// listType="picture-card"
>
2024-09-04 15:52:35 +08:00
<Button icon={<UploadOutlined />} style={{ marginTop: 2 }}></Button>
2024-08-22 16:33:01 +08:00
</Upload>
</Form.Item>
</div>
</div>
<Form.Item>
<div className='refunModal-btn'>
<Button type="primary" htmlType="submit" style={{
width: 273,
height: 52
2024-08-26 18:03:35 +08:00
}}
2024-09-04 15:52:35 +08:00
disabled={isDisabled}
2024-08-26 18:03:35 +08:00
>
2024-08-22 16:33:01 +08:00
</Button>
</div>
</Form.Item>
</Form>
2024-09-04 15:52:35 +08:00
<Modal title="选择退款项目"
destroyOnClose
okText="确认"
cancelText="取消"
open={projModal}
onOk={
() => {
if (newprojId) {
setProjName(newprojName)
setProjId(newprojId)
setProjModal(false)
setselectedRowKeys([newprojId])
form.setFieldsValue({
title: newprojName
});
} else {
messageApi.open({
type: 'error',
content: '请选择要退款项目'
})
}
}
}
width={1220}
onCancel={() => {
setselectedRowKeys([projId])
setnewProjId(projId)
setnewprojName(projName)
setProjModal(false)
}}>
<Search placeholder="输入项目名称"
onSearch={handleSearch}
onChange={handleChange}
style={{
width: '200px',
height: '31px',
marginBottom: 15
}}
allowClear
/>
<Table
rowSelection={{
selectedRowKeys: selectedRowKeys,
type: 'radio',
// ...rowSelection,
onChange: (_selectedRowKeys: React.Key[], selectedRows: DataType[]) => {
console.log('selectedRows: ', selectedRows);
setselectedRowKeys([selectedRows[0].projId])
setnewProjId(selectedRows[0].projId)
setnewprojName(selectedRows[0].projName)
},
}}
columns={columns}
dataSource={refunDataArray}
rowKey={'projId'}
pagination={
{
pageSize: 20,
total: total,
onChange: (currentPage) => {
setPage(currentPage);
},
showSizeChanger: false,
current: page
}
}
locale={{
emptyText: <Empty
description="暂无数据"
/>,
}}
scroll={{ y: 500 }}
/>
</Modal>
2024-08-22 16:33:01 +08:00
</div>
)
}