import Authorization from '@/components/Authorization' import DatePicker from '@/components/DatePicker' import MoneyInput from '@/components/MoneyInput' import { commonStore, contractStore, tenderStore } from '@/store/mobx' import { ContractType } from '@/store/mobx/contract' import { iModalCommonProps } from '@/types/contract' import { apiContractSection } from '@/utils/common/api' import { contractTreeBaseId } from '@/utils/common/constStatus' import consts from '@/utils/consts' import { dayjsFormat, handleAutoCode } from '@/utils/util' import { Button, Form, Input, Modal, Select, TreeSelect } from 'antd' import locale from 'antd/es/date-picker/locale/zh_CN' import dayjs from 'dayjs' import React, { useEffect, useState } from 'react' import styles from './index.module.scss' import { BigNumber } from "bignumber.js" import { observer } from 'mobx-react' interface ContractSection { id: string; treeType: number; parentId: string; name: string; depth: number; serial: number; attribution: string; code: string; projectId: string; bidsectionId: string; contractId: string; contractName: string; contractCode: string; contractPrice: string; contractReturned: string; contractsPaid: string; contractStatus: number; contractLocking: number; createTime: string; children?: any; templateNumber: number; operation: string; elderBrother: boolean; isEnd: boolean; key: string; title: string; } const ContractModal: React.FC = ({ modalObj: { type, visible, confirmLoading, contractType }, onConfirm, onCancel, reload, row }) => { const { Option } = Select const [ contractSection, setContractSection ] = useState([]) const [ form ] = Form.useForm() const modalObj = { create: { title: '新建合同', cancelText: '取消', okText: '确认添加' }, update: { title: '编辑合同', cancelText: '取消', okText: '确认' }, close: { title: '关闭合同', cancelText: '取消', okText: '确认关闭' }, del: { title: '删除合同', cancelText: '取消', okText: '确认删除' }, unlock: { title: '解锁合同', cancelText: '取消', okText: '确认解锁' }, add: { title: contractType === ContractType.INCOME ? '添加回款' : '添加支付', cancelText: '关闭', okText: '确认' } } const initTreeSection = async () => { const { code = -1, sectionTree: data = {} } = await apiContractSection(tenderStore.bid, contractType === ContractType.INCOME ? consts.CONTRACT_TREE.RETURN : consts.CONTRACT_TREE.PAID) if (code === consts.RET_CODE.SUCCESS) { setContractSection(data.children) } } useEffect(() => { if (visible) { form.setFieldsValue({ treeId: row.id, bidsectionId: tenderStore.bid }) if (type === 'create') { initTreeSection() form.setFieldsValue({ treeId: row.contractId === contractTreeBaseId ? row.id : row.parentId }) } if (type === 'update') { const { content = '', name = '', price = '', partyA = '', partyB = '', partyASigner = '', partyBSigner = '', signerTime = '', remarks = '' } = contractStore.contract form.setFieldsValue({ content, name, price, partyA, partyB, partyASigner, partyBSigner, signerTime: signerTime ? dayjs(signerTime) : '', remarks }) } else if (type === 'add') { commonStore.returnWayOptions && commonStore.queryWayOptions() form.setFieldsValue({ contractsId: contractStore.contract.id }) } else { form.setFieldsValue({ id: contractStore.contract.id }) } } }, [ visible ]) const autoCode = async () => { const ruleArr = await handleAutoCode(tenderStore.tender.bidsectionId, contractType === ContractType.INCOME ? 'contractReturnRule' : 'contractPaidRule') form.setFieldsValue({ code: ruleArr.join('-') }) } // 处理添加回款的金额不应该超出最大值 const maxPrice = new BigNumber(contractStore.contract.price).minus(contractType === ContractType.INCOME ? contractStore.contract.returned : contractStore.contract.paid) const minPrice = new BigNumber(contractType === ContractType.INCOME ? row.contractReturned : row.contractsPaid) return ( { form.resetFields() onCancel() }} footer={
{type === 'update' ? ( ) : null}
}>
{/* */} {type === 'create' ? ( <> autoCode()}> 自动编号 } /> {/* */} {/* 元} /> */} ) : ( '' )} {type === 'update' ? ( <> ({ validator(_, value) { if (value && (new BigNumber(value).lt(minPrice))) { return Promise.reject(`当前金额不能低于${minPrice}`) } return Promise.resolve() } }) ]}> ) : null } {type === 'close' ? ( <> 关闭后,合同将锁定,无法进行编辑、上传文件等操作。 ) : ( '' )} {type === 'unlock' ? ( <> 解锁后,合同将锁定,无法进行编辑、上传文件等操作。 ) : ( '' )} {type === 'del' ? ( <>

删除后,数据无法恢复,请谨慎操作。

请在下方文本框输入文本「确认删除本合同」,以此确认删除操作。

({ validator(rule, value) { if (!value || value !== '确认删除本合同') { return Promise.reject('请按照提示信息进行删除操作!') } return Promise.resolve() } }) ]}> ) : ( '' )} {type === 'add' ? ( <> ({ validator(_, value) { if (value && (new BigNumber(value).gt(maxPrice))) { return Promise.reject(`当前金额不能大于${maxPrice}`) } return Promise.resolve() } }) ]}> {/* */} ) : ( '' )}
) } export default observer(ContractModal)