1
0

edit.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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={24}>
  199. <Form.Item
  200. {...formItemLayoutTwo}
  201. name="address"
  202. label="详细地址"
  203. rules={[{ required: true, message: '请输入详细地址' }]}
  204. initialValue={detailData?.address || ''}
  205. >
  206. <TextArea rows={4} placeholder="请输入详细地址" />
  207. </Form.Item>
  208. </Col>
  209. <Col span={12}>
  210. <Form.Item
  211. {...formItemLayout}
  212. name="area"
  213. label="建筑面积"
  214. rules={[{ required: true, message: '请输入建筑面积' }]}
  215. initialValue={detailData?.area || ''}
  216. >
  217. <Input placeholder="请输入建筑面积" />
  218. </Form.Item>
  219. </Col>
  220. <Col span={12}>
  221. <Form.Item
  222. {...formItemLayout}
  223. name="bidding_form"
  224. label="招标形式"
  225. rules={[{ required: true, message: '请选择招标形式' }]}
  226. initialValue={detailData?.bidding_form || undefined}
  227. >
  228. <Select
  229. placeholder="请选择招标形式"
  230. options={[
  231. {
  232. value: '1',
  233. label: '内部仪标',
  234. },
  235. {
  236. value: '2',
  237. label: '公开招标',
  238. },
  239. {
  240. value: '3',
  241. label: '提供方案书',
  242. },
  243. ]}
  244. />
  245. </Form.Item>
  246. </Col>
  247. <Col span={12}>
  248. <Form.Item
  249. {...formItemLayout}
  250. name="project_effect"
  251. label="项目用途"
  252. rules={[{ required: true, message: '请选择项目用途' }]}
  253. initialValue={detailData?.project_effect || undefined}
  254. >
  255. <Select
  256. placeholder="请选择项目用途"
  257. options={[
  258. {
  259. value: '1',
  260. label: '酒店餐饮',
  261. },
  262. {
  263. value: '2',
  264. label: '商务办公',
  265. },
  266. {
  267. value: '3',
  268. label: '政府项目',
  269. },
  270. {
  271. value: '4',
  272. label: '工矿企业',
  273. },
  274. {
  275. value: '5',
  276. label: '文教卫生',
  277. },
  278. {
  279. value: '6',
  280. label: '商业建筑',
  281. },
  282. {
  283. value: '7',
  284. label: '房产配套',
  285. },
  286. {
  287. value: '8',
  288. label: '其他',
  289. },
  290. ]}
  291. />
  292. </Form.Item>
  293. </Col>
  294. <Col span={12}>
  295. <Form.Item
  296. {...formItemLayout}
  297. name="project_progress"
  298. label="工程进展"
  299. rules={[{ required: true, message: '请选择工程进展' }]}
  300. initialValue={detailData?.project_progress || undefined}
  301. >
  302. <Select
  303. placeholder="请选择工程进展"
  304. options={[
  305. {
  306. value: '1',
  307. label: '了解信息',
  308. },
  309. {
  310. value: '2',
  311. label: '确认经销商',
  312. },
  313. {
  314. value: '3',
  315. label: '方案报价',
  316. },
  317. {
  318. value: '4',
  319. label: '邀请招标',
  320. },
  321. {
  322. value: '5',
  323. label: '投标询价',
  324. },
  325. {
  326. value: '6',
  327. label: '价格竞争',
  328. },
  329. {
  330. value: '7',
  331. label: '商务谈判',
  332. },
  333. {
  334. value: '8',
  335. label: '合同准备',
  336. },
  337. {
  338. value: '9',
  339. label: '收到定金',
  340. },
  341. ]}
  342. />
  343. </Form.Item>
  344. </Col>
  345. <Col span={12}>
  346. <Form.Item
  347. {...formItemLayout}
  348. name="air_conditioner_type"
  349. label="空调类型"
  350. rules={[{ required: true, message: '请选择空调类型' }]}
  351. initialValue={detailData?.air_conditioner_type || undefined}
  352. >
  353. <Select
  354. placeholder="请选择空调类型"
  355. options={[
  356. {
  357. value: '6s水机',
  358. label: '6s水机',
  359. },
  360. {
  361. value: '8s水机',
  362. label: '8s水机',
  363. },
  364. {
  365. value: '7.2kw氟机',
  366. label: '7.2kw氟机',
  367. },
  368. {
  369. value: '12kw氟机',
  370. label: '12kw氟机',
  371. },
  372. {
  373. value: '12kw水机',
  374. label: '12kw水机',
  375. },
  376. ]}
  377. />
  378. </Form.Item>
  379. </Col>
  380. <Col span={12}>
  381. <Form.Item
  382. {...formItemLayout}
  383. name="contact_person"
  384. label="甲方联系人"
  385. rules={[{ required: true, message: '请输入甲方联系人' }]}
  386. initialValue={detailData?.contact_person || ''}
  387. >
  388. <Input placeholder="请输入甲方联系人" />
  389. </Form.Item>
  390. </Col>
  391. <Col span={12}>
  392. <Form.Item
  393. {...formItemLayout}
  394. name="phone"
  395. label="联系方式"
  396. rules={[{ required: true, message: '请输入联系方式' }]}
  397. initialValue={detailData?.phone || ''}
  398. >
  399. <Input placeholder="请输入联系方式" />
  400. </Form.Item>
  401. </Col>
  402. <Col span={12}>
  403. <Form.Item
  404. {...formItemLayout}
  405. name="planned_fixture_date"
  406. label="计划成交日期"
  407. rules={[{ required: true, message: '请输入计划成交日期' }]}
  408. initialValue={
  409. detailData?.planned_fixture_date ? moment(detailData?.planned_fixture_date) : ''
  410. }
  411. >
  412. <DatePicker style={{ width: '235px' }} />
  413. </Form.Item>
  414. </Col>
  415. <Col span={12}>
  416. <Form.Item
  417. {...formItemLayout}
  418. name="follow_people"
  419. label="跟进人"
  420. rules={[{ required: true, message: '请输入跟进人' }]}
  421. initialValue={detailData?.follow_people || ''}
  422. >
  423. <Input placeholder="请输入跟进人" />
  424. </Form.Item>
  425. </Col>
  426. <Col span={12}>
  427. <Form.Item
  428. {...formItemLayout}
  429. name="success_probability"
  430. label="成功几率"
  431. rules={[{ required: true, message: '请输入成功几率' }]}
  432. initialValue={detailData?.success_probability || ''}
  433. >
  434. <InputNumber
  435. min={0}
  436. max={100}
  437. placeholder="请输入成功几率"
  438. addonAfter="%"
  439. style={{ width: '235px' }}
  440. />
  441. </Form.Item>
  442. </Col>
  443. <Col span={24}>
  444. <Form.Item
  445. {...formItemLayoutTwo}
  446. name="success_probability_analysis"
  447. label="成功几率分析"
  448. rules={[{ required: false, message: '请输入成功几率分析' }]}
  449. initialValue={detailData?.success_probability_analysis || ''}
  450. >
  451. <TextArea rows={4} placeholder="请输入成功几率分析" />
  452. </Form.Item>
  453. </Col>
  454. <Col span={24}>
  455. <Form.Item
  456. {...formItemLayoutTwo}
  457. name="files"
  458. label="上传图片"
  459. initialValue={detailData?.files || []}
  460. >
  461. <UploadCommon
  462. value={detailData?.files ? detailData?.files : []}
  463. onChange={onUploadChange}
  464. maxCount={9}
  465. />
  466. </Form.Item>
  467. </Col>
  468. </Row>
  469. </Form>
  470. </Modal>
  471. );
  472. };
  473. export default Edit;