CreateModal.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import { advanceSubmitNextNode } from '@/services/boom';
  2. import { CloudUploadOutlined } from '@ant-design/icons';
  3. import { useModel, useRequest } from '@umijs/max';
  4. import {
  5. Modal,
  6. Form,
  7. Input,
  8. Upload,
  9. Select,
  10. Button,
  11. Steps,
  12. Row,
  13. Col,
  14. Cascader,
  15. } from 'antd';
  16. import { useEffect, useState } from 'react';
  17. import ApprovalProcess from '@/pages/Flow/components/ApprovalProcess';
  18. import { getRandomString } from '@/utils/utils';
  19. //计算审批流数据
  20. const advance = {
  21. flow_id: 67,
  22. form_list: null,
  23. formComponentValues: '',
  24. };
  25. const formItemValues = [
  26. {
  27. name: '是否PID图或平面图',
  28. id: 'DDSelectField_b8169258-d569-442e-a7b0-e2bd171aaac2',
  29. type: 'DDSelectField',
  30. value: [],
  31. },
  32. // {
  33. // name: '图纸审批"',
  34. // id: 'TextField_eb5b191b-6135-48ba-a01c-5609ed367d83"',
  35. // type: 'TextField',
  36. // value: [],
  37. // },
  38. ];
  39. const CreateModal = ({
  40. loading,
  41. projectList,
  42. dirList,
  43. open,
  44. onOk,
  45. handleCancel,
  46. }) => {
  47. const { userList, run: userListRun } = useModel('userList');
  48. const [form] = Form.useForm();
  49. const layout = {
  50. labelCol: { span: 6 },
  51. wrapperCol: { span: 16 },
  52. };
  53. const [upLoading, setUpLoading] = useState([]);
  54. const [auditCheck, setAuditCheck] = useState([]);
  55. const [approvalProcess, setApprovalProcess] = useState([]);
  56. const pic_type = Form.useWatch('pic_type', form);
  57. const [cadPath, setCadPath] = useState([]);
  58. useEffect(() => {
  59. if (!open) return;
  60. form.resetFields();
  61. setCadPath([]);
  62. setApprovalProcess([]);
  63. userListRun();
  64. const params = { ...advance };
  65. runAuditList(params);
  66. }, [open]);
  67. useEffect(() => {
  68. const formComponentValues = [...formItemValues];
  69. formComponentValues[0].value = [pic_type];
  70. runAuditList({ ...advance, formComponentValues });
  71. }, [pic_type]);
  72. //填写表单时计算审批流接口
  73. const { run: runAuditList } = useRequest(
  74. (data) => advanceSubmitNextNode(data),
  75. {
  76. debounceInterval: 500,
  77. manual: true,
  78. formatResult(res) {
  79. setApprovalProcess(res.data[0]);
  80. },
  81. },
  82. );
  83. const UploadProps = {
  84. action: `https://cad.greentech.com.cn/sdk/doc/upload`,
  85. multiple: true,
  86. data: { path: getRandomString() },
  87. headers: {
  88. 'JWT-TOKEN': localStorage.getItem('JWT-TOKEN'),
  89. },
  90. onChange({ file, fileList }) {
  91. if (file.status !== 'uploading') {
  92. setCadPath([...cadPath, file.response.data.path]);
  93. }
  94. },
  95. };
  96. const handleOk = () => {
  97. let audit_list = [];
  98. let cc_list = [];
  99. approvalProcess?.forEach((item, index) => {
  100. let arr = item[0].is_cc === 1 ? cc_list : audit_list;
  101. if (item[0].type === 'role') arr.push(auditCheck[index]);
  102. else if (item[0].type === 'leader')
  103. arr.push(
  104. ...leaderData.slice(0, item[0].value).map((leader) => leader.ID),
  105. );
  106. else arr.push(item.map((cur) => cur.value));
  107. });
  108. form.validateFields().then((values) => {
  109. if (values.project_id)
  110. values.project_name = projectList.find(
  111. (item) => item.value == values.project_id,
  112. )?.label;
  113. if (values.dir_id) values.dir_name = values.dir_id.join(',');
  114. values.dir_id = 0;
  115. if (!values.cad_path) values.cad_path = cadPath.join(',');
  116. console.log(values, audit_list);
  117. onOk(values, { audit_list: audit_list.flat(), cc_list: cc_list.flat() });
  118. });
  119. };
  120. return (
  121. <Modal
  122. title="新建图纸"
  123. width={1200}
  124. open={open}
  125. confirmLoading={loading}
  126. onOk={handleOk}
  127. onCancel={handleCancel}
  128. >
  129. <Row gutter={24}>
  130. <Col span={16}>
  131. <Form {...layout} name="basic" form={form}>
  132. <Form.Item
  133. name="name"
  134. label="图纸名称:"
  135. rules={[{ required: true }]}
  136. >
  137. <Input />
  138. </Form.Item>
  139. <Form.Item
  140. name="project_id"
  141. label="所属项目:"
  142. rules={[{ required: true }]}
  143. >
  144. <Select
  145. showSearch
  146. allowClear
  147. options={projectList}
  148. filterOption={(input, option) =>
  149. (option?.label ?? '')
  150. .toLowerCase()
  151. .includes(input.toLowerCase())
  152. }
  153. />
  154. </Form.Item>
  155. <Form.Item
  156. name="dir_id"
  157. label="归档目录:"
  158. rules={[{ required: true }]}
  159. >
  160. <Cascader
  161. options={dirList}
  162. fieldNames={{
  163. label: 'value',
  164. value: 'value',
  165. children: 'children',
  166. }}
  167. />
  168. </Form.Item>
  169. <Form.Item
  170. name="pic_type"
  171. label="是否PID图和平面图"
  172. rules={[{ required: true }]}
  173. >
  174. <Select
  175. options={[
  176. {
  177. value: '是',
  178. },
  179. {
  180. value: '否',
  181. },
  182. ]}
  183. />
  184. </Form.Item>
  185. <Form.Item
  186. name="version"
  187. label="版本:"
  188. rules={[{ required: true }]}
  189. >
  190. <Input />
  191. </Form.Item>
  192. <Form.Item label="上传:">
  193. <Upload {...UploadProps}>
  194. <Button icon={<CloudUploadOutlined />}>Upload</Button>
  195. </Upload>
  196. {/* {form.getFieldValue('cad_path')} */}
  197. </Form.Item>
  198. <Form.Item name="remark" label="备注:">
  199. <Input.TextArea />
  200. </Form.Item>
  201. </Form>
  202. </Col>
  203. <Col span={8}>
  204. <ApprovalProcess
  205. leaderData={[]}
  206. approvalProcess={approvalProcess}
  207. onChange={setAuditCheck}
  208. />
  209. </Col>
  210. </Row>
  211. </Modal>
  212. );
  213. };
  214. export default CreateModal;