123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- 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;
|