123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- import React from 'react';
- import { Input, Button, Form, Select, Radio, Upload, Icon, Spin, message, InputNumber } from 'antd';
- import './person.less';
- import { addressInit } from '../../tools.js';
- const FormItem = Form.Item;
- const Option = Select.Option;
- const RadioGroup = Radio.Group;
- const edulvlArr = ["企业", "院校", "研究机构", "政府部门", "非法人团体"];
- const zizhiArr = ["高新技术型企业", "创新型企业", "双软企业", "小心微利企业", "科技部认定示范企业","其他"];
- function getBase64(img, callback) {
- const reader = new FileReader();
- reader.addEventListener('load', () => callback(reader.result));
- reader.readAsDataURL(img);
- };
- function beforeUpload(file) {
- const isJPG = file.type === 'image/jpeg';
- if (!isJPG) {
- message.error('You can only upload JPG file!');
- }
- const isLt2M = file.size / 1024 / 1024 < 2;
- if (!isLt2M) {
- message.error('Image must smaller than 2MB!');
- }
- return isJPG && isLt2M;
- };
- class Avatar extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- imageUrl: ''
- }
- }
- handleChange(info) {
- if (info.file.status === 'done') {
- // Get this url from response in real world.
- getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
- }
- }
- render() {
- const imageUrl = this.state.imageUrl;
- return (
- <Upload
- className="avatar-uploader"
- name="avatar"
- showUploadList={false}
- action="/upload.do"
- beforeUpload={beforeUpload}
- onChange={this.handleChange}
- >
- {
- imageUrl ?
- <img src={imageUrl} role="presentation" className="avatar" /> :
- <Icon type="plus" className="avatar-uploader-trigger" />
- }
- </Upload>
- );
- }
- };
- const PersonFrom = Form.create()(React.createClass({
- getInitialState() {
- return {
- loading: false,
- };
- },
- handleSubmit(e) {
- e.preventDefault();
- this.props.form.validateFields((err, values) => {
- if (!err) {
- console.log('Received values of form: ', values);
- }
- });
- },
- normFile(e) {
- if (Array.isArray(e)) {
- return e;
- }
- return e && e.fileList;
- },
- componentDidMount() {
- addressInit('cmbProvince', 'cmbCity', 'cmbArea');
- },
- render() {
- const { getFieldDecorator } = this.props.form;
- const formItemLayout = {
- labelCol: { span: 3 },
- wrapperCol: { span: 12 },
- };
- const _me = this;
- return (
- <Form horizontal onSubmit={this.handleSubmit} className="person-form">
- <FormItem
- labelCol={{ span: 3 }}
- wrapperCol={{ span: 8 }}
- label="身份类型"
- >
- {getFieldDecorator('edulvl')(
- <Select className="acc-edu-lvl">
- {
- edulvlArr.map(function (item, i) {
- return <Option key={i} value={item} >{item}</Option>
- })
- }
- </Select>
- )}
- </FormItem>
- <FormItem
- {...formItemLayout}
- label="单位名称"
- >
- {getFieldDecorator('nickname', {
- initialValue: this.props.companyname
- })(
- <Input />
- )}
- </FormItem>
- <FormItem
- {...formItemLayout}
- label="居住地"
- >
- {getFieldDecorator('province')(
- <div>
- <select id="cmbProvince" name="cmbProvince"></select>
- <select id="cmbCity" name="cmbCity"></select>
- <select id="cmbArea" name="cmbArea"></select>
- </div>
- )}
- </FormItem>
- <FormItem
- {...formItemLayout}
- label="单位规模"
- >
- {getFieldDecorator('peoplenum')(
- <div className="numberinput">
- <InputNumber /><span>人</span>
- </div>
- )}
- </FormItem>
- <FormItem
- labelCol={{ span: 3 }}
- wrapperCol={{ span: 20 }}
- label="单位简介"
- >
- {getFieldDecorator('intro')(
- <div>
- <Input type="textarea"
- placeholder="全面介绍自己,让商友更深入了解您,内容长度不超过1000个字。"
- rows={6} />
- <p>还可输入{
- (() => {
- if (_me.props.form.getFieldValue('intro') && _me.props.form.getFieldValue('intro').length) {
- return 1000 - _me.props.form.getFieldValue('intro').length;
- } else {
- return 1000;
- }
- })()
- }字/1000</p>
- </div>
- )}
- </FormItem>
- <FormItem
- {...formItemLayout}
- label="归属单位"
- >
- {getFieldDecorator('companyfrom')(
- <Input placeholder="非法人单位填写。"/>
- )}
- </FormItem>
- <FormItem
- labelCol={{ span: 3 }}
- wrapperCol={{ span: 8 }}
- label="企业资质"
- >
- {getFieldDecorator('qiyezizhi')(
- <Select className="acc-edu-lvl">
- {
- zizhiArr.map(function (item, i) {
- return <Option key={i} value={item} >{item}</Option>
- })
- }
- </Select>
- )}
- </FormItem>
- <FormItem
- labelCol={{ span: 3 }}
- wrapperCol={{ span: 6 }}
- label="年营业额"
- >
- {getFieldDecorator('turnover')(
- <div>
- <InputNumber /><span>万元</span>
- </div>
- )}
- </FormItem>
- <FormItem
- {...formItemLayout}
- label="公司logo"
- labelCol={{ span: 3 }}
- wrapperCol={{ span: 20 }}
- hasFeedback
- >
- {getFieldDecorator('avatar')(
- <Avatar />
- )}
- </FormItem>
- <div className="set-explain">
- <p>上传的照片图片格式应为jpg格式,大小在2M以内</p>
- </div>
- <FormItem
- {...formItemLayout}
- label="宣传图片"
- >
- {getFieldDecorator('companyimg', {
- valuePropName: 'fileList',
- normalize: this.normFile,
- })(
- <Upload
- name="companyimg"
- action="/upload.do"
- listType="picture"
- beforeUpload={beforeUpload}
- onChange={this.handleUpload}>
- <Button type="primary">
- <Icon type="upload" /> 点击选择文件
- </Button>
- <p>上传的照片图片格式应为jpg格式,大小在2M以内</p>
- </Upload>
- )}
- </FormItem>
- <FormItem wrapperCol={{ span: 12, offset: 3 }}>
- <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
- </FormItem>
- </Form >
- );
- },
- }));
- const Person = React.createClass({
- getInitialState() {
- return {
- companyname: '湖南智明信息技术有限公司',
- loading: false
- };
- },
- render() {
- return (
- <Spin spinning={this.state.loading} className='spin-box'>
- <div className="set-person">
- <div className="acc-detail">
- <p className="acc-title">个人资料</p>
- <PersonFrom companyname={this.state.companyname} />
- </div>
- </div>
- </Spin>
- )
- }
- });
- export default Person;
|