144 lines
4.2 KiB
Vue
144 lines
4.2 KiB
Vue
<template>
|
|
<div class="AddBuildingBox">
|
|
<PageHeader></PageHeader>
|
|
<div class="AddBuildingBody">
|
|
<div class="title">基本信息</div>
|
|
<div class="addBuildingFormBody">
|
|
<el-form ref="formRef" :model="form" :rules="rules" class="formBody" label-position="right" label-width="130px">
|
|
<el-form-item label="物料名称" prop="materialName">
|
|
<el-input v-model.trim="form.materialName" maxlength="20" placeholder="请输入物料名称" />
|
|
</el-form-item>
|
|
<el-form-item label="品牌" prop="brand">
|
|
<el-input v-model.trim="form.brand" maxlength="20" placeholder="请输入品牌" />
|
|
</el-form-item>
|
|
<el-form-item label="规格型号" prop="model">
|
|
<el-input v-model.trim="form.model" maxlength="20" placeholder="请输入规格型号" />
|
|
</el-form-item>
|
|
<el-form-item label="计量单位" prop="unit">
|
|
<el-input v-model.trim="form.unit" maxlength="20" placeholder="请输入计量单位" />
|
|
</el-form-item>
|
|
<el-form-item label="备注" prop="remark">
|
|
<el-input v-model.trim="form.remark" :rows="5" maxlength="30" placeholder="请输入备注" show-word-limit type="textarea" />
|
|
</el-form-item>
|
|
<el-form-item style="margin-top: 30px">
|
|
<el-button type="primary" @click="submitForm">提交</el-button>
|
|
<el-button @click="cancelForm">返回</el-button>
|
|
</el-form-item>
|
|
</el-form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { ref } from 'vue';
|
|
import PageHeader from '@/components/Pageheader/index.vue';
|
|
import { getMaterial, updateMaterial, addMaterial } from '@/api/system/Tmaterial';
|
|
|
|
const router = useRouter();
|
|
const route = useRoute();
|
|
|
|
const formRef = ref();
|
|
const form = ref({
|
|
id: null,
|
|
materialName: '', // 物料名称
|
|
brand: '', // 联系电话
|
|
model: '', // 邮箱
|
|
unit: '', // 地址
|
|
remark: '', // 备注
|
|
villageId: ''
|
|
});
|
|
const rules = ref({
|
|
materialName: [{ required: true, message: '请输入 物料名称', trigger: 'blur' }],
|
|
brand: [{ required: true, message: '请输入 品牌', trigger: 'blur' }],
|
|
model: [{ required: true, message: '请输入 规格型号', trigger: 'blur' }],
|
|
unit: [{ required: true, message: '请输入 计量单位', trigger: 'blur' }]
|
|
});
|
|
const userid = ref(null);
|
|
if (route.query.id) {
|
|
userid.value = route.query.id;
|
|
getMaterial(userid.value).then((res) => {
|
|
form.value = {
|
|
id: res.data.id,
|
|
materialName: res.data.materialName,
|
|
brand: res.data.brand,
|
|
model: res.data.model,
|
|
unit: res.data.unit,
|
|
remark: res.data.remark,
|
|
villageId: res.data.villageId
|
|
};
|
|
});
|
|
}
|
|
// !== 提交 =============================================================================
|
|
// 提交
|
|
const submitForm = () => {
|
|
const villageId = localStorage.getItem('villageid');
|
|
form.value.villageId = villageId;
|
|
formRef.value?.validate(async (valid: boolean) => {
|
|
if (valid) {
|
|
if (userid.value) {
|
|
updateMaterial(form.value).then(() => {
|
|
ElMessage.success('编辑成功');
|
|
cancelForm();
|
|
});
|
|
} else {
|
|
addMaterial(form.value).then(() => {
|
|
ElMessage.success('添加成功');
|
|
cancelForm();
|
|
});
|
|
}
|
|
}
|
|
});
|
|
};
|
|
// 推出
|
|
const cancelForm = () => {
|
|
router.back();
|
|
};
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.AddBuildingBox {
|
|
padding: 15px;
|
|
height: 100%;
|
|
width: 100%;
|
|
}
|
|
.AddBuildingBody {
|
|
margin-top: 20px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
background-color: white;
|
|
padding: 15px;
|
|
.title {
|
|
height: 40px;
|
|
line-height: 40px;
|
|
padding-left: 20px;
|
|
background-color: rgba(255, 255, 255, 1);
|
|
color: rgba(16, 16, 16, 1);
|
|
border-bottom: 1px solid #bbbbbb;
|
|
margin-bottom: 60px;
|
|
}
|
|
|
|
.formBody {
|
|
width: 650px;
|
|
margin: 0 auto;
|
|
&:deep(.el-form-item__content, .el-select, .el-input) {
|
|
width: 350px !important;
|
|
margin-right: 10px;
|
|
.el-cascader {
|
|
width: 100%;
|
|
}
|
|
}
|
|
.el-form-item {
|
|
margin-bottom: 20px;
|
|
align-items: center;
|
|
}
|
|
.el-button {
|
|
width: 80px;
|
|
height: 35px;
|
|
margin-right: 20px;
|
|
}
|
|
}
|
|
}
|
|
</style>
|