ApprovalModal.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Select, Modal, Input, TreeSelect, Button } from 'antd';
  3. import moment from 'moment';
  4. import provinces from './provinces';
  5. import { queryApproval } from '@/services/approval';
  6. import FirmModal from './ManufacturerModal';
  7. import TableRender from './TableRender';
  8. const { Option } = Select;
  9. const { TreeNode } = TreeSelect;
  10. // 新建
  11. function AddModal(props) {
  12. const {
  13. total,
  14. dispatch,
  15. visible,
  16. onClose,
  17. onOk,
  18. data,
  19. currentUser,
  20. depUserTree,
  21. flowList = [],
  22. industryList = [],
  23. typeList = [],
  24. disabled,
  25. loading,
  26. supplierList = [],
  27. onAddFirm,
  28. } = props;
  29. const [form] = Form.useForm();
  30. const [codes, setCodes] = useState({
  31. type: '',
  32. industry: '',
  33. location: '',
  34. name: '',
  35. version: '',
  36. });
  37. const [type, setType] = useState({});
  38. const [addFirmVisible, setAddFirmVisible] = useState(false);
  39. const handleOk = () => {
  40. form.validateFields().then(fieldsValue => {
  41. let values = { ...fieldsValue, id: data.id };
  42. values.project_name = fieldsValue.project_name;
  43. values.flow_id = Number(fieldsValue.flow_id);
  44. values.type_id = Number(fieldsValue.type_id);
  45. // 获得flow下第一个node的id
  46. values.node_id = flowList.find(item => item.id == values.flow_id).Nodes[0].id;
  47. //项目分类为不为研发时
  48. if (fieldsValue.type_id != 7) {
  49. values.industry_id = Number(fieldsValue.industry_id);
  50. let [location, location_code] = fieldsValue.location.split('##');
  51. values.location = location;
  52. values.location_code = location_code;
  53. values.project_full_code = `${codes.type}${codes.industry}${codes.location}${codes.name}${codes.version}`;
  54. }
  55. if (fieldsValue.author) {
  56. values.author = Number(fieldsValue.author.split('||')[0]);
  57. values.author_dep_id = Number(fieldsValue.author.split('||')[1]);
  58. } else {
  59. values.author = null;
  60. }
  61. const supplierName = supplierList.find(item => item.id == fieldsValue.supplier_id)?.name;
  62. if (supplierName) values.supplier_name = supplierName;
  63. onOk(values);
  64. });
  65. };
  66. const renderTreeNodes = data => {
  67. return data.map(item => {
  68. let title = item.name;
  69. let code = item.code || '';
  70. if (code.length == 4) {
  71. code = code.substr(1);
  72. }
  73. if (code) {
  74. title += `(${code})`;
  75. }
  76. let key = `${item.name}##${code}`;
  77. return (
  78. <TreeNode title={title} key={key} value={key} dataRef={item} selectable={Boolean(code)}>
  79. {item.children && renderTreeNodes(item.children || [])}
  80. </TreeNode>
  81. );
  82. });
  83. };
  84. const changeType = id => {
  85. const item = typeList.find(item => item.id == id);
  86. setCodes({
  87. ...codes,
  88. type: item.code,
  89. });
  90. setType(item);
  91. form.setFieldsValue({ flow_id: id == 7 ? '4' : '1' });
  92. };
  93. const changeIndustry = id => {
  94. const item = industryList.find(item => item.id == id);
  95. setCodes({
  96. ...codes,
  97. industry: item.code,
  98. });
  99. };
  100. const changeVersion = index => {
  101. setCodes({
  102. ...codes,
  103. version: index,
  104. });
  105. };
  106. const changeLocation = value => {
  107. const [location, code] = value.split('##');
  108. setCodes({
  109. ...codes,
  110. location: code,
  111. });
  112. };
  113. const onBlurName = e => {
  114. let value = e.target.value.toUpperCase();
  115. while (value.length < 3) {
  116. value = value + 'V';
  117. }
  118. form.setFieldsValue({
  119. name: value,
  120. });
  121. setCodes({
  122. ...codes,
  123. name: value,
  124. });
  125. };
  126. const renderDetail = () => {
  127. return (
  128. <>
  129. <Form.Item
  130. label="行业名称"
  131. name="industry_id"
  132. initialValue={String(data.industry_id || '')}
  133. rules={[{ required: true, message: '请选择行业名称' }]}
  134. >
  135. <Select style={{ width: '100%' }} onChange={changeIndustry}>
  136. {industryList.map(item => (
  137. <Option key={item.id}>
  138. {item.name}({item.code})
  139. </Option>
  140. ))}
  141. </Select>
  142. </Form.Item>
  143. <Form.Item
  144. label="项目客户"
  145. name="supplier_id"
  146. initialValue={data.supplier_id}
  147. rules={[{ required: true, message: '请选择项目客户' }]}
  148. >
  149. <Select style={{ width: '100%' }} onChange={e => form.setFieldsValue({ supplier_id: e })}>
  150. {supplierList.map(item => (
  151. <Option key={item.id} value={item.id}>
  152. {item.name}({item.id})
  153. </Option>
  154. ))}
  155. </Select>
  156. <Button
  157. style={{ position: 'absolute', right: ' -95px' }}
  158. type="primary"
  159. onClick={onAddFirm}
  160. >
  161. 新建客户
  162. </Button>
  163. </Form.Item>
  164. <Form.Item
  165. label="项目规模"
  166. name="process_info"
  167. // initialValue={String(data.industry_id || '')}
  168. rules={[{ required: true, message: '请填写项目规模' }]}
  169. >
  170. <TableRender />
  171. </Form.Item>
  172. <Form.Item
  173. label="项目地区"
  174. name="location"
  175. initialValue={data.location}
  176. rules={[{ required: true, message: '请选择项目地区' }]}
  177. >
  178. <TreeSelect
  179. dropdownStyle={{ maxHeight: 300, overflow: 'auto' }}
  180. onChange={changeLocation}
  181. >
  182. {renderTreeNodes(provinces)}
  183. </TreeSelect>
  184. </Form.Item>
  185. <Form.Item
  186. label="项目简称"
  187. name="name"
  188. initialValue={data.name}
  189. rules={[
  190. { required: true, message: '请输入项目简称' },
  191. {
  192. validator: (rule, value) => {
  193. if (value && value.match(/[^A-Za-z]/g))
  194. return Promise.reject(new Error('项目简称只能是英文字符'));
  195. else return Promise.resolve();
  196. },
  197. },
  198. ]}
  199. >
  200. <Input maxLength={3} onBlur={onBlurName} />
  201. </Form.Item>
  202. <Form.Item
  203. label="项目期数"
  204. name="version"
  205. initialValue={data.version}
  206. rules={[{ required: true, message: '请选择项目期数' }]}
  207. >
  208. <Select style={{ width: '100%' }} onChange={changeVersion}>
  209. {['一期', '二期', '三期', '四期', '五期'].map((item, index) => (
  210. <Option key={index + 1}>{item}</Option>
  211. ))}
  212. </Select>
  213. </Form.Item>
  214. <Form.Item label="项目编号">
  215. {codes.type || '***'}-{codes.industry || '***'}-{codes.location || '***'}-
  216. {codes.name || '***'}-{codes.version || '*'}
  217. </Form.Item>
  218. </>
  219. );
  220. };
  221. useEffect(() => {
  222. if (data.id) {
  223. const type = typeList.find(item => item.id == data.type_id);
  224. const industry = industryList.find(item => item.id == data.industry_id);
  225. setCodes({
  226. type: type?.code,
  227. industry: industry?.code,
  228. location: data.location_code,
  229. name: data.name,
  230. version: data.version,
  231. });
  232. setType(type);
  233. } else {
  234. setCodes({
  235. type: '',
  236. industry: '',
  237. location: '',
  238. name: '',
  239. version: '',
  240. });
  241. setType({});
  242. }
  243. }, [data, visible]);
  244. useEffect(() => {
  245. form.resetFields();
  246. }, [visible]);
  247. return (
  248. <Modal
  249. title="项目立项"
  250. confirmLoading={loading}
  251. maskClosable={false}
  252. destroyOnClose
  253. visible={visible}
  254. onCancel={onClose}
  255. onOk={handleOk}
  256. >
  257. <Form labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} form={form}>
  258. <Form.Item
  259. label="项目名称"
  260. name="project_name"
  261. initialValue={String(data.project_name || '')}
  262. rules={[{ required: true, message: '请输入项目名称' }]}
  263. >
  264. <Input style={{ width: '100%' }} />
  265. </Form.Item>
  266. <Form.Item
  267. label="项目类别"
  268. name="type_id"
  269. initialValue={String(data.type_id || '')}
  270. rules={[{ required: true, message: '请选择项目类别' }]}
  271. >
  272. <Select style={{ width: '100%' }} onChange={changeType}>
  273. {typeList.map(item => (
  274. <Option key={item.id}>
  275. {item.name}({item.code})
  276. </Option>
  277. ))}
  278. </Select>
  279. </Form.Item>
  280. <Form.Item
  281. label="流程"
  282. name="flow_id"
  283. initialValue={String(data.flow_id || '')}
  284. rules={[{ required: true, message: '请选择流程' }]}
  285. >
  286. <Select style={{ width: '100%' }} disabled>
  287. {flowList
  288. .filter(item => item && item.id != 2 && item.id != 3)
  289. .map(item => (
  290. <Option key={item.id}>{item.name}</Option>
  291. ))}
  292. </Select>
  293. </Form.Item>
  294. {currentUser.IsSuper && (
  295. <Form.Item
  296. label="售前经理"
  297. name="author"
  298. initialValue={String(
  299. data.author && data.author_dep_id ? `${data.author}||${data.author_dep_id}` : ''
  300. )}
  301. >
  302. <TreeSelect
  303. showSearch
  304. allowClear
  305. style={{ width: '100%' }}
  306. multiple={false}
  307. filterTreeNode={(input, option) => {
  308. return option.props.title === input;
  309. }}
  310. treeData={depUserTree}
  311. />
  312. </Form.Item>
  313. )}
  314. {type?.id != 7 && renderDetail()}
  315. </Form>
  316. </Modal>
  317. );
  318. }
  319. export default AddModal;