xujunjie 2 سال پیش
والد
کامیت
218b13d37d
3فایلهای تغییر یافته به همراه69 افزوده شده و 2 حذف شده
  1. 2 2
      config/config.js
  2. 60 0
      src/components/DDComponents/DepartmentField/index.js
  3. 7 0
      src/services/boom.js

+ 2 - 2
config/config.js

@@ -140,8 +140,8 @@ export default {
   chainWebpack: webpackPlugin,
   proxy: {
     '/api': {
-      // target: 'http://192.168.20.152:8888/',
-      target: 'http://47.96.12.136:8896/',
+      target: 'http://192.168.20.152:8888/',
+      // target: 'http://47.96.12.136:8896/',
       // target: 'http://oraysmart.com:8889/',
       // target: 'http://oraysmart.com:8888/api',
       // changeOrigin: true,

+ 60 - 0
src/components/DDComponents/DepartmentField/index.js

@@ -0,0 +1,60 @@
+import { TreeSelect } from 'antd';
+import React, { useState } from 'react';
+import { queryDDdepList } from '@/services/boom';
+
+function DepartmentField(props) {
+  const { value, onChange } = props;
+
+  // const [value, setValue] = useState();
+  const [treeData, setTreeData] = useState([]);
+
+  const genTreeNode = dep => {
+    return {
+      id: dep.dept_id,
+      pId: dep.parent_id,
+      value: dep.dept_id,
+      title: dep.name,
+      isLeaf: true,
+    };
+  };
+
+  const onLoadData = async parentId => {
+    let depList = await queryDDdepList({ dept_id: parentId });
+    if (depList.length > 0) {
+      let nodes = depList.map(genTreeNode);
+      setTreeData([...treeData, ...nodes]);
+    } else if (parentId) {
+      let parentNode = treeData.find(item => item.id == parentId);
+      parentNode.isLeaf = false;
+      setTreeData([...treeData]);
+    }
+  };
+
+  const onChangeValue = newValue => {
+    onChange(newValue);
+  };
+
+  useEffect(() => {
+    onLoadData();
+  }, []);
+
+  return (
+    <TreeSelect
+      treeDataSimpleMode
+      style={{
+        width: '100%',
+      }}
+      value={value}
+      dropdownStyle={{
+        maxHeight: 400,
+        overflow: 'auto',
+      }}
+      placeholder="请选择部门"
+      onChange={onChangeValue}
+      loadData={onLoadData}
+      treeData={treeData}
+    />
+  );
+}
+
+export default DepartmentField;

+ 7 - 0
src/services/boom.js

@@ -287,3 +287,10 @@ export async function queryRecordSheet(data) {
 export async function queryDingTemplateList() {
   return request(`/purchase/bom/ding/template/list`);
 }
+
+export async function queryDDdepList(data) {
+  return request(`/api/v1/purchase/bom/ding/department-list`, {
+    method: 'POST',
+    body: data,
+  });
+}