修复项目修改为合伙人时合伙人为空问题
parent
e69afe7f68
commit
ad6d91f78c
|
|
@ -8,6 +8,7 @@
|
|||
v-loading="formLoading"
|
||||
>
|
||||
<el-row>
|
||||
{{ formData }}
|
||||
<el-col :span="12">
|
||||
<el-form-item label="项目名称" prop="deptId">
|
||||
<el-select
|
||||
|
|
@ -157,10 +158,10 @@
|
|||
<el-col>
|
||||
<el-tabs v-if="formData.type === 2" v-model="subTabsName" class="-mt-15px mb-10px">
|
||||
<el-tab-pane label="合伙人明细" name="partner">
|
||||
<ProjectPartnerForm
|
||||
ref="partnerFormRef"
|
||||
:partners="formData.partners"
|
||||
:disabled="formLoading"
|
||||
<ProjectPartnerForm
|
||||
ref="partnerFormRef"
|
||||
v-model:partners="formData.partners"
|
||||
:disabled="formLoading"
|
||||
:price="formData.totalInvestment"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
|
|
|
|||
|
|
@ -94,19 +94,30 @@ const getChartData = async () => {
|
|||
updateChartOption()
|
||||
}
|
||||
|
||||
function toFixed2(val: any) {
|
||||
if (val === null || val === undefined || isNaN(val)) return val
|
||||
return Number(val).toFixed(2)
|
||||
}
|
||||
|
||||
function updateChartOption() {
|
||||
// 站点对比,x轴为站点名
|
||||
const xData = chartData.value.map(item => item.projectName || '-')
|
||||
const chargingQuantity = chartData.value.map(item => item.chargingQuantity)
|
||||
const totalIncome = chartData.value.map(item => item.totalIncome)
|
||||
const grossProfit = chartData.value.map(item => item.grossProfit)
|
||||
const grossProfitRate = chartData.value.map(item => item.grossProfitRate)
|
||||
const perGunCharging = chartData.value.map(item => item.perGunCharging)
|
||||
const perGunProfit = chartData.value.map(item => item.perGunProfit)
|
||||
const electricityServiceFee = chartData.value.map(item => item.electricityServiceFee)
|
||||
const chargingQuantity = chartData.value.map(item => toFixed2(item.chargingQuantity))
|
||||
const totalIncome = chartData.value.map(item => toFixed2(item.totalIncome))
|
||||
const grossProfit = chartData.value.map(item => toFixed2(item.grossProfit))
|
||||
const grossProfitRate = chartData.value.map(item => toFixed2(item.grossProfitRate))
|
||||
const perGunCharging = chartData.value.map(item => toFixed2(item.perGunCharging))
|
||||
const perGunProfit = chartData.value.map(item => toFixed2(item.perGunProfit))
|
||||
const electricityServiceFee = chartData.value.map(item => toFixed2(item.electricityServiceFee))
|
||||
|
||||
chartOption.value = {
|
||||
tooltip: { trigger: 'axis' },
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
valueFormatter: (value: any) => {
|
||||
if (value === null || value === undefined || value === '' || isNaN(value)) return value
|
||||
return Number(value).toFixed(2)
|
||||
}
|
||||
},
|
||||
legend: { data: [
|
||||
'充电量(万度)', '总营收(万元)', '毛利润(万元)', '毛利率(%)',
|
||||
'单枪充电量(度)', '单枪服务费(元)', '度电服务费(元)'
|
||||
|
|
@ -115,8 +126,11 @@ function updateChartOption() {
|
|||
{ type: 'category', data: xData, axisTick: { alignWithLabel: true }}
|
||||
],
|
||||
yAxis: [
|
||||
{ type: 'value', name: '金额/充电量', position: 'left', min: null, max: null, alignTicks: true },
|
||||
{ type: 'value', name: '毛利率', position: 'right', min: null, max: null, axisLabel: { formatter: '{value}%' }, alignTicks: true }
|
||||
{ type: 'value', name: '金额/充电量', position: 'left', min: null, max: null, alignTicks: true,
|
||||
axisLabel: { formatter: (val: any) => (val === null || val === undefined || isNaN(val) ? val : Number(val).toFixed(2)) }
|
||||
},
|
||||
{ type: 'value', name: '毛利率', position: 'right', min: null, max: null,
|
||||
axisLabel: { formatter: (val: any) => (val === null || val === undefined || isNaN(val) ? val : Number(val).toFixed(2) + '%') }, alignTicks: true }
|
||||
],
|
||||
series: [
|
||||
{ name: '总营收(万元)', type: 'bar', data: totalIncome, yAxisIndex: 0, barMaxWidth: 28 },
|
||||
|
|
|
|||
|
|
@ -91,6 +91,11 @@ const getChartData = async () => {
|
|||
updateChartOption()
|
||||
}
|
||||
|
||||
function toFixed2(val: any) {
|
||||
if (val === null || val === undefined || isNaN(val)) return val
|
||||
return Number(val).toFixed(2)
|
||||
}
|
||||
|
||||
function updateChartOption() {
|
||||
const xData = chartData.value.map(item => {
|
||||
const str = String(item.statMonth)
|
||||
|
|
@ -99,16 +104,22 @@ function updateChartOption() {
|
|||
}
|
||||
return item.statMonth
|
||||
})
|
||||
const chargingQuantity = chartData.value.map(item => item.chargingQuantity)
|
||||
const totalIncome = chartData.value.map(item => item.totalIncome)
|
||||
const grossProfit = chartData.value.map(item => item.grossProfit)
|
||||
const grossProfitRate = chartData.value.map(item => item.grossProfitRate)
|
||||
const perGunCharging = chartData.value.map(item => item.perGunCharging)
|
||||
const perGunProfit = chartData.value.map(item => item.perGunProfit)
|
||||
const electricityServiceFee = chartData.value.map(item => item.electricityServiceFee)
|
||||
const chargingQuantity = chartData.value.map(item => toFixed2(item.chargingQuantity))
|
||||
const totalIncome = chartData.value.map(item => toFixed2(item.totalIncome))
|
||||
const grossProfit = chartData.value.map(item => toFixed2(item.grossProfit))
|
||||
const grossProfitRate = chartData.value.map(item => toFixed2(item.grossProfitRate))
|
||||
const perGunCharging = chartData.value.map(item => toFixed2(item.perGunCharging))
|
||||
const perGunProfit = chartData.value.map(item => toFixed2(item.perGunProfit))
|
||||
const electricityServiceFee = chartData.value.map(item => toFixed2(item.electricityServiceFee))
|
||||
|
||||
chartOption.value = {
|
||||
tooltip: { trigger: 'axis' },
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
valueFormatter: (value: any) => {
|
||||
if (value === null || value === undefined || value === '' || isNaN(value)) return value
|
||||
return Number(value).toFixed(2)
|
||||
}
|
||||
},
|
||||
legend: { data: [
|
||||
'充电量(万度)', '总营收(万元)', '毛利润(万元)', '毛利率(%)',
|
||||
'单枪充电量(度)', '单枪服务费(元)', '度电服务费(元)'
|
||||
|
|
@ -117,8 +128,11 @@ function updateChartOption() {
|
|||
{ type: 'category', data: xData, axisTick: { alignWithLabel: true }}
|
||||
],
|
||||
yAxis: [
|
||||
{ type: 'value', name: '金额/充电量', position: 'left', min: null, max: null, alignTicks: true }, // 0: 总营收/毛利润/充电量/单枪充电量/单枪服务费/度电服务费
|
||||
{ type: 'value', name: '毛利率', position: 'right', min: null, max: null, axisLabel: { formatter: '{value}%' }, alignTicks: true } // 1: 毛利率
|
||||
{ type: 'value', name: '金额/充电量', position: 'left', min: null, max: null, alignTicks: true,
|
||||
axisLabel: { formatter: (val: any) => (val === null || val === undefined || isNaN(val) ? val : Number(val).toFixed(2)) }
|
||||
},
|
||||
{ type: 'value', name: '毛利率', position: 'right', min: null, max: null,
|
||||
axisLabel: { formatter: (val: any) => (val === null || val === undefined || isNaN(val) ? val : Number(val).toFixed(2) + '%') }, alignTicks: true }
|
||||
],
|
||||
series: [
|
||||
{ name: '总营收(万元)', type: 'bar', data: totalIncome, yAxisIndex: 0, barMaxWidth: 28 },
|
||||
|
|
|
|||
|
|
@ -77,7 +77,15 @@ const emit = defineEmits(['update:partners'])
|
|||
const formLoading = ref(false)
|
||||
const userOptions = ref<any[]>([])
|
||||
|
||||
const formData = ref([])
|
||||
const formData = ref<any[]>([])
|
||||
// 监听 formData 变化,自动同步到父组件
|
||||
watch(
|
||||
formData,
|
||||
(val) => {
|
||||
emit('update:partners', val)
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
const formRules = reactive({
|
||||
userId: [
|
||||
|
|
@ -99,24 +107,29 @@ const formRules = reactive({
|
|||
})
|
||||
const formRef = ref<any>(null)
|
||||
|
||||
|
||||
onMounted(async () => {
|
||||
// 获取用户列表
|
||||
userOptions.value = await UserApi.getSimpleUserList()
|
||||
// 初始化合伙人数据
|
||||
formData.value = Array.isArray(props.partners) ? props.partners.map(item => ({ ...item })) : []
|
||||
})
|
||||
|
||||
|
||||
|
||||
const handleAdd = () => {
|
||||
formData.value.push()
|
||||
const row = {
|
||||
userId: undefined,
|
||||
ratio: undefined,
|
||||
investment: undefined
|
||||
}
|
||||
const row = {
|
||||
userId: undefined,
|
||||
ratio: undefined,
|
||||
investment: undefined
|
||||
}
|
||||
formData.value.push(row)
|
||||
emit('update:partners', formData.value)
|
||||
}
|
||||
|
||||
const handleDelete = (index: number) => {
|
||||
formData.value.splice(index, 1)
|
||||
emit('update:partners', formData.value)
|
||||
}
|
||||
|
||||
const validate = async () => {
|
||||
|
|
@ -142,12 +155,14 @@ const getMaxRatio = (index: number) => {
|
|||
const used = formData.value.reduce((sum, item, idx) => idx !== index ? sum + (Number(item.ratio) || 0) : sum, 0)
|
||||
return Math.max(0, 100 - used)
|
||||
}
|
||||
|
||||
// 只 watch formData,避免递归
|
||||
watch(
|
||||
() => props.partners,
|
||||
formData,
|
||||
(val) => {
|
||||
formData.value = val || []
|
||||
emit('update:partners', val)
|
||||
},
|
||||
{ immediate: true }
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
defineExpose({ validate })
|
||||
|
|
|
|||
Loading…
Reference in New Issue