From ab003fccad96beb96d18f8018980e6c75ed03edc Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 08 八月 2023 16:28:43 +0800
Subject: [PATCH] 2023-08-08

---
 src/tabviews/custom/components/chart/antv-X6/nodeupdate/memberform.jsx |  101 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 96 insertions(+), 5 deletions(-)

diff --git a/src/tabviews/custom/components/chart/antv-X6/nodeupdate/memberform.jsx b/src/tabviews/custom/components/chart/antv-X6/nodeupdate/memberform.jsx
index 4602e47..37827b0 100644
--- a/src/tabviews/custom/components/chart/antv-X6/nodeupdate/memberform.jsx
+++ b/src/tabviews/custom/components/chart/antv-X6/nodeupdate/memberform.jsx
@@ -1,9 +1,11 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { Modal, Transfer, Tree } from 'antd'
+import { fromJS } from 'immutable'
+import { Modal, Transfer, Tree, Input, notification } from 'antd'
 import { FormOutlined } from '@ant-design/icons'
 
 const { TreeNode } = Tree
+const { Search } = Input
 
 const isChecked = (selectedKeys, eventKey) => {
   return selectedKeys.indexOf(eventKey) !== -1
@@ -72,20 +74,108 @@
 
   state = {
     visible: false,
-    targetKeys: ['sifuweoifuweifuo']
+    targetKeys: [],
+    users: []
   }
 
   onChange = targetKeys => {
     this.setState({ targetKeys })
   }
 
-  render() {
+  search = (val) => {
     const { orgs } = this.props
-    const { visible, targetKeys } = this.state
+    
+    let _orgs = fromJS(orgs).toJS()
+    let _orgs_ = []
+    if (val) {
+      let getOrg = (ors) => {
+        return ors.filter(or => {
+          if (or.key.indexOf(val) > -1 || or.title.indexOf(val) > -1) {
+            return true
+          } else if (!or.children) {
+            return false
+          }
+
+          or.children = getOrg(or.children)
+
+          return or.children.length > 0
+        })
+      }
+
+      _orgs_ = getOrg(_orgs)
+    } else {
+      _orgs_ = _orgs
+    }
+
+    this.setState({orgs: _orgs_})
+  }
+
+  trigger = () => {
+    const { orgs, value, title } = this.props
+
+    let userIds = []
+    let users = {}
+
+    let getUsers = (ors) => {
+      ors.forEach(or => {
+        if (or.children) {
+          getUsers(or.children)
+        } else {
+          users[or.worker_id] = or
+          userIds.push(or.worker_id)
+        }
+      })
+    }
+
+    getUsers(orgs)
+
+    let targetKeys = []
+    let lost_works = []
+    value.forEach(user => {
+      if (userIds.includes(user.worker_id)) {
+        targetKeys.push(user.worker_id)
+      } else {
+        lost_works.push(user)
+      }
+    })
+
+    if (lost_works.length) {
+      notification.warning({
+        top: 92,
+        message: `鍘�${title} ${lost_works.map(item => item.workername).join('銆�')} 涓嶅瓨鍦紝璇烽噸鏂版坊鍔犮�俙,
+        duration: 10
+      })
+    }
+
+    this.setState({visible: true, orgs: fromJS(orgs).toJS(), targetKeys, users})
+  }
+
+  confirm = () => {
+    const { targetKeys, users } = this.state
+
+    let value = []
+    targetKeys.forEach(key => {
+      if (!users[key]) return
+
+      let user = fromJS(users[key]).toJS()
+
+      delete user.key
+      delete user.title
+
+      value.push(user)
+    })
+
+    this.setState({visible: false})
+    this.props.onChange(value)
+  }
+
+  render() {
+    const { value } = this.props
+    const { orgs, visible, targetKeys } = this.state
 
     return (
       <>
-        <div className="member-input">0浜�<FormOutlined onClick={() => this.setState({visible: true})} /></div>
+        <div className="member-input">{value.length}浜�<FormOutlined onClick={this.trigger} /></div>
         <Modal
           wrapClassName="member-modal"
           title="閫夋嫨浜哄憳"
@@ -97,6 +187,7 @@
           onCancel={() => this.setState({visible: false})}
           destroyOnClose
         >
+          <Search onSearch={this.search}/>
           <TreeTransfer dataSource={orgs} targetKeys={targetKeys} onChange={this.onChange} />
         </Modal>
       </>

--
Gitblit v1.8.0