From 27c8277d717b34b55f3ea967027b53b067f77df3 Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期四, 20 八月 2026 16:58:49 +0800
Subject: [PATCH] feat 功能变更
---
src/views/mes/pd/basedata/modules/price-calc.vue | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 171 insertions(+), 0 deletions(-)
diff --git a/src/views/mes/pd/basedata/modules/price-calc.vue b/src/views/mes/pd/basedata/modules/price-calc.vue
new file mode 100644
index 0000000..5b45dda
--- /dev/null
+++ b/src/views/mes/pd/basedata/modules/price-calc.vue
@@ -0,0 +1,171 @@
+<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: '妗d綅涓嬮檺(鍚�,kWh)', dataIndex: 'startValue', key: 'startValue' },
+ { title: '妗d綅涓婇檺(涓嶅惈,kWh)', dataIndex: 'endValue', key: 'endValue' },
+ { title: '鏈。鐢甸噺(kWh)', dataIndex: 'tierQuantity', key: 'tierQuantity' },
+ { title: '妗d綅鍗曚环', 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>
--
Gitblit v1.9.3