index.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. import { useRef, useEffect, useState } from 'react';
  2. import PageContent from '@/components/PageContent';
  3. import {
  4. queryCadDirList,
  5. queryCadList,
  6. queryCreateCad,
  7. queryProject,
  8. } from '@/services/cad';
  9. import { useRequest, useNavigate, useModel } from '@umijs/max';
  10. import { Table, Button, message, Space, Select, Input } from 'antd';
  11. import CreateModal from './components/CreateModal';
  12. import { createAduit } from '@/services/boom';
  13. import CreateChildrenModal from './components/CreateChildrenModal';
  14. import { queryCreateCadVer } from '../../services/cad';
  15. import { queryApprovalProject } from '@/services/contract';
  16. const CadDemo = () => {
  17. const { initialState } = useModel('@@initialState');
  18. const user = initialState?.user || {};
  19. let navigate = useNavigate();
  20. const [createLoading, setCreateLoading] = useState(false);
  21. const [visible, setVisible] = useState(false);
  22. const [childrenVisible, setChildrenVisible] = useState(false);
  23. const [parentId, setParentId] = useState();
  24. const [params, setParams] = useState({
  25. page: 1,
  26. page_size: 20,
  27. });
  28. const auditListRef = useRef();
  29. const columns = [
  30. {
  31. title: '名称',
  32. dataIndex: 'name',
  33. key: 'name',
  34. width: 160,
  35. },
  36. {
  37. title: '所属项目',
  38. dataIndex: 'project_name',
  39. key: 'project_name',
  40. width: 120,
  41. },
  42. {
  43. title: '状态',
  44. // dataIndex: 'cad_status',
  45. // key: 'cad_status',
  46. width: 100,
  47. render: (record) => {
  48. let str = '';
  49. let color = 'black';
  50. switch (record.cad_status) {
  51. case 1:
  52. str = '已归档';
  53. color = 'green';
  54. break;
  55. case 2:
  56. str = '审核拒绝';
  57. color = 'red';
  58. break;
  59. case 0:
  60. str = '待审核';
  61. color = 'blue';
  62. }
  63. return record.parent_id ? <div style={{ color }}>{str}</div> : '';
  64. },
  65. },
  66. {
  67. title: '操作',
  68. width: '10%',
  69. render: (record) => {
  70. return (
  71. <Space>
  72. {record.canShow && (
  73. <a
  74. onClick={() =>
  75. navigate('/cad/detail', {
  76. state: {
  77. user,
  78. path: record.path,
  79. project_id: record.project_id,
  80. },
  81. })
  82. }
  83. >
  84. 查看
  85. </a>
  86. )}
  87. {record.showCreate && (
  88. <a
  89. onClick={() => {
  90. setParentId(record.id);
  91. setChildrenVisible(true);
  92. }}
  93. >
  94. 新建
  95. </a>
  96. )}
  97. </Space>
  98. );
  99. },
  100. },
  101. ];
  102. const { data: projectList } = useRequest(queryApprovalProject, {
  103. formatResult: (res) => {
  104. return res?.data?.map((item) => {
  105. return {
  106. label: `${item.project_name}(${item.project_full_code})`,
  107. value: item.id,
  108. };
  109. });
  110. },
  111. });
  112. //请求归档目录
  113. const { data: dirList } = useRequest(queryCadDirList, {
  114. formatResult: (res) => {
  115. return res.data;
  116. },
  117. });
  118. //请求列表
  119. const { data, run, loading } = useRequest(queryCadList, {
  120. defaultParams: [params],
  121. formatResult: (res) => {
  122. res.data?.list?.forEach((item) => {
  123. const project_id = item.project_id;
  124. item.children?.forEach((cur) => {
  125. cur.name = item.name + cur.version;
  126. item.showCreate = cur.cad_status == 2 ? true : false;
  127. if (cur.cad_path) {
  128. const pathList = cur.cad_path.split(',');
  129. cur.children = pathList.map((item) => {
  130. const names = item.split('/');
  131. const name = names?.length > 1 ? names[1] : names[0];
  132. return {
  133. name,
  134. path: item,
  135. canShow: true,
  136. project_id,
  137. parent_id: cur.parent_id,
  138. };
  139. });
  140. }
  141. });
  142. });
  143. return res.data?.list;
  144. },
  145. });
  146. //创建审批
  147. const { run: runCreate } = useRequest(queryCreateCad, {
  148. manual: true,
  149. onSuccess: (data) => {
  150. createOARun({
  151. ...auditListRef.current,
  152. extend_code: data.cad_id + '',
  153. extend_type: 2, //2图纸
  154. });
  155. },
  156. });
  157. //创建子审批
  158. const { run: runCreateVer, loading: loadingCreateVer } = useRequest(
  159. queryCreateCadVer,
  160. {
  161. manual: true,
  162. onSuccess: (data) => {
  163. run();
  164. message.success('新建成功');
  165. setChildrenVisible(false);
  166. // createOARun({
  167. // ...auditListRef.current,
  168. // extend_code: data.cad_id + '',
  169. // extend_type: 2, //2图纸
  170. // });
  171. },
  172. },
  173. );
  174. //发起OA审批
  175. const { run: createOARun } = useRequest(
  176. (data) => createAduit({ ...data, flow_id: 67, files: '' }),
  177. {
  178. manual: true,
  179. onSuccess: () => {
  180. run();
  181. message.success('新建成功');
  182. setVisible(false);
  183. setCreateLoading(false);
  184. },
  185. },
  186. );
  187. const handleCreate = (values, audit_list) => {
  188. setCreateLoading(true);
  189. auditListRef.current = audit_list;
  190. runCreate(values);
  191. };
  192. return (
  193. <PageContent>
  194. <Space>
  195. <Button type="primary" onClick={() => setVisible(true)}>
  196. 新建图纸
  197. </Button>
  198. <div>
  199. 项目名称:
  200. <Select
  201. style={{ width: 130 }}
  202. allowClear
  203. options={projectList}
  204. onChange={(value) => {
  205. const project_name = projectList?.find(
  206. (item) => item.value == value,
  207. )?.label;
  208. setParams({ ...params, project_name });
  209. }}
  210. />
  211. </div>
  212. <div>
  213. 图纸名称:
  214. <Input
  215. allowClear
  216. style={{ width: '200px' }}
  217. onChange={(e) => {
  218. setParams({ ...params, name: e.target.value });
  219. }}
  220. />
  221. </div>
  222. <Button type="primary" onClick={() => run(params)}>
  223. 查询
  224. </Button>
  225. </Space>
  226. <Table
  227. rowKey="id"
  228. loading={loading}
  229. columns={columns}
  230. dataSource={data}
  231. indentSize={70}
  232. />
  233. <CreateModal
  234. loading={createLoading}
  235. dirList={dirList}
  236. projectList={projectList}
  237. open={visible}
  238. onOk={handleCreate}
  239. handleCancel={() => setVisible(false)}
  240. />
  241. <CreateChildrenModal
  242. parentId={parentId}
  243. loading={loadingCreateVer}
  244. open={childrenVisible}
  245. onOk={runCreateVer}
  246. handleCancel={() => setChildrenVisible(false)}
  247. />
  248. </PageContent>
  249. );
  250. };
  251. export default CadDemo;