Commit a11effeb67a8b573947a8c1ba2a4c34634f0d11d
1 parent
c62f707b
fix: 客户需求改为多选
Showing
2 changed files
with
49 additions
and
12 deletions
src/pages/Client/Client/Components/ClientDrawer.tsx
@@ -6,7 +6,6 @@ import { | @@ -6,7 +6,6 @@ import { | ||
6 | postDistrictSelectByNameAndLevel, | 6 | postDistrictSelectByNameAndLevel, |
7 | postDistrictSelOrderProvince, | 7 | postDistrictSelOrderProvince, |
8 | postServiceConstClientLevels, | 8 | postServiceConstClientLevels, |
9 | - postServiceConstClientRequirements, | ||
10 | postServiceConstClientSource, | 9 | postServiceConstClientSource, |
11 | postServiceConstTradeStatus, | 10 | postServiceConstTradeStatus, |
12 | } from '@/services'; | 11 | } from '@/services'; |
@@ -24,6 +23,12 @@ import { useState } from 'react'; | @@ -24,6 +23,12 @@ import { useState } from 'react'; | ||
24 | 23 | ||
25 | export default ({ optType, record, onFinish }) => { | 24 | export default ({ optType, record, onFinish }) => { |
26 | const [form] = Form.useForm(); | 25 | const [form] = Form.useForm(); |
26 | + const requirementsEnum = { | ||
27 | + EXPERIMENTAL_EQUIPMENT: '实验设备', | ||
28 | + EXPERIMENTAL_MATERIALS: '实验材料', | ||
29 | + OTHER: '其他', | ||
30 | + PILOT_TEST_VALIDATION_SERVICES: '中式验证服务', | ||
31 | + }; | ||
27 | //省市区 | 32 | //省市区 |
28 | const [province, setProvince] = useState(''); | 33 | const [province, setProvince] = useState(''); |
29 | const [city, setCity] = useState(''); | 34 | const [city, setCity] = useState(''); |
@@ -87,6 +92,20 @@ export default ({ optType, record, onFinish }) => { | @@ -87,6 +92,20 @@ export default ({ optType, record, onFinish }) => { | ||
87 | // 在这里可以添加其他逻辑,比如根据选择更新其他表单项的值 | 92 | // 在这里可以添加其他逻辑,比如根据选择更新其他表单项的值 |
88 | }; | 93 | }; |
89 | 94 | ||
95 | + // MODIFIED: 增加处理非 JSON 格式字符串的逻辑 | ||
96 | + const parsedRecord = record | ||
97 | + ? { | ||
98 | + ...record, | ||
99 | + requirements: (() => { | ||
100 | + try { | ||
101 | + return JSON.parse(record.requirements); // 尝试解析 JSON | ||
102 | + } catch (error) { | ||
103 | + return record.requirements ? record.requirements.split(',') : []; // 如果不是 JSON,则按逗号分隔字符串 | ||
104 | + } | ||
105 | + })(), | ||
106 | + } | ||
107 | + : {}; // 如果 record 为空,返回一个空对象 | ||
108 | + | ||
90 | return ( | 109 | return ( |
91 | <DrawerForm | 110 | <DrawerForm |
92 | title={optTypeEnum[optType].text} | 111 | title={optTypeEnum[optType].text} |
@@ -97,7 +116,7 @@ export default ({ optType, record, onFinish }) => { | @@ -97,7 +116,7 @@ export default ({ optType, record, onFinish }) => { | ||
97 | maxWidth: window.innerWidth * 0.8, | 116 | maxWidth: window.innerWidth * 0.8, |
98 | minWidth: 300, | 117 | minWidth: 300, |
99 | }} | 118 | }} |
100 | - initialValues={record} | 119 | + initialValues={parsedRecord} |
101 | form={form} | 120 | form={form} |
102 | trigger={optTypeEnum[optType].button} | 121 | trigger={optTypeEnum[optType].button} |
103 | autoFocusFirstInput | 122 | autoFocusFirstInput |
@@ -345,20 +364,22 @@ export default ({ optType, record, onFinish }) => { | @@ -345,20 +364,22 @@ export default ({ optType, record, onFinish }) => { | ||
345 | name="requirements" | 364 | name="requirements" |
346 | label="客户需求" | 365 | label="客户需求" |
347 | placeholder="请输入客户需求" | 366 | placeholder="请输入客户需求" |
348 | - // fieldProps={{ | ||
349 | - // mode: 'multiple', | ||
350 | - // }} | 367 | + valueEnum={requirementsEnum} |
368 | + fieldProps={{ | ||
369 | + mode: 'multiple', | ||
370 | + }} | ||
351 | rules={[ | 371 | rules={[ |
352 | { | 372 | { |
353 | required: true, | 373 | required: true, |
354 | message: '请输入客户需求', | 374 | message: '请输入客户需求', |
355 | - // type: 'array', | 375 | + type: 'array', |
356 | }, | 376 | }, |
357 | ]} | 377 | ]} |
358 | - request={async () => { | ||
359 | - const res = await postServiceConstClientRequirements(); | ||
360 | - return enumToSelect(res.data); | ||
361 | - }} | 378 | + // request={async () => { |
379 | + // const res = await postServiceConstClientRequirements(); | ||
380 | + // console.log(res.data, '5656require'); | ||
381 | + // return enumToSelect(res.data); | ||
382 | + // }} | ||
362 | /> | 383 | /> |
363 | <ProFormSelect | 384 | <ProFormSelect |
364 | name="hasScheme" | 385 | name="hasScheme" |
@@ -403,7 +424,17 @@ export default ({ optType, record, onFinish }) => { | @@ -403,7 +424,17 @@ export default ({ optType, record, onFinish }) => { | ||
403 | ]} | 424 | ]} |
404 | request={async () => { | 425 | request={async () => { |
405 | const res = await postServiceConstClientLevels(); | 426 | const res = await postServiceConstClientLevels(); |
406 | - return enumToSelect(res.data); | 427 | + function enumToSelectLevel(data: any) { |
428 | + const order = [ | ||
429 | + 'PRIMARY_CLIENT', | ||
430 | + 'SECONDARY_CLIENT', | ||
431 | + 'TERTIARY_CLIENT', | ||
432 | + ]; | ||
433 | + return order.map((key) => { | ||
434 | + return { label: data[key], value: key }; | ||
435 | + }); | ||
436 | + } | ||
437 | + return enumToSelectLevel(res.data); | ||
407 | }} | 438 | }} |
408 | /> | 439 | /> |
409 | <ProFormSelect | 440 | <ProFormSelect |
src/pages/Client/Client/index.tsx
@@ -87,7 +87,7 @@ const columns = [ | @@ -87,7 +87,7 @@ const columns = [ | ||
87 | }, | 87 | }, |
88 | { | 88 | { |
89 | title: '客户需求', | 89 | title: '客户需求', |
90 | - width: 150, | 90 | + width: 240, |
91 | ellipsis: true, | 91 | ellipsis: true, |
92 | dataIndex: 'requirementsText', | 92 | dataIndex: 'requirementsText', |
93 | hideInSearch: true, | 93 | hideInSearch: true, |
@@ -99,6 +99,12 @@ const columns = [ | @@ -99,6 +99,12 @@ const columns = [ | ||
99 | hideInTable: true, | 99 | hideInTable: true, |
100 | request: async () => { | 100 | request: async () => { |
101 | const res = await postServiceConstClientRequirements(); | 101 | const res = await postServiceConstClientRequirements(); |
102 | + // function enumToSelect(data: any) { | ||
103 | + // const keys = Object.keys(data); | ||
104 | + // return keys.map((value) => { | ||
105 | + // return { label: data[value], value: value }; | ||
106 | + // }); | ||
107 | + // } | ||
102 | return enumToSelect(res.data); | 108 | return enumToSelect(res.data); |
103 | }, | 109 | }, |
104 | }, | 110 | }, |