2025-06-26 09:33:34 +08:00
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { computed, ref } from 'vue';
|
2025-07-30 09:58:55 +08:00
|
|
|
|
import { Button, message, Table } from 'ant-design-vue';
|
2025-06-26 09:33:34 +08:00
|
|
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
|
|
|
import { $t } from '@vben/locales';
|
|
|
|
|
import { cloneDeep } from '@vben/utils';
|
|
|
|
|
|
|
|
|
|
import { useVbenForm } from '#/adapter/form';
|
2025-07-30 09:58:55 +08:00
|
|
|
|
import {
|
|
|
|
|
rentalPlanAdd,
|
|
|
|
|
rentalPlanInfo,
|
|
|
|
|
rentalPlanUpdate,
|
|
|
|
|
} from '#/api/property/rentalPlan';
|
2025-06-26 09:33:34 +08:00
|
|
|
|
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
|
|
|
|
|
|
|
|
|
import { modalSchema } from './data';
|
2025-07-01 17:48:47 +08:00
|
|
|
|
import productDetailModal from './rentalPlan-detial-modal.vue';
|
2025-07-02 14:42:17 +08:00
|
|
|
|
import { getDictOptions } from '#/utils/dict';
|
2025-07-10 17:52:54 +08:00
|
|
|
|
import { Item } from 'ant-design-vue/es/menu';
|
2025-07-02 14:42:17 +08:00
|
|
|
|
|
2025-06-26 09:33:34 +08:00
|
|
|
|
const emit = defineEmits<{ reload: [] }>();
|
|
|
|
|
|
|
|
|
|
const isUpdate = ref(false);
|
2025-07-01 17:48:47 +08:00
|
|
|
|
const isReadonly = ref(false);
|
2025-06-26 09:33:34 +08:00
|
|
|
|
const title = computed(() => {
|
2025-07-30 09:58:55 +08:00
|
|
|
|
return isUpdate.value
|
|
|
|
|
? $t('pages.common.edit')
|
|
|
|
|
: isReadonly.value
|
|
|
|
|
? '详情'
|
|
|
|
|
: $t('pages.common.add');
|
2025-06-26 09:33:34 +08:00
|
|
|
|
});
|
2025-07-30 09:58:55 +08:00
|
|
|
|
const editId = ref<string | number | undefined>('');
|
2025-06-26 09:33:34 +08:00
|
|
|
|
const [BasicForm, formApi] = useVbenForm({
|
|
|
|
|
commonConfig: {
|
|
|
|
|
// 默认占满两列
|
2025-06-30 17:42:56 +08:00
|
|
|
|
formItemClass: 'col-span-1',
|
2025-06-26 09:33:34 +08:00
|
|
|
|
// 默认label宽度 px
|
2025-06-30 17:42:56 +08:00
|
|
|
|
labelWidth: 120,
|
2025-06-26 09:33:34 +08:00
|
|
|
|
// 通用配置项 会影响到所有表单项
|
2025-07-15 16:12:11 +08:00
|
|
|
|
componentProps: computed(() => ({
|
2025-06-26 09:33:34 +08:00
|
|
|
|
class: 'w-full',
|
2025-07-15 16:12:11 +08:00
|
|
|
|
disabled: isReadonly.value,
|
|
|
|
|
})),
|
2025-06-26 09:33:34 +08:00
|
|
|
|
},
|
|
|
|
|
schema: modalSchema(),
|
|
|
|
|
showDefaultActions: false,
|
|
|
|
|
wrapperClass: 'grid-cols-2',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
|
|
|
|
{
|
|
|
|
|
initializedGetter: defaultFormValueGetter(formApi),
|
|
|
|
|
currentGetter: defaultFormValueGetter(formApi),
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const [BasicModal, modalApi] = useVbenModal({
|
|
|
|
|
// 在这里更改宽度
|
2025-06-30 17:42:56 +08:00
|
|
|
|
class: 'w-[70%]',
|
2025-06-26 09:33:34 +08:00
|
|
|
|
fullscreenButton: false,
|
|
|
|
|
onBeforeClose,
|
|
|
|
|
onClosed: handleClosed,
|
|
|
|
|
onConfirm: handleConfirm,
|
|
|
|
|
onOpenChange: async (isOpen) => {
|
|
|
|
|
if (!isOpen) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2025-07-01 17:48:47 +08:00
|
|
|
|
modalApi.modalLoading(true);
|
2025-07-30 09:58:55 +08:00
|
|
|
|
const { id, readonly } = modalApi.getData() as {
|
|
|
|
|
id?: number | string;
|
|
|
|
|
readonly?: boolean;
|
|
|
|
|
};
|
2025-07-02 14:42:17 +08:00
|
|
|
|
editId.value = id || '';
|
2025-07-01 17:48:47 +08:00
|
|
|
|
isReadonly.value = !!readonly;
|
2025-07-30 09:58:55 +08:00
|
|
|
|
if (isReadonly.value) {
|
2025-07-01 17:48:47 +08:00
|
|
|
|
isUpdate.value = false;
|
2025-07-30 09:58:55 +08:00
|
|
|
|
} else {
|
2025-07-01 17:48:47 +08:00
|
|
|
|
isUpdate.value = !!id;
|
|
|
|
|
}
|
|
|
|
|
// 查看与编辑时需要获取详情
|
|
|
|
|
if ((isUpdate.value || isReadonly.value) && id) {
|
2025-06-26 09:33:34 +08:00
|
|
|
|
const record = await rentalPlanInfo(id);
|
2025-07-02 14:42:17 +08:00
|
|
|
|
// 后端返回绿植产品包列表结构处理
|
2025-07-11 11:37:04 +08:00
|
|
|
|
// detailTable.value = record.productList.map((item:any) => {...item.product,item.productNum,});
|
2025-07-30 09:58:55 +08:00
|
|
|
|
detailTable.value = record.productList.map((item: any) => ({
|
|
|
|
|
...item.product,
|
|
|
|
|
productNum: item.productNum,
|
|
|
|
|
productId: item.productId,
|
|
|
|
|
}));
|
2025-07-10 17:52:54 +08:00
|
|
|
|
|
2025-06-26 09:33:34 +08:00
|
|
|
|
await formApi.setValues(record);
|
|
|
|
|
}
|
|
|
|
|
await markInitialized();
|
|
|
|
|
|
|
|
|
|
modalApi.modalLoading(false);
|
|
|
|
|
},
|
|
|
|
|
});
|
2025-07-01 17:48:47 +08:00
|
|
|
|
const detailTable = ref<any>([]);
|
2025-06-26 09:33:34 +08:00
|
|
|
|
|
|
|
|
|
async function handleConfirm() {
|
|
|
|
|
try {
|
|
|
|
|
modalApi.lock(true);
|
|
|
|
|
const { valid } = await formApi.validate();
|
|
|
|
|
if (!valid) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
|
|
|
|
|
const data = cloneDeep(await formApi.getValues());
|
2025-07-07 14:38:01 +08:00
|
|
|
|
// data.productIds = detailTable.value.map((item:any) => item.productId);
|
|
|
|
|
data.productList = detailTable.value;
|
2025-07-30 09:58:55 +08:00
|
|
|
|
if (data.productList.length == 0) {
|
|
|
|
|
message.error('请添加植物组合包产品');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await (isUpdate.value
|
|
|
|
|
? rentalPlanUpdate({ ...data, id: editId.value })
|
|
|
|
|
: rentalPlanAdd(data));
|
2025-06-26 09:33:34 +08:00
|
|
|
|
resetInitialized();
|
|
|
|
|
emit('reload');
|
|
|
|
|
modalApi.close();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
} finally {
|
|
|
|
|
modalApi.lock(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function handleClosed() {
|
2025-07-01 17:48:47 +08:00
|
|
|
|
detailTable.value = [];
|
2025-06-26 09:33:34 +08:00
|
|
|
|
await formApi.resetForm();
|
|
|
|
|
resetInitialized();
|
|
|
|
|
}
|
2025-07-01 17:48:47 +08:00
|
|
|
|
const [ProductDetailModal, detailModalApi] = useVbenModal({
|
|
|
|
|
connectedComponent: productDetailModal,
|
|
|
|
|
});
|
|
|
|
|
|
2025-06-30 17:42:56 +08:00
|
|
|
|
const detailColumns = [
|
|
|
|
|
{ title: '序号', key: 'index' },
|
|
|
|
|
{ title: '产品编号', dataIndex: 'plantCode', key: 'plantCode' },
|
|
|
|
|
{ title: '产品名称', dataIndex: 'plantName', key: 'plantName' },
|
|
|
|
|
{ title: '产品分类', dataIndex: 'plantType', key: 'plantType' },
|
2025-07-07 14:38:01 +08:00
|
|
|
|
{ title: '产品数量', dataIndex: 'productNum', key: 'productNum' },
|
2025-07-11 11:37:04 +08:00
|
|
|
|
// {
|
|
|
|
|
// title: '图片',
|
|
|
|
|
// dataIndex: 'imgPath',
|
|
|
|
|
// key: 'imgPath',
|
|
|
|
|
// },
|
2025-06-30 17:42:56 +08:00
|
|
|
|
{
|
|
|
|
|
title: '规格',
|
|
|
|
|
dataIndex: 'specification',
|
|
|
|
|
key: 'specification',
|
|
|
|
|
},
|
|
|
|
|
{ title: '租金', dataIndex: 'rent', key: 'rent' },
|
|
|
|
|
{ title: '备注', dataIndex: 'remark', key: 'remark' },
|
|
|
|
|
{
|
|
|
|
|
title: '状态',
|
|
|
|
|
dataIndex: 'state',
|
|
|
|
|
key: 'state',
|
|
|
|
|
customRender: ({ value }: { value: number }) =>
|
2025-07-07 14:38:01 +08:00
|
|
|
|
value == 1 ? '上架' : '下架',
|
2025-06-30 17:42:56 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '操作',
|
|
|
|
|
key: 'action',
|
|
|
|
|
fixed: 'right' as const,
|
|
|
|
|
},
|
|
|
|
|
];
|
2025-07-01 17:48:47 +08:00
|
|
|
|
function handleAddDetail() {
|
2025-07-15 16:45:51 +08:00
|
|
|
|
// 传递已选产品id列表
|
2025-07-30 09:58:55 +08:00
|
|
|
|
const selectedIds = detailTable.value.map(
|
|
|
|
|
(item: any) => item.productId || item.plantName,
|
|
|
|
|
);
|
|
|
|
|
detailModalApi.setData({ selectedIds, add: true });
|
2025-07-01 17:48:47 +08:00
|
|
|
|
detailModalApi.open();
|
|
|
|
|
}
|
|
|
|
|
//添加植物组合包产品
|
2025-07-30 09:58:55 +08:00
|
|
|
|
function handleDetailReload(data: any) {
|
2025-07-01 17:48:47 +08:00
|
|
|
|
detailTable.value.push(data);
|
|
|
|
|
}
|
|
|
|
|
// 编辑植物组合包产品
|
2025-07-30 09:58:55 +08:00
|
|
|
|
function handleEditDetailReload(data: any) {
|
2025-07-01 17:48:47 +08:00
|
|
|
|
detailTable.value[data.index] = data;
|
|
|
|
|
}
|
|
|
|
|
// 删除植物组合包产品
|
|
|
|
|
function handleDeleteDetail(record: any, index: number) {
|
|
|
|
|
detailTable.value.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
// 查看产品详情
|
|
|
|
|
function handleViewDetail(record: any) {
|
|
|
|
|
detailModalApi.setData({ ...record, readonly: true });
|
|
|
|
|
detailModalApi.open();
|
|
|
|
|
}
|
|
|
|
|
// 编辑产品详情
|
|
|
|
|
function handleEditDetail(record: any, index: number) {
|
2025-07-15 16:45:51 +08:00
|
|
|
|
// 编辑时,排除当前项id
|
2025-07-30 09:58:55 +08:00
|
|
|
|
const selectedIds = detailTable.value
|
|
|
|
|
.filter((_: any, i: number) => i !== index)
|
|
|
|
|
.map((item: any) => item.productId || item.plantName);
|
|
|
|
|
detailModalApi.setData({ ...record, index, selectedIds, edit: true });
|
2025-07-01 17:48:47 +08:00
|
|
|
|
detailModalApi.open();
|
|
|
|
|
}
|
2025-07-02 14:42:17 +08:00
|
|
|
|
//分类字典
|
|
|
|
|
function getPlantTypeLabel(value: string | number) {
|
|
|
|
|
const opts = getDictOptions('pro_product_classification');
|
2025-07-30 09:58:55 +08:00
|
|
|
|
const found = opts.find((opt) => opt.value == value);
|
2025-07-02 14:42:17 +08:00
|
|
|
|
return found ? found.label : value;
|
|
|
|
|
}
|
2025-06-26 09:33:34 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<BasicModal :title="title">
|
|
|
|
|
<BasicForm />
|
2025-07-30 09:58:55 +08:00
|
|
|
|
<!-- 添加产品部分、 -->
|
2025-06-30 17:42:56 +08:00
|
|
|
|
<div class="mt-4">
|
|
|
|
|
<div class="mb-2 flex items-center justify-between">
|
2025-07-30 09:58:55 +08:00
|
|
|
|
<h3 class="text-lg font-medium">
|
|
|
|
|
{{
|
|
|
|
|
isUpdate
|
|
|
|
|
? '编辑植物组合包产品'
|
|
|
|
|
: isReadonly
|
|
|
|
|
? '查看植物组合包产品'
|
|
|
|
|
: '添加植物组合包产品'
|
|
|
|
|
}}
|
|
|
|
|
</h3>
|
2025-07-01 17:48:47 +08:00
|
|
|
|
<a-button v-if="!isReadonly" type="primary" @click="handleAddDetail">
|
2025-06-30 17:42:56 +08:00
|
|
|
|
{{ $t('pages.common.add') }}
|
|
|
|
|
</a-button>
|
|
|
|
|
</div>
|
|
|
|
|
<Table
|
|
|
|
|
:data-source="detailTable"
|
|
|
|
|
:columns="detailColumns"
|
|
|
|
|
:pagination="false"
|
|
|
|
|
>
|
|
|
|
|
<template #bodyCell="{ column, index, record }">
|
|
|
|
|
<template v-if="column.key === 'index'">
|
|
|
|
|
{{ index + 1 }}
|
|
|
|
|
</template>
|
2025-07-02 14:42:17 +08:00
|
|
|
|
<template v-else-if="column.key === 'plantType'">
|
2025-07-30 09:58:55 +08:00
|
|
|
|
<div>{{ getPlantTypeLabel(record.plantType) }}</div>
|
2025-07-02 14:42:17 +08:00
|
|
|
|
</template>
|
2025-06-30 17:42:56 +08:00
|
|
|
|
<template v-else-if="column.key === 'action'">
|
2025-07-30 09:58:55 +08:00
|
|
|
|
<template v-if="isReadonly">
|
|
|
|
|
<Button
|
|
|
|
|
type="primary"
|
|
|
|
|
size="small"
|
|
|
|
|
style="margin-right: 5px"
|
|
|
|
|
@click="handleViewDetail(record)"
|
|
|
|
|
>查看</Button
|
|
|
|
|
>
|
2025-07-01 17:48:47 +08:00
|
|
|
|
</template>
|
2025-07-30 09:58:55 +08:00
|
|
|
|
<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)"
|
|
|
|
|
>
|
2025-07-01 17:48:47 +08:00
|
|
|
|
删除
|
|
|
|
|
</Button>
|
|
|
|
|
</template>
|
2025-06-30 17:42:56 +08:00
|
|
|
|
</template>
|
|
|
|
|
</template>
|
|
|
|
|
</Table>
|
2025-07-01 17:48:47 +08:00
|
|
|
|
<!-- <div>费用合计:{{ totalSumPeices }}元</div> -->
|
2025-06-30 17:42:56 +08:00
|
|
|
|
</div>
|
2025-07-30 09:58:55 +08:00
|
|
|
|
<ProductDetailModal
|
|
|
|
|
@reload="handleDetailReload"
|
|
|
|
|
@editReload="handleEditDetailReload"
|
|
|
|
|
/>
|
2025-06-26 09:33:34 +08:00
|
|
|
|
</BasicModal>
|
|
|
|
|
</template>
|
|
|
|
|
|
2025-07-01 17:48:47 +08:00
|
|
|
|
<style scoped>
|
|
|
|
|
.mt-4 {
|
|
|
|
|
margin-top: 1rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.mb-2 {
|
|
|
|
|
margin-bottom: 0.5rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.flex {
|
|
|
|
|
display: flex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.items-center {
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.justify-between {
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.text-lg {
|
|
|
|
|
font-size: 1.125rem;
|
|
|
|
|
line-height: 1.75rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.font-medium {
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
}
|
|
|
|
|
/* 使用 :deep() 穿透 scoped 样式,影响子组件 */
|
|
|
|
|
:deep(.ant-input[disabled]),
|
|
|
|
|
:deep(.ant-input-number-disabled .ant-input-number-input),
|
|
|
|
|
:deep(.ant-select-disabled .ant-select-selection-item),
|
|
|
|
|
:deep(.ant-picker-disabled .ant-picker-input > input) {
|
|
|
|
|
/* 设置一个更深的颜色 */
|
|
|
|
|
color: rgb(0 0 0 / 65%) !important;
|
|
|
|
|
|
|
|
|
|
/* 有些浏览器需要这个来覆盖默认颜色 */
|
|
|
|
|
-webkit-text-fill-color: rgb(0 0 0 / 65%) !important;
|
|
|
|
|
}
|
|
|
|
|
</style>
|