Sanakey
3 天以前 b5c1614fe473330ceca8b7cff0f1802e19bd5039
提交 | 用户 | age
f353bc 1 <template>
S 2   <BasicDrawer
3     v-bind="$attrs"
4     title="新建客户"
5     @register="registerDrawer"
6     :maskClosable="false"
7     :keyboard="false"
8     width="860px"
9     showFooter
10     @ok="handleSubmit"
11   >
12     <template #title>
13       <div class="flex flex-justify-between">
14         <div>{{ getTitle }}</div>
15         <div class="text-right">
16         <span>
b5c161 17 <!--          <Tooltip title="已关注">-->
S 18 <!--            <Icon-->
19 <!--              icon="mingcute:heart-fill"-->
20 <!--              class="mr-15px cursor-pointer"-->
21 <!--              @click=""-->
22 <!--              :size="20"-->
23 <!--            />-->
24 <!--          </Tooltip>-->
f353bc 25           <Tooltip title="未关注">
S 26             <Icon
27               icon="mingcute:heart-line"
28               class="mr-15px cursor-pointer"
29               @click=""
30               :size="20"
31             />
32           </Tooltip>
33         </span>
34
35         </div>
36       </div>
37
38     </template>
39 <!--    <Content :schemas="schemas"></Content>-->
40     <div :class="prefixCls">
41       <Row :class="`${prefixCls}-top`">
42         <Col :span="11" :class="`${prefixCls}-col`">
b5c161 43           <div class="mb-10px font-size-16px">公司常用信息</div>
f353bc 44           <div class="pt-3px pr-3px">
S 45             <BasicForm @register="registerForm" :model="modelRef" />
46           </div>
47         </Col>
48         <Col :span="11" :offset="2" :class="`${prefixCls}-col`">
49           <div class="mb-10px font-size-16px">联系人</div>
50           <div class="p-10px bg-gray-1">
51             <BasicForm @register="registerForm2" />
52           </div>
53         </Col>
54       </Row>
55
56     </div>
57   </BasicDrawer>
58 </template>
59 <script lang="ts" setup>
60   // import {  useForm } from '@/components/Form';
61   // import { formSchema } from './drawerData';
62   import {BasicDrawer, useDrawerInner} from '@/components/Drawer';
63   import Icon from "@/components/Icon/Icon.vue";
64   import {Alert, Col, Row, Tooltip} from "ant-design-vue";
65   // import Content from "./drawer-form/index.vue";
66   import {computed, ref, unref} from "vue";
67   import {getMenuList} from "@/api/demo/system";
68   import {TreeItem} from "@/components/Tree";
69   import {BasicForm, useForm} from "@/components/Form";
70   import {schemas} from './drawerFormData'
71   import {schemas as schemas2} from './drawerContacterFormData'
72
73   const emit = defineEmits(['success', 'register']);
74   const isUpdate = ref(true);
b5c161 75   const getTitle = computed(() => (!unref(isUpdate) ? '新建客户' : '编辑客户'));
f353bc 76
S 77   // const [registerForm, { setFieldsValue, }] = useForm({
78   //   labelWidth: 90,
79   //   baseColProps: { span: 24 },
80   //   schemas: formSchema,
81   //   showActionButtonGroup: false,
82   // });
83
84   // const [registerDrawer] = useDrawer();
85
86   const modelRef = ref({});
87   // 左侧表单
88   const [
89     registerForm,
90     { resetFields, setFieldsValue, validate }
91     // {
92     //   // setFieldsValue,
93     //   // setProps
94     // },
95   ] = useForm({
96     layout: 'vertical',
97     // labelWidth: 100,
98     showAdvancedButton: true, //开启折叠
99     autoAdvancedLine: 9, // 超过多少行折叠
100     alwaysShowLines: 8, // 始终显示多少行
101     schemas,
102     // showActionButtonGroup: false, // 默认显示操作按钮,开启才会显示折叠按钮
103     showResetButton:false, // 隐藏重置按钮
104     showSubmitButton:false,  // 隐藏提交按钮
105     actionColOptions: {
106       span: 24,
107     },
108   });
109
110   // 右侧表单
111   const [
112     registerForm2,
113     { resetFields:resetFields2, setFieldsValue:setFieldsValue2, validate:validate2 }
114     // {
115     //   // setFieldsValue,
116     //   // setProps
117     // },
118   ] = useForm({
119     layout: 'vertical',
120     // labelWidth: 100,
121     showAdvancedButton: true, //开启折叠
122     autoAdvancedLine: 5, // 超过多少行折叠
123     alwaysShowLines: 4, // 始终显示多少行
124     schemas:schemas2,
125     // showActionButtonGroup: false, // 默认显示操作按钮,开启才会显示折叠按钮
126     showResetButton:false, // 隐藏重置按钮
127     showSubmitButton:false,  // 隐藏提交按钮
128     actionColOptions: {
129       span: 24,
130     },
131   });
132
133
134   const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
135     Logger.log('打开了DrawerForm', data);
136     isUpdate.value = !!data?.isUpdate;
137     // // 方式1
138     // setFieldsValue({
139     //   field2: data.data,
140     //   field1: data.info,
141     // });
142
143     // setDrawerProps({ confirmLoading: true });
144     // setTimeout(() => {
145     //   setDrawerProps({ confirmLoading: false });
146     // }, 1000);
147
148     resetFields();
149     resetFields2();
150     if (unref(isUpdate)) {
151       setFieldsValue({
152         ...data.record,
153       });
154       setFieldsValue2({
155         ...data.record,
156       });
157     }
158   });
159
160
161   async function handleSubmit() {
162   try {
163     // const values = await validate();
164     const [values, values2] = await Promise.all([validate(), validate2()]);
165
166     // const values = getFieldsValue();
167     Logger.log('点击submit 左侧表单values:',values);
168     Logger.log('点击submit 右侧表单values2:', values2);
169     setDrawerProps({ confirmLoading: true });
170     // TODO custom api
171
172     closeDrawer();
173     emit('success');
174   } finally {
175     setDrawerProps({ confirmLoading: false });
176   }
177 }
178
179
180
181
182   const prefixCls = 'clues-drawer';
183   // 关闭提示信息
184   const visible = ref<boolean>(true);
185   const handleClose = () => {
186     visible.value = false;
187   };
188 </script>