1
0

edit.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. import React, { useEffect, useState } from 'react';
  2. import {
  3. Cascader,
  4. Col,
  5. DatePicker,
  6. Form,
  7. Input,
  8. InputNumber,
  9. Modal,
  10. Row,
  11. Select,
  12. message,
  13. } from 'antd';
  14. import { cityQuery, createReporting, editReporting } from '@/services/ReportingManagement';
  15. import moment from 'moment';
  16. import UploadCommon from '@/components/UploadImage';
  17. interface userEditPros {
  18. visible: boolean;
  19. editCallback: () => void;
  20. detailData: any;
  21. }
  22. const { TextArea } = Input;
  23. /**
  24. * 报备编辑页面
  25. * @param props
  26. * @constructor
  27. */
  28. const Edit: React.FC<userEditPros> = (props) => {
  29. const { visible, editCallback, detailData } = props;
  30. const [form] = Form.useForm();
  31. const [cityList, setCityList] = useState([]);
  32. const [filesList, setFilesList] = useState([]);
  33. // 获取城市列表
  34. const getCityList = () => {
  35. cityQuery({ q: 'tree' }).then((res) => {
  36. if (res?.code === 0) {
  37. const arr = res?.data?.list;
  38. setCityList(arr);
  39. }
  40. });
  41. };
  42. useEffect(() => {
  43. getCityList();
  44. }, []);
  45. const onOk = () => {
  46. form.validateFields().then((values) => {
  47. if (values) {
  48. const data = { ...values };
  49. if (values.success_probability) {
  50. data.success_probability = values.success_probability.toString();
  51. }
  52. if (values.success_probability_analysis) {
  53. data.success_probability_analysis = values.success_probability_analysis;
  54. }
  55. if (values.planned_fixture_date) {
  56. data.planned_fixture_date = moment(values.planned_fixture_date).format('YYYY-MM-DD');
  57. }
  58. if (values.files && values.files.length) {
  59. data.files = filesList;
  60. }
  61. if (detailData) {
  62. data.record_id = detailData.record_id;
  63. const cityInfo = values.city
  64. .split('')
  65. .filter((x: { charCodeAt: () => number }) => x.charCodeAt() != 32)
  66. .join('')
  67. .split('/');
  68. data.province = cityInfo[0];
  69. data.city = cityInfo[1];
  70. data.district = cityInfo[2];
  71. editReporting(data)
  72. .then((res) => {
  73. if (res && res.code === 0) {
  74. message.success('编辑成功');
  75. editCallback();
  76. } else {
  77. message.error('编辑失败');
  78. }
  79. })
  80. .catch((e) => {
  81. message.error(e?.message);
  82. });
  83. } else {
  84. data.province = values.city[0];
  85. data.city = values.city[1];
  86. data.district = values.city[2];
  87. createReporting(data)
  88. .then((res) => {
  89. if (res && res.code === 0) {
  90. message.success('新增成功');
  91. editCallback();
  92. } else {
  93. message.error('新增失败');
  94. }
  95. })
  96. .catch((e) => {
  97. message.error(e?.message);
  98. });
  99. }
  100. }
  101. });
  102. };
  103. // 上传图片回调
  104. const onUploadChange = (files: any) => {
  105. if (files && files.length) {
  106. const arr: any = [];
  107. files.forEach((el: any) => {
  108. arr.push({ url: el?.response?.data?.url || '' });
  109. });
  110. setFilesList(arr);
  111. }
  112. };
  113. const onCancel = () => {
  114. editCallback();
  115. };
  116. const formItemLayout = {
  117. labelCol: {
  118. span: 7,
  119. },
  120. wrapperCol: {
  121. span: 15,
  122. },
  123. };
  124. const formItemLayoutTwo = {
  125. labelCol: {
  126. span: 4,
  127. },
  128. wrapperCol: {
  129. span: 19,
  130. },
  131. };
  132. return (
  133. <Modal
  134. title={`${detailData ? '编辑' : '新增'}`}
  135. open={visible}
  136. onOk={onOk}
  137. onCancel={onCancel}
  138. width={800}
  139. >
  140. <Form form={form}>
  141. <Row>
  142. <Col span={12}>
  143. <Form.Item
  144. {...formItemLayout}
  145. name="project_name"
  146. label="工程名称"
  147. rules={[{ required: true, message: '请输入工程名称' }]}
  148. initialValue={detailData?.project_name || ''}
  149. >
  150. <Input placeholder="请输入工程名称" />
  151. </Form.Item>
  152. </Col>
  153. <Col span={12}>
  154. <Form.Item
  155. {...formItemLayout}
  156. name="city"
  157. label="城市"
  158. rules={[{ required: true, message: '请选择城市' }]}
  159. initialValue={
  160. detailData && JSON.stringify(detailData) !== '{}'
  161. ? `${detailData?.province}` +
  162. ' / ' +
  163. `${detailData?.city}` +
  164. ' / ' +
  165. `${detailData?.district}`
  166. : ''
  167. }
  168. >
  169. <Cascader
  170. options={cityList}
  171. fieldNames={{ label: 'name', value: 'name', children: 'children' }}
  172. placeholder="请选择城市"
  173. />
  174. </Form.Item>
  175. </Col>
  176. <Col span={12}>
  177. <Form.Item
  178. {...formItemLayout}
  179. name="street"
  180. label="街道"
  181. rules={[{ required: true, message: '请输入街道' }]}
  182. initialValue={detailData?.street || ''}
  183. >
  184. <Input placeholder="请输入街道" />
  185. </Form.Item>
  186. </Col>
  187. <Col span={12}>
  188. <Form.Item
  189. {...formItemLayout}
  190. name="rode"
  191. label="路"
  192. rules={[{ required: true, message: '请输入路' }]}
  193. initialValue={detailData?.rode || ''}
  194. >
  195. <Input placeholder="请输入路" />
  196. </Form.Item>
  197. </Col>
  198. <Col span={12}>
  199. <Form.Item
  200. {...formItemLayout}
  201. name="residence"
  202. label="小区"
  203. rules={[{ required: true, message: '请输入小区' }]}
  204. initialValue={detailData?.residence || ''}
  205. >
  206. <Input placeholder="请输入小区" />
  207. </Form.Item>
  208. </Col>
  209. <Col span={12}>
  210. <Form.Item
  211. {...formItemLayout}
  212. name="doorplate"
  213. label="门牌"
  214. rules={[{ required: true, message: '请输入门牌' }]}
  215. initialValue={detailData?.doorplate || ''}
  216. >
  217. <Input placeholder="请输入门牌" />
  218. </Form.Item>
  219. </Col>
  220. <Col span={24}>
  221. <Form.Item
  222. {...formItemLayoutTwo}
  223. name="address"
  224. label="详细地址"
  225. rules={[{ required: true, message: '请输入详细地址' }]}
  226. initialValue={detailData?.address || ''}
  227. >
  228. <TextArea rows={4} placeholder="请输入详细地址" />
  229. </Form.Item>
  230. </Col>
  231. <Col span={12}>
  232. <Form.Item
  233. {...formItemLayout}
  234. name="area"
  235. label="建筑面积"
  236. rules={[{ required: true, message: '请输入建筑面积' }]}
  237. initialValue={detailData?.area || ''}
  238. >
  239. <Input placeholder="请输入建筑面积" />
  240. </Form.Item>
  241. </Col>
  242. <Col span={12}>
  243. <Form.Item
  244. {...formItemLayout}
  245. name="bidding_form"
  246. label="招标形式"
  247. rules={[{ required: true, message: '请选择招标形式' }]}
  248. initialValue={detailData?.bidding_form || undefined}
  249. >
  250. <Select
  251. placeholder="请选择招标形式"
  252. options={[
  253. {
  254. value: '1',
  255. label: '内部仪标',
  256. },
  257. {
  258. value: '2',
  259. label: '公开招标',
  260. },
  261. {
  262. value: '3',
  263. label: '提供方案书',
  264. },
  265. ]}
  266. />
  267. </Form.Item>
  268. </Col>
  269. <Col span={12}>
  270. <Form.Item
  271. {...formItemLayout}
  272. name="project_effect"
  273. label="项目用途"
  274. rules={[{ required: true, message: '请选择项目用途' }]}
  275. initialValue={detailData?.project_effect || undefined}
  276. >
  277. <Select
  278. placeholder="请选择项目用途"
  279. options={[
  280. {
  281. value: '1',
  282. label: '酒店餐饮',
  283. },
  284. {
  285. value: '2',
  286. label: '商务办公',
  287. },
  288. {
  289. value: '3',
  290. label: '政府项目',
  291. },
  292. {
  293. value: '4',
  294. label: '工矿企业',
  295. },
  296. {
  297. value: '5',
  298. label: '文教卫生',
  299. },
  300. {
  301. value: '6',
  302. label: '商业建筑',
  303. },
  304. {
  305. value: '7',
  306. label: '房产配套',
  307. },
  308. {
  309. value: '8',
  310. label: '其他',
  311. },
  312. ]}
  313. />
  314. </Form.Item>
  315. </Col>
  316. <Col span={12}>
  317. <Form.Item
  318. {...formItemLayout}
  319. name="project_progress"
  320. label="工程进展"
  321. rules={[{ required: true, message: '请选择工程进展' }]}
  322. initialValue={detailData?.project_progress || undefined}
  323. >
  324. <Select
  325. placeholder="请选择工程进展"
  326. options={[
  327. {
  328. value: '1',
  329. label: '了解信息',
  330. },
  331. {
  332. value: '2',
  333. label: '确认经销商',
  334. },
  335. {
  336. value: '3',
  337. label: '方案报价',
  338. },
  339. {
  340. value: '4',
  341. label: '邀请招标',
  342. },
  343. {
  344. value: '5',
  345. label: '投标询价',
  346. },
  347. {
  348. value: '6',
  349. label: '价格竞争',
  350. },
  351. {
  352. value: '7',
  353. label: '商务谈判',
  354. },
  355. {
  356. value: '8',
  357. label: '合同准备',
  358. },
  359. {
  360. value: '9',
  361. label: '收到定金',
  362. },
  363. ]}
  364. />
  365. </Form.Item>
  366. </Col>
  367. <Col span={12}>
  368. <Form.Item
  369. {...formItemLayout}
  370. name="air_conditioner_type"
  371. label="空调类型"
  372. rules={[{ required: true, message: '请选择空调类型' }]}
  373. initialValue={detailData?.air_conditioner_type || undefined}
  374. >
  375. <Select
  376. placeholder="请选择空调类型"
  377. options={[
  378. {
  379. value: '1',
  380. label: '组合式方案',
  381. },
  382. {
  383. value: '2',
  384. label: '供暖机组',
  385. },
  386. {
  387. value: '3',
  388. label: '雅居多联机',
  389. },
  390. {
  391. value: '4',
  392. label: '多联机系列',
  393. },
  394. {
  395. value: '5',
  396. label: '螺杆机系列',
  397. },
  398. {
  399. value: '6',
  400. label: '热水机系列',
  401. },
  402. {
  403. value: '7',
  404. label: '离心机系列',
  405. },
  406. {
  407. value: '8',
  408. label: '地源热泵',
  409. },
  410. {
  411. value: '9',
  412. label: '模块机系列',
  413. },
  414. ]}
  415. />
  416. </Form.Item>
  417. </Col>
  418. <Col span={12}>
  419. <Form.Item
  420. {...formItemLayout}
  421. name="contact_person"
  422. label="甲方联系人"
  423. rules={[{ required: true, message: '请输入甲方联系人' }]}
  424. initialValue={detailData?.contact_person || ''}
  425. >
  426. <Input placeholder="请输入甲方联系人" />
  427. </Form.Item>
  428. </Col>
  429. <Col span={12}>
  430. <Form.Item
  431. {...formItemLayout}
  432. name="phone"
  433. label="联系方式"
  434. rules={[{ required: true, message: '请输入联系方式' }]}
  435. initialValue={detailData?.phone || ''}
  436. >
  437. <Input placeholder="请输入联系方式" />
  438. </Form.Item>
  439. </Col>
  440. <Col span={12}>
  441. <Form.Item
  442. {...formItemLayout}
  443. name="planned_fixture_date"
  444. label="计划成交日期"
  445. rules={[{ required: true, message: '请输入计划成交日期' }]}
  446. initialValue={
  447. detailData?.planned_fixture_date ? moment(detailData?.planned_fixture_date) : ''
  448. }
  449. >
  450. <DatePicker style={{ width: '235px' }} />
  451. </Form.Item>
  452. </Col>
  453. <Col span={12}>
  454. <Form.Item
  455. {...formItemLayout}
  456. name="follow_people"
  457. label="跟进人"
  458. rules={[{ required: true, message: '请输入跟进人' }]}
  459. initialValue={detailData?.follow_people || ''}
  460. >
  461. <Input placeholder="请输入跟进人" />
  462. </Form.Item>
  463. </Col>
  464. <Col span={12}>
  465. <Form.Item
  466. {...formItemLayout}
  467. name="success_probability"
  468. label="成功几率"
  469. rules={[{ required: true, message: '请输入成功几率' }]}
  470. initialValue={detailData?.success_probability || ''}
  471. >
  472. <InputNumber
  473. min={0}
  474. max={100}
  475. placeholder="请输入成功几率"
  476. addonAfter="%"
  477. style={{ width: '235px' }}
  478. />
  479. </Form.Item>
  480. </Col>
  481. <Col span={24}>
  482. <Form.Item
  483. {...formItemLayoutTwo}
  484. name="success_probability_analysis"
  485. label="成功几率分析"
  486. rules={[{ required: false, message: '请输入成功几率分析' }]}
  487. initialValue={detailData?.success_probability_analysis || ''}
  488. >
  489. <TextArea rows={4} placeholder="请输入成功几率分析" />
  490. </Form.Item>
  491. </Col>
  492. <Col span={24}>
  493. <Form.Item
  494. {...formItemLayoutTwo}
  495. name="files"
  496. label="上传图片"
  497. initialValue={detailData?.files || []}
  498. >
  499. <UploadCommon
  500. value={detailData?.files ? detailData?.files : []}
  501. onChange={onUploadChange}
  502. maxCount={9}
  503. />
  504. </Form.Item>
  505. </Col>
  506. </Row>
  507. </Form>
  508. </Modal>
  509. );
  510. };
  511. export default Edit;