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"> <script setup lang="ts">
import { computed, ref } from 'vue'; 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 { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils'; import { cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter/form'; 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 { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
import { modalSchema } from './data'; import { modalSchema } from './data';
@ -19,9 +23,13 @@ const emit = defineEmits<{ reload: [] }>();
const isUpdate = ref(false); const isUpdate = ref(false);
const isReadonly = ref(false); const isReadonly = ref(false);
const title = computed(() => { 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({ const [BasicForm, formApi] = useVbenForm({
commonConfig: { commonConfig: {
// //
@ -58,12 +66,15 @@ const [BasicModal, modalApi] = useVbenModal({
return null; return null;
} }
modalApi.modalLoading(true); 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 || ''; editId.value = id || '';
isReadonly.value = !!readonly; isReadonly.value = !!readonly;
if(isReadonly.value){ if (isReadonly.value) {
isUpdate.value = false; isUpdate.value = false;
}else{ } else {
isUpdate.value = !!id; isUpdate.value = !!id;
} }
// //
@ -71,7 +82,11 @@ const [BasicModal, modalApi] = useVbenModal({
const record = await rentalPlanInfo(id); 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,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); await formApi.setValues(record);
} }
@ -93,7 +108,13 @@ async function handleConfirm() {
const data = cloneDeep(await formApi.getValues()); const data = cloneDeep(await formApi.getValues());
// data.productIds = detailTable.value.map((item:any) => item.productId); // data.productIds = detailTable.value.map((item:any) => item.productId);
data.productList = detailTable.value; 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(); resetInitialized();
emit('reload'); emit('reload');
modalApi.close(); modalApi.close();
@ -146,18 +167,19 @@ const detailColumns = [
]; ];
function handleAddDetail() { function handleAddDetail() {
// id // id
const selectedIds = detailTable.value.map((item: any) => item.productId || item.plantName); const selectedIds = detailTable.value.map(
detailModalApi.setData({ selectedIds,add:true }); (item: any) => item.productId || item.plantName,
);
detailModalApi.setData({ selectedIds, add: true });
detailModalApi.open(); detailModalApi.open();
} }
// //
function handleDetailReload (data: any) { function handleDetailReload(data: any) {
detailTable.value.push(data); detailTable.value.push(data);
} }
// //
function handleEditDetailReload (data: any) { function handleEditDetailReload(data: any) {
detailTable.value[data.index] = data; detailTable.value[data.index] = data;
} }
// //
function handleDeleteDetail(record: any, index: number) { function handleDeleteDetail(record: any, index: number) {
@ -171,14 +193,16 @@ function handleViewDetail(record: any) {
// //
function handleEditDetail(record: any, index: number) { function handleEditDetail(record: any, index: number) {
// id // id
const selectedIds = detailTable.value.filter((_: any, i: number) => i !== index).map((item: any) => item.productId || item.plantName); const selectedIds = detailTable.value
detailModalApi.setData({ ...record, index, selectedIds,edit:true }); .filter((_: any, i: number) => i !== index)
.map((item: any) => item.productId || item.plantName);
detailModalApi.setData({ ...record, index, selectedIds, edit: true });
detailModalApi.open(); detailModalApi.open();
} }
// //
function getPlantTypeLabel(value: string | number) { function getPlantTypeLabel(value: string | number) {
const opts = getDictOptions('pro_product_classification'); 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; return found ? found.label : value;
} }
</script> </script>
@ -186,10 +210,18 @@ function getPlantTypeLabel(value: string | number) {
<template> <template>
<BasicModal :title="title"> <BasicModal :title="title">
<BasicForm /> <BasicForm />
<!-- 添加产品部分 --> <!-- 添加产品部分 -->
<div class="mt-4"> <div class="mt-4">
<div class="mb-2 flex items-center justify-between"> <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"> <a-button v-if="!isReadonly" type="primary" @click="handleAddDetail">
{{ $t('pages.common.add') }} {{ $t('pages.common.add') }}
</a-button> </a-button>
@ -204,16 +236,38 @@ function getPlantTypeLabel(value: string | number) {
{{ index + 1 }} {{ index + 1 }}
</template> </template>
<template v-else-if="column.key === 'plantType'"> <template v-else-if="column.key === 'plantType'">
<div>{{getPlantTypeLabel(record.plantType)}}</div> <div>{{ getPlantTypeLabel(record.plantType) }}</div>
</template> </template>
<template v-else-if="column.key === 'action'"> <template v-else-if="column.key === 'action'">
<template v-if="isReadonly"> <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>
<template v-else > <template v-else>
<Button type="primary" size="small" style="margin-right: 5px;" @click="handleViewDetail(record)">查看</Button> <Button
<Button type="primary" size="small" style="margin-right: 5px;" @click="handleEditDetail(record, index)">编辑</Button> type="primary"
<Button danger size="small" @click="handleDeleteDetail(record, index)"> 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> </Button>
</template> </template>
@ -222,7 +276,10 @@ function getPlantTypeLabel(value: string | number) {
</Table> </Table>
<!-- <div>费用合计{{ totalSumPeices }}</div> --> <!-- <div>费用合计{{ totalSumPeices }}</div> -->
</div> </div>
<ProductDetailModal @reload="handleDetailReload" @editReload="handleEditDetailReload"/> <ProductDetailModal
@reload="handleDetailReload"
@editReload="handleEditDetailReload"
/>
</BasicModal> </BasicModal>
</template> </template>