costEdit.vue
2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<template>
<BasicDrawer
v-cloakv-bind="$attrs"
@register="register"
title="编辑"
width="35%"
showFooter
@ok="handleSubmit"
ref="formRef"
okText="保存"
:destroyOnClose="true"
:isDetail="true"
:showDetailBack="false"
:mask="false"
class="z-20"
>
<a-space direction="vertical" style="width: 100%">
<a-input v-model:value="fixCost" addonBefore="固定成本 " />
<a-input v-model:value="ratio" addonBefore="提成比例 " />
<a-input v-model:value="spainRatio" addonBefore="西班牙提成比例 " />
<!-- <a-input v-model:value="price" addonBefore="生产提成单价" /> -->
</a-space>
</BasicDrawer>
</template>
<script lang="ts" setup>
import { BasicDrawer, useDrawerInner } from '@/components/Drawer';
import { ref } from 'vue';
import { saveConfig } from '/@/api/sys/config';
const emit = defineEmits(['success']);
const [register, { closeDrawer }] = useDrawerInner((data) => {
listAll.value = data.data;
relationValue.value = JSON.parse(listAll.value.relationValue);
fixCost.value = relationValue.value[0].relationValue;
// 将小数转换为百分比格式显示
ratio.value = relationValue.value[1].relationValue
? (parseFloat(relationValue.value[1].relationValue) * 100).toFixed(2) + '%'
: '';
spainRatio.value = relationValue.value[2].relationValue
? (parseFloat(relationValue.value[2].relationValue) * 100).toFixed(2) + '%'
: '';
});
//获取现有的列表
const listAll = ref();
const fixCost = ref();
const ratio = ref();
const spainRatio = ref();
const relationValue = ref();
// 格式化百分比值,去除百分号并除以100
function formatPercentage(value) {
if (!value) return '';
// 检查值是否包含百分号
if (typeof value === 'string' && value.includes('%')) {
// 去除百分号并转为数值,然后除以100
return (parseFloat(value.replace('%', '')) / 100).toString();
}
// 如果没有百分号但是是数值,直接除以100
return value;
}
//完成编辑
async function handleSubmit() {
relationValue.value[0].relationValue = fixCost.value;
relationValue.value[1].relationValue = formatPercentage(ratio.value);
relationValue.value[2].relationValue = formatPercentage(spainRatio.value);
await saveConfig({
id: listAll.value.id,
settingCode: 'customerCode',
settingName: '客户提成成本配置',
settingValue: listAll.value.settingValue,
settingType: 3,
relationCode: 'costSettingItem',
relationName: '成本配置项集合',
costSettingItemVOS: relationValue.value,
});
emit('success');
closeDrawer();
}
</script>