Files
estate/src/views/system/Decoration/addDecoration.vue
2026-08-06 09:09:53 +08:00

230 lines
6.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="ResidentMainBox p-2 w-full">
<PageHeader></PageHeader>
<div class="ResidentMainBody">
<el-card>
<template #header>
<div class="title">基本信息</div>
</template>
<div class="addBuildingFormBody">
<div class="formBox">
<el-form ref="formRef" :model="form" :rules="rules" label-width="120px">
<el-row>
<el-col :span="12">
<el-form-item label="房屋" prop="houseId">
<el-cascader @change="handleChange" v-model="userHousepath" :options="treedata" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="申请人" prop="applyName">
<el-input maxlength="20" v-model.trim="form.applyName" placeholder="请输入申请人" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="装修公司" prop="decorationCompany">
<el-input maxlength="20" v-model.trim="form.decorationCompany" placeholder="请输入装修公司" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="装修内容" prop="decorationContent">
<el-input maxlength="200" show-word-limit type="textarea" v-model.trim="form.decorationContent" placeholder="请输入装修内容" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="装修押金(元)" prop="decorationDeposit">
<el-input maxlength="8" placeholder="请输入装修押金,最多保留2位小数" v-model.number.trim="form.decorationDeposit" />
</el-form-item>
</el-col>
</el-row>
<el-form-item>
<el-button type="primary" @click="submitForm">提交</el-button>
<el-button @click="handleBack">返回</el-button>
</el-form-item>
</el-form>
</div>
</div>
</el-card>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import PageHeader from '@/components/Pageheader/index.vue';
import { addDecoration, getDecoration, updateDecoration } from '@/api/system/Decoration';
import { useHouseStore } from '@/store/modules/house';
import { validator } from '@/utils/Reg';
const houseStore = useHouseStore();
const treedata = ref([]);
const route = useRoute();
const router = useRouter();
const formRef = ref();
const form = ref({
'id': null,
'houseId': null,
'buildingId': null,
'unitNoId': null,
'applyName': '',
'inspectionResult': '0',
'decorationCompany': '',
'decorationContent': '',
'decorationDeposit': null
});
const rules = {
houseId: [{ required: true, message: '请选择具体房屋', trigger: 'blur' }],
applyName: [
{ required: true, message: '请输入申请人', trigger: 'blur' },
{
validator: (_: any, value: string | number, callback: any) => {
if (value === '' || value === undefined) {
return callback(new Error('请输入申请人姓名'));
}
return !validator(value, 'fullFilterReg') ? callback() : callback(new Error('请输入正确的申请人姓名'));
}
}
],
decorationCompany: [
{ required: true, message: '请输入装修公司名称', trigger: 'blur' },
{
validator: (_: any, value: string | number, callback: any) => {
if (value === '' || value === '') {
return callback();
}
return !validator(value, 'fullFilterReg') ? callback() : callback(new Error('请输入正确的装修公司名称'));
}
}
],
decorationDeposit: [
{ required: true, message: '请输入装修押金', trigger: 'blur' },
{
validator: (rule, val, callback) => {
if (val === '' || val === null) {
return callback(new Error('请输入装修押金'));
}
const num = Number(val);
console.log(val);
if (Number.isNaN(num)) {
return callback(new Error('请输入装修押金'));
}
if (num < 0) {
return callback(new Error('装修押金不能为负数'));
}
if (num > 99999999) {
return callback(new Error('装修押金过大'));
}
return validator(val, 'money');
},
trigger: ['blur', 'change']
}
],
decorationContent: [
{ required: true, message: '请输入装修内容', trigger: 'blur' },
{
validator: (_: any, value: string | number, callback: any) => {
if (value === '' || value === '') {
return callback();
}
return !validator(value, 'fullFilterReg') ? callback() : callback(new Error('请输入正确的装修内容'));
}
}
]
};
const userid = ref();
// 获取房屋
const userHousepath = ref([]);
function handleChange(val: (string | number)[]) {
if (val.length >= 3) {
form.value.houseId = val.at(2) as number;
} else {
form.value.houseId = null;
}
}
// ! 投诉 ====================================================================================================
function getTree() {
houseStore.getCurrentVilageTreeHouse().then((res) => {
treedata.value = res;
if (route.query.id) {
userid.value = route.query.id;
init();
}
});
}
getTree();
// TODO
function init() {
getDecoration(userid.value).then((res) => {
form.value = {
...form.value,
...res.data
};
userHousepath.value = [form.value.buildingId, form.value.unitNoId, form.value.houseId];
});
}
// 提交
const submitForm = () => {
formRef.value?.validate(async (valid: boolean) => {
if (valid) {
if (userid.value) {
updateDecoration(form.value).then(() => {
ElMessage.success('编辑成功');
handleBack();
});
} else {
addDecoration(form.value).then(() => {
ElMessage.success('添加成功');
handleBack();
});
}
}
});
};
// 返回
function handleBack() {
router.back();
}
</script>
<style scoped lang="scss">
.ResidentMainBox {
display: flex;
flex-direction: column;
.ResidentMainBody {
margin-top: 20px;
flex: 1;
.formBox {
width: 1000px;
margin: 0 auto;
}
&:deep(div.el-step__head.is-process) {
& > div.el-step__line {
width: 0;
border: 1px dashed gray;
background: transparent;
}
}
&:deep(.el-step.is-vertical .el-step__line) {
top: 20px;
}
&:deep(div.el-step__head.is-finish) {
& > div.el-step__line {
width: 0;
border: 1px solid var(--el-color-primary);
background: transparent;
}
}
}
}
</style>