123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- import { useRef, useEffect, useState } from 'react';
- import PageContent from '@/components/PageContent';
- import {
- queryCadDirList,
- queryCadList,
- queryCreateCad,
- queryProject,
- } from '@/services/cad';
- import { useRequest, useNavigate } from '@umijs/max';
- import { Table, Button, message, Space, Select, Input } from 'antd';
- import CreateModal from './components/CreateModal';
- import { createAduit } from '@/services/boom';
- import CreateChildrenModal from './components/CreateChildrenModal';
- import { queryCreateCadVer } from '../../services/cad';
- import { queryApprovalProject } from '@/services/contract';
- const CadDemo = () => {
- let navigate = useNavigate();
- const [createLoading, setCreateLoading] = useState(false);
- const [visible, setVisible] = useState(false);
- const [childrenVisible, setChildrenVisible] = useState(false);
- const [parentId, setParentId] = useState();
- const [params, setParams] = useState({
- // project_name: '',
- // name: '',
- page: 1,
- page_size: 20,
- });
- const auditListRef = useRef();
- const columns = [
- {
- title: '名称',
- dataIndex: 'name',
- key: 'name',
- width: 160,
- },
- {
- title: '所属项目',
- dataIndex: 'project_name',
- key: 'project_name',
- width: 120,
- },
- {
- title: '状态',
- // dataIndex: 'cad_status',
- // key: 'cad_status',
- width: 100,
- render: (record) => {
- let str = '';
- let color = 'black';
- switch (record.cad_status) {
- case 1:
- str = '已归档';
- color = 'green';
- break;
- case 2:
- str = '审核拒绝';
- color = 'red';
- break;
- case 0:
- str = '待审核';
- color = 'blue';
- }
- return record.parent_id ? <div style={{ color }}>{str}</div> : '';
- },
- },
- {
- title: '操作',
- width: '10%',
- render: (record) => {
- return (
- <Space>
- {record.canShow && (
- <a
- onClick={() =>
- navigate('/cad/detail', {
- state: {
- path: record.path,
- },
- })
- }
- >
- 查看
- </a>
- )}
- {record.showCreate && (
- <a
- onClick={() => {
- setParentId(record.id);
- setChildrenVisible(true);
- }}
- >
- 新建
- </a>
- )}
- </Space>
- );
- },
- },
- ];
- const { data: projectList } = useRequest(queryApprovalProject, {
- formatResult: (res) => {
- return res?.data?.map((item) => {
- return {
- label: `${item.project_name}(${item.project_full_code})`,
- value: item.id,
- };
- });
- },
- });
- //请求归档目录
- const { data: dirList } = useRequest(queryCadDirList, {
- formatResult: (res) => {
- return res.data;
- },
- });
- //请求列表
- const { data, run, loading } = useRequest(queryCadList, {
- defaultParams: [params],
- formatResult: (res) => {
- res.data?.list?.forEach((item) => {
- item.children?.forEach((cur) => {
- cur.name = item.name + cur.version;
- item.showCreate = cur.cad_status == 2 ? true : false;
- if (cur.cad_path) {
- const pathList = cur.cad_path.split(',');
- cur.children = pathList.map((item) => {
- const names = item.split('/');
- const name = names?.length > 1 ? names[1] : names[0];
- return {
- name: name,
- path: item,
- canShow: true,
- parent_id: cur.parent_id,
- };
- });
- }
- });
- });
- return res.data?.list;
- },
- });
- //创建审批
- const { run: runCreate } = useRequest(queryCreateCad, {
- manual: true,
- onSuccess: (data) => {
- createOARun({
- ...auditListRef.current,
- extend_code: data.cad_id + '',
- extend_type: 2, //2图纸
- });
- },
- });
- //创建子审批
- const { run: runCreateVer, loading: loadingCreateVer } = useRequest(
- queryCreateCadVer,
- {
- manual: true,
- onSuccess: (data) => {
- message.success('新建成功');
- setChildrenVisible(false);
- // createOARun({
- // ...auditListRef.current,
- // extend_code: data.cad_id + '',
- // extend_type: 2, //2图纸
- // });
- },
- },
- );
- //发起OA审批
- const { run: createOARun } = useRequest(
- (data) => createAduit({ ...data, flow_id: 67, files: '' }),
- {
- manual: true,
- onSuccess: () => {
- run();
- message.success('新建成功');
- setVisible(false);
- setCreateLoading(false);
- },
- },
- );
- useEffect(() => {
- ZwCloud2D.ZwDataProcessor.ZwSetConnectUrl(
- 'https://cad.greentech.com.cn', //47.111.24.13
- 'https://cad.greentech.com.cn:5121',
- 'https://cad.greentech.com.cn',
- );
- }, []);
- const handleCreate = (values, audit_list) => {
- setCreateLoading(true);
- auditListRef.current = audit_list;
- runCreate(values);
- };
- return (
- <PageContent>
- <Space>
- <Button type="primary" onClick={() => setVisible(true)}>
- 新建图纸
- </Button>
- <div>
- 项目名称:
- <Select
- style={{ width: 130 }}
- allowClear
- options={projectList}
- onChange={(value) => {
- const project_name = projectList?.find(
- (item) => item.value == value,
- )?.label;
- setParams({ ...params, project_name });
- }}
- />
- </div>
- <div>
- 图纸名称:
- <Input
- allowClear
- style={{ width: '200px' }}
- onChange={(e) => {
- setParams({ ...params, name: e.target.value });
- }}
- />
- </div>
- <Button type="primary" onClick={() => run(params)}>
- 查询
- </Button>
- </Space>
- <Table
- rowKey="id"
- loading={loading}
- columns={columns}
- dataSource={data}
- indentSize={70}
- />
- <CreateModal
- loading={createLoading}
- dirList={dirList}
- projectList={projectList}
- open={visible}
- onOk={handleCreate}
- handleCancel={() => setVisible(false)}
- />
- <CreateChildrenModal
- parentId={parentId}
- loading={loadingCreateVer}
- open={childrenVisible}
- onOk={runCreateVer}
- handleCancel={() => setChildrenVisible(false)}
- />
- </PageContent>
- );
- };
- export default CadDemo;
|