Browse Source

synchronization

ZhaoJun 1 year ago
parent
commit
e3d410abd5

+ 4 - 4
src/components/AuditForm/FormulaModal.js

@@ -29,7 +29,7 @@ const FormulaModal = props => {
   }, [formula]);
   console.log('-----------------', formula);
 
-  const isSameBeforItem = type => {
+  const isSameBeforeItem = type => {
     return formula.length > 0 && formula[formula.length - 1].type == type;
   };
 
@@ -38,7 +38,7 @@ const FormulaModal = props => {
     console.log(formula[formula.length - 1]);
     switch (type) {
       case FormulaType.Filed:
-        if (isSameBeforItem(FormulaType.Filed)) {
+        if (isSameBeforeItem(FormulaType.Filed)) {
           message.error('不能选择连续两个组件');
         }
         obj = {
@@ -49,7 +49,7 @@ const FormulaModal = props => {
         setFormula([...formula, obj]);
         break;
       case FormulaType.Symbol:
-        if (isSameBeforItem(FormulaType.Symbol)) {
+        if (isSameBeforeItem(FormulaType.Symbol)) {
           message.error('不能选择连续两个符号');
         }
         obj = { type: FormulaType.Symbol, label: item };
@@ -57,7 +57,7 @@ const FormulaModal = props => {
         break;
       case FormulaType.Number:
         // 如果前一个选择的也是数字则合并数字 否则直接添加
-        if (isSameBeforItem(FormulaType.Number)) {
+        if (isSameBeforeItem(FormulaType.Number)) {
           const len = formula.length - 1;
           const label = formula[len].label + item;
           obj = { type: FormulaType.Number, label };

+ 58 - 0
src/components/AuditForm/ItemAttribute.js

@@ -51,6 +51,12 @@ function ItemAttribute(props) {
       case 'FormulaField':
         FormContent = <FormulaField {...formProps} onFormulaClick={onFormulaClick} />;
         break;
+      case 'ProjectField':
+        FormContent = <ProjectField {...formProps} onFormulaClick={onFormulaClick} />;
+        break;
+      case 'ManufacturerField':
+        FormContent = <ManufacturerField {...formProps} />;
+        break;
       default:
         FormContent = null;
         break;
@@ -419,6 +425,32 @@ function NumberField(props) {
   );
 }
 
+function ProjectField(props) {
+  const { item, btns, onFinish } = props;
+  const [form] = Form.useForm();
+  return (
+    <Form
+      form={form}
+      labelCol={{ span: 6 }}
+      wrapperCol={{ span: 20 }}
+      autoComplete="off"
+      initialValues={item.props}
+      onFinish={onFinish}
+    >
+      <Form.Item label="标题" name="label">
+        <Input />
+      </Form.Item>
+      <Form.Item label="提示文字" name="placeholder">
+        <Input />
+      </Form.Item>
+      <Form.Item label="必填" name="required" valuePropName="checked">
+        <Switch />
+      </Form.Item>
+      {btns}
+    </Form>
+  );
+}
+
 function DIYTableField(props) {
   const { item, btns, onFinish } = props;
   const [form] = Form.useForm();
@@ -470,3 +502,29 @@ function FormulaField(props) {
     </Form>
   );
 }
+
+function ManufacturerField(props) {
+  const { item, btns, onFinish } = props;
+  const [form] = Form.useForm();
+  return (
+    <Form
+      form={form}
+      labelCol={{ span: 6 }}
+      wrapperCol={{ span: 18 }}
+      autoComplete="off"
+      initialValues={item.props}
+      onFinish={onFinish}
+    >
+      <Form.Item label="标题" name="label">
+        <Input />
+      </Form.Item>
+      <Form.Item label="提示文字" name="placeholder">
+        <Input />
+      </Form.Item>
+      <Form.Item label="必填" name="required" valuePropName="checked">
+        <Switch />
+      </Form.Item>
+      {btns}
+    </Form>
+  );
+}

+ 22 - 0
src/components/AuditForm/constant.js

@@ -9,6 +9,8 @@ import {
   InsertRowAboveOutlined,
   TableOutlined,
   LaptopOutlined,
+  ProjectOutlined,
+  SolutionOutlined,
 } from '@ant-design/icons';
 
 export const COMPONENT_LIST = [
@@ -32,6 +34,26 @@ export const COMPONENT_LIST = [
       choice: '0',
     },
   },
+  {
+    componentName: 'ProjectField',
+    icon: <ProjectOutlined />,
+    props: {
+      label: '选择项目',
+      placeholder: '请选择项目',
+      required: false,
+      choice: '0',
+    },
+  },
+  {
+    componentName: 'ManufacturerField',
+    icon: <SolutionOutlined />,
+    props: {
+      label: '选择供应商',
+      placeholder: '请选择供应商',
+      required: false,
+      // choice: '0',
+    },
+  },
   {
     componentName: 'TextField',
     icon: <ItalicOutlined />,

+ 52 - 0
src/components/DDComponents/CodeFiled/index.js

@@ -0,0 +1,52 @@
+import React, { useEffect, useState } from 'react';
+import { Input } from 'antd';
+import { useRequest, useModel } from 'umi';
+import { queryContractCode } from '@/services/contract';
+
+function CodeField(props) {
+  const { depId, onChange } = props;
+  const { depList, run } = useModel('depList');
+  const [value, setValue] = useState('');
+
+  // 计算合同编号接口
+  const { run: runCode } = useRequest(data => queryContractCode(data), {
+    manual: true,
+    onSuccess: data => {
+      setValue(data?.code);
+      onChange?.(data?.code);
+    },
+  });
+  useEffect(() => {
+    run();
+  }, []);
+
+  useEffect(() => {
+    if (!depId) return;
+    const dep_code = getDepItemById(depId)?.Code;
+    const compony = depList.find(item => item.Flag == 1);
+    let params = {
+      company_id: compony?.ID,
+      company_code: compony?.Code,
+      dep_code,
+    };
+    runCode(params);
+  }, [depId, depList]);
+
+  const getDepItemById = id => {
+    const fun = list => {
+      for (let i = 0; i < list.length; i++) {
+        let item = list[i];
+        if (item.ID == id) {
+          return item;
+        } else if (item.children?.length > 0) {
+          let res = fun(item.children);
+          if (res) return res;
+        }
+      }
+    };
+    return fun(depList);
+  };
+  return <Input value={value} placeholder="选择部门后自动生成" disabled />;
+}
+
+export default CodeField;

+ 1 - 0
src/components/DDComponents/DDAttachment/index.js

@@ -1,6 +1,7 @@
 import React, { useState, useEffect } from 'react';
 import { Upload, Button, message } from 'antd';
 import { PlusOutlined } from '@ant-design/icons';
+import AliyunOSSUpload from '@/components/OssUpload/AliyunOssUploader';
 
 const CORP_ID = 'ding0cdce2d5dbf986d9';
 const AGENT_ID = '1788653353';

+ 53 - 0
src/components/DDComponents/ManufacturerField/index.js

@@ -0,0 +1,53 @@
+import React, { useState, useEffect } from 'react';
+import { Select } from 'antd';
+import { querySupplierList } from '@/services/contract';
+
+const { Option } = Select;
+
+function ManufacturerField(props) {
+  const { value, disabled = false, onChange } = props;
+  const user = JSON.parse(localStorage.getItem('currentUser'));
+
+  const [option, setOption] = useState([]);
+  const [loading, setLoading] = useState(false);
+
+  const getSupplier = async () => {
+    setLoading(true);
+    const res = await querySupplierList({
+      project_id: 1,
+      is_super: user.IsSuper,
+      created_by: user.CName,
+      pageSize: 9999,
+    }).catch(err => {
+      console.log(err);
+      setLoading(false);
+    });
+    console.log('--------------------------', res);
+    if (res?.code === 200) {
+      const supplier = res?.data.list.map(item => {
+        return { label: item.name, value: item.id };
+      });
+      setOption(supplier);
+    }
+    setLoading(false);
+  };
+  useEffect(() => {
+    getSupplier();
+  }, []);
+  return (
+    <Select
+      showSearch
+      loading={loading}
+      style={{ width: '100%' }}
+      disabled={disabled}
+      defaultValue={value ? Number(value) : undefined}
+      onChange={val => {
+        onChange(String(val));
+      }}
+      filterOption={(input, opt) => (opt?.label ?? '').toLowerCase().includes(input.toLowerCase())}
+      options={option}
+    />
+  );
+}
+
+export default ManufacturerField;

+ 50 - 0
src/components/DDComponents/ProjectField/index.js

@@ -0,0 +1,50 @@
+import React, { useEffect, useState } from 'react';
+import { Select } from 'antd';
+import { queryApproval } from '@/services/approval';
+
+function DDProjectField(props) {
+  const { value, disabled = false, onChange } = props;
+  const [projectList, setProjectList] = useState([]);
+  const [loading, setLoading] = useState(false);
+
+  const getProjectList = async () => {
+    setLoading(true);
+    const res = await queryApproval({ pageSize: 9999 }).catch(err => {
+      console.log(err);
+      setLoading(false);
+    });
+    if (res.code === 200) {
+      console.log(res.data.list);
+      setProjectList(res.data.list);
+      setLoading(false);
+    }
+  };
+
+  useEffect(() => {
+    getProjectList();
+  }, []);
+  return (
+    <Select
+      showSearch
+      loading={loading}
+      style={{ width: '100%' }}
+      disabled={disabled}
+      defaultValue={value ? Number(value) : undefined}
+      onChange={val => {
+        console.log(val);
+        onChange(String(val));
+      }}
+      filterOption={(input, option) =>
+        (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
+      }
+      options={projectList.map(item => {
+        return {
+          label: `${item.project_name}(${item.project_full_code})`,
+          value: item.id,
+        };
+      })}
+    />
+  );
+}
+
+export default DDProjectField;

+ 10 - 1
src/components/DDComponents/index.js

@@ -14,12 +14,14 @@ import DDDateRangeField from './DDDateRangeField';
 import FormulaField from './FormulaField';
 import DIYTable from './DIYTable/index.tsx';
 import TextNode from './TextNote';
+import DDProjectField from './ProjectField';
+import ManufacturerField from './ManufacturerField';
 
 const { Option } = Select;
 const { RangePicker } = DatePicker;
 
 export default function DDComponents(props) {
-  const { evalStr = '', item, onChange } = props;
+  const { depId = '', evalStr = '', item, onChange } = props;
   const {
     id,
     label,
@@ -130,12 +132,18 @@ export default function DDComponents(props) {
     case 'DepartmentField': // 部门控件
       component = <DepartmentField onChange={onChange} />;
       break;
+    case 'ProjectField': // 项目控件
+      component = <DDProjectField value={defaultValue} disabled={disabled} onChange={onChange} />;
+      break;
     case 'DIYTable': // 可自定义表格控件
       component = <DIYTable table={item} columns={item.columns} onChange={onChange} />;
       break;
     case 'FormulaField':
       component = <FormulaField evalStr={evalStr} onChange={onChange} />;
       break;
+    case 'ManufacturerField':
+      component = <ManufacturerField onChange={onChange} />;
+      break;
     case 'RelateField': // 关联审批单
       component = '关联审批单控件未渲染!';
       break;
@@ -148,6 +156,7 @@ export default function DDComponents(props) {
     case 'FormRelateField': // 关联控件
       component = '关联控件未渲染!';
       break;
+
     default:
       break;
   }

+ 4 - 5
src/pages/Detail/AuditDetailed.js

@@ -65,18 +65,17 @@ const AuditDetailed = props => {
 
     const renderComponents = () => {
       let content = '';
-      if (item.componentName === 'CodeField') {
+      if (item.componentName === 'CodeFiled') {
         content = <DDComponents item={item} depId={depId} />;
       } else if (item.componentName === 'FormulaField') {
         const strList = item.props?.formula?.map(formu => {
-          if (formu.type == FormulaType.Filed) {
+          if (formu.type === FormulaType.Filed) {
             const numItem = allValues?.find(item => item.id == formu.id);
             return numItem?.value[0] || 0;
-          } else {
-            return formu.label;
           }
+          return formu.label;
         });
-        console.log('-------44444-------------', item, strList);
+        console.log('-------formula-------------', item, strList);
         const evalStr = strList?.join('');
         content = <DDComponents item={item} evalStr={evalStr} />;
       } else {

+ 2 - 1
src/pages/Detail/CommitAuditModal.js

@@ -467,6 +467,7 @@ function CommitAuditModal(props) {
       });
     }
     setFormComponentValues({ ...formComponentValues, [currentNodeID]: componentValue });
+    formValueRef.current.form[currentNodeID] = [...componentValue];
     advanceSubmit();
   };
 
@@ -846,7 +847,7 @@ function CommitAuditModal(props) {
             <Row>
               <Col span={17}>
                 <AuditDetailed
-                  allValues={formValueRef.current.form}
+                  allValues={formValueRef.current.form[item.nodeId]}
                   items={item.items}
                   form={aduitDetailForm}
                   onValuesChange={onFormValueChange}

+ 1 - 1
src/pages/Detail/Index.js

@@ -401,7 +401,7 @@ function Detail(props) {
 
   const changeVersion = async id => {
     let version;
-    if (typeof id == 'object') {
+    if (typeof id === 'object') {
       version = id;
       localStorage.excelId = version.id;
       localStorage.excelItem = JSON.stringify(version);

+ 15 - 0
src/services/contract.js

@@ -0,0 +1,15 @@
+import request from '@/utils/request';
+
+//计算合同编号
+export const queryContractCode = async data => {
+  return await request('/api/contract/v1/code', {
+    params: data,
+  });
+};
+
+export const querySupplierList = async data => {
+  return await request('/api/supplier/v1/supplier/list', {
+    method: 'POST',
+    body: data,
+  });
+};

+ 2 - 1
src/utils/request.js

@@ -81,12 +81,13 @@ export default function request(url, option, jwt) {
   // console.log(API_HOST);
   const time = url.indexOf('?') > -1 ? `&time=${number}` : `?time=${number}`;
   if (url.indexOf('http://') == -1 && url.indexOf('https://') == -1) {
-    if (url.indexOf('/api/v') === -1) {
+    if (url.indexOf('/api/v') === -1 && url.indexOf('/api/supplier')) {
       url = `/api/v1${url}${time}`;
     }
     // API_HOST在config/config.js的define中配置
     // url = API_HOST + url
   }
+  console.log(url);
   let token = getToken();
   if (!token) {
     token = GetTokenFromUrl();