forked from b2894lxlx/tuanwei-admin
238 lines
6.1 KiB
Vue
238 lines
6.1 KiB
Vue
<!-- 编辑弹窗 -->
|
|
<template>
|
|
<ele-modal
|
|
:width="500"
|
|
:visible="visible"
|
|
:confirm-loading="loading"
|
|
:title="isUpdate ? '修改保养记录' : '新建保养记录'"
|
|
:body-style="{ paddingBottom: '8px' }"
|
|
@update:visible="updateVisible"
|
|
@ok="save"
|
|
>
|
|
<a-form
|
|
ref="formRef"
|
|
:model="form"
|
|
:rules="rules"
|
|
:label-col="styleResponsive ? { md: 6, sm: 6, xs: 24 } : { flex: '90px' }"
|
|
:wrapper-col="
|
|
styleResponsive ? { md: 18, sm: 20, xs: 24 } : { flex: '1' }
|
|
"
|
|
>
|
|
<a-row :gutter="16">
|
|
<a-col
|
|
v-bind="styleResponsive ? { md: 22, sm: 24, xs: 24 } : { span: 12 }"
|
|
>
|
|
<a-form-item label="选择构件" name="projectName">
|
|
<TowerAccessory
|
|
:placeholder="`请选择构件`"
|
|
v-model:value="form.projectName"
|
|
@done="chooseProject"
|
|
/>
|
|
</a-form-item>
|
|
<a-form-item label="配件编号" name="accessoryNo">
|
|
<a-input
|
|
allow-clear
|
|
placeholder="请选择构件"
|
|
:disabled="true"
|
|
v-model:value="form.accessoryNo"
|
|
/>
|
|
</a-form-item>
|
|
<a-form-item label="配件分类" name="accessoryCategory">
|
|
<a-input
|
|
allow-clear
|
|
placeholder="请选择构件"
|
|
:disabled="true"
|
|
v-model:value="form.accessoryCategory"
|
|
/>
|
|
</a-form-item>
|
|
<a-form-item label="适用设备型号" name="accessoryModel">
|
|
<a-input
|
|
allow-clear
|
|
placeholder="请选择构件"
|
|
:disabled="true"
|
|
v-model:value="form.accessoryModel"
|
|
/>
|
|
</a-form-item>
|
|
|
|
<a-form-item label="配件规格" name="accessorySpecs">
|
|
<a-input
|
|
allow-clear
|
|
placeholder="请选择构件"
|
|
:disabled="true"
|
|
v-model:value="form.accessorySpecs"
|
|
/>
|
|
</a-form-item>
|
|
<a-form-item label="保养内容" name="comments">
|
|
<a-textarea
|
|
:rows="4"
|
|
:maxlength="200"
|
|
placeholder="请输入保养内容"
|
|
v-model:value="form.comments"
|
|
/>
|
|
</a-form-item>
|
|
</a-col>
|
|
</a-row>
|
|
</a-form>
|
|
</ele-modal>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { ref, reactive, watch } from 'vue';
|
|
import { message } from 'ant-design-vue/es';
|
|
import type { FormInstance, Rule } from 'ant-design-vue/es/form';
|
|
import { storeToRefs } from 'pinia';
|
|
import { useThemeStore } from '@/store/modules/theme';
|
|
import useFormData from '@/utils/use-form-data';
|
|
import type { Security } from '@/api/tower/security/model';
|
|
import { Accessory } from '@/api/tower/accessory/model';
|
|
import {
|
|
addSecurityPlant,
|
|
updateSecurityPlant
|
|
} from '@/api/tower/security-plant';
|
|
import { SecurityPlant } from '@/api/tower/security-plant/model';
|
|
|
|
// 是否开启响应式布局
|
|
const themeStore = useThemeStore();
|
|
const { styleResponsive } = storeToRefs(themeStore);
|
|
|
|
const emit = defineEmits<{
|
|
(e: 'done'): void;
|
|
(e: 'update:visible', visible: boolean): void;
|
|
}>();
|
|
|
|
const props = defineProps<{
|
|
// 弹窗是否打开
|
|
visible: boolean;
|
|
// 修改回显的数据
|
|
data?: Security | null;
|
|
}>();
|
|
|
|
const formRef = ref<FormInstance | null>(null);
|
|
// 是否是修改
|
|
const isUpdate = ref(false);
|
|
// 提交状态
|
|
const loading = ref(false);
|
|
|
|
// 表单数据
|
|
const { form, resetFields, assignFields } = useFormData<SecurityPlant>({
|
|
securityPlantId: undefined,
|
|
securityId: undefined,
|
|
projectId: undefined,
|
|
projectName: undefined,
|
|
securityCode: undefined,
|
|
accessoryCategory: undefined,
|
|
address: '',
|
|
status: 0,
|
|
sortNumber: 100
|
|
});
|
|
|
|
// 表单验证规则
|
|
const rules = reactive<Record<string, Rule[]>>({
|
|
projectName: [
|
|
{
|
|
required: true,
|
|
message: '请选择构件',
|
|
type: 'string',
|
|
trigger: 'blur'
|
|
}
|
|
],
|
|
model: [
|
|
{
|
|
required: true,
|
|
message: '请输入设备型号',
|
|
type: 'string',
|
|
trigger: 'blur'
|
|
}
|
|
],
|
|
yearLife: [
|
|
{
|
|
required: true,
|
|
message: '请输入设备使用年限',
|
|
type: 'number',
|
|
trigger: 'blur'
|
|
}
|
|
],
|
|
sortNumber: [
|
|
{
|
|
required: true,
|
|
message: '请输入排序号',
|
|
type: 'number',
|
|
trigger: 'blur'
|
|
}
|
|
]
|
|
});
|
|
|
|
/* 保存编辑 */
|
|
const save = () => {
|
|
if (!formRef.value) {
|
|
return;
|
|
}
|
|
formRef.value
|
|
.validate()
|
|
.then(() => {
|
|
loading.value = true;
|
|
const categoryForm = {
|
|
...form
|
|
};
|
|
const saveOrUpdate = isUpdate.value
|
|
? updateSecurityPlant
|
|
: addSecurityPlant;
|
|
saveOrUpdate(categoryForm)
|
|
.then((msg) => {
|
|
loading.value = false;
|
|
message.success(msg);
|
|
updateVisible(false);
|
|
emit('done');
|
|
})
|
|
.catch((e) => {
|
|
loading.value = false;
|
|
message.error(e.message);
|
|
});
|
|
})
|
|
.catch(() => {});
|
|
};
|
|
|
|
/* 更新visible */
|
|
const updateVisible = (value: boolean) => {
|
|
emit('update:visible', value);
|
|
};
|
|
|
|
const chooseProject = (row: Accessory) => {
|
|
form.projectId = row.accessoryId;
|
|
form.projectName = row.accessoryName;
|
|
form.securityId = row.accessoryId;
|
|
form.accessoryNo = row.accessoryNo;
|
|
form.accessorySpecs = row.accessorySpecs;
|
|
form.accessoryModel = row.accessoryModel;
|
|
form.accessoryCategory = row.accessoryCategory;
|
|
};
|
|
|
|
watch(
|
|
() => props.visible,
|
|
(visible) => {
|
|
if (visible) {
|
|
if (props.data) {
|
|
assignFields({
|
|
...props.data
|
|
});
|
|
isUpdate.value = true;
|
|
} else {
|
|
isUpdate.value = false;
|
|
}
|
|
} else {
|
|
resetFields();
|
|
formRef.value?.clearValidate();
|
|
}
|
|
}
|
|
);
|
|
</script>
|
|
|
|
<style lang="less">
|
|
.tab-pane {
|
|
min-height: 300px;
|
|
}
|
|
.ml-10 {
|
|
margin-left: 5px;
|
|
}
|
|
</style>
|