fix: 为租赁方案绿植产品组合包添加必选校验

This commit is contained in:
fyy 2025-07-30 09:58:55 +08:00
parent 4f156a3f58
commit e08cbdf345

View File

@ -1,12 +1,16 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { Button, Table } from 'ant-design-vue';
import { Button, message, Table } from 'ant-design-vue';
import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter/form';
import { rentalPlanAdd, rentalPlanInfo, rentalPlanUpdate } from '#/api/property/rentalPlan';
import {
rentalPlanAdd,
rentalPlanInfo,
rentalPlanUpdate,
} from '#/api/property/rentalPlan';
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
import { modalSchema } from './data';
@ -19,9 +23,13 @@ const emit = defineEmits<{ reload: [] }>();
const isUpdate = ref(false);
const isReadonly = ref(false);
const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : isReadonly.value ? '详情' : $t('pages.common.add');
return isUpdate.value
? $t('pages.common.edit')
: isReadonly.value
? '详情'
: $t('pages.common.add');
});
const editId = ref<string | number | undefined>('')
const editId = ref<string | number | undefined>('');
const [BasicForm, formApi] = useVbenForm({
commonConfig: {
//
@ -58,7 +66,10 @@ const [BasicModal, modalApi] = useVbenModal({
return null;
}
modalApi.modalLoading(true);
const { id, readonly } = modalApi.getData() as { id?: number | string, readonly?: boolean; };
const { id, readonly } = modalApi.getData() as {
id?: number | string;
readonly?: boolean;
};
editId.value = id || '';
isReadonly.value = !!readonly;
if (isReadonly.value) {
@ -71,7 +82,11 @@ const [BasicModal, modalApi] = useVbenModal({
const record = await rentalPlanInfo(id);
// 绿
// detailTable.value = record.productList.map((item:any) => {...item.product,item.productNum,});
detailTable.value = record.productList.map((item: any) => ({ ...item.product, productNum: item.productNum,productId: item.productId }));
detailTable.value = record.productList.map((item: any) => ({
...item.product,
productNum: item.productNum,
productId: item.productId,
}));
await formApi.setValues(record);
}
@ -93,7 +108,13 @@ async function handleConfirm() {
const data = cloneDeep(await formApi.getValues());
// data.productIds = detailTable.value.map((item:any) => item.productId);
data.productList = detailTable.value;
await (isUpdate.value ? rentalPlanUpdate({...data,id:editId.value}) : rentalPlanAdd(data));
if (data.productList.length == 0) {
message.error('请添加植物组合包产品');
return;
}
await (isUpdate.value
? rentalPlanUpdate({ ...data, id: editId.value })
: rentalPlanAdd(data));
resetInitialized();
emit('reload');
modalApi.close();
@ -146,7 +167,9 @@ const detailColumns = [
];
function handleAddDetail() {
// id
const selectedIds = detailTable.value.map((item: any) => item.productId || item.plantName);
const selectedIds = detailTable.value.map(
(item: any) => item.productId || item.plantName,
);
detailModalApi.setData({ selectedIds, add: true });
detailModalApi.open();
}
@ -157,7 +180,6 @@ function handleDetailReload (data: any) {
//
function handleEditDetailReload(data: any) {
detailTable.value[data.index] = data;
}
//
function handleDeleteDetail(record: any, index: number) {
@ -171,14 +193,16 @@ function handleViewDetail(record: any) {
//
function handleEditDetail(record: any, index: number) {
// id
const selectedIds = detailTable.value.filter((_: any, i: number) => i !== index).map((item: any) => item.productId || item.plantName);
const selectedIds = detailTable.value
.filter((_: any, i: number) => i !== index)
.map((item: any) => item.productId || item.plantName);
detailModalApi.setData({ ...record, index, selectedIds, edit: true });
detailModalApi.open();
}
//
function getPlantTypeLabel(value: string | number) {
const opts = getDictOptions('pro_product_classification');
const found = opts.find(opt => opt.value == value);
const found = opts.find((opt) => opt.value == value);
return found ? found.label : value;
}
</script>
@ -189,7 +213,15 @@ function getPlantTypeLabel(value: string | number) {
<!-- 添加产品部分 -->
<div class="mt-4">
<div class="mb-2 flex items-center justify-between">
<h3 class="text-lg font-medium">{{ isUpdate ? '编辑植物组合包产品' : isReadonly ? '查看植物组合包产品' : '添加植物组合包产品' }} </h3>
<h3 class="text-lg font-medium">
{{
isUpdate
? '编辑植物组合包产品'
: isReadonly
? '查看植物组合包产品'
: '添加植物组合包产品'
}}
</h3>
<a-button v-if="!isReadonly" type="primary" @click="handleAddDetail">
{{ $t('pages.common.add') }}
</a-button>
@ -208,12 +240,34 @@ function getPlantTypeLabel(value: string | number) {
</template>
<template v-else-if="column.key === 'action'">
<template v-if="isReadonly">
<Button type="primary" size="small" style="margin-right: 5px;" @click="handleViewDetail(record)">查看</Button>
<Button
type="primary"
size="small"
style="margin-right: 5px"
@click="handleViewDetail(record)"
>查看</Button
>
</template>
<template v-else>
<Button type="primary" size="small" style="margin-right: 5px;" @click="handleViewDetail(record)">查看</Button>
<Button type="primary" size="small" style="margin-right: 5px;" @click="handleEditDetail(record, index)">编辑</Button>
<Button danger size="small" @click="handleDeleteDetail(record, index)">
<Button
type="primary"
size="small"
style="margin-right: 5px"
@click="handleViewDetail(record)"
>查看</Button
>
<Button
type="primary"
size="small"
style="margin-right: 5px"
@click="handleEditDetail(record, index)"
>编辑</Button
>
<Button
danger
size="small"
@click="handleDeleteDetail(record, index)"
>
删除
</Button>
</template>
@ -222,7 +276,10 @@ function getPlantTypeLabel(value: string | number) {
</Table>
<!-- <div>费用合计{{ totalSumPeices }}</div> -->
</div>
<ProductDetailModal @reload="handleDetailReload" @editReload="handleEditDetailReload"/>
<ProductDetailModal
@reload="handleDetailReload"
@editReload="handleEditDetailReload"
/>
</BasicModal>
</template>