Files
admin-vben5/apps/web-antd/src/views/property/greenPlantRentalManagement/orderManagement/rentalOrder-modal.vue

450 lines
12 KiB
Vue
Raw Normal View History

2025-06-26 18:04:51 +08:00
<script setup lang="ts">
2025-09-12 19:27:04 +08:00
import { computed, ref } from 'vue';
2025-06-26 18:04:51 +08:00
2025-09-12 19:27:04 +08:00
import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
2025-06-26 18:04:51 +08:00
2025-09-12 19:27:04 +08:00
import { useVbenForm } from '#/adapter/form';
2025-07-01 17:57:12 +08:00
import {
rentalOrderAdd,
rentalOrderInfo,
2025-09-12 19:27:04 +08:00
rentalOrderUpdate,
2025-07-01 17:57:12 +08:00
} from '#/api/property/rentalOrder';
2025-09-12 19:27:04 +08:00
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
2025-06-26 18:04:51 +08:00
2025-09-12 19:27:04 +08:00
import { plantsProductList } from '#/api/property/productManagement';
import { rentalPlanInfo, rentalPlanList } from '#/api/property/rentalPlan';
import { getDictOptions } from '#/utils/dict';
import type { PropertyVO } from '#/api/property/productManagement/model';
import type { RentalPlanVO } from '#/api/property/rentalPlan/model';
import { planInfoColumns } from './data';
import { Table } from 'ant-design-vue';
import { resident_unitList } from '#/api/property/resident/unit';
2025-07-02 18:00:26 +08:00
2025-06-26 18:04:51 +08:00
const emit = defineEmits<{ reload: [] }>();
const isUpdate = ref(false);
2025-07-01 17:57:12 +08:00
const planList = ref<RentalPlanVO[]>([]);
const plantsList = ref<PropertyVO[]>([]);
2025-07-04 17:58:09 +08:00
const planProducts = ref<any[]>([]);
const totalAmount = ref(0);
2025-07-05 17:42:37 +08:00
const singleAmount = ref('0');
2025-07-04 17:58:09 +08:00
const plantInfo = ref<PropertyVO>();
2025-06-26 18:04:51 +08:00
const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
});
2025-07-01 17:57:12 +08:00
const modalSchema = [
{
label: '主键',
fieldName: 'id',
component: 'Input',
dependencies: {
show: () => false,
triggerFields: [''],
},
},
{
label: '客户名称',
fieldName: 'customerName',
component: 'Input',
rules: 'required',
},
{
label: '客户类型',
fieldName: 'customerType',
component: 'Select',
componentProps: {
2025-09-12 19:27:04 +08:00
options: getDictOptions('wy_khlx'),
2025-07-01 17:57:12 +08:00
},
rules: 'selectRequired',
2025-09-12 16:39:18 +08:00
},
2025-09-12 19:27:04 +08:00
{
2025-09-12 16:39:18 +08:00
component: 'ApiSelect',
2025-09-12 19:27:04 +08:00
fieldName: 'residentUnitId',
2025-09-12 16:39:18 +08:00
label: '租赁单位',
componentProps: {
api: getUnitList,
resultField: 'data',
labelField: 'label',
valueField: 'value',
immediate: true,
debounceTime: 500,
allowClear: true,
placeholder: '请选择租赁单位',
filterOption: true,
},
2025-09-12 19:27:04 +08:00
rules: 'selectRequired',
2025-07-01 17:57:12 +08:00
},
{
label: '租赁周期',
fieldName: 'rentalPeriod',
component: 'Select',
componentProps: {
2025-09-12 19:27:04 +08:00
options: getDictOptions('wy_time_unit'),
2025-07-01 17:57:12 +08:00
},
rules: 'selectRequired',
},
{
label: '租赁时间',
fieldName: 'rentalTime',
component: 'RangePicker',
componentProps: {
showTime: true,
format: 'YYYY-MM-DD',
valueFormat: 'YYYY-MM-DD',
},
rules: 'selectRequired',
},
{
label: '租赁方式',
fieldName: 'rentalType',
component: 'Select',
componentProps: {
2025-09-12 19:27:04 +08:00
options: getDictOptions('wy_zlfs'),
2025-07-01 17:57:12 +08:00
},
rules: 'selectRequired',
2025-09-12 19:27:04 +08:00
formItemClass: 'col-span-2',
2025-07-01 17:57:12 +08:00
},
{
label: '租赁方案',
fieldName: 'planId',
2025-07-02 18:00:26 +08:00
component: 'ApiSelect',
2025-07-01 17:57:12 +08:00
dependencies: {
// 仅当 租赁方式 为 2套餐 时显示
show: (formValues: any) => formValues.rentalType === '2',
triggerFields: ['rentalType'],
},
rules: 'selectRequired',
2025-07-02 18:00:26 +08:00
formItemClass: 'col-span-2',
componentProps: {
api: async () => {
2025-09-12 19:27:04 +08:00
const res = await rentalPlanList({
pageNum: 1,
pageSize: 1000,
state: 1,
});
2025-07-02 18:00:26 +08:00
planList.value = res.rows || [];
2025-09-12 19:27:04 +08:00
return planList.value.map((item) => ({
2025-07-02 18:00:26 +08:00
label: item.planName,
value: item.id,
}));
},
onChange: async (value: string) => {
2025-09-12 19:27:04 +08:00
await getPlanProducts(value);
2025-07-02 18:00:26 +08:00
},
showSearch: true,
filterOption: (input: any, option: any) =>
option.label.toLowerCase().includes(input.toLowerCase()),
2025-09-12 19:27:04 +08:00
},
2025-07-01 17:57:12 +08:00
},
{
label: '方案详情',
fieldName: 'planInfo',
2025-07-04 17:58:09 +08:00
component: 'Input',
2025-09-12 19:27:04 +08:00
slots: { default: 'planInfo' },
2025-07-01 17:57:12 +08:00
dependencies: {
// 仅当 租赁方式 为 2套餐 时显示
2025-09-12 19:27:04 +08:00
show: (formValues: any) =>
formValues.rentalType === '2' && formValues.planId != null,
2025-07-02 18:00:26 +08:00
triggerFields: ['planId', 'rentalType'],
2025-07-01 17:57:12 +08:00
},
formItemClass: 'col-span-2',
},
{
label: '绿植产品',
fieldName: 'productId',
component: 'ApiSelect',
dependencies: {
// 仅当 租赁方式 为 1单点 时显示
show: (formValues: any) => formValues.rentalType === '1',
triggerFields: ['rentalType'],
},
rules: 'selectRequired',
formItemClass: 'col-span-2',
componentProps: {
api: async () => {
2025-09-12 19:27:04 +08:00
const res = await plantsProductList({
pageNum: 1,
pageSize: 1000,
inventory: 0,
});
2025-07-01 17:57:12 +08:00
plantsList.value = res.rows || [];
2025-09-12 19:27:04 +08:00
return plantsList.value.map((item) => ({
label:
item.plantName +
'-' +
item.plantCode +
'\xa0\xa0租金' +
item.rent +
'\xa0\xa0库存数量' +
item.inventory,
2025-07-01 17:57:12 +08:00
value: item.id,
}));
},
onChange: async (value: string) => {
2025-09-12 19:27:04 +08:00
plantInfo.value = plantsList.value.find((item) => item.id === value);
2025-07-04 17:58:09 +08:00
if (plantInfo.value) {
2025-09-12 19:27:04 +08:00
formApi.updateSchema([
{
componentProps: () => ({
min: 1,
max: plantInfo.value?.inventory,
precision: 0,
onChange: async () => {
const formValues = await formApi.getValues();
if (formValues.productNum && plantInfo.value?.rent) {
singleAmount.value = (
plantInfo.value.rent * formValues.productNum
).toFixed(2);
}
},
}),
fieldName: 'productNum',
},
]);
2025-07-02 18:00:26 +08:00
}
2025-07-01 17:57:12 +08:00
},
showSearch: true,
filterOption: (input: any, option: any) =>
option.label.toLowerCase().includes(input.toLowerCase()),
2025-09-12 19:27:04 +08:00
},
2025-07-01 17:57:12 +08:00
},
{
label: '租赁数量',
fieldName: 'productNum',
component: 'InputNumber',
componentProps: {
min: 1,
precision: 0,
step: 1,
2025-07-04 17:58:09 +08:00
placeholder: '租赁数量不可超出绿植产品库存数量',
onChange: async (value: number) => {
if (plantInfo.value) {
singleAmount.value = (plantInfo.value.rent * value).toFixed(2);
}
},
2025-07-01 17:57:12 +08:00
},
dependencies: {
// 仅当 租赁方式 为 1单点 时显示
show: (formValues: any) => formValues.rentalType === '1',
triggerFields: ['rentalType', 'productId'],
},
rules: 'required',
},
{
2025-07-04 17:58:09 +08:00
label: '总金额(元)',
2025-07-01 17:57:12 +08:00
fieldName: 'totalAmount',
2025-07-02 18:00:26 +08:00
component: 'InputNumber',
2025-09-12 19:27:04 +08:00
slots: { default: 'totalAmount' },
2025-07-01 17:57:12 +08:00
dependencies: {
// 仅当 租赁方式 为 1单点 时显示
2025-09-12 19:27:04 +08:00
show: (formValues: any) =>
formValues.productNum &&
formValues.productId &&
formValues.rentalType === '1',
2025-07-07 17:30:51 +08:00
triggerFields: ['productNum', 'rentalType'],
2025-07-04 17:58:09 +08:00
disabled: true,
2025-07-01 17:57:12 +08:00
},
2025-09-12 19:27:04 +08:00
labelWidth: 110,
2025-07-01 17:57:12 +08:00
},
2025-07-02 18:00:26 +08:00
{
label: '是否续租',
fieldName: 'isRelet',
component: 'RadioGroup',
componentProps: {
buttonStyle: 'solid',
optionType: 'button',
options: getDictOptions('wy_sf'),
},
2025-09-12 19:27:04 +08:00
rules: 'required',
2025-07-02 18:00:26 +08:00
},
2025-07-01 17:57:12 +08:00
{
label: '合同状态',
fieldName: 'contractStatus',
component: 'Select',
componentProps: {
options: getDictOptions('wy_htzt'),
},
2025-09-12 19:27:04 +08:00
rules: 'selectRequired',
2025-07-01 17:57:12 +08:00
},
{
label: '合同编号',
fieldName: 'contractCode',
component: 'Input',
dependencies: {
2025-09-12 19:27:04 +08:00
show: (formValues: any) =>
formValues.contractStatus != null && formValues.contractStatus != 1,
2025-07-01 17:57:12 +08:00
triggerFields: ['contractStatus'],
},
2025-09-12 19:27:04 +08:00
rules: 'required',
2025-07-01 17:57:12 +08:00
},
{
label: '签署时间',
fieldName: 'signTime',
component: 'DatePicker',
componentProps: {
showTime: true,
format: 'YYYY-MM-DD',
valueFormat: 'YYYY-MM-DD',
},
dependencies: {
2025-09-12 19:27:04 +08:00
show: (formValues: any) =>
formValues.contractStatus != null && formValues.contractStatus != 1,
2025-07-01 17:57:12 +08:00
triggerFields: ['contractStatus'],
},
2025-09-12 19:27:04 +08:00
rules: 'required',
2025-07-01 17:57:12 +08:00
},
];
2025-06-26 18:04:51 +08:00
const [BasicForm, formApi] = useVbenForm({
commonConfig: {
// 默认占满两列
2025-06-30 14:45:06 +08:00
formItemClass: 'col-span-1',
2025-06-26 18:04:51 +08:00
// 默认label宽度 px
labelWidth: 80,
// 通用配置项 会影响到所有表单项
componentProps: {
class: 'w-full',
2025-09-12 19:27:04 +08:00
},
2025-06-26 18:04:51 +08:00
},
2025-07-01 17:57:12 +08:00
schema: modalSchema,
2025-06-26 18:04:51 +08:00
showDefaultActions: false,
wrapperClass: 'grid-cols-2',
});
2025-09-12 19:27:04 +08:00
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
2025-06-26 18:04:51 +08:00
{
initializedGetter: defaultFormValueGetter(formApi),
currentGetter: defaultFormValueGetter(formApi),
},
);
const [BasicModal, modalApi] = useVbenModal({
// 在这里更改宽度
2025-06-30 14:45:06 +08:00
class: 'w-[70%]',
2025-06-26 18:04:51 +08:00
fullscreenButton: false,
onBeforeClose,
onClosed: handleClosed,
onConfirm: handleConfirm,
onOpenChange: async (isOpen) => {
if (!isOpen) {
return null;
}
modalApi.modalLoading(true);
2025-09-12 19:27:04 +08:00
const { id } = modalApi.getData() as { id?: number | string };
2025-06-26 18:04:51 +08:00
isUpdate.value = !!id;
if (isUpdate.value && id) {
const record = await rentalOrderInfo(id);
await formApi.setValues(record);
}
await markInitialized();
modalApi.modalLoading(false);
},
});
2025-09-12 19:27:04 +08:00
async function getUnitList() {
2025-09-12 16:39:18 +08:00
const queryParam = {
pageNum: 1,
pageSize: 1000,
2025-09-12 19:27:04 +08:00
};
const res = await resident_unitList(queryParam);
const data: { value: number; label: string }[] = [];
2025-06-26 18:04:51 +08:00
2025-09-12 16:39:18 +08:00
res.rows.forEach((r: any) => {
data.push({
value: r.id,
label: r.name,
2025-09-12 19:27:04 +08:00
});
});
2025-09-12 16:39:18 +08:00
return data;
}
2025-06-26 18:04:51 +08:00
async function handleConfirm() {
try {
modalApi.lock(true);
2025-09-12 19:27:04 +08:00
const { valid } = await formApi.validate();
2025-06-26 18:04:51 +08:00
if (!valid) {
return;
}
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
const data = cloneDeep(await formApi.getValues());
2025-07-01 17:57:12 +08:00
if (data.rentalType == 1) {
data.planId = undefined;
2025-09-12 19:27:04 +08:00
data.totalAmount = singleAmount.value;
2025-07-01 17:57:12 +08:00
} else {
data.productId = undefined;
data.productNum = undefined;
2025-09-12 19:27:04 +08:00
data.productList = planProducts.value;
data.totalAmount = totalAmount.value;
2025-07-01 17:57:12 +08:00
}
2025-07-04 17:58:09 +08:00
if (data.rentalTime) {
data.startTime = data.rentalTime[0];
data.endTime = data.rentalTime[1];
2025-07-02 18:00:26 +08:00
}
2025-09-12 19:27:04 +08:00
data.paymentStatus = 0;
2025-06-26 18:04:51 +08:00
await (isUpdate.value ? rentalOrderUpdate(data) : rentalOrderAdd(data));
resetInitialized();
emit('reload');
modalApi.close();
} catch (error) {
console.error(error);
} finally {
modalApi.lock(false);
}
}
2025-07-01 17:57:12 +08:00
//获取有库存的绿植
2025-07-02 18:00:26 +08:00
async function getPlanProducts(id: string) {
2025-09-12 19:27:04 +08:00
const res = await rentalPlanInfo(id);
planProducts.value = res.productList.map((item) => ({
id: item.productId,
2025-07-07 17:30:51 +08:00
plantName: item.product?.plantName,
rent: item.product?.rent,
inventory: item.productNum,
2025-09-12 19:27:04 +08:00
}));
totalAmount.value = planProducts.value
?.reduce((sum, item: any) => sum + item.rent * item.inventory, 0)
.toFixed(2);
2025-07-01 17:57:12 +08:00
}
2025-06-26 18:04:51 +08:00
async function handleClosed() {
await formApi.resetForm();
resetInitialized();
}
</script>
<template>
<BasicModal :title="title">
2025-07-04 17:58:09 +08:00
<BasicForm>
<template #planInfo="slotProps">
2025-07-05 17:42:37 +08:00
<div v-if="planProducts.length" style="width: 100%" v-bind="slotProps">
2025-09-12 19:27:04 +08:00
<Table
:dataSource="planProducts"
:columns="planInfoColumns"
:pagination="false"
bordered
size="small"
>
2025-07-04 17:58:09 +08:00
<template #bodyCell="{ column, record, index }">
<template v-if="column.field === 'id'">
{{ index + 1 }}
</template>
<template v-else>
{{ record[column.field] }}
</template>
</template>
<template #footer>
2025-09-12 19:27:04 +08:00
<div style="text-align: right; margin-right: 20px">
2025-07-04 17:58:09 +08:00
<b>总金额</b>
{{ totalAmount }}
</div>
</template>
</Table>
</div>
</template>
<template #totalAmount="slotProps">
2025-07-05 17:42:37 +08:00
<div v-bind="slotProps">{{ singleAmount }}</div>
2025-07-04 17:58:09 +08:00
</template>
</BasicForm>
2025-06-26 18:04:51 +08:00
</BasicModal>
</template>