Compare commits

...

2 Commits

Author SHA1 Message Date
fyy
85975db5ee Merge branch 'master' of http://47.109.37.87:3000/by2025/admin-vben5
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 7m1s
2025-06-24 16:45:56 +08:00
fyy
a0f5599d92 feat: 设置一个保洁订单可选多个服务 2025-06-24 16:43:49 +08:00
3 changed files with 427 additions and 29 deletions

View File

@ -0,0 +1,230 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter/form';
import { cleanList } from '#/api/property/clean';
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
const emit = defineEmits<{ reload: [data: any] }>();
const isUpdate = ref(false);
const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
});
//
let cleanListData: any[] = [];
const detailSchema = [
{
label: '劳务名称',
fieldName: 'name',
component: 'ApiSelect',
componentProps: {
api: async () => {
const res = await cleanList({stater:1});
cleanListData = res.rows || [];
return res;
},
resultField: 'rows',
labelField: 'name',
valueField: 'id',
onChange: async (value: string) => {
//
const selectedService = cleanListData.find(item => item.id === value);
if (selectedService) {
//
await formApi.setValues({
measure: selectedService.measure,
method: selectedService.method,
peices: selectedService.peices,
frequency: selectedService.frequency,
standard: selectedService.standard,
remark: selectedService.remark,
stater: selectedService.stater,
});
}
},
},
rules: 'required',
},
{
label: '计量单位',
fieldName: 'measure',
component: 'Input',
componentProps: {
disabled: true,
},
rules: 'required',
},
{
label: '计算方式',
fieldName: 'method',
component: 'Input',
componentProps: {
disabled: true,
},
rules: 'required',
},
{
label: '申报单价含税(元)',
fieldName: 'peices',
component: 'InputNumber',
componentProps: {
disabled: true,
},
rules: 'required',
},
{
label: '保洁频率',
fieldName: 'frequency',
component: 'Input',
componentProps: {
disabled: true,
},
rules: 'required',
},
{
label: '保洁标准',
fieldName: 'standard',
component: 'Input',
componentProps: {
disabled: true,
},
rules: 'required',
},
{
label: '备注',
fieldName: 'remark',
component: 'Input',
componentProps: {
disabled: true,
},
},
{
label: '状态',
fieldName: 'stater',
component: 'Select',
componentProps: {
disabled: true,
options: [
{ label: '上架', value: 1 },
{ label: '下架', value: 0 },
],
},
rules: 'required',
},
{
label: '保洁面积',
fieldName: 'area',
component: 'InputNumber',
rules: 'required',
componentProps: {
onChange: async (value: number) => {
const formValues = await formApi.getValues();
if (formValues.peices && value) {
await formApi.setValues({
sumPeices: Number((formValues.peices * value).toFixed(2)),
});
}
},
},
},
{
label: '合计费用',
fieldName: 'sumPeices',
component: 'InputNumber',
componentProps: {
disabled: true,
},
},
];
const [BasicForm, formApi] = useVbenForm({
commonConfig: {
labelWidth: 120,
componentProps: {
class: 'w-full',
},
},
schema: detailSchema,
showDefaultActions: false,
});
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
{
initializedGetter: defaultFormValueGetter(formApi),
currentGetter: defaultFormValueGetter(formApi),
},
);
const [BasicModal, modalApi] = useVbenModal({
onBeforeClose,
onClosed: handleClosed,
onConfirm: handleConfirm,
onOpenChange: async (isOpen) => {
if (!isOpen) {
return null;
}
modalApi.modalLoading(true);
const { id } = modalApi.getData() as { id?: number | string };
isUpdate.value = !!id;
if (isUpdate.value && id) {
// TODO:
}
await markInitialized();
modalApi.modalLoading(false);
},
});
async function handleConfirm() {
console.log('handleConfirm');
try {
modalApi.lock(true);
const { valid } = await formApi.validate();
if (!valid) {
return;
}
const data = cloneDeep(await formApi.getValues());
//
const selectedService = cleanListData.find(item => item.id === data.name);
if (selectedService) {
data.name = selectedService.name;
}
handleClosed()
await markInitialized();
emit('reload', data);
modalApi.close();
} catch (error) {
console.error(error);
} finally {
modalApi.lock(false);
}
}
async function handleClosed() {
console.log('handleClosed');
await formApi.resetForm();
resetInitialized();
}
</script>
<template>
<BasicModal :title="title">
<BasicForm />
</BasicModal>
</template>
<style scoped>
/* 使用 :deep() 穿透 scoped 样式,影响子组件 */
:deep(.ant-input[disabled]),
:deep(.ant-input-number-disabled .ant-input-number-input),
:deep(.ant-select-disabled .ant-select-selection-item) {
/* 设置一个更深的颜色,可以自己调整 */
color: rgba(0, 0, 0, 0.65) !important;
/* 有些浏览器需要这个来覆盖默认颜色 */
-webkit-text-fill-color: rgba(0, 0, 0, 0.65) !important;
}
</style>

View File

@ -12,11 +12,19 @@ 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 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)
.toFixed(2);
});
const emit = defineEmits<{ reload: [] }>();
const isUpdate = ref(false);
const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
@ -99,8 +107,9 @@ const [BasicModal, modalApi] = useVbenModal({
const { id } = modalApi.getData() as { id?: number | string };
isUpdate.value = !!id;
if (isUpdate.value && id) {
const record = 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 || '';
@ -112,6 +121,121 @@ const [BasicModal, modalApi] = useVbenModal({
},
});
//
const detailGridOptions: VxeGridProps = {
height: '300px',
columns: [
{ type: 'checkbox', width: 60 },
{
title: '序号',
field: 'index',
slots: {
default: ({ rowIndex }) => {
return (rowIndex + 1).toString();
},
},
},
{
title: '劳务名称',
field: 'name',
},
{
title: '计量单位',
field: 'measure',
},
{
title: '计算方式',
field: 'method',
},
{
title: '申报单价含税(元)',
field: 'peices',
},
{
title: '保洁频率',
field: 'frequency',
},
{
title: '保洁标准',
field: 'standard',
},
{
title: '备注',
field: 'remark',
},
{
title: '状态',
field: 'stater',
slots: {
default: ({ row }) => row.stater === 1 ? '启用' : '禁用',
},
},
{
title: '保洁面积',
field: 'area',
},
{
title: '合计费用',
field: 'sumPeices',
},
{
field: 'action',
fixed: 'right',
slots: { default: 'action' },
title: '操作',
width: 120,
},
],
data: [],
};
const detailColumns = [
{ title: '序号', key: 'index'},
{ title: '劳务名称', dataIndex: 'name', key: 'name' },
{ title: '计量单位', dataIndex: 'measure', key: 'measure' },
{ title: '计算方式', dataIndex: 'method', key: 'method' },
{ title: '申报单价含税(元)', dataIndex: 'peices', key: 'peices' },
{ title: '保洁频率', dataIndex: 'frequency', key: 'frequency' },
{ title: '保洁标准', dataIndex: 'standard', key: 'standard' },
{ title: '备注', dataIndex: 'remark', key: 'remark' },
{
title: '状态',
dataIndex: 'stater',
key: 'stater',
customRender: ({ value }: { value: number }) => (value === 1 ? '启用' : '禁用')
},
{ title: '保洁面积', dataIndex: 'area', key: 'area' },
{ title: '合计费用', dataIndex: 'sumPeices', key: 'sumPeices' },
{
title: '操作',
key: 'action',
fixed: 'right',
width: 120,
},
]
const [DetailTable, detailTableApi] = useVbenVxeGrid({
gridOptions: detailGridOptions,
});
const detailTable = ref<any>([])
const [CleanDetailModal, detailModalApi] = useVbenModal({
connectedComponent: cleanDetailModal,
});
function handleAddDetail() {
detailModalApi.setData({});
detailModalApi.open();
}
function handleDetailReload(data: any) {
detailTable.value.push(data)
}
function handleDeleteDetail(record: any,index: number) {
console.log(record,index);
detailTable.value.splice(index,1)
}
async function handleConfirm() {
try {
modalApi.lock(true);
@ -120,15 +244,13 @@ async function handleConfirm() {
return;
}
const data = cloneDeep(await formApi.getValues());
console.log(data);
console.log(data);
//
if (unitListData.length === 0) {
const res = await resident_unitList();
unitListData = res.rows || [];
}
// cleanListData
// label
const unitObj = unitListData.find(item => item.id === data.unit);
const cleanObj = cleanListData.find(item => item.id === data.name);
@ -160,8 +282,54 @@ async function handleClosed() {
</script>
<template>
<BasicModal :title="title">
<BasicModal :title="title" >
<BasicForm />
<!-- 添加订单详情部分 -->
<div class="mt-4">
<div class="flex items-center justify-between mb-2">
<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>
</template>
</template>
</Table>
<div>费用合计{{ totalSumPeices }}</div>
</div>
<CleanDetailModal @reload="handleDetailReload" />
</BasicModal>
</template>
<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;
}
</style>

View File

@ -131,28 +131,28 @@ export const modalSchema: FormSchemaGetter = () => [
component: 'Input',
rules: 'required',
},
{
label: '劳务名称',
fieldName: 'name',
component: 'ApiSelect',
componentProps: {
api: cleanList,
resultField: 'rows',
labelField: 'name',
valueField: 'id',
},
rules: 'required',
},
{
label: '服务单价',
fieldName: 'prices',
component: 'Input',
rules: 'required',
componentProps: {
placeholder: '',
disabled: true,
},
},
// {
// label: '劳务名称',
// fieldName: 'name',
// component: 'ApiSelect',
// componentProps: {
// api: cleanList,
// resultField: 'rows',
// labelField: 'name',
// valueField: 'id',
// },
// rules: 'required',
// },
// {
// label: '服务单价',
// fieldName: 'prices',
// component: 'Input',
// rules: 'required',
// componentProps: {
// placeholder: '',
// disabled: true,
// },
// },
// {
// label: '保洁频率',
// fieldName: 'frequency',