system-copyright-react/src/route/proj/ProjNew.tsx

225 lines
10 KiB
TypeScript
Raw Normal View History

2024-03-14 18:33:58 +08:00
import './proj-new.css';
2024-05-12 07:45:51 +08:00
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
import { Button, Flex, Form, Input, message, Modal, Spin } from "antd";
import { useContext, useEffect, useState } from "react";
import { get, post } from "../../util/AjaxUtils.ts";
import { IProjCharge, ProjAdditionalType, ProjChargeType } from "../../interfaces/proj/IProj.ts";
import { GlobalDispatchContext, reloadUser } from "../../context/GlobalContext.ts";
2024-05-23 14:57:22 +08:00
// const { TextArea } = Input;
2024-03-20 18:30:39 +08:00
type ProjInfo = {
projName: string;
projIntroduction: string;
2024-03-14 18:33:58 +08:00
};
export default function ProjNew() {
2024-04-02 18:45:46 +08:00
const globalDispatchContext = useContext(GlobalDispatchContext);
2024-03-14 18:33:58 +08:00
const nav = useNavigate();
2024-03-20 18:30:39 +08:00
const pathParams = useParams();
const [queryParams] = useSearchParams();
2024-03-14 18:33:58 +08:00
2024-03-20 18:30:39 +08:00
const [messageApi, contextHolder] = message.useMessage();
const [loading, setLoading] = useState<boolean>(false);
2024-05-21 11:21:34 +08:00
const height = window.innerHeight - 180;
2024-03-20 18:30:39 +08:00
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
const [chargePrice, setChargePrice] = useState(0);
const [projInfo, setProjInfo] = useState<ProjInfo>({
projName: '',
projIntroduction: '',
});
2024-03-21 22:22:35 +08:00
const [createProjId, setCreateProjId] = useState('');
2024-05-23 16:20:14 +08:00
const oldlistProjChargeAdditional: string[] = [];
const [listProjChargeAdditional,setlistProjChargeAdditional] = useState<string[]>([])
2024-03-14 23:34:40 +08:00
2024-03-20 18:30:39 +08:00
useEffect(() => {
get({
messageApi: messageApi,
url: '/api/proj/charge/get',
2024-05-12 07:45:51 +08:00
onSuccess({ data }) {
2024-03-20 18:30:39 +08:00
const charge = data as IProjCharge;
2024-05-08 17:54:01 +08:00
// console.log('创建页price',charge.proj.materialAgent);
2024-05-12 07:45:51 +08:00
2024-03-20 18:30:39 +08:00
let price = 0;
switch (pathParams.projChargeType) {
case ProjChargeType.ALL:
price = charge.proj.all;
break;
case ProjChargeType.MATERIAL_AGENT:
2024-05-12 07:45:51 +08:00
price = charge.proj.materialAgent;
2024-03-20 18:30:39 +08:00
break;
case ProjChargeType.MATERIAL_AGENT_URGENT:
price = charge.proj.materialAgentUrgent;
break;
case ProjChargeType.MATERIAL:
price = charge.proj.material;
break;
case ProjChargeType.FREE:
price = charge.proj.free;
break;
default:
messageApi.error({
type: 'error',
content: '价格类型错误',
})
}
2024-05-12 07:45:51 +08:00
const pkg = queryParams.get('pkg') == 'true' ? true : false
const videoDemo = queryParams.get('videoDemo') == 'true' ? true : false
2024-05-08 17:54:01 +08:00
if (pkg) {
2024-03-20 18:30:39 +08:00
price += charge.additional.pkg;
2024-05-23 16:20:14 +08:00
oldlistProjChargeAdditional.push(ProjAdditionalType.PKG);
console.log(listProjChargeAdditional);
2024-03-20 18:30:39 +08:00
}
2024-05-08 17:54:01 +08:00
if (videoDemo) {
2024-03-20 18:30:39 +08:00
price += charge.additional.videoDemo;
2024-05-23 16:20:14 +08:00
oldlistProjChargeAdditional.push(ProjAdditionalType.VIDEO_DEMO);
console.log(listProjChargeAdditional);
2024-03-20 18:30:39 +08:00
}
setChargePrice(price);
2024-05-23 16:20:14 +08:00
setlistProjChargeAdditional(oldlistProjChargeAdditional)
2024-05-12 07:45:51 +08:00
// console.log('传递信息pkg:',pkg,'videoDemo:',videoDemo);
// console.log('显示价格',price);
2024-03-20 18:30:39 +08:00
}
})
}, []);
2024-03-14 23:34:40 +08:00
2024-03-14 18:33:58 +08:00
return (
<>
2024-03-20 18:30:39 +08:00
{contextHolder}
2024-05-12 07:45:51 +08:00
{/* <Breadcrumb
2024-03-14 18:33:58 +08:00
items={[
{title: <Link to={'/'}></Link>},
{title: <Link to={'/proj-create'}></Link>},
2024-03-14 23:34:40 +08:00
{title: '新建项目'},
2024-03-14 18:33:58 +08:00
]}
2024-05-12 07:45:51 +08:00
/> */}
2024-05-21 11:21:34 +08:00
<div className='projNew' style={{height: `${height}px`, overflow: 'auto' }}>
2024-03-14 23:34:40 +08:00
<div className="proj-new">
2024-05-12 07:45:51 +08:00
{/* <div className="proj-title">请完善项目的基本信息</div> */}
2024-03-14 23:34:40 +08:00
<div className="proj-form">
<Form
name="basic"
layout={'vertical'}
2024-05-12 07:45:51 +08:00
labelCol={{ span: 24 }}
wrapperCol={{ span: 24 }}
2024-05-23 14:57:22 +08:00
style={{ width: '100%' }}
2024-03-20 18:30:39 +08:00
onFinish={(formData) => {
setIsCreateModalOpen(true);
setProjInfo({
projName: formData.projName,
projIntroduction: formData.projIntroduction
})
}}
2024-03-14 23:34:40 +08:00
autoComplete="off"
2024-03-14 18:33:58 +08:00
>
2024-05-12 07:45:51 +08:00
<div className='formItemOne'>
<div className='formItem-title oneTitle'>*</div>
<Form.Item<ProjInfo>
name="projName"
rules={[{ required: true, message: '请输入系统标题' }]}
>
2024-05-23 14:57:22 +08:00
<Input style={{ background: '#eeeeee', width: '1000px', height: '50px' ,fontSize:'16px'}} placeholder="请输入系统标题" />
2024-05-12 07:45:51 +08:00
</Form.Item>
</div>
2024-05-23 14:57:22 +08:00
{/* <div className='formItemTwo'>
2024-05-12 07:45:51 +08:00
<div className='formItem-title '></div>
<Form.Item<ProjInfo>
name="projIntroduction"
>
<TextArea rows={10} style={{ background: '#eeeeee', resize: 'none',width:"328px",height:'220px',fontSize:'16px' }} placeholder="请对系统作出简单的描述,以使可准确生成资料..." />
</Form.Item>
2024-05-23 14:57:22 +08:00
</div> */}
<div style={{ marginTop: '20px' }}>
2024-05-12 07:45:51 +08:00
<Form.Item>
<Flex align="center" justify="center" gap="large">
2024-05-21 11:21:34 +08:00
<Button
// style={{
// backgroundColor: '#F5F5F5', width: '216px',
// height: '50px', color: '#AFAFAF', fontSize: '16px'
// }}
size='large'
type="default" htmlType="button" onClick={() => {
2024-05-12 07:45:51 +08:00
nav(-1);
2024-05-21 11:21:34 +08:00
}}
>
2024-05-12 07:45:51 +08:00
</Button>
<Button type="primary" htmlType="submit"
2024-05-21 11:21:34 +08:00
size='large'
// style={{
// backgroundColor: 'var(--color-primary)', width: '216px',
// height: '50px', fontSize: '16px', marginLeft: '53px'
// }}
>
2024-05-12 07:45:51 +08:00
</Button>
2024-03-14 18:33:58 +08:00
2024-05-12 07:45:51 +08:00
</Flex>
</Form.Item>
</div>
2024-03-14 23:34:40 +08:00
</Form>
</div>
2024-03-14 18:33:58 +08:00
</div>
</div>
2024-03-20 18:30:39 +08:00
<Modal title="提示"
2024-05-12 07:45:51 +08:00
okText="确定"
cancelText="取消"
open={isCreateModalOpen}
onOk={() => {
2024-05-23 16:20:14 +08:00
// console.log('最终',listProjChargeAdditional);
2024-05-12 07:45:51 +08:00
setIsCreateModalOpen(false);
post<any>({
messageApi,
url: '/api/proj/create',
body: {
projName: projInfo.projName,
projChargeType: pathParams.projChargeType,
listProjChargeAdditional: listProjChargeAdditional
},
onBefore() {
setLoading(true);
},
onSuccess({ data }) {
setIsEditModalOpen(true);
setCreateProjId(data.data);
reloadUser(messageApi, globalDispatchContext).then(() => {
messageApi.success('扣款成功');
});
},
onFinally() {
setLoading(false);
}
})
}}
onCancel={() => {
setIsCreateModalOpen(false);
}}>
2024-03-20 18:30:39 +08:00
<div> {chargePrice / 100} </div>
</Modal>
<Modal title="提示"
2024-05-12 07:45:51 +08:00
okText="确定"
cancelText="取消"
open={isEditModalOpen}
onOk={() => {
if (pathParams.projChargeType == ProjChargeType.ALL) {
nav(`/proj-eall/${createProjId}`);
} else if (pathParams.projChargeType == ProjChargeType.FREE) {
nav(`/proj-efree/${createProjId}`);
} else {
nav(`/proj-edit/${createProjId}`);
}
}}
onCancel={() => {
setIsEditModalOpen(false);
}}>
2024-03-20 18:30:39 +08:00
<div></div>
2024-03-14 23:34:40 +08:00
</Modal>
2024-05-12 07:45:51 +08:00
<Spin tip="正在提交..." spinning={loading} fullscreen />
2024-03-14 18:33:58 +08:00
</>
)
}