|
@@ -2,13 +2,14 @@ import React, { useEffect, useState } from 'react';
|
|
|
import { Input } from 'antd';
|
|
|
import { useRequest, useModel } from 'umi';
|
|
|
import { queryContractCode } from '@/services/contract';
|
|
|
+import { queryDepsV2 } from '@/services/department';
|
|
|
|
|
|
function CodeField(props) {
|
|
|
const { depId, onChange } = props;
|
|
|
- const { depList, run } = useModel('depList');
|
|
|
+ const [depList, setDepList] = useState([]);
|
|
|
const [value, setValue] = useState('');
|
|
|
|
|
|
- // 计算合同编号接口
|
|
|
+ // 每次更新时 计算合同编号接口 并返回
|
|
|
const { run: runCode } = useRequest(data => queryContractCode(data), {
|
|
|
manual: true,
|
|
|
onSuccess: data => {
|
|
@@ -16,12 +17,21 @@ function CodeField(props) {
|
|
|
onChange?.(data?.code);
|
|
|
},
|
|
|
});
|
|
|
+
|
|
|
+ const getDepList = async () => {
|
|
|
+ const res = await queryDepsV2().catch(err => console.log(err));
|
|
|
+ console.log(res);
|
|
|
+ if (res && res.code === 200) {
|
|
|
+ setDepList(res.data.list);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // 初始化时请求部门列表
|
|
|
useEffect(() => {
|
|
|
- run();
|
|
|
+ getDepList();
|
|
|
}, []);
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (!depId) return;
|
|
|
+ if (!depId || !depList.length) return;
|
|
|
const dep_code = getDepItemById(depId)?.Code;
|
|
|
const compony = depList.find(item => item.Flag == 1);
|
|
|
let params = {
|
|
@@ -35,11 +45,12 @@ function CodeField(props) {
|
|
|
const getDepItemById = id => {
|
|
|
const fun = list => {
|
|
|
for (let i = 0; i < list.length; i++) {
|
|
|
- let item = list[i];
|
|
|
- if (item.ID == id) {
|
|
|
+ const item = list[i];
|
|
|
+ if (Number(item.ID) === Number(id)) {
|
|
|
return item;
|
|
|
- } else if (item.children?.length > 0) {
|
|
|
- let res = fun(item.children);
|
|
|
+ }
|
|
|
+ if (item.children?.length > 0) {
|
|
|
+ const res = fun(item.children);
|
|
|
if (res) return res;
|
|
|
}
|
|
|
}
|