zhengyiming
7 小时以前 97f29024ce18babeb4b635c5d73f907ac493976e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<template>
  <ProDialog
    :title="form.title"
    v-model="visible"
    @close="onDialogClose"
    destroy-on-close
    draggable
  >
    <ProForm :model="form" ref="dialogForm" label-width="120px">
      <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"
          :convertEnumValue="false"
        />
      </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"
          :value-on-clear="0"
        ></ProFormInputNumber>
      </ProFormItemV2>
      <ProFormItemV2 label="编号:" prop="code" :check-rules="[{ message: '请输入编号' }]">
        <ProFormText v-model.trim="form.code" :disabled="!!form.id"></ProFormText>
      </ProFormItemV2>
      <template v-if="category?.data?.code === CategoryCode.ElectronSignParam">
        <ProFormItemV2
          label="参数字段名:"
          prop="field3"
          :check-rules="[{ message: '请输入参数字段名' }]"
        >
          <ProFormText v-model.trim="form.field3" placeholder="请输入参数字段名"></ProFormText>
        </ProFormItemV2>
        <ProFormItemV2
          label="绑定字段名:"
          prop="field4"
          :check-rules="[{ message: '请输入绑定字段名' }]"
        >
          <ProFormText v-model.trim="form.field4" placeholder="请输入绑定字段名"></ProFormText>
        </ProFormItemV2>
      </template>
 
      <ProFormItemV2
        label="图片:"
        prop="field2"
        v-if="category?.data?.code === CategoryCode.Welfare"
        :check-rules="[{ type: 'upload', message: '请上传图片' }]"
      >
        <ProFormImageUpload v-model:file-url="form.field2" :limitFileCount="1"></ProFormImageUpload>
      </ProFormItemV2>
      <ProFormItemV2 label="状态:" prop="isDisabled" required>
        <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 = {
  title?: string;
  id?: string;
  categoryId: string;
  content: string;
  code: string;
  sort: number;
  isDisabled: boolean;
  field1?: string;
  field2?: UploadUserFile[];
  field3?: string;
  field4?: string;
};
 
const form = defineModel<Form>('form');
const visible = defineModel<boolean>('modelValue');
 
const { getDictionaryCategoryById } = useGetDictionaryCategorySelect();
 
const { dictionaryDataList } = useDictionaryDataSelect({
  categoryCode: computed(() => CategoryCode.IndustryCategory),
});
 
const category = computed(() => {
  return getDictionaryCategoryById(form.value.categoryId);
});
 
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>