index.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 } 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. let navigate = useNavigate();
  18. const [createLoading, setCreateLoading] = useState(false);
  19. const [visible, setVisible] = useState(false);
  20. const [childrenVisible, setChildrenVisible] = useState(false);
  21. const [parentId, setParentId] = useState();
  22. const [params, setParams] = useState({
  23. // project_name: '',
  24. // name: '',
  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. path: record.path,
  78. },
  79. })
  80. }
  81. >
  82. 查看
  83. </a>
  84. )}
  85. {record.showCreate && (
  86. <a
  87. onClick={() => {
  88. setParentId(record.id);
  89. setChildrenVisible(true);
  90. }}
  91. >
  92. 新建
  93. </a>
  94. )}
  95. </Space>
  96. );
  97. },
  98. },
  99. ];
  100. const { data: projectList } = useRequest(queryApprovalProject, {
  101. formatResult: (res) => {
  102. return res?.data?.map((item) => {
  103. return {
  104. label: `${item.project_name}(${item.project_full_code})`,
  105. value: item.id,
  106. };
  107. });
  108. },
  109. });
  110. //请求归档目录
  111. const { data: dirList } = useRequest(queryCadDirList, {
  112. formatResult: (res) => {
  113. return res.data;
  114. },
  115. });
  116. //请求列表
  117. const { data, run, loading } = useRequest(queryCadList, {
  118. defaultParams: [params],
  119. formatResult: (res) => {
  120. res.data?.list?.forEach((item) => {
  121. item.children?.forEach((cur) => {
  122. cur.name = item.name + cur.version;
  123. item.showCreate = cur.cad_status == 2 ? true : false;
  124. if (cur.cad_path) {
  125. const pathList = cur.cad_path.split(',');
  126. cur.children = pathList.map((item) => {
  127. const names = item.split('/');
  128. const name = names?.length > 1 ? names[1] : names[0];
  129. return {
  130. name: name,
  131. path: item,
  132. canShow: true,
  133. parent_id: cur.parent_id,
  134. };
  135. });
  136. }
  137. });
  138. });
  139. return res.data?.list;
  140. },
  141. });
  142. //创建审批
  143. const { run: runCreate } = useRequest(queryCreateCad, {
  144. manual: true,
  145. onSuccess: (data) => {
  146. createOARun({
  147. ...auditListRef.current,
  148. extend_code: data.cad_id + '',
  149. extend_type: 2, //2图纸
  150. });
  151. },
  152. });
  153. //创建子审批
  154. const { run: runCreateVer, loading: loadingCreateVer } = useRequest(
  155. queryCreateCadVer,
  156. {
  157. manual: true,
  158. onSuccess: (data) => {
  159. message.success('新建成功');
  160. setChildrenVisible(false);
  161. // createOARun({
  162. // ...auditListRef.current,
  163. // extend_code: data.cad_id + '',
  164. // extend_type: 2, //2图纸
  165. // });
  166. },
  167. },
  168. );
  169. //发起OA审批
  170. const { run: createOARun } = useRequest(
  171. (data) => createAduit({ ...data, flow_id: 67, files: '' }),
  172. {
  173. manual: true,
  174. onSuccess: () => {
  175. run();
  176. message.success('新建成功');
  177. setVisible(false);
  178. setCreateLoading(false);
  179. },
  180. },
  181. );
  182. useEffect(() => {
  183. ZwCloud2D.ZwDataProcessor.ZwSetConnectUrl(
  184. 'https://cad.greentech.com.cn', //47.111.24.13
  185. 'https://cad.greentech.com.cn:5121',
  186. 'https://cad.greentech.com.cn',
  187. );
  188. }, []);
  189. const handleCreate = (values, audit_list) => {
  190. setCreateLoading(true);
  191. auditListRef.current = audit_list;
  192. runCreate(values);
  193. };
  194. return (
  195. <PageContent>
  196. <Space>
  197. <Button type="primary" onClick={() => setVisible(true)}>
  198. 新建图纸
  199. </Button>
  200. <div>
  201. 项目名称:
  202. <Select
  203. style={{ width: 130 }}
  204. allowClear
  205. options={projectList}
  206. onChange={(value) => {
  207. const project_name = projectList?.find(
  208. (item) => item.value == value,
  209. )?.label;
  210. setParams({ ...params, project_name });
  211. }}
  212. />
  213. </div>
  214. <div>
  215. 图纸名称:
  216. <Input
  217. allowClear
  218. style={{ width: '200px' }}
  219. onChange={(e) => {
  220. setParams({ ...params, name: e.target.value });
  221. }}
  222. />
  223. </div>
  224. <Button type="primary" onClick={() => run(params)}>
  225. 查询
  226. </Button>
  227. </Space>
  228. <Table
  229. rowKey="id"
  230. loading={loading}
  231. columns={columns}
  232. dataSource={data}
  233. indentSize={70}
  234. />
  235. <CreateModal
  236. loading={createLoading}
  237. dirList={dirList}
  238. projectList={projectList}
  239. open={visible}
  240. onOk={handleCreate}
  241. handleCancel={() => setVisible(false)}
  242. />
  243. <CreateChildrenModal
  244. parentId={parentId}
  245. loading={loadingCreateVer}
  246. open={childrenVisible}
  247. onOk={runCreateVer}
  248. handleCancel={() => setChildrenVisible(false)}
  249. />
  250. </PageContent>
  251. );
  252. };
  253. export default CadDemo;