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 (
{
imageUrl ?
:
}
);
}
};
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 = (
);
return (
{
this.handleChange(infor)
}}
fileList={fileList}
/>
);
}
};
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 (
);
},
}));
const Person = React.createClass({
getInitialState() {
return {
loading: false
};
},
spinChange(e) {
this.setState({
loading: e
});
},
render() {
return (
)
}
});
export default Person;