123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- import React from 'react';
- import { Cascader, Input, Button, Form, Select, Radio, Upload, Icon, Spin, message, Modal } from 'antd';
- import './person.less';
- import { splitUrl, getBase64, beforeUpload } from '../../tools.js';
- import { areaSelect } from '../../NewDicProvinceList';
- import ajax from 'jquery/src/ajax/xhr.js';
- import $ from 'jquery/src/ajax';
- import ImgList from "../../common/imgList";
- const FormItem = Form.Item;
- const Option = Select.Option;
- const RadioGroup = Radio.Group;
- class Avatar extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- imageUrl: '',
- propsbool: true,
- }
- }
- handleChange(info) {
- if (info.file.status === 'done') {
- // Get this url from response in real world.
- getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
- this.props.urlData(info.file.response.data);
- }
- }
- componentWillReceiveProps(nextProps) {
- if (nextProps.picUrl && this.state.propsbool) {
- this.state.imageUrl = globalConfig.avatarHost + "/upload" + nextProps.picUrl;
- this.state.propsbool = false;
- }
- }
- render() {
- const imageUrl = this.state.imageUrl;
- return (
- <Upload
- className="avatar-uploader"
- name="avatar"
- showUploadList={false}
- action={globalConfig.context + "/api/user/avatar/uploadReplace"}
- data={{ 'sign': this.props.name }}
- beforeUpload={beforeUpload}
- onChange={this.handleChange.bind(this)}
- >
- {
- imageUrl ?
- <img src={imageUrl} role="presentation" className="avatar" /> :
- <Icon type="plus" className="avatar-uploader-trigger" />
- }
- </Upload>
- );
- }
- };
- class PicturesWall extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- previewVisible: false,
- propsbool: true,
- previewImage: '',
- fileList: [],
- }
- }
- handleCancel() {
- this.setState({ previewVisible: false })
- }
- handlePreview(file) {
- this.setState({
- previewImage: file.url || file.thumbUrl,
- previewVisible: true,
- });
- }
- handleChange(info) {
- let fileList = info.fileList;
- this.setState({ fileList });
- this.props.fileList(fileList);
- }
- componentWillReceiveProps(nextProps) {
- if (nextProps.lifePhotoList.length && this.state.propsbool) {
- this.state.fileList = nextProps.lifePhotoList ;
- this.state.propsbool = false;
- }
- }
- render() {
- const { previewVisible, previewImage, fileList } = this.state;
- const uploadButton = (
- <div>
- <Icon type="plus" />
- <div className="ant-upload-text">Upload</div>
- </div>
- );
- return (
- <div className="clearfix">
- <ImgList
- domId={this.props.domId}
- uploadConfig={{
- action:globalConfig.context + "/api/user/avatar/upload",
- data:{ 'sign': this.props.pictureSign, 'uid': this.props.uid},
- multiple:true,
- listType:"picture-card",
- }}
- onChange={(infor)=>{
- this.handleChange(infor)
- }}
- fileList={fileList}
- />
- </div>
- );
- }
- };
- const PersonFrom = Form.create()(React.createClass({
- getData() {
- this.props.spinState(true);
- $.ajax({
- method: "get",
- dataType: "json",
- url: globalConfig.context + "/api/user/member",
- success: function (data) {
- if (data.data) {
- let theArr = splitUrl(data.data.lifePhotoUrl, ',', globalConfig.avatarHost + '/upload');
- this.setState({
- id: data.data.id,
- nickname: data.data.nickname,
- theAddress: [data.data.residenceProvince, data.data.residenceCity, data.data.residenceArea],
- intro: data.data.personalProfile,
- email: data.data.email,
- fixTelArea: data.data.fixedTelArea,
- fixTel: data.data.fixedTel,
- fixTelExtension: data.data.fixedTelExtension,
- qq: data.data.qq,
- personPortraitUrl: data.data.personPortraitUrl,
- address: data.data.postalAddress,
- postcode: data.data.postcode,
- lifePhotoList: theArr
- });
- }
- }.bind(this),
- }).always(function () {
- this.props.spinState(false);
- }.bind(this));
- },
- getInitialState() {
- return {
- loading: false,
- livePicUrlArr: [],
- lifePhotoList: []
- };
- },
- handleSubmit(e) {
- e.preventDefault();
- this.props.form.validateFields((err, values) => {
- //lifePhotoUrl
- let livePicArr = [];
- this.state.lifePhotoList.map(function (item) {
- if ( item.response && item.response.data && item.response.data.length ){
- livePicArr.push(item.response.data);
- }
- });
- let lifePhotoUrl = livePicArr.join(",");
- if (!err) {
- this.props.spinState(true);
- $.ajax({
- method: "POST",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/user/userInfo",
- data: {
- "id": this.state.id,
- "nickname": values.nickname,
- "residenceProvince": values.theAddress[0],
- "residenceCity": values.theAddress[1],
- "residenceArea": values.theAddress[2],
- "personPortraitUrl": this.state.avatarUrlData,
- "lifePhotoUrl": lifePhotoUrl,
- "personalProfile": values.intro,
- "email": values.email,
- "fixedTelArea": this.state.fixTelArea,
- "fixedTel": this.state.fixTel,
- "fixedTelExtension": this.state.fixTelExtension,
- "qq": values.qq,
- "postalAddress": values.address,
- "postcode": values.postcode
- }
- }).done(function (data) {
- if (!data.error.length) {
- message.success('保存成功!');
- this.getData();
- } else {
- message.warning(data.error[0].message);
- }
- }.bind(this)).always(function () {
- this.props.spinState(false);
- }.bind(this));
- }
- });
- },
- avatarUrl(e) {
- this.state.avatarUrlData = e;
- },
- livePicFileList(e) {
- this.state.lifePhotoList = e;
- },
- componentWillMount() {
- this.getData();
- },
- fixTelAreaChange(e) {
- this.setState({
- fixTelArea: e.target.value
- });
- },
- fixTelChange(e) {
- this.setState({
- fixTel: e.target.value
- });
- },
- fixTelExtensionChange(e) {
- this.setState({
- fixTelExtension: e.target.value
- });
- },
- 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
- {...formItemLayout}
- label="社区昵称"
- >
- {getFieldDecorator('nickname', {
- initialValue: this.state.nickname || null
- })(
- <Input />
- )}
- </FormItem>
- <FormItem
- {...formItemLayout}
- label="居住地"
- >
- {getFieldDecorator('theAddress', {
- initialValue: this.state.theAddress || []
- })(
- <Cascader options={areaSelect()} />
- )}
- </FormItem>
- <FormItem
- {...formItemLayout}
- label="个人头像"
- labelCol={{ span: 3 }}
- wrapperCol={{ span: 21 }}
- >
- {getFieldDecorator('avatar')(
- <Avatar urlData={this.avatarUrl} name='personPortrait' picUrl={this.state.personPortraitUrl} />
- )}
- </FormItem>
- <div className="set-explain">
- <p>请上传清晰的个人身份证正反面原件照片/扫描件 (不能截图、图片内容要求完整 ),</p>
- <p>要求2M 以下的jpg、jpeg格式的图片。该资料不会公开展示,仅作为审核材料使用。</p>
- </div>
- <FormItem
- labelCol={{ span: 3 }}
- wrapperCol={{ span: 21 }}
- label="生活照"
- >
- {getFieldDecorator('livePic')(
- <PicturesWall
- domId={'person1'}
- fileList={this.livePicFileList}
- lifePhotoList={this.state.lifePhotoList}
- />
- )}
- </FormItem>
- <FormItem
- labelCol={{ span: 3 }}
- wrapperCol={{ span: 20 }}
- label="个人简介"
- >
- {getFieldDecorator('intro', {
- initialValue: this.state.intro || null
- })(
- <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>
- </FormItem>
- <FormItem
- {...formItemLayout}
- label="电子邮箱"
- hasFeedback
- >
- {getFieldDecorator('email', {
- rules: [{
- type: 'email', message: '请输入正确的邮箱地址!',
- }],
- initialValue: this.state.email || null
- })(
- <Input />
- )}
- </FormItem>
- <FormItem
- {...formItemLayout}
- label="固定电话"
- >
- {getFieldDecorator('telephone')(
- <p>
- <Input value={this.state.fixTelArea} id="fixTelArea" onChange={this.fixTelAreaChange} /> - <Input value={this.state.fixTel} id="fixTel" onChange={this.fixTelChange} /> - <Input value={this.state.fixTelExtension} id="fixTelExtension" onChange={this.fixTelExtensionChange} />
- </p>
- )}
- </FormItem>
- <FormItem
- {...formItemLayout}
- label="QQ"
- >
- {getFieldDecorator('qq', {
- initialValue: this.state.qq || null
- })(
- <Input />
- )}
- </FormItem>
- <FormItem
- {...formItemLayout}
- label="通讯地址"
- >
- {getFieldDecorator('address', {
- initialValue: this.state.address || null
- })(
- <Input />
- )}
- </FormItem>
- <FormItem
- {...formItemLayout}
- label="邮编"
- >
- {getFieldDecorator('postcode', {
- initialValue: this.state.postcode || null
- })(
- <Input />
- )}
- </FormItem>
- <FormItem wrapperCol={{ span: 12, offset: 3 }}>
- <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
- </FormItem>
- </Form >
- );
- },
- }));
- const Person = React.createClass({
- getInitialState() {
- return {
- loading: false
- };
- },
- spinChange(e) {
- this.setState({
- loading: e
- });
- },
- render() {
- return (
- <Spin spinning={this.state.loading} className='spin-box'>
- <div className="set-person">
- <div className="acc-detail">
- <p className="acc-title">个人资料</p>
- <PersonFrom spinState={this.spinChange} />
- </div>
- </div>
- </Spin>
- )
- }
- });
- export default Person;
|