wms-antdvue/.svn/pristine/8c/8c1325b03cd88f30402393b4484954df333c7682.svn-base
2024-11-07 16:33:03 +08:00

113 lines
2.9 KiB
Plaintext

<template>
<a-modal
v-model:visible="props.visible"
:title="props.dictId ? '编辑' : '新增'"
width="500px"
@cancel="dialogClose"
>
<a-form
class="ls-form"
ref="formRef"
:model="formData"
:label-col="{ style: { width: '80px' } }"
>
<a-form-item
label="字典名称"
name="name"
:rules="{ required: true, message: '请输入字典名称', trigger: 'blur' }"
>
<a-input v-model:value="formData.name" placeholder="请输入字典名称" allow-clear />
</a-form-item>
<a-form-item
label="字典编码"
name="code"
:rules="{ required: true, message: '请输入字典编码', trigger: 'blur' }"
>
<a-input
v-model:value="formData.code"
:disabled="props.dictId"
placeholder="请输入字典编码"
allow-clear
/>
</a-form-item>
<a-form-item label="排序" name="sort">
<a-input-number v-model:value="formData.sort" />
</a-form-item>
<a-form-item label="备注" name="note">
<a-input
v-model:value="formData.note"
type="textarea"
placeholder="请输入备注"
allow-clear
/>
</a-form-item>
</a-form>
<template #footer>
<span class="dialog-footer">
<a-button @click="dialogClose">取消</a-button>
<a-button :loading="subLoading" type="primary" @click="submit"> 确定 </a-button>
</span>
</template>
</a-modal>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'ant-design-vue';
import { dictAdd, dictUpdate, getDictDetail } from '@/api/data/dictionary';
import { onMounted, reactive, shallowRef } from 'vue';
import { message } from 'ant-design-vue';
import { useLockFn } from '@/utils/useLockFn';
const emit = defineEmits(['success', 'update:visible']);
const formRef = shallowRef<FormInstance>();
const formData = reactive({
id: '',
name: '',
code: '',
sort: 0,
note: '',
});
const props = defineProps({
visible: {
type: Boolean,
required: true,
default: false,
},
dictId: {
type: Number,
required: true,
default: 0,
},
});
const handleSubmit = async () => {
await formRef.value?.validate();
props.dictId ? await dictUpdate(formData) : await dictAdd(formData);
message.success('操作成功');
emit('update:visible', false);
emit('success');
};
const dialogClose = () => {
emit('update:visible', false);
};
const { isLock: subLoading, lockFn: submit } = useLockFn(handleSubmit);
const setFormData = async () => {
const data = await getDictDetail(props.dictId);
for (const key in formData) {
if (data[key] != null && data[key] != undefined) {
//@ts-ignore
formData[key] = data[key];
}
}
};
onMounted(() => {
if (props.dictId) {
setFormData();
}
});
</script>