<script lang="ts" setup>
|
import type { VbenFormSchema } from '#/adapter/form';
|
import type { MesPdPriceApi } from '#/api/mes/pd/price';
|
|
import { ref } from 'vue';
|
|
import { useVbenModal } from '@vben/common-ui';
|
import { $t } from '@vben/locales';
|
|
import { Descriptions, Empty, Table } from 'ant-design-vue';
|
|
import { useVbenForm } from '#/adapter/form';
|
import { calcPrice } from '#/api/mes/pd/price';
|
import { getServicePackageList, getVoltageLevelList } from '#/api/mes/pd/basedata';
|
|
const result = ref<MesPdPriceApi.PriceCalcResp>();
|
const hasResult = ref(false);
|
|
const [Form, formApi] = useVbenForm({
|
commonConfig: {
|
componentProps: {
|
class: 'w-full',
|
},
|
formItemClass: 'col-span-1',
|
labelWidth: 130,
|
},
|
wrapperClass: 'grid-cols-3',
|
layout: 'horizontal',
|
schema: [],
|
showDefaultActions: false,
|
});
|
|
/** 测算表单字段 */
|
function useCalcSchema(): VbenFormSchema[] {
|
return [
|
{
|
fieldName: 'calcType',
|
label: '测算类型',
|
component: 'Select',
|
rules: 'selectRequired',
|
componentProps: {
|
options: [
|
{ label: '服务套餐', value: 1 },
|
{ label: '电压等级', value: 2 },
|
],
|
placeholder: '请选择测算类型',
|
},
|
},
|
{
|
fieldName: 'packageId',
|
label: '服务套餐',
|
component: 'Select',
|
rules: 'selectRequired',
|
dependencies: {
|
triggerFields: ['calcType'],
|
show: (values) => values.calcType === 1,
|
async componentProps(values, form) {
|
if (values.calcType !== 1) {
|
form.setFieldValue('packageId', undefined);
|
return { allowClear: true, options: [], placeholder: '请选择服务套餐' };
|
}
|
const list = await getServicePackageList();
|
return {
|
allowClear: true,
|
options: list.map((i) => ({ label: i.name, value: i.id })),
|
placeholder: '请选择服务套餐',
|
};
|
},
|
},
|
},
|
{
|
fieldName: 'voltageLevelId',
|
label: '电压等级',
|
component: 'Select',
|
rules: 'selectRequired',
|
dependencies: {
|
triggerFields: ['calcType'],
|
show: (values) => values.calcType === 2,
|
async componentProps(values, form) {
|
if (values.calcType !== 2) {
|
form.setFieldValue('voltageLevelId', undefined);
|
return { allowClear: true, options: [], placeholder: '请选择电压等级' };
|
}
|
const list = await getVoltageLevelList();
|
return {
|
allowClear: true,
|
options: list.map((i) => ({ label: i.name, value: i.id })),
|
placeholder: '请选择电压等级',
|
};
|
},
|
},
|
},
|
{
|
fieldName: 'quantity',
|
label: '用电量(kWh)',
|
component: 'InputNumber',
|
componentProps: { class: '!w-full', min: 0, precision: 2 },
|
rules: 'required',
|
},
|
];
|
}
|
|
const [Modal, modalApi] = useVbenModal({
|
async onConfirm() {
|
const { valid } = await formApi.validate();
|
if (!valid) {
|
return;
|
}
|
modalApi.lock();
|
try {
|
const data = (await formApi.getValues()) as MesPdPriceApi.PriceCalcReq;
|
result.value = await calcPrice(data);
|
hasResult.value = true;
|
} finally {
|
modalApi.unlock();
|
}
|
},
|
async onOpenChange(isOpen: boolean) {
|
if (!isOpen) {
|
return;
|
}
|
result.value = undefined;
|
hasResult.value = false;
|
formApi.setState({ schema: useCalcSchema() });
|
formApi.resetForm();
|
modalApi.setState({ confirmText: '测算', showConfirmButton: true });
|
},
|
});
|
</script>
|
|
<template>
|
<Modal :title="'阶梯电价测算'" class="w-4/5">
|
<Form class="mx-4 mb-4" />
|
<div v-if="hasResult && result" class="mx-4">
|
<Descriptions
|
:column="3"
|
bordered
|
size="small"
|
class="mb-4"
|
>
|
<Descriptions.Item label="原价">
|
{{ result.originalPrice ?? 0 }}
|
</Descriptions.Item>
|
<Descriptions.Item label="优惠金额">
|
{{ result.discountAmount ?? 0 }}
|
</Descriptions.Item>
|
<Descriptions.Item label="优惠后总价">
|
<span class="text-lg font-bold text-primary">
|
{{ result.finalPrice ?? 0 }}
|
</span>
|
</Descriptions.Item>
|
</Descriptions>
|
<Table
|
:columns="[
|
{ title: '档位下限(含,kWh)', dataIndex: 'startValue', key: 'startValue' },
|
{ title: '档位上限(不含,kWh)', dataIndex: 'endValue', key: 'endValue' },
|
{ title: '本档电量(kWh)', dataIndex: 'tierQuantity', key: 'tierQuantity' },
|
{ title: '档位单价', dataIndex: 'pricePerUnit', key: 'pricePerUnit' },
|
{ title: '小计', dataIndex: 'subtotal', key: 'subtotal' },
|
]"
|
:data-source="result.details ?? []"
|
:pagination="false"
|
size="small"
|
class="mb-4"
|
/>
|
</div>
|
<div v-else class="mx-4">
|
<Empty description="请选择测算类型并输入用电量后点击「测算」" />
|
</div>
|
</Modal>
|
</template>
|