备份:大改造前的完整版本 - 修复合同细节/付款节点/文件上传/施工管理/项目保存等BUG
This commit is contained in:
@@ -15,7 +15,7 @@ import {
|
||||
DollarOutlined,
|
||||
SafetyOutlined
|
||||
} from '@ant-design/icons'
|
||||
import axios from 'axios'
|
||||
import apiClient from '../../utils/request'
|
||||
|
||||
const { TabPane } = Tabs
|
||||
|
||||
@@ -106,8 +106,8 @@ const ProjectDetail: React.FC = () => {
|
||||
const fetchUsers = async () => {
|
||||
setUsersLoading(true)
|
||||
try {
|
||||
const response = await fetch('/api/users')
|
||||
const data = await response.json()
|
||||
const response = await apiClient.get('/users')
|
||||
const data = response.data
|
||||
if (data.success) {
|
||||
setUsers(data.data)
|
||||
}
|
||||
@@ -209,7 +209,7 @@ const ProjectDetail: React.FC = () => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
|
||||
const response = await axios.post('/api/upload/single', formData, {
|
||||
const response = await apiClient.post('/upload/single', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
@@ -286,7 +286,7 @@ const ProjectDetail: React.FC = () => {
|
||||
contractAmount = totalAmount;
|
||||
}
|
||||
|
||||
const response = await axios.post(`/api/projects/${id}/subcontracts`, {
|
||||
const response = await apiClient.post(`/projects/${id}/subcontracts`, {
|
||||
subcontractor_id: values.subcontractor_id,
|
||||
subcontractor_name: values.subcontractor_name,
|
||||
contract_amount: contractAmount,
|
||||
@@ -322,7 +322,7 @@ const ProjectDetail: React.FC = () => {
|
||||
|
||||
const fetchProject = async () => {
|
||||
try {
|
||||
const response = await axios.get(`/api/projects/${id}`)
|
||||
const response = await apiClient.get(`/projects/${id}`)
|
||||
if (response.data.success) {
|
||||
setProject(response.data.data)
|
||||
}
|
||||
@@ -336,43 +336,43 @@ const ProjectDetail: React.FC = () => {
|
||||
const fetchProjectData = async () => {
|
||||
try {
|
||||
// 获取合同信息
|
||||
const contractsResponse = await axios.get(`/api/projects/${id}/contracts`)
|
||||
const contractsResponse = await apiClient.get(`/projects/${id}/contracts`)
|
||||
if (contractsResponse.data.success) {
|
||||
setContracts(contractsResponse.data.data)
|
||||
}
|
||||
|
||||
// 获取分包信息
|
||||
const subcontractsResponse = await axios.get(`/api/projects/${id}/subcontracts`)
|
||||
const subcontractsResponse = await apiClient.get(`/projects/${id}/subcontracts`)
|
||||
if (subcontractsResponse.data.success) {
|
||||
setSubcontracts(subcontractsResponse.data.data)
|
||||
}
|
||||
|
||||
// 获取材料信息
|
||||
const materialsResponse = await axios.get(`/api/projects/${id}/materials`)
|
||||
const materialsResponse = await apiClient.get(`/projects/${id}/materials`)
|
||||
if (materialsResponse.data.success) {
|
||||
setMaterials(materialsResponse.data.data)
|
||||
}
|
||||
|
||||
// 获取施工节点
|
||||
const milestonesResponse = await axios.get(`/api/projects/${id}/milestones`)
|
||||
const milestonesResponse = await apiClient.get(`/projects/${id}/milestones`)
|
||||
if (milestonesResponse.data.success) {
|
||||
setMilestones(milestonesResponse.data.data)
|
||||
}
|
||||
|
||||
// 获取财务信息
|
||||
const financesResponse = await axios.get(`/api/projects/${id}/finances`)
|
||||
const financesResponse = await apiClient.get(`/projects/${id}/finances`)
|
||||
if (financesResponse.data.success) {
|
||||
setFinances(financesResponse.data.data)
|
||||
}
|
||||
|
||||
// 获取质保金信息
|
||||
const warrantyDepositsResponse = await axios.get(`/api/projects/${id}/warranty-deposits`)
|
||||
const warrantyDepositsResponse = await apiClient.get(`/projects/${id}/warranty-deposits`)
|
||||
if (warrantyDepositsResponse.data.success) {
|
||||
setWarrantyDeposits(warrantyDepositsResponse.data.data)
|
||||
}
|
||||
|
||||
// 获取施工日志
|
||||
const constructionLogsResponse = await axios.get(`/api/projects/${id}/construction-logs`)
|
||||
const constructionLogsResponse = await apiClient.get(`/projects/${id}/construction-logs`)
|
||||
if (constructionLogsResponse.data.success) {
|
||||
setConstructionLogs(constructionLogsResponse.data.data)
|
||||
}
|
||||
@@ -392,7 +392,7 @@ const ProjectDetail: React.FC = () => {
|
||||
// 获取分包商列表
|
||||
const fetchSubcontractors = async () => {
|
||||
try {
|
||||
const response = await axios.get('/api/subcontractors')
|
||||
const response = await apiClient.get('/subcontractors')
|
||||
if (response.data.success) {
|
||||
setSubcontractors(response.data.data)
|
||||
}
|
||||
@@ -464,6 +464,10 @@ const ProjectDetail: React.FC = () => {
|
||||
newNodes[index].percentage = value
|
||||
newNodes[index].amount = Math.round((contractTotal * value) / 100)
|
||||
setPaymentNodes(newNodes)
|
||||
const total = newNodes.reduce((sum, n) => sum + (n.percentage || 0), 0)
|
||||
if (total > 100) {
|
||||
message.warning(`付款比例合计为 ${total}%,已超过 100%,请调整`)
|
||||
}
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
@@ -1046,10 +1050,9 @@ const ProjectDetail: React.FC = () => {
|
||||
description: values.description
|
||||
};
|
||||
|
||||
console.log('保存基本信息数据:', saveData);
|
||||
|
||||
// 发送保存请求
|
||||
const response = await axios.put(`/api/projects/${id}`, saveData);
|
||||
const response = await apiClient.put(`/projects/${id}`, saveData);
|
||||
if (response.data.success) {
|
||||
message.success('基本信息保存成功');
|
||||
// 重新获取项目信息
|
||||
@@ -1475,10 +1478,9 @@ const ProjectDetail: React.FC = () => {
|
||||
contract_file: contractFile
|
||||
};
|
||||
|
||||
console.log('保存数据:', saveData);
|
||||
|
||||
// 发送保存请求
|
||||
const response = await axios.put(`/api/projects/${id}/contract`, saveData);
|
||||
const response = await apiClient.put(`/projects/${id}/contract`, saveData);
|
||||
if (response.data.success) {
|
||||
message.success('合同细节保存成功');
|
||||
// 重新获取项目信息
|
||||
@@ -1630,7 +1632,7 @@ const ProjectDetail: React.FC = () => {
|
||||
/>
|
||||
)
|
||||
},
|
||||
{ title: '操作', key: 'action', render: () => <Button danger>删除</Button> }
|
||||
{ title: '操作', key: 'action', render: (_, record, index) => <Button danger onClick={() => removeUnitPriceItem(index)}>删除</Button> }
|
||||
]}
|
||||
pagination={false}
|
||||
locale={{ emptyText: '暂无项目单项' }}
|
||||
@@ -1709,12 +1711,12 @@ const ProjectDetail: React.FC = () => {
|
||||
key: 'status',
|
||||
render: () => <Tag color="default">未到达付款节点</Tag>
|
||||
},
|
||||
{ title: '操作', key: 'action', render: () => <Button danger>删除</Button> }
|
||||
{ title: '操作', key: 'action', render: (_, record, index) => <Button danger onClick={() => { const newNodes = [...paymentNodes]; newNodes.splice(index, 1); setPaymentNodes(newNodes); }}>删除</Button> }
|
||||
]}
|
||||
pagination={false}
|
||||
locale={{ emptyText: '暂无付款节点' }}
|
||||
/>
|
||||
<Button type="dashed" style={{ marginTop: 16 }}>添加付款节点</Button>
|
||||
<Button type="dashed" style={{ marginTop: 16 }} onClick={() => { setPaymentNodes([...paymentNodes, { key: String(Date.now()), name: '', condition: '', percentage: 0, amount: 0, status: 'pending' }]); }}>添加付款节点</Button>
|
||||
</Form.Item>
|
||||
|
||||
{/* 合同附件 */}
|
||||
@@ -1722,7 +1724,7 @@ const ProjectDetail: React.FC = () => {
|
||||
<Upload
|
||||
name="file"
|
||||
customRequest={handleFileUpload}
|
||||
listType="file"
|
||||
listType="text"
|
||||
maxCount={1}
|
||||
fileList={contractFile ? [{ uid: '1', name: contractFile.split('/').pop() || '', status: 'done', url: contractFile }] : []}
|
||||
onRemove={() => setContractFile('')}
|
||||
|
||||
Reference in New Issue
Block a user