CreateModal.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. // function dwgUpload() {
  84. // let uploadDwg = document.getElementById('uploadDwg');
  85. // uploadDwg.click();
  86. // }
  87. // function uploadDwg(event) {
  88. // const selectedFile = event.target.files[0];
  89. // if (selectedFile) {
  90. // setUpLoading(true);
  91. // ZwCloud2D.ZwDataProcessor.uploadDwg(selectedFile).then((res) => {
  92. // if (res.code == 200) {
  93. // const oldPath = form.getFieldValue('cad_path');
  94. // const cad_path = oldPath
  95. // ? oldPath + ',' + res.data.path
  96. // : res.data.path;
  97. // form.setFieldsValue({ cad_path });
  98. // }
  99. // setUpLoading(false);
  100. // });
  101. // }
  102. // }
  103. const UploadProps = {
  104. action: `https://cad.greentech.com.cn/sdk/doc/upload`,
  105. multiple: true,
  106. data: { path: getRandomString() },
  107. headers: {
  108. 'JWT-TOKEN': localStorage.getItem('JWT-TOKEN'),
  109. },
  110. onChange({ file, fileList }) {
  111. if (file.status !== 'uploading') {
  112. setCadPath([...cadPath, file.response.data.path]);
  113. }
  114. },
  115. };
  116. const handleOk = () => {
  117. let audit_list = [];
  118. let cc_list = [];
  119. approvalProcess?.forEach((item, index) => {
  120. let arr = item[0].is_cc === 1 ? cc_list : audit_list;
  121. if (item[0].type === 'role') arr.push(auditCheck[index]);
  122. else if (item[0].type === 'leader')
  123. arr.push(
  124. ...leaderData.slice(0, item[0].value).map((leader) => leader.ID),
  125. );
  126. else arr.push(item.map((cur) => cur.value));
  127. });
  128. form.validateFields().then((values) => {
  129. if (values.project_id)
  130. values.project_name = projectList.find(
  131. (item) => item.value == values.project_id,
  132. )?.label;
  133. if (values.dir_id) values.dir_name = values.dir_id.join(',');
  134. values.dir_id = 0;
  135. if (!values.cad_path) values.cad_path = cadPath.join(',');
  136. console.log(values, audit_list);
  137. onOk(values, { audit_list: audit_list.flat(), cc_list: cc_list.flat() });
  138. });
  139. };
  140. return (
  141. <Modal
  142. title="新建图纸"
  143. width={1200}
  144. open={open}
  145. confirmLoading={loading}
  146. onOk={handleOk}
  147. onCancel={handleCancel}
  148. >
  149. <Row gutter={24}>
  150. <Col span={16}>
  151. <Form {...layout} name="basic" form={form}>
  152. <Form.Item
  153. name="name"
  154. label="图纸名称:"
  155. rules={[{ required: true }]}
  156. >
  157. <Input />
  158. </Form.Item>
  159. <Form.Item
  160. name="project_id"
  161. label="所属项目:"
  162. rules={[{ required: true }]}
  163. >
  164. <Select options={projectList} />
  165. </Form.Item>
  166. <Form.Item
  167. name="dir_id"
  168. label="归档目录:"
  169. rules={[{ required: true }]}
  170. >
  171. <Cascader
  172. options={dirList}
  173. fieldNames={{
  174. label: 'value',
  175. value: 'value',
  176. children: 'children',
  177. }}
  178. />
  179. </Form.Item>
  180. <Form.Item
  181. name="pic_type"
  182. label="是否PID图和平面图"
  183. rules={[{ required: true }]}
  184. >
  185. <Select
  186. options={[
  187. {
  188. value: '是',
  189. },
  190. {
  191. value: '否',
  192. },
  193. ]}
  194. />
  195. </Form.Item>
  196. <Form.Item
  197. name="version"
  198. label="版本:"
  199. rules={[{ required: true }]}
  200. >
  201. <Input />
  202. </Form.Item>
  203. <Form.Item label="上传:">
  204. <Upload {...UploadProps}>
  205. <Button icon={<CloudUploadOutlined />}>Upload</Button>
  206. </Upload>
  207. {/* {form.getFieldValue('cad_path')} */}
  208. </Form.Item>
  209. <Form.Item name="remark" label="备注:">
  210. <Input.TextArea />
  211. </Form.Item>
  212. </Form>
  213. </Col>
  214. <Col span={8}>
  215. <ApprovalProcess
  216. leaderData={[]}
  217. approvalProcess={approvalProcess}
  218. onChange={setAuditCheck}
  219. />
  220. </Col>
  221. </Row>
  222. </Modal>
  223. );
  224. };
  225. export default CreateModal;