|
|
|
@ -28,15 +28,15 @@ |
|
|
|
:max="2100" |
|
|
|
/> |
|
|
|
</a-form-item> |
|
|
|
<a-form-item label="月份" name="declareMonth"> |
|
|
|
<a-form-item label="季度" name="declareQuarter"> |
|
|
|
<a-select |
|
|
|
v-model:value="form.declareMonth" |
|
|
|
placeholder="请选择月份" |
|
|
|
@change="onMonthChange" |
|
|
|
v-model:value="form.declareQuarter" |
|
|
|
placeholder="请选择季度" |
|
|
|
@change="onQuarterChange" |
|
|
|
style="width: 100%" |
|
|
|
> |
|
|
|
<a-select-option v-for="month in monthOptions" :key="month.value" :value="month.value"> |
|
|
|
{{ month.label }} |
|
|
|
<a-select-option v-for="quarter in quarterOptions" :key="quarter.value" :value="quarter.value"> |
|
|
|
{{ quarter.label }} |
|
|
|
</a-select-option> |
|
|
|
</a-select> |
|
|
|
</a-form-item> |
|
|
|
@ -62,7 +62,7 @@ |
|
|
|
/> |
|
|
|
<div style="font-size: 12px; color: #666; margin-top: 4px;"> |
|
|
|
本年度已填报收入:{{ annualIncomeInfo.revenue || 0 }} 万元 |
|
|
|
<span v-if="annualIncomeInfo.revenue > 0 && form.revenue">,合计:{{ formatNumber((annualIncomeInfo.revenue || 0) + (form.revenue || 0)) }} 万元</span> |
|
|
|
<span v-if="annualIncomeInfo.revenue > 0 && form.revenue">,合计:{{ formatNumber(parseFloat(annualIncomeInfo.revenue || 0) + parseFloat(form.revenue || 0)) }} 万元</span> |
|
|
|
</div> |
|
|
|
</a-form-item> |
|
|
|
|
|
|
|
@ -156,37 +156,37 @@ |
|
|
|
totalCost: 0 // 总成本支出 |
|
|
|
}); |
|
|
|
|
|
|
|
// 月份选项(只能填报上一个月) |
|
|
|
const monthOptions = ref([]); |
|
|
|
// 季度选项(只能填报上一个季度) |
|
|
|
const quarterOptions = ref([]); |
|
|
|
|
|
|
|
// 初始化月份选项,只能选择上一个月 |
|
|
|
async function initMonthOptions() { |
|
|
|
// 初始化季度选项,只能选择上一个季度 |
|
|
|
async function initQuarterOptions() { |
|
|
|
const currentDate = new Date(); |
|
|
|
const currentYear = currentDate.getFullYear(); |
|
|
|
const currentMonth = currentDate.getMonth() + 1; // 当前月份(1-12) |
|
|
|
const currentMonth = currentDate.getMonth() + 1; |
|
|
|
|
|
|
|
// 计算上一个月 |
|
|
|
let lastMonth = currentMonth - 1; |
|
|
|
let lastMonthYear = currentYear; |
|
|
|
// 计算当前季度 |
|
|
|
const currentQuarter = Math.ceil(currentMonth / 3); |
|
|
|
|
|
|
|
if (lastMonth === 0) { |
|
|
|
lastMonth = 12; |
|
|
|
lastMonthYear = currentYear - 1; |
|
|
|
// 计算上一个季度 |
|
|
|
let lastQuarter = currentQuarter - 1; |
|
|
|
let lastQuarterYear = currentYear; |
|
|
|
|
|
|
|
if (lastQuarter === 0) { |
|
|
|
lastQuarter = 4; |
|
|
|
lastQuarterYear = currentYear - 1; |
|
|
|
} |
|
|
|
|
|
|
|
// 设置默认年份为上一个月所在的年份 |
|
|
|
form.declareYear = lastMonthYear; |
|
|
|
// 设置默认年份为上一个季度所在的年份 |
|
|
|
form.declareYear = lastQuarterYear; |
|
|
|
|
|
|
|
// 只能选择上一个月 |
|
|
|
monthOptions.value = [ |
|
|
|
{ label: `${lastMonth}月`, value: `${lastMonth}月` } |
|
|
|
// 只能选择上一个季度 |
|
|
|
quarterOptions.value = [ |
|
|
|
{ label: `第${lastQuarter}季度`, value: lastQuarter } |
|
|
|
]; |
|
|
|
|
|
|
|
// 默认选中上一个月 |
|
|
|
form.declareMonth = `${lastMonth}月`; |
|
|
|
|
|
|
|
// 设置默认月份后,立即获取公益成本数据 |
|
|
|
await getPublicWelfareCost(); |
|
|
|
// 默认选中上一个季度 |
|
|
|
form.declareQuarter = lastQuarter; |
|
|
|
} |
|
|
|
|
|
|
|
// 格式化数字 |
|
|
|
@ -202,8 +202,8 @@ |
|
|
|
const result = await firmReportsApi.income(); |
|
|
|
if (result.data) { |
|
|
|
annualIncomeInfo.value = { |
|
|
|
revenue: result.data.revenue || 0, |
|
|
|
totalCost: result.data.totalCost || 0 |
|
|
|
revenue: parseFloat(result.data.revenue) || 0, |
|
|
|
totalCost: parseFloat(result.data.totalCost) || 0 |
|
|
|
}; |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
@ -212,9 +212,9 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 获取系统计算的公益成本 |
|
|
|
// 获取系统计算的公益成本(季度累计) |
|
|
|
async function getPublicWelfareCost() { |
|
|
|
console.log('开始获取公益成本,部门ID:', departmentId.value, '年份:', form.declareYear, '月份:', form.declareMonth); |
|
|
|
console.log('开始获取公益成本,部门ID:', departmentId.value, '年份:', form.declareYear, '季度:', form.declareQuarter); |
|
|
|
|
|
|
|
if (!departmentId.value) { |
|
|
|
message.warning('无法获取机构信息,请重新登录'); |
|
|
|
@ -227,40 +227,49 @@ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (!form.declareMonth) { |
|
|
|
console.log('月份未选择,跳过API调用'); |
|
|
|
if (!form.declareQuarter) { |
|
|
|
console.log('季度未选择,跳过API调用'); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
// 将月度字符串转换为数字(如"1月" -> 1, "2月" -> 2, ..., "12月" -> 12) |
|
|
|
let monthNumber; |
|
|
|
if (typeof form.declareMonth === 'string') { |
|
|
|
const monthMatch = form.declareMonth.match(/^(\d+)/); |
|
|
|
if (monthMatch && monthMatch[1]) { |
|
|
|
monthNumber = parseInt(monthMatch[1]); |
|
|
|
} |
|
|
|
} else if (typeof form.declareMonth === 'number') { |
|
|
|
monthNumber = form.declareMonth; |
|
|
|
// 处理季度值,可能是数字1-4或字符串"第一季度 (Q1)"等 |
|
|
|
let quarterNum = form.declareQuarter; |
|
|
|
if (typeof quarterNum === 'string') { |
|
|
|
// 从字符串中提取数字,如"第一季度 (Q1)"提取1 |
|
|
|
const match = quarterNum.match(/(\d+)/); |
|
|
|
if (match) { |
|
|
|
quarterNum = parseInt(match[1], 10); |
|
|
|
} else { |
|
|
|
console.error('无法解析季度字符串:', quarterNum); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
// 计算季度对应的月份范围 |
|
|
|
const startMonth = (quarterNum - 1) * 3 + 1; |
|
|
|
const endMonth = startMonth + 2; |
|
|
|
|
|
|
|
// 获取季度内3个月的公益成本累计 |
|
|
|
let totalCost = 0; |
|
|
|
|
|
|
|
for (let month = startMonth; month <= endMonth; month++) { |
|
|
|
const queryForm = { |
|
|
|
firmId: departmentId.value, |
|
|
|
year: form.declareYear, |
|
|
|
month: month |
|
|
|
}; |
|
|
|
|
|
|
|
// 构建请求参数:包含部门ID、年份和月度数字 |
|
|
|
const queryForm = { |
|
|
|
firmId: departmentId.value, |
|
|
|
year: form.declareYear, // 后端期望的year字段 |
|
|
|
month: monthNumber // 月度字段转换为数字 |
|
|
|
}; |
|
|
|
console.log('调用接口: /serviceApplications/statistics/cost, 参数:', queryForm); |
|
|
|
const response = await serviceApplicationsApi.getServiceApplicationsCost(queryForm); |
|
|
|
console.log(`第${month}月接口返回数据:`, response); |
|
|
|
|
|
|
|
console.log('调用接口: /serviceApplications/statistics/cost, 参数:', queryForm); |
|
|
|
const response = await serviceApplicationsApi.getServiceApplicationsCost(queryForm); |
|
|
|
console.log('接口返回数据:', response); |
|
|
|
totalCost += parseFloat(response.data) || 0; |
|
|
|
} |
|
|
|
|
|
|
|
// 将分转换为万元(API返回的是分单位) |
|
|
|
const costInYuan = response.data; // 分转元 |
|
|
|
//const costInWanYuan = costInYuan / 10000; // 元转万元 |
|
|
|
form.publicWelfareCost = costInYuan; |
|
|
|
form.publicWelfareCost = totalCost; |
|
|
|
|
|
|
|
console.log('转换后的公益成本:', form.publicWelfareCost, '万元'); |
|
|
|
console.log('季度累计公益成本:', form.publicWelfareCost, '万元'); |
|
|
|
calculateCosts(); |
|
|
|
} catch (error) { |
|
|
|
message.error('获取公益成本失败'); |
|
|
|
@ -270,7 +279,7 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function show(rowData) { |
|
|
|
async function show(rowData) { |
|
|
|
console.log('表单show函数被调用,rowData:', rowData); |
|
|
|
|
|
|
|
Object.assign(form, formDefault); |
|
|
|
@ -280,26 +289,22 @@ |
|
|
|
|
|
|
|
// 正确判断模式:只有当rowData是对象且有id字段时才认为是编辑模式 |
|
|
|
if (rowData && typeof rowData === 'object' && rowData.id) { |
|
|
|
console.log('编辑模式,使用现有数据'); |
|
|
|
console.log('编辑模式,使用现有数据:', rowData); |
|
|
|
// 先设置表单数据 |
|
|
|
Object.assign(form, rowData); |
|
|
|
|
|
|
|
// 确保declareMonth字段格式与字典系统匹配 |
|
|
|
if (form.declareMonth && typeof form.declareMonth === 'number') { |
|
|
|
// 如果后端返回的是数字格式,转换为字典期望的字符串格式 |
|
|
|
form.declareMonth = form.declareMonth + '月'; |
|
|
|
} else if (form.declareMonth && form.declareMonth.includes('(')) { |
|
|
|
// 如果返回的是显示名称格式(如"1月 (1)"),提取字典值 |
|
|
|
const match = form.declareMonth.match(/\(([^)]+)\)/); |
|
|
|
if (match && match[1]) { |
|
|
|
form.declareMonth = match[1] + '月'; // 提取数字并添加"月"后缀 |
|
|
|
} |
|
|
|
} |
|
|
|
// 编辑模式下也需要重新获取公益成本(驳回后可能需要更新) |
|
|
|
// 确保表单数据已更新后再获取成本 |
|
|
|
await nextTick(); |
|
|
|
console.log('编辑模式表单数据:', form.declareYear, form.declareQuarter); |
|
|
|
await getPublicWelfareCost(); |
|
|
|
} else { |
|
|
|
console.log('新建模式,等待用户选择月份后获取公益成本'); |
|
|
|
// 新建模式下初始化月份选项(只能选择上一个月) |
|
|
|
initMonthOptions(); |
|
|
|
console.log('新建模式,等待用户选择季度后获取公益成本'); |
|
|
|
// 新建模式下初始化季度选项(只能选择上一个季度) |
|
|
|
await initQuarterOptions(); |
|
|
|
// 新建模式下获取本年度已填报收入 |
|
|
|
fetchAnnualIncome(); |
|
|
|
await fetchAnnualIncome(); |
|
|
|
// 获取公益成本数据 |
|
|
|
await getPublicWelfareCost(); |
|
|
|
} |
|
|
|
|
|
|
|
visibleFlag.value = true; |
|
|
|
@ -324,7 +329,7 @@ |
|
|
|
id: undefined, |
|
|
|
firmId: undefined, // 律师事务所ID(部门ID) |
|
|
|
declareYear: new Date().getFullYear(), // 报表年份 |
|
|
|
declareMonth: undefined, // 月度ID (1,2,3,4,5,6,7,8,9,10,11,12) |
|
|
|
declareQuarter: undefined, // 季度 (1,2,3,4) |
|
|
|
revenue: undefined, // 营业收入(万元) |
|
|
|
//totalCost: 0, // 总成本支出(万元) |
|
|
|
publicWelfareCost: undefined, // 公益成本支出(万元) |
|
|
|
@ -334,7 +339,7 @@ |
|
|
|
let form = reactive({ ...formDefault }); |
|
|
|
|
|
|
|
const rules = { |
|
|
|
declareMonth: [{ required: true, message: '请选择月份' }], |
|
|
|
declareQuarter: [{ required: true, message: '请选择季度' }], |
|
|
|
declareYear: [{ required: true, message: '请输入报表年份' }], |
|
|
|
revenue: [{ required: true, message: '请输入律所收入' }], |
|
|
|
publicWelfareCost: [{ required: true, message: '系统正在计算公益成本,请稍后' }], |
|
|
|
@ -345,12 +350,12 @@ |
|
|
|
const showCostWarning = ref(false); |
|
|
|
const costRatio = ref(0); // 当前成本比例 |
|
|
|
|
|
|
|
// 月份选择变化时的处理 |
|
|
|
function onMonthChange() { |
|
|
|
console.log('月份选择变化:', form.declareMonth); |
|
|
|
// 季度选择变化时的处理 |
|
|
|
function onQuarterChange() { |
|
|
|
console.log('季度选择变化:', form.declareQuarter); |
|
|
|
|
|
|
|
// 只有当选择了月份时才获取公益成本 |
|
|
|
if (form.declareMonth) { |
|
|
|
// 只有当选择了季度时才获取公益成本 |
|
|
|
if (form.declareQuarter) { |
|
|
|
getPublicWelfareCost(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -425,7 +430,7 @@ |
|
|
|
// 保存草稿 |
|
|
|
async function saveAsDraft() { |
|
|
|
try { |
|
|
|
await formRef.value.validateFields(['declareMonth', 'declareYear', 'revenue', 'publicWelfareCost']); |
|
|
|
await formRef.value.validateFields(['declareQuarter', 'declareYear', 'revenue', 'publicWelfareCost']); |
|
|
|
form.approvalStatus = '0'; // 草稿状态 |
|
|
|
await save(); |
|
|
|
} catch (err) { |
|
|
|
@ -455,12 +460,9 @@ |
|
|
|
// 准备保存的数据,如果超过上限则使用计算值 |
|
|
|
const saveData = { ...form }; |
|
|
|
|
|
|
|
// 将月份格式转换为数字格式(如"1月" -> 1, "2月" -> 2) |
|
|
|
if (saveData.declareMonth && typeof saveData.declareMonth === 'string') { |
|
|
|
const monthMatch = saveData.declareMonth.match(/^(\d+)/); |
|
|
|
if (monthMatch && monthMatch[1]) { |
|
|
|
saveData.declareMonth = parseInt(monthMatch[1]); |
|
|
|
} |
|
|
|
// 确保季度是整数类型 |
|
|
|
if (saveData.declareQuarter) { |
|
|
|
saveData.declareQuarter = parseInt(saveData.declareQuarter); |
|
|
|
} |
|
|
|
|
|
|
|
// 确保年份是整数类型 |
|
|
|
|