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

278 lines
10 KiB
TypeScript
Raw Normal View History

2024-08-22 16:33:01 +08:00
import { useEffect, useState } from 'react'
import './RefunModal.css'
import { Form, Select, Button, Upload, message, Input } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
2024-08-23 11:16:52 +08:00
import { uploadImageUrl, DevUserId, get, post } from "../../util/AjaxUtils.ts";
import { getMenuActive } from '../../util/cache.ts'
import { useDispatch } from 'react-redux'
2024-08-22 16:33:01 +08:00
const { TextArea } = Input;
2024-08-22 18:28:15 +08:00
export default function RefunModal(props: any) {
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);
// };
// 获取当前选择类型
const type = getMenuActive()
const dispath = useDispatch()
2024-08-22 18:28:15 +08:00
const [refunDataArray, setRefunDataArray] = useState<any[]>([]) //未退款项目
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);
// console.log(refunArray);
2024-08-22 18:28:15 +08:00
post<any>({
messageApi,
url: `/api/proj/refund/apply/save`,
body: {
projId: values.title,
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-23 11:16:52 +08:00
2024-08-22 18:28:15 +08:00
},
onSuccess() {
messageApi.success('提交成功')
2024-08-23 11:16:52 +08:00
setTimeout(() => {
props.closeModal()
}, 1000)
if ( type === 'PENDING') {
getData()
}
2024-08-22 18:28:15 +08:00
},
onFinally() {
2024-08-23 11:16:52 +08:00
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,
url: `/api/proj/refund/apply/listpage`,
// url: `/api/proj/refund/apply/listpage?applyStatus=${state.type}`,
config: {
params: {
page: 1,
2024-08-26 09:10:30 +08:00
rows: 20,
2024-08-23 11:16:52 +08:00
applyStatus: type
}
},
onSuccess(data: any) {
// console.log('更新');
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,
url: `/api/proj/refund/apply/list-proj-unapply/self`,
2024-08-22 18:28:15 +08:00
// config: {
// params: {
// }
// },
onBefore() {
},
onSuccess(data: any) {
2024-08-23 11:16:52 +08:00
// console.log(data);
2024-08-22 18:28:15 +08:00
const newArray = (data.data).map((item: { projId: any; projName: any; }) => ({
value: item.projId,
label: item.projName
}))
setRefunDataArray(newArray)
},
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-08-23 11:16:52 +08:00
// console.log(type);
2024-08-22 18:28:15 +08:00
}, [])
2024-08-22 16:33:01 +08:00
return (
<div className='refunModal'>
{contextHolder}
<Form
name="Form"
onFinish={onFinish}
initialValues={{ softWare: '' }}
style={{ maxWidth: 600 }}
>
<div className='refunModal-item'>
<div className='refunModal-title'>
退<span className='refunModal-red'>*</span>
</div>
<Form.Item
name="title"
// label="退款软著"
rules={[{ required: true, message: '请选择一个软著!' }]}
>
<Select
showSearch
placeholder="选择需要退款的软著"
filterOption={(input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
}
2024-08-22 18:28:15 +08:00
options={refunDataArray}
2024-08-22 16:33:01 +08:00
style={{
width: 405,
height: 46,
}}
/>
</Form.Item>
</div>
2024-08-22 18:28:15 +08:00
{/* <div className='refunModal-item'>
2024-08-22 16:33:01 +08:00
<div className='refunModal-title'>
退<span className='refunModal-red'>*</span>
</div>
<Form.Item
name="reason"
// label="退款软著"
rules={[{ required: true, message: '请选择退款原因' }]}
>
<Select
placeholder="选择退款原因"
options={[
{ value: '没钱', label: '没钱' },
{ value: '不想买', label: '不想买' },
{ value: '其他', label: '其他' },
]}
style={{
width: 405,
height: 46,
}}
onChange={handleReasonChange}
/>
</Form.Item>
2024-08-22 18:28:15 +08:00
</div> */}
{/* {selectedReason === '' && (
2024-08-22 16:33:01 +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 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>
<Form.Item
name="other"
// label="退款软著"
rules={[{ required: true, message: '请输入退款原因' }]}
>
<TextArea
// showCount
// maxLength={100}
placeholder="其他退款原因"
style={{ height: 120, resize: 'none', width: 405, }}
/>
</Form.Item>
</div> */}
<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') {
refunArray.push(e.file.response.data.fileId);
setRefunArray(refunArray);
}
if (e.file.status === 'removed') {
const idArray = refunArray.filter(item => item != e.file.response.data.fileId);
setRefunArray(idArray);
}
return e.fileList;
}}
rules={[{ required: true, message: '请上传凭证' }]}
>
<Upload
name="image"
action={uploadImageUrl()}
headers={{ 'X-USER-ID': DevUserId }}
beforeUpload={(file) => {
const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
if (!isJpgOrPng) {
message.error('只能上传 JPG/PNG 格式文件!');
return Upload.LIST_IGNORE; // 不允许上传非
}
return isJpgOrPng;
}}
// listType="picture-card"
>
<Button icon={<UploadOutlined />} style={{ marginTop: 2 }}></Button>
</Upload>
</Form.Item>
</div>
</div>
<Form.Item>
<div className='refunModal-btn'>
<Button type="primary" htmlType="submit" style={{
width: 273,
height: 52
}}>
</Button>
</div>
</Form.Item>
</Form>
</div>
)
}