Browse Source

alert delett

baozhangchao 3 years ago
parent
commit
65b3b5e4e1
2 changed files with 312 additions and 228 deletions
  1. 158
    120
      src/pages/staff/Organization/form.jsx
  2. 154
    108
      src/pages/staff/Organization/index.jsx

+ 158
- 120
src/pages/staff/Organization/form.jsx View File

@@ -1,16 +1,20 @@
1 1
 
2 2
 
3 3
 import React, { useEffect, useState, useCallback } from 'react';
4
-import { Button, Form, Select, Input, InputNumber, Radio, message, Card,DatePicker, } from 'antd';
5
-import ImageUpload from '@/components/XForm/ImageUpload';
4
+import { Button, Form, Select, Input, InputNumber, Radio, message, Card, DatePicker, } from 'antd';
5
+// import ImageUpload from '@/components/XForm/ImageUpload';
6
+// import { ProFormDatePicker } from "@ant-design/pro-form";
7
+
6 8
 import { values } from 'lodash';
7 9
 const FormItem = Form.Item;
8
-const {RangePicker}=DatePicker
10
+const { RangePicker } = DatePicker
9 11
 const { Option } = Select;
10 12
 const TreedataFrom = React.forwardRef((props, ref) => {
11
-  const [treeData, setTreeData] = useState();
13
+  // const [treeData, onChangethis] = useState();
14
+  const [treeData, settreeData] = useState(0)
15
+  const OnchangeThis = (value) => { }
12 16
   const [data, setData] = useState(treeData);
13
-  const { form, treeTitle } = props;
17
+  const { form, treeTitle, onChangethis } = props;
14 18
   const { getFieldDecorator, setFieldsValue, validateFields } = form;
15 19
 
16 20
   const formItemLayout = {
@@ -21,132 +25,166 @@ const TreedataFrom = React.forwardRef((props, ref) => {
21 25
   };
22 26
   const formRef = React.createRef();
23 27
 
24
-  const onChange=(date, dateString)=> {
28
+  const onChange = (date, dateString) => {
29
+    // onChangethis(value)
25 30
     console.log(date, dateString);
26 31
   }
27 32
 
33
+  const handleSubmit = (value) => {
34
+    props.onChangethis(value)
35
+    console.log(value);
36
+
37
+    setFieldsValue(treeData)
38
+
39
+  }
40
+
41
+
28 42
 
29 43
 
30
- const handleChange=(value)=> {
31
-    console.log(`selected ${value}`);
44
+
45
+  const handleChange = (e, props) => {
46
+
47
+    // e.preventDefault();
48
+    let arr = []
49
+    arr = props.form.getFieldsValue()
50
+    // console.log(arr)
51
+    onChangethis(arr)
52
+
32 53
   }
33
-  const handleSubmit = (e) => {
34
-    e.preventDefault();
35
-    validateFields((err, values) => {
36
-      if (err) {
37
-        return;
38
-        //字符验证未填写---返回
39
-      }
40
-    });
54
+  // const handleSubmit = (e) => {s
55
+  //   e.preventDefault();
56
+  //   validateFields((err, values) => {
57
+  //     if (err) {
58
+  //       return;
59
+  //       //字符验证未填写---返回
60
+  //     }
61
+  //   });
62
+  // }
63
+  //挂载 我先看看
64
+  const componentDidMount = () => {
65
+    console.log(this.props.FromValue)
66
+
67
+    this.props.triggerRef(this)
41 68
   }
42 69
 
43 70
 
44 71
   return (
45 72
 
46
-    <Form {...formItemLayout}  ref={formRef}  onChange={onChange}   onSubmit={handleSubmit} >
47
-            <FormItem label="姓名">
48
-              {getFieldDecorator('title', {
49
-                rules: [{ required: true, message: '请输入姓名!' }],
50
-              })(<Input/>)}
51
-            </FormItem>
52
-            <FormItem label="身份证号" >
53
-               {
54
-                getFieldDecorator('cardId', {
55
-                  rules: [{ required: true, message: '请输入身份证号' }]
56
-                })(
57
-                  <Input maxLength={19} />
58
-                )
59
-              }
60
-            </FormItem>
61
-            <FormItem label="性别">
62
-              {
63
-                getFieldDecorator('sex', {
64
-                  rules: [
65
-                    { required: true, message: '请选择性别' }
66
-                  ]
67
-                })(
68
-                  <Radio.Group  style={{ width: '500px' }} initialValue={1}>
69
-                    <Radio value={1}>男</Radio>
70
-                    <Radio value={2}>女</Radio>
71
-                  </Radio.Group>
72
-                )
73
-              }
74
-            </FormItem>
75
-            <FormItem label="联系方式" >
76
-               {
77
-                getFieldDecorator('phone', {
78
-                  rules: [{ required: true, message: '请输入联系方式' }]
79
-                })(
80
-                  <Input  maxLength={11}/>
81
-                )
82
-              }
83
-            </FormItem>
84
-            <FormItem label="员工卡号" >
85
-               {
86
-                getFieldDecorator('id', {
87
-                  rules: [{ required: true, message: '请输入员工卡号' }]
88
-                })(
89
-                  <Input />
90
-                )
91
-              }
92
-            </FormItem>
93
-            <FormItem label="归属部门" >
94
-               {
95
-                getFieldDecorator('belon', {
96
-                  rules: [{ required: true, message: '请选择归属部门' }]
97
-                })(
98
-                  <Select initialValue={1}  onChange={handleChange}>
99
-                  <Option value={1}>财务部</Option>
100
-                  <Option value={2}>宣传部</Option>
101
-                  <Option value={3}>研发部</Option>
102
-                  <Option value={4}>仓储物流部</Option>
103
-                </Select>
104
-                )
105
-              }
106
-            </FormItem>
107
-            <FormItem label="居住所在地" >
108
-               {
109
-                getFieldDecorator('homeaddres', {
110
-                  rules: [{ required: true, message: '请选择所在地' }]
111
-                })(
112
-                  <Select initialValue={1}  onChange={handleChange}>
113
-                  <Option value={1}>南京</Option>
114
-                  <Option value={2}>北京</Option>
115
-                  <Option value={3}>湖北</Option>
116
-                  <Option value={4}>湖南</Option>
117
-                  <Option value={5}>上海</Option>
118
-                  <Option value={6}>四川</Option>
119
-                </Select>
120
-                )
121
-              }
122
-            </FormItem>
123
-            <FormItem label="备注" >
124
-               {
125
-                getFieldDecorator('remark', {
126
-                  rules: [{ required: false, message: '请输入备注' }]
127
-                })(
128
-                  <Input />
129
-                )
130
-              }
131
-            </FormItem>
132
-            <FormItem label="出生日期" style={{ marginBottom: 0 }} >
133
-              {
134
-                getFieldDecorator('day', {
135
-                  rules: [
136
-                    { required: true, message: '请选择出生日期' }
137
-                  ]
138
-                })(
139
-                // <RangePicker style={{width: '255px'}} />
140
-                <DatePicker onChange={onChange} />
141
-                )
142
-              }
143
-            </FormItem>
144
-            <FormItem wrapperCol={{ span: 12, offset: 5 }}>
145
-              <Button type="primary"  htmlType="submit" style={{marginLeft:'80px' , marginTop:'30px'}}>
146
-                修改
147
-              </Button>
148
-            </FormItem>
149
-          </Form>
73
+    <Form   {...formItemLayout} ref={formRef}
74
+      // onChange={onChange}  onSubmit只有一个 随便写个不行吗onDelete
75
+      onSubmit={e => handleChange(e, props)}
76
+
77
+
78
+    >
79
+      <FormItem hidden >
80
+        {getFieldDecorator('key')(<Input />)}
81
+      </FormItem>
82
+      <FormItem label="姓名">
83
+        {getFieldDecorator('title', {
84
+          rules: [{ required: true, message: '请输入姓名!' }],
85
+        })(<Input />)}
86
+      </FormItem>
87
+      <FormItem label="身份证号" >
88
+        {
89
+          getFieldDecorator('cardId', {
90
+            rules: [{ required: true, message: '请输入身份证号' }]
91
+          })(
92
+            <Input maxLength={19} />
93
+          )
94
+        }
95
+      </FormItem>
96
+      <FormItem label="性别">
97
+        {
98
+          getFieldDecorator('sex', {
99
+            rules: [
100
+              { required: true, message: '请选择性别' }
101
+            ]
102
+          })(
103
+            <Radio.Group style={{ width: '500px' }} initialValue={1}>
104
+              <Radio value={1}>男</Radio>
105
+              <Radio value={2}>女</Radio>
106
+            </Radio.Group>
107
+          )
108
+        }
109
+      </FormItem>
110
+      <FormItem label="联系方式" >
111
+        {
112
+          getFieldDecorator('phone', {
113
+            rules: [{ required: true, message: '请输入联系方式' }]
114
+          })(
115
+            <Input maxLength={11} />
116
+          )
117
+        }
118
+      </FormItem>
119
+      <FormItem label="员工卡号" >
120
+        {
121
+          getFieldDecorator('id', {
122
+            rules: [{ required: true, message: '请输入员工卡号' }]
123
+          })(
124
+            <Input />
125
+          )
126
+        }
127
+      </FormItem>
128
+      <FormItem label="归属部门" >
129
+        {
130
+          getFieldDecorator('belon', {
131
+            rules: [{ required: true, message: '请选择归属部门' }]
132
+          })(
133
+            <Select initialValue={1} onChange={handleChange}>
134
+              <Option value={1}>财务部</Option>
135
+              <Option value={2}>宣传部</Option>
136
+              <Option value={3}>研发部</Option>
137
+              <Option value={4}>仓储物流部</Option>
138
+            </Select>
139
+          )
140
+        }
141
+      </FormItem>
142
+      <FormItem label="居住所在地" >
143
+        {
144
+          getFieldDecorator('homeaddres', {
145
+            rules: [{ required: true, message: '请选择所在地' }]
146
+          })(
147
+            <Select initialValue={1} onChange={handleChange}>
148
+              <Option value={1}>南京</Option>
149
+              <Option value={2}>北京</Option>
150
+              <Option value={3}>湖北</Option>
151
+              <Option value={4}>湖南</Option>
152
+              <Option value={5}>上海</Option>
153
+              <Option value={6}>四川</Option>
154
+            </Select>
155
+          )
156
+        }
157
+      </FormItem>
158
+      <FormItem label="备注" >
159
+        {
160
+          getFieldDecorator('remark', {
161
+            rules: [{ required: false, message: '请输入备注' }]
162
+          })(
163
+            <Input />
164
+          )
165
+        }
166
+      </FormItem>
167
+      <FormItem label="出生日期" style={{ marginBottom: 0 }} >
168
+        {
169
+          getFieldDecorator('day', {
170
+            rules: [
171
+              { required: true, message: '请选择出生日期' }
172
+            ]
173
+          })(
174
+            // <RangePicker style={{width: '255px'}} 还是有点问题0.0为啥 />
175
+            <DatePicker onChange={onChange} />
176
+          )
177
+        }
178
+      </FormItem>
179
+      <FormItem wrapperCol={{ span: 12, offset: 5 }}>
180
+        <Button type="primary" htmlType="submit" style={{ marginLeft: '80px', marginTop: '30px' }}>
181
+          修改
182
+        </Button>
183
+        <Button type="danger">
184
+          删除
185
+        </Button>
186
+      </FormItem>
187
+    </Form>
150 188
   )
151 189
 })
152 190
 

+ 154
- 108
src/pages/staff/Organization/index.jsx View File

@@ -1,36 +1,37 @@
1 1
 
2 2
 import { Row, Col, Card, Tree, Form, TreeSelect, Input, InputNumber, Modal, Button, message } from 'antd'
3
+import moment from 'moment';
3 4
 // import React, { useEffect, useState, useCallback,useRef } from 'react';
4 5
 import TreedataFrom from './form';
5 6
 
6
-const { TreeNode,DirectoryTree } = Tree;
7
+const { TreeNode, DirectoryTree } = Tree;
7 8
 const FormItem = Form.Item;
8 9
 
9 10
 //-----------------------------------
10
-  const onAdd = (key) => {
11
-    if (expandedKeys.indexOf(key) === -1) {
12
-      expandedKeyArr.push(key);
13
-    }
14
-    expandedKeys(expandedKeyArr.slice());
15
-    addNode(key, treeData);//添加节点 树形
16
-    setData(treeData.slice());//添加子项
17
-  };
11
+const onAdd = (key) => {
12
+  if (expandedKeys.indexOf(key) === -1) {
13
+    expandedKeyArr.push(key);
14
+  }
15
+  expandedKeys(expandedKeyArr.slice());
16
+  addNode(key, treeData);//添加节点 树形
17
+  setData(treeData.slice());//添加子项
18
+};
18 19
 //-----------------------------------
19 20
 const confirm = data => {
20 21
   // {...data,isPublish}
21
-    if (data.key !== 0) {
22
-      Modal.confirm({
23
-        title: '确认删除吗?',
24
-        okText: '确认',
25
-        cancelText: '取消',
26
-        onOk() {
27
-          message.error('失败');
28
-
29
-        },
30
-      });
31
-    }else{
32
-      message.error('error')
33
-    }
22
+  if (data.key !== 0) {
23
+    Modal.confirm({
24
+      title: '确认删除吗?',
25
+      okText: '确认',
26
+      cancelText: '取消',
27
+      onOk() {
28
+        message.error('失败');
29
+
30
+      },
31
+    });
32
+  } else {
33
+    message.error('error')
34
+  }
34 35
 }
35 36
 
36 37
 
@@ -44,41 +45,51 @@ const confirm = data => {
44 45
 //   var uuid = s.join("");
45 46
 //   return uuid;
46 47
 // }
47
-const treeData = [
48
-  {
49
-    title: '分厂厂长管理',
50
-    key: '0',
51
-    children: [
52
-        { title: '郎岩',phone:'15920583224', cardId:'511502199103223189',sex:1,id:'0212',belon:1,homeaddres:1, key: '0-0-0-1' },
53
-        { title: '柯琼彦',phone:'13184013427', cardId:'210203197503102721', sex:2 ,id:'4242',belon:2,homeaddres:2, key: '0-0-0-2' ,},
54
-    ],
55
-  },
56
-  {
48
+// import moment from 'moment';
49
+
50
+
51
+const treeData =
52
+  [
53
+    {
54
+      title: '分厂厂长管理',
55
+      key: '0',
56
+      selectable: false,
57
+      children: [
58
+        { title: '郎岩', phone: '15920583224', remark: "", day: "1992-11-13", cardId: '511502199103223189', sex: 1, id: '0212', belon: 1, homeaddres: 1, key: '0-0-0-1' },//这个不行么 你写错了 你那是v4的写法在哪?刚刚那个啊。对
59
+        { title: '柯琼彦', phone: '13184013427', remark: "", day: "1991-11-22", cardId: '210203197503102721', sex: 2, id: '4242', belon: 2, homeaddres: 2, key: '0-0-0-2', },
60
+      ],
61
+    },
62
+    {
57 63
       title: '分厂员工管理',
58 64
       key: '0-0-1',
65
+      selectable: false,
59 66
       children: [
60
-        { title: '伏佳', phone:'18613523527', cardId:'520323197806058856',sex:1  ,id:'1124', belon:4,homeaddres:4,key: '0-0-1-0' },
61
-        { title: '舒宏', phone:'14736632088', cardId:'610729197408202551', sex:1 ,id:'4534', belon:3,homeaddres:2,key: '0-0-1-1' },
62
-        { title: '狄莉珍',phone:'17604898508', cardId:'820000195008115837', sex:1 ,id:'4242',belon:1,homeaddres:5,  key: '0-0-1-2' },
67
+        { title: '伏佳', phone: '18613523527', remark: "", day: "1992-10-11", cardId: '520323197806058856', sex: 1, id: '1124', belon: 4, homeaddres: 4, key: '0-0-1-0' },
68
+        { title: '舒宏', phone: '14736632088', remark: "", day: "1992-12-13", cardId: '610729197408202551', sex: 1, id: '4534', belon: 3, homeaddres: 2, key: '0-0-1-1' },
69
+        { title: '狄莉珍', phone: '17604898508', remark: "", day: "1993-10-11", cardId: '820000195008115837', sex: 1, id: '4242', belon: 1, homeaddres: 5, key: '0-0-1-2' },
63 70
       ],
64
-  },
65
-];
66
-// const item = this.info.node.key
71
+    },
72
+  ]
73
+
74
+
75
+
76
+
77
+// const item = this.info.node.key 不是!!!!
67 78
 
68 79
 class TreeDemo extends React.Component {
69 80
   formRef = React.createRef();
70
-  
71
-  
72
-  constructor(props){
73
-    super(props)  
81
+
82
+
83
+  constructor(props) {
84
+    super(props)
74 85
     this.state = {
75 86
       expandedKeys: ['0-0-0', '0-0-1'],
76 87
       autoExpandParent: false,
77 88
       checkedKeys: ['0-0-0'],
78 89
       selectedKeys: [],
79
-      treeTitle:[],
80
-      checked:true
81
-      
90
+      // treeTitle: [info.node.props],
91
+      checked: true,
92
+      treeData: treeData
82 93
     };
83 94
   }
84 95
 
@@ -86,8 +97,8 @@ class TreeDemo extends React.Component {
86 97
   onExpand = expandedKeys => {
87 98
     console.log('onExpand', expandedKeys);
88 99
 
89
-      // 如果没有将 autoExpandParent 设置为 false,如果子项展开,父项不能折叠。
90
-     // 或者,您可以删除所有扩展的子键。
100
+    // 如果没有将 autoExpandParent 设置为 false,如果子项展开,父项不能折叠。
101
+    // 或者,您可以删除所有扩展的子键。
91 102
     this.setState({
92 103
       expandedKeys,
93 104
       autoExpandParent: false,
@@ -102,36 +113,75 @@ class TreeDemo extends React.Component {
102 113
   };
103 114
 
104 115
 
116
+  onChangethis = (value) => {
105 117
 
118
+    const treeData = this.state.treeData
106 119
 
107
-  onSelect=(value,info)=>{
108
-    this.setState({value},()=>{
109
-        this.formRef.current.setFieldsValue({
110
-          ...info.node.props,
111
-        })
120
+    let Data1 = this.state.treeData
121
+    for (var i = 0; i < treeData.length; i++) {
122
+
123
+      for (var j = 0; j < treeData[i].children.length; j++) {
124
+        // console.log(Data1[i].children[j].key);
125
+        // console.log("---------")
126
+        // console.log(value);
127
+        if (treeData[i].children[j].key == value.key) {
128
+
129
+          Data1[i].children[j] = value
130
+          //qileguaile wo cao
131
+          console.log(Data1[i].children[j]);
132
+          // console.log(treeData[i].children[j].key)
133
+          break
134
+        }
135
+      }
136
+
137
+    }
138
+  }
139
+  //删除
140
+  onDelect = (value) => {
141
+    const treeData = this.state.treeData
142
+    let Data1 = this.state.treeData
143
+    for (var i = 0; i < treeData.length; i++) {
144
+      for (var j = 0; j < treeData[i].children.length; j++) {
145
+
146
+        if (treeData[i].children[j].key == value.key) {
147
+
148
+          delete Data1[i].children[j]
149
+          break
150
+        }
151
+      }
152
+
153
+    }
154
+    // console.log("----Data1-----")
155
+    // console.log(Data1)
156
+    this.setState({
157
+      treeData: Data1
158
+    }, () => {
159
+      message.success('shanchuchenggong')
112 160
     })
161
+
113 162
   }
114 163
 
115 164
 
116 165
 
117
-// onSelect=(value,info)=>{
118
-//   this.setState({value},()=>{
119
-//     this.$nextTick(()=>{
120
-//       setTimeout(()=>{
121
-//         this.formRef.current.setFieldsValue({
122
-//           ...info.node.props,
123
-//         })
124
-//       })
125
-//     })
166
+  onSelect = (values, info) => {
167
+    // this.FromValue(info.node)
168
+    console.log(this.state.treeData)
169
+    console.log(info)
170
+    this.setState({ values }, () => {
171
+      this.formRef.current.setFieldsValue({
172
+        ...info.node.props,
173
+        key: info.node.props.eventKey,//event
174
+        day: moment(info.node.props.day)
175
+      })
126 176
 
127
-//   console.log(this.state.info);
177
+      console.log(values, info)
128 178
 
129
-//   })
130
-// }
179
+      // moment(info.node.props.day).format('YYYY-MM-DD')
180
+    })
181
+  }
131 182
 
132 183
 
133 184
 
134
-;
135 185
 
136 186
   renderTreeNodes = data =>
137 187
     data.map(item => {
@@ -139,8 +189,7 @@ class TreeDemo extends React.Component {
139 189
         return (
140 190
           <TreeNode title={item.title} key={item.key} dataRef={item}  >
141 191
             {this.renderTreeNodes(item.children)}
142
-            
143
-          </TreeNode>
192
+          </TreeNode >
144 193
         );
145 194
       }
146 195
       return <TreeNode key={item.key} {...item} />;
@@ -151,50 +200,47 @@ class TreeDemo extends React.Component {
151 200
   render() {
152 201
 
153 202
     return (
154
-     <Card>
155
-      <Row >
156
-        <Col xs={{ span: 5, offset: 1 }} lg={{ span: 6, offset: 0 }}>
157
-          <Card>
203
+      <Card>
204
+        <Row >
205
+          <Col xs={{ span: 5, offset: 1 }} lg={{ span: 6, offset: 0 }}>
206
+            <Card>
158 207
               <FormItem
159
-              label="管辖部门"
160
-            >
161
-              <Button type="primary" style={{marginRight:'20px'}} onClick={onAdd} >
162
-                增加
163
-              </Button>
164
-          {/* onDelete={() => onDelete(item.key)} */}
165
-              <Button type="danger" >
166
-                删除
167
-              </Button> 
168
-               <Tree 
169
-                allowClear
170
-                treeDefaultExpandAll
171
-                treeData={this.state.treeData}
172
-                showLine={true}
173
-                onExpand={this.onExpand}
174
-                expandedKeys={this.state.expandedKeys}
175
-                autoExpandParent={this.state.autoExpandParent}
176
-                onCheck={this.onCheck}
177
-                checkedKeys={this.state.checkedKeys}
178
-                onSelect={this.onSelect}
179
-                selectedKeys={this.state.selectedKeys}
208
+                label="管辖部门"
180 209
               >
181
-                {this.renderTreeNodes(treeData)}
182
-              </Tree > 
183
-
184
-            </FormItem>
185
-          </Card>
186
-        </Col>
187
-        <Col xs={{ span: 10, offset: 10 }} lg={{ span: 10, offset: 4 }}>
188
-          <Card>
189
-          <TreedataFrom 
190
-          ref={this.formRef} 
191
-          />
192
-          </Card>
193
-        </Col>
194
-      </Row>
195
-     </Card> 
210
+                <Button type="primary" onClick={onAdd} >
211
+                  增加
212
+                </Button>
213
+
214
+                <Tree
215
+
216
+                  showLine
217
+                  // switcherIcon={<DownOutlined />}
218
+                  defaultExpandedKeys={['0-0-0']}
219
+                  onSelect={this.onSelect}
220
+                  treeData={this.state.treeData}
221
+                >
222
+                  {this.renderTreeNodes(this.state.treeData)}
223
+                  {/* 动态渲染 */}
224
+                </Tree >
225
+                {/* 不加入生命周期不会有更改a */}
226
+              </FormItem>
227
+            </Card>
228
+          </Col>
229
+          <Col xs={{ span: 10, offset: 10 }} lg={{ span: 10, offset: 4 }}>
230
+            <Card>
231
+              <TreedataFrom
232
+                ref={this.formRef}
233
+                triggerRef={this.bindRef}
234
+                onChangethis={this.onChangethis}
235
+                onSubmit={this.onChangethis}
236
+              />
237
+            </Card>
238
+          </Col>
239
+        </Row>
240
+      </Card>
196 241
     );
197 242
   }
243
+
198 244
 }
199 245
 
200
-export default TreeDemo 
246
+export default TreeDemo