feat: 保洁接口对接
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
fyy
2025-06-27 18:03:13 +08:00
parent f01cb4abce
commit 3e8ba86305
10 changed files with 62158 additions and 366 deletions

View File

@@ -1,31 +1,45 @@
<script setup lang="ts">
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { CleanVO } from '#/api/property/clean/model';
import { computed, ref } from 'vue';
import dayjs from 'dayjs';
import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { Button, Table } from 'ant-design-vue';
import dayjs from 'dayjs';
import { useVbenForm } from '#/adapter/form';
import { cleanAdd, cleanInfo, cleanUpdate, cleanList } from '#/api/property/clean';
import type { CleanVO } from '#/api/property/clean/model';
import { clean_orderAdd, clean_orderInfo, clean_orderUpdate } from '#/api/property/clean_order';
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
import { resident_unitList } from '#/api/property/resident/unit';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { cleanList } from '#/api/property/clean';
import {
clean_orderAdd,
clean_orderInfo,
clean_orderUpdate,
} from '#/api/property/clean_order';
import { resident_unitList } from '#/api/property/resident/unit';
import RoomSelect from '#/components/roomSelect/room-select.vue';
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
import cleanDetailModal from './clean-detail-modal.vue';
import { Table, Button } from 'ant-design-vue';
import { modalSchema } from './data';
const emit = defineEmits<{ reload: [] }>();
// 计算合计费用
const totalSumPeices = computed(() => {
return detailTable.value
.reduce((total: number, item: any) => total + (Number(item.sumPeices) || 0), 0)
.reduce(
(total: number, item: any) => total + (Number(item.sumPeices) || 0),
0,
)
.toFixed(2);
});
const emit = defineEmits<{ reload: [] }>();
const isUpdate = ref(false);
const isReadonly = ref(false);
const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
});
@@ -46,9 +60,10 @@ const [BasicForm, formApi] = useVbenForm({
// 默认label宽度 px
labelWidth: 120,
// 通用配置项 会影响到所有表单项
componentProps: {
componentProps: computed(() => ({
class: 'w-full',
}
disabled: isReadonly.value,
})),
},
// 1. 使用正确的属性名 handleValuesChange
handleValuesChange: async (values, fieldsChanged) => {
@@ -59,23 +74,23 @@ const [BasicForm, formApi] = useVbenForm({
try {
const res = await cleanList(); // 查询所有
cleanListData = res.rows || [];
} catch (e) {
console.error('获取劳务列表失败:', e);
} catch (error) {
console.error('获取劳务列表失败:', error);
cleanListData = []; // 出错时清空
}
}
// 3. 从 values 中获取当前选中的 id
const selectedId = values.name;
const selectedItem = cleanListData.find(item => item.id === selectedId);
const selectedItem = cleanListData.find((item) => item.id === selectedId);
if (selectedItem) {
// 4. 使用正确的 formApi.setValues 方法
await formApi.setValues({
prices: selectedItem.peices, // 服务单价
prices: selectedItem.peices, // 服务单价
frequency: selectedItem.frequency, // 保洁频率
standard: selectedItem.standard, // 保洁内容
peices: selectedItem.peices, // 保洁标准
standard: selectedItem.standard, // 保洁内容
peices: selectedItem.peices, // 保洁标准
});
}
}
@@ -104,12 +119,14 @@ const [BasicModal, modalApi] = useVbenModal({
return null;
}
modalApi.modalLoading(true);
const { id } = modalApi.getData() as { id?: number | string };
const { id, readonly } = modalApi.getData() as {
id?: number | string;
readonly?: boolean;
};
isUpdate.value = !!id;
isReadonly.value = !!readonly;
if (isUpdate.value && id) {
const record:any = await clean_orderInfo(id);
const record: any = await clean_orderInfo(id);
if (record.starTime) record.starTime = dayjs(record.starTime);
if (record.endTime) record.endTime = dayjs(record.endTime);
editUnitId.value = record.unitId || '';
@@ -125,11 +142,10 @@ const [BasicModal, modalApi] = useVbenModal({
const detailGridOptions: VxeGridProps = {
height: '300px',
columns: [
{
title: '序号',
field: 'index',
width: 'auto',
width: 'auto',
slots: {
default: ({ rowIndex }) => {
return (rowIndex + 1).toString();
@@ -139,97 +155,112 @@ const detailGridOptions: VxeGridProps = {
{
title: '劳务名称',
field: 'name',
width: 'auto',
width: 'auto',
},
{
title: '计量单位',
field: 'measure',
width: 'auto',
width: 'auto',
},
{
title: '计算方式',
field: 'method',
width: 'auto',
width: 'auto',
},
{
title: '申报单价含税(元)',
field: 'peices',
width: 'auto',
width: 'auto',
},
{
title: '保洁频率',
field: 'frequency',
width: 'auto',
width: 'auto',
},
{
title: '保洁标准',
field: 'standard',
width: 'auto',
width: 'auto',
},
{
title: '备注',
field: 'remark',
width: 'auto',
width: 'auto',
},
{
title: '状态',
field: 'stater',
width: 'auto',
width: 'auto',
slots: {
default: ({ row }) => row.stater === 1 ? '启用' : '禁用',
default: ({ row }) => (row.stater === 1 ? '启用' : '禁用'),
},
},
{
title: '保洁面积',
field: 'area',
width: 'auto',
width: 'auto',
},
{
title: '合计费用',
field: 'sumPeices',
width: 'auto',
width: 'auto',
},
{
field: 'action',
fixed: 'right',
slots: { default: 'action' },
title: '操作',
width: 'auto',
width: 'auto',
},
],
data: [],
};
const detailColumns = [
{ title: '序号', key: 'index', width: 'auto'},
{ title: '序号', key: 'index', width: 'auto' },
{ title: '劳务名称', dataIndex: 'name', key: 'name', width: 'auto' },
{ title: '计量单位', dataIndex: 'measure', key: 'measure', width: 'auto' },
{ title: '计算方式', dataIndex: 'method', key: 'method', width: 'auto' },
{ title: '申报单价含税(元)', dataIndex: 'peices', key: 'peices' , width: 'auto'},
{ title: '保洁频率', dataIndex: 'frequency', key: 'frequency' , width: 'auto'},
{ title: '保洁标准', dataIndex: 'standard', key: 'standard' , width: 'auto'},
{ title: '备注', dataIndex: 'remark', key: 'remark' , width: 'auto'},
{
title: '申报单价含税(元)',
dataIndex: 'peices',
key: 'peices',
width: 'auto',
},
{
title: '保洁频率',
dataIndex: 'frequency',
key: 'frequency',
width: 'auto',
},
{ title: '保洁标准', dataIndex: 'standard', key: 'standard', width: 'auto' },
{ title: '备注', dataIndex: 'remark', key: 'remark', width: 'auto' },
{
title: '状态',
dataIndex: 'stater',
key: 'stater',
width: 'auto',
customRender: ({ value }: { value: number }) => (value === 1 ? '启用' : '禁用')
customRender: ({ value }: { value: number }) =>
value === 1 ? '启用' : '禁用',
},
{ title: '保洁面积', dataIndex: 'area', key: 'area', width: 'auto' },
{ title: '合计费用', dataIndex: 'sumPeices', key: 'sumPeices', width: 'auto' },
{
title: '合计费用',
dataIndex: 'sumPeices',
key: 'sumPeices',
width: 'auto',
},
{
title: '操作',
key: 'action',
fixed: 'right' as const,
width: 'auto',
},
]
];
const [DetailTable, detailTableApi] = useVbenVxeGrid({
gridOptions: detailGridOptions,
});
const detailTable = ref<any>([])
const detailTable = ref<any>([]);
const [CleanDetailModal, detailModalApi] = useVbenModal({
connectedComponent: cleanDetailModal,
@@ -241,15 +272,19 @@ function handleAddDetail() {
}
function handleDetailReload(data: any) {
detailTable.value.push(data)
detailTable.value.push(data);
}
function handleDeleteDetail(record: any,index: number) {
console.log(record,index);
detailTable.value.splice(index,1)
function handleDeleteDetail(record: any, index: number) {
console.log(record, index);
detailTable.value.splice(index, 1);
}
async function handleConfirm() {
if (isReadonly.value) {
modalApi.close();
return;
}
try {
modalApi.lock(true);
const { valid } = await formApi.validate();
@@ -265,14 +300,18 @@ async function handleConfirm() {
}
// 劳务数据缓存 cleanListData 已有
// 查找label
const unitObj = unitListData.find(item => item.id === data.unit);
const cleanObj = cleanListData.find(item => item.id === data.name);
data.unit = unitObj ? unitObj.name : data.unit || '' ;
data.name = cleanObj ? cleanObj.name :data.name || '';
data.unitId = unitObj ? unitObj.id : (isUpdate.value ? editUnitId.value : '');
data.cleanId = cleanObj ? cleanObj.id : (isUpdate.value ? editCleanId.value : '');
const unitObj = unitListData.find((item) => item.id === data.unit);
const cleanObj = cleanListData.find((item) => item.id === data.name);
data.unit = unitObj ? unitObj.name : data.unit || '';
data.name = cleanObj ? cleanObj.name : data.name || '';
data.unitId = unitObj ? unitObj.id : isUpdate.value ? editUnitId.value : '';
data.cleanId = cleanObj
? cleanObj.id
: isUpdate.value
? editCleanId.value
: '';
data.sumPeices = totalSumPeices;
// 组装 cleanIds
data.cleanIds = detailTable.value.map((item: any) => item.id);
data.details = detailTable.value;
@@ -295,28 +334,38 @@ async function handleClosed() {
</script>
<template>
<BasicModal :title="title" >
<BasicForm />
<BasicModal :title="title">
<BasicForm>
<template #location="soltProps">
<RoomSelect v-bind="soltProps" />
</template>
</BasicForm>
<!-- 添加订单详情部分 -->
<div class="mt-4">
<div class="flex items-center justify-between mb-2">
<div class="mb-2 flex items-center justify-between">
<h3 class="text-lg font-medium">添加保洁订单详情</h3>
<a-button type="primary" @click="handleAddDetail">
{{ $t('pages.common.add') }}
</a-button>
</div>
<Table :dataSource="detailTable" :columns="detailColumns" :pagination="false" >
<template #bodyCell="{ column, index,record }">
<template v-if="column.key === 'index'">
{{ index + 1 }}
</template>
<template v-else-if="column.key === 'action'">
<Button danger @click="handleDeleteDetail(record,index)">删除</Button>
<Table
:data-source="detailTable"
:columns="detailColumns"
:pagination="false"
>
<template #bodyCell="{ column, index, record }">
<template v-if="column.key === 'index'">
{{ index + 1 }}
</template>
<template v-else-if="column.key === 'action'">
<Button danger @click="handleDeleteDetail(record, index)">
删除
</Button>
</template>
</template>
</template>
</Table>
<div>费用合计{{ totalSumPeices }}</div>
</div>
</Table>
<div>费用合计{{ totalSumPeices }}</div>
</div>
<CleanDetailModal @reload="handleDetailReload" />
</BasicModal>
</template>
@@ -325,24 +374,29 @@ async function handleClosed() {
.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;
}
</style>