فهرست منبع

审批流表单添加合同编号控件

Renxy 1 سال پیش
والد
کامیت
a36b70a560

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

@@ -57,6 +57,9 @@ function ItemAttribute(props) {
       case 'DDDateField':
         FormContent = <DDDateField {...formProps} />;
         break;
+      case 'CodeField':
+        FormContent = <CodeField {...formProps} />;
+        break;
     }
 
     return FormContent;
@@ -176,6 +179,31 @@ function ProjectField(props) {
     </Form>
   );
 }
+function CodeField(props) {
+  const { item, btns, onFinish } = props;
+  const [form] = Form.useForm();
+  return (
+    <Form
+      form={form}
+      labelCol={{ span: 4 }}
+      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 ManufacturerField(props) {
   const { item, btns, onFinish } = props;
   const [form] = Form.useForm();

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

@@ -11,6 +11,7 @@ import {
   FontColorsOutlined,
   ProjectOutlined,
   SolutionOutlined,
+  NumberOutlined,
 } from '@ant-design/icons';
 
 export const COMPONENT_LIST = [
@@ -131,4 +132,14 @@ export const COMPONENT_LIST = [
       required: false,
     },
   },
+  {
+    componentName: 'CodeField',
+    icon: <NumberOutlined />,
+    props: {
+      label: '合同编号',
+      bizAlias: '',
+      placeholder: '自动生成',
+      required: false,
+    },
+  },
 ];

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

@@ -0,0 +1,51 @@
+import React, { useEffect, useState } from 'react';
+import { Input } from 'antd';
+import { useRequest, useModel } from '@umijs/max';
+import { queryContractCode } from '@/services/contract';
+
+function CodeField(props) {
+  const { depId } = props;
+  const { depList, run } = useModel('depList');
+  const [value, setValue] = useState('');
+
+  //计算合同编号接口
+  const { run: runCode } = useRequest((data) => queryContractCode(data), {
+    manual: true,
+    onSuccess: (data) => {
+      setValue(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;

+ 15 - 5
src/components/DDComponents/DepartmentField/index.js

@@ -1,10 +1,20 @@
-import { useModel } from '@umijs/max';
-import { TreeSelect } from 'antd';
+import { useRequest } from '@umijs/max';
+import { Select, TreeSelect } from 'antd';
 import { useEffect } from 'react';
+import { queryDepsV2 } from '@/services/approval';
 
 function DepartmentField(props) {
   const { value, onChange, disabled = false } = props;
-  const { depList, run, loading } = useModel('depList');
+  // const { depList, run, loading } = useModel('depList');
+  // 新建合同时,选择本部时,需要用另一个接口请求部门数据
+  const { data, run, loading } = useRequest(queryDepsV2, {
+    manual: true,
+    formatResult: (response) => {
+      return response.data?.map((item) => {
+        return { value: item.ID, label: item.Name };
+      });
+    },
+  });
 
   const onChangeValue = (newValue) => {
     onChange(String(newValue));
@@ -14,7 +24,7 @@ function DepartmentField(props) {
   }, []);
 
   return (
-    <TreeSelect
+    <Select
       showSearch
       // multiple
       allowClear
@@ -26,7 +36,7 @@ function DepartmentField(props) {
       loading={loading}
       style={{ width: '100%' }}
       placeholder="请选择部门"
-      treeData={depList}
+      options={data}
       onChange={onChangeValue}
       disabled={disabled}
     />

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

@@ -13,9 +13,10 @@ import DDDateField from './DDDateField';
 import DDDateRangeField from './DDDateRangeField';
 import DDAttachment from './DDAttachment';
 import TextNote from './TextNote';
+import CodeField from './CodeFiled';
 
 export default function DDComponents(props) {
-  const { item, onChange } = props;
+  const { depId = '', item, onChange } = props;
   const { placeholder, options, format, unit, disabled, notUpper } = item.props;
   let component = null;
   switch (item.componentName) {
@@ -123,6 +124,9 @@ export default function DDComponents(props) {
     case 'FormRelateField': //关联控件
       component = '关联控件未渲染!';
       break;
+    case 'CodeField': //合同编号控件
+      component = <CodeField depId={depId} />;
+      break;
   }
 
   return (

+ 1 - 0
src/pages/Flow/OaDetail.js

@@ -147,6 +147,7 @@ const OaDetail = () => {
               />
             )} */}
           <AuditDetailed
+            allValues={formValueRef.current.form}
             form={form}
             items={data?.formData}
             onValuesChange={advanceSubmit}

+ 15 - 2
src/pages/Flow/components/AuditDetailed.js

@@ -4,7 +4,16 @@ import { Button, Form } from 'antd';
 
 const AuditDetailed = (props) => {
   // const [form] = Form.useForm();
-  const { items, form, onValuesChange } = props;
+  const { allValues = [], items, form, onValuesChange } = props;
+
+  const depId = useMemo(() => {
+    const id = items.find((item) => item.componentName == 'DepartmentField')
+      ?.props.id;
+    const value = allValues.find((item) => item.id == id)?.value;
+    if (value) return value[0];
+  }, [allValues, items]);
+
+  console.log(items, allValues);
   const data = useMemo(() => {
     let linkedData = {};
     items.forEach((d) => {
@@ -66,7 +75,11 @@ const AuditDetailed = (props) => {
         label={formLabel}
         rules={[{ required: required }]}
       >
-        <DDComponents item={item} />
+        {item.componentName == 'CodeField' ? (
+          <DDComponents item={item} depId={depId} />
+        ) : (
+          <DDComponents item={item} />
+        )}
       </Form.Item>
     );
   };