<template>
|
<ProDialog
|
:title="`${title}类别`"
|
v-model="visible"
|
@close="onDialogClose"
|
destroy-on-close
|
draggable
|
>
|
<ProForm :model="form" ref="dialogForm" label-width="90px">
|
<ProFormItemV2
|
label="行业类型:"
|
prop="field1"
|
v-if="category?.data?.code === CategoryCode.Position"
|
:check-rules="[{ message: '请选择行业类型' }]"
|
>
|
<ProFormSelect
|
v-model="form.field1"
|
:value-enum="dictionaryDataList"
|
enum-value-key="code"
|
/>
|
</ProFormItemV2>
|
<ProFormItemV2 label="名称:" prop="content" :check-rules="[{ message: '请输入名称' }]">
|
<ProFormText
|
placeholder="请输入名称"
|
v-model.trim="form.content"
|
:maxlength="15"
|
></ProFormText>
|
</ProFormItemV2>
|
<ProFormItemV2 label="排序:" prop="sort">
|
<ProFormInputNumber
|
v-model="form.sort"
|
:controls="false"
|
:min="0"
|
:max="999999"
|
></ProFormInputNumber>
|
</ProFormItemV2>
|
<ProFormItemV2 label="编号:" prop="code">
|
<ProFormText v-model.trim="form.code"></ProFormText>
|
</ProFormItemV2>
|
<ProFormItemV2 label="图片:" prop="src" v-if="category?.data?.code === CategoryCode.Welfare">
|
<ProFormImageUpload v-model:file-url="form.field2" :limitFileCount="1"></ProFormImageUpload>
|
</ProFormItemV2>
|
<ProFormItemV2 label="状态:" prop="status">
|
<ProFormRadio
|
v-model="form.isDisabled"
|
:value-enum="[
|
{ label: '启用', value: false },
|
{ label: '禁用', value: true },
|
]"
|
></ProFormRadio>
|
</ProFormItemV2>
|
</ProForm>
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button @click="emit('onCancel')">取 消</el-button>
|
<el-button type="primary" @click="handleConfirm">确 定</el-button>
|
</span>
|
</template>
|
</ProDialog>
|
</template>
|
|
<script setup lang="ts">
|
import { FormInstance } from 'element-plus';
|
import {
|
ProDialog,
|
ProForm,
|
ProFormItemV2,
|
ProFormText,
|
ProFormInputNumber,
|
ProFormSelect,
|
ProFormRadio,
|
UploadUserFile,
|
ProFormImageUpload,
|
} from '@bole-core/components';
|
import { useDictionaryDataSelect, useGetDictionaryCategorySelect } from '@/hooks';
|
import { CategoryCode } from '@/constants';
|
|
defineOptions({
|
name: 'AddOrEditDictionaryDialog',
|
});
|
|
type Form = {
|
id?: string;
|
categoryId: string;
|
content: string;
|
code: string;
|
sort: number;
|
isDisabled: boolean;
|
field1?: string;
|
field2?: UploadUserFile[];
|
};
|
|
const form = defineModel<Form>('form');
|
const visible = defineModel<boolean>('modelValue');
|
|
const title = computed(() => (form.value.id ? '编辑' : '新增'));
|
|
const { getDictionaryCategoryById } = useGetDictionaryCategorySelect();
|
|
const { dictionaryDataList, refetch, getDictionaryDataNameById } = useDictionaryDataSelect({
|
categoryCode: computed(() => CategoryCode.IndustryCategory),
|
});
|
|
const category = computed(() => {
|
return getDictionaryCategoryById(form.value.categoryId);
|
});
|
|
watch(
|
() => visible.value,
|
(value) => {
|
if (value) {
|
refetch();
|
}
|
},
|
{
|
immediate: true,
|
}
|
);
|
|
const emit = defineEmits<{
|
(e: 'onConfirm'): void;
|
(e: 'onCancel'): void;
|
}>();
|
|
const dialogForm = ref<FormInstance>();
|
|
function onDialogClose() {
|
if (!dialogForm.value) return;
|
dialogForm.value.resetFields();
|
}
|
|
function handleConfirm() {
|
if (!dialogForm.value) return;
|
dialogForm.value.validate((valid) => {
|
if (valid) {
|
emit('onConfirm');
|
} else {
|
return;
|
}
|
});
|
}
|
</script>
|