forked from nsjcy/frontEnd/nsjcy

liuwh
2020-03-29 bc647c5e5e95f3898e3af66c02d7911df8547b4e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
import React from 'react';
 
import HeadView from '../view/HeadView';
import TableBtnView from '../view/TableBtnView';
import CommonSearchForm from '../view/CommonSearchForm';
import { Input, Button, DatePicker, Divider, Modal, message } from 'antd'
import moment from 'moment'
import Fetch from '../fetch';
import TableView from '../view/TableView';
const confirm = Modal.confirm;
export default class Company extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      data: [],
      loading: false,
      visible: false,
      savedate: {},
      formData: {
        __key: Date.now(),
        companyName: '',
        companyLegal: '',
        companyTel: '',
      },
      resetKey: Date.now(),
      closeKey: Date.now()
    };
  }
 
  componentDidMount() {
    document.title = '涉未成年负责部门组织';
    this.getData();
  }
 
  setFormData = data => {
    console.log('form', data);
    this.setState({
      formData: data,
    });
  }
 
  searchonClick = data => {
    console.log('form', data);
    this.setState({
      formData: data,
    });
    this.setState({ loading: true })
    Fetch.socialCompany({ ...data })
      .then(res => {
        for (var i = 0; i < res.length; i++) {
          res[i]['index'] = i + 1;
        }
        this.setState({
          data: res,
          loading: false
        });
      });
  }
  getData = () => {
    const { formdata } = this.state;
    this.setState({ loading: true })
    Fetch.socialCompany({ formdata })
      .then(res => {
        for (var i = 0; i < res.length; i++) {
          res[i]['index'] = i + 1;
        }
        this.setState({
          data: res,
          loading: false
        });
      });
  }
  onInputChange = ({ target: { value, name } }) => {
    this.setState(({ formdata }) => ({
      formdata: {
        ...formdata,
        [name]: value
      }
    }))
  }
  saveInputChange = ({ target: { value, name } }) => {
    this.setState(({ savedate }) => ({
      savedate: {
        ...savedate,
        [name]: value
      }
    }))
  }
  Seaech = () => {
    const { formdata } = this.state;
    Fetch.socialCompany(formdata)
      .then(res => {
        for (var i = 0; i < res.length; i++) {
          res[i]['index'] = i + 1;
        }
        this.setState({
          data: res
        });
      });
  }
  Reset = () => {
    this.setState({
      resetKey: Date.now(),
      formdata: {}
    }, this.getData);
  }
 
  showModal = (id) => {
    this.setState({
      visible: true,
    });
    Fetch.socialCompanyDetail(id)
      .then(res => {
        this.setState({ savedate: res })
      })
  }
 
  handleOk = () => {
    this.setState({ loading: true });
    const { savedate } = this.state;
    if (savedate.companyTel) {
      if (!validator.mobile(savedate.companyTel)) {
        this.setState({
          loading: false
        });
        return message.warning("电话号码格式不正确");
      }
    }
    if (!savedate.companyAccount) {
      return message.warning("账号不能为空");
    }
    if (!savedate.companyPassword) {
      return message.warning("密码不能为控");
    }
    Fetch.socialCompanySave(savedate)
      .then(res => {
        if (res.statuscode === 1) {
          this.setState({
            loading: false,
            visible: false,
            closeKey: Date.now()
          }, this.getData);
          message.success("提交成功!")
        } else {
          message.error('保存失败,请联系管理员', 2)
        }
      });
  }
 
  handleCancel = () => {
    this.setState({
      closeKey: Date.now(),
      visible: false
    });
  }
 
  deleteItems = (id) => {
    confirm({
      title: '确认要删除这条数据吗?',
      onOk: () => {
        Fetch.socialCompanydelete(id)
          .then(data => {
            if (data.statuscode == 1) {
              message.success("删除成功!")
              this.setState({
                resetKey: Date.now(),
                formdata: {}
              }, this.getData);
            } else {
              message.error('删除失败,请联系管理员', 2)
            }
          })
      }
    });
  }
  render() {
    const columns = [{
      title: '序号',
      dataIndex: 'index',
      key: 'index'
    }, {
      title: '公司名称',
      dataIndex: 'companyName',
      key: 'companyName'
    }, {
      title: '法人姓名',
      dataIndex: 'companyLegal',
      key: 'companyLegal',
    }, {
      title: '联系电话',
      dataIndex: 'companyTel',
      key: 'companyTel',
    }, {
      title: '公司地址',
      dataIndex: 'companyAddress',
      key: 'companyAddress',
    }, {
      title: '管理员账号',
      dataIndex: 'companyAccount',
      key: 'companyAccount',
    }, {
      title: '管理员密码',
      dataIndex: 'companyPassword',
      key: 'companyPassword',
      render: text => <span>***********</span>
    }, {
      title: '创建时间',
      dataIndex: 'createTime',
      key: 'createTime',
      render: text => <span>{moment(text).format("YYYY-MM-DD HH:mm")}</span>
    }, {
      title: '操作',
      key: 'action',
      render: (text, record) => (
        <span>
          <label onClick={() => this.showModal(record.id)} className='theme-color' style={{ cursor: 'pointer' }}>编辑</label>
          <Divider type="vertical" />
          <label onClick={() => this.deleteItems(record.id)} className='theme-color' style={{ cursor: 'pointer' }}>删除</label>
        </span>
      ),
    }];
    const { data, resetKey, visible, loading, savedate, closeKey, formData } = this.state;
    return (
 
      <div className="app-page">
        <HeadView history={this.props.history} />
        <div style={{ marginLeft: '90%', marginBottom: '20px', marginTop: '20px' }}>
          <Button type="primary" size='large' onClick={() => this.showModal('new')}>新增</Button>
        </div>
        <div style={{ background: '#fff', margin: 20 }}>
          <CommonSearchForm
            {...this.props}
            formData={formData}
            setFormData={this.setFormData}
            searchonClick={this.searchonClick}
            pathName={this.props.location.pathname}
            data={[
              {
                type: 'input', name: '公司名称', label: '公司名称', key: 'companyName'
              },
              {
                type: 'input', name: '法人姓名', label: '法人姓名', key: 'companyLegal'
              },
              {
                type: 'input', name: '联系电话', label: '联系电话', key: 'companyTel'
              },
            ]} />
          <TableView columns={columns} data={data} pageSize='10' size='default' loading={loading} />
        </div>
        {/* <TableBtnView key={-resetKey} type="infoManage" name='涉未成年负责部门组织' btnName='新建公司' onClick={() => this.showModal('new')}>
          <Input placeholder="根据公司名称模糊查询" style={{ width: "200px" }} name='companyName' onChange={this.onInputChange} />
          <Input placeholder="根据法人姓名模糊查询" style={{ width: "200px" }} name='companyLegal' onChange={this.onInputChange} />
          <Input placeholder="根据联系电话模糊查询" style={{ width: "200px" }} name='companyTel' onChange={this.onInputChange} />
          <Input placeholder="根据管理员账号模糊查询" style={{ width: "200px" }} name='companyAccount' onChange={this.onInputChange} />
          <DatePicker onChange={(_, value) => this.onInputChange({ target: { name: 'createTime', value } })} placeholder="根据创建时间查询" />
          <Button type="primary" onClick={this.Seaech}>查询</Button>
          <Button onClick={this.Reset}>重置</Button>
        </TableBtnView>
        <TableView columns={columns} data={data} pageSize='10' size='default' /> */}
        <Modal
          key={closeKey}
          confirmLoading={loading}
          visible={visible}
          title="公司信息"
          onOk={this.handleOk}
          onCancel={this.handleCancel}
          bodyStyle={{ lineHeight: 4 }}
        >
          <Input addonBefore="公司名称" name='companyName' onChange={this.saveInputChange} value={savedate.companyName || ''} />
          <Input addonBefore="法人姓名" name='companyLegal' onChange={this.saveInputChange} value={savedate.companyLegal || ''} />
          <Input addonBefore="联系电话" name='companyTel' onChange={this.saveInputChange} value={savedate.companyTel || ''} />
          <Input addonBefore="公司地址" name='companyAddress' onChange={this.saveInputChange} value={savedate.companyAddress || ''} />
          <Input addonBefore="管理员账号" name='companyAccount' onChange={this.saveInputChange} value={savedate.companyAccount || ''} />
          <Input addonBefore="管理员密码" name='companyPassword' onChange={this.saveInputChange} value={savedate.companyPassword || ''} />
        </Modal>
      </div>
    );
  }
 
}