person.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. import React from 'react';
  2. import { Cascader, Input, Button, Form, Select, Radio, Upload, Icon, Spin, message, Modal } from 'antd';
  3. import './person.less';
  4. import { splitUrl, getBase64, beforeUpload } from '../../tools.js';
  5. import { areaSelect } from '../../NewDicProvinceList';
  6. import ajax from 'jquery/src/ajax/xhr.js';
  7. import $ from 'jquery/src/ajax';
  8. import ImgList from "../../common/imgList";
  9. const FormItem = Form.Item;
  10. const Option = Select.Option;
  11. const RadioGroup = Radio.Group;
  12. class Avatar extends React.Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. imageUrl: '',
  17. propsbool: true,
  18. }
  19. }
  20. handleChange(info) {
  21. if (info.file.status === 'done') {
  22. // Get this url from response in real world.
  23. getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
  24. this.props.urlData(info.file.response.data);
  25. }
  26. }
  27. componentWillReceiveProps(nextProps) {
  28. if (nextProps.picUrl && this.state.propsbool) {
  29. this.state.imageUrl = globalConfig.avatarHost + "/upload" + nextProps.picUrl;
  30. this.state.propsbool = false;
  31. }
  32. }
  33. render() {
  34. const imageUrl = this.state.imageUrl;
  35. return (
  36. <Upload
  37. className="avatar-uploader"
  38. name="avatar"
  39. showUploadList={false}
  40. action={globalConfig.context + "/api/user/avatar/uploadReplace"}
  41. data={{ 'sign': this.props.name }}
  42. beforeUpload={beforeUpload}
  43. onChange={this.handleChange.bind(this)}
  44. >
  45. {
  46. imageUrl ?
  47. <img src={imageUrl} role="presentation" className="avatar" /> :
  48. <Icon type="plus" className="avatar-uploader-trigger" />
  49. }
  50. </Upload>
  51. );
  52. }
  53. };
  54. class PicturesWall extends React.Component {
  55. constructor(props) {
  56. super(props);
  57. this.state = {
  58. previewVisible: false,
  59. propsbool: true,
  60. previewImage: '',
  61. fileList: [],
  62. }
  63. }
  64. handleCancel() {
  65. this.setState({ previewVisible: false })
  66. }
  67. handlePreview(file) {
  68. this.setState({
  69. previewImage: file.url || file.thumbUrl,
  70. previewVisible: true,
  71. });
  72. }
  73. handleChange(info) {
  74. let fileList = info.fileList;
  75. this.setState({ fileList });
  76. this.props.fileList(fileList);
  77. }
  78. componentWillReceiveProps(nextProps) {
  79. if (nextProps.lifePhotoList.length && this.state.propsbool) {
  80. this.state.fileList = nextProps.lifePhotoList ;
  81. this.state.propsbool = false;
  82. }
  83. }
  84. render() {
  85. const { previewVisible, previewImage, fileList } = this.state;
  86. const uploadButton = (
  87. <div>
  88. <Icon type="plus" />
  89. <div className="ant-upload-text">Upload</div>
  90. </div>
  91. );
  92. return (
  93. <div className="clearfix">
  94. <ImgList
  95. domId={this.props.domId}
  96. uploadConfig={{
  97. action:globalConfig.context + "/api/user/avatar/upload",
  98. data:{ 'sign': this.props.pictureSign, 'uid': this.props.uid},
  99. multiple:true,
  100. listType:"picture-card",
  101. }}
  102. onChange={(infor)=>{
  103. this.handleChange(infor)
  104. }}
  105. fileList={fileList}
  106. />
  107. </div>
  108. );
  109. }
  110. };
  111. const PersonFrom = Form.create()(React.createClass({
  112. getData() {
  113. this.props.spinState(true);
  114. $.ajax({
  115. method: "get",
  116. dataType: "json",
  117. url: globalConfig.context + "/api/user/member",
  118. success: function (data) {
  119. if (data.data) {
  120. let theArr = splitUrl(data.data.lifePhotoUrl, ',', globalConfig.avatarHost + '/upload');
  121. this.setState({
  122. id: data.data.id,
  123. nickname: data.data.nickname,
  124. theAddress: [data.data.residenceProvince, data.data.residenceCity, data.data.residenceArea],
  125. intro: data.data.personalProfile,
  126. email: data.data.email,
  127. fixTelArea: data.data.fixedTelArea,
  128. fixTel: data.data.fixedTel,
  129. fixTelExtension: data.data.fixedTelExtension,
  130. qq: data.data.qq,
  131. personPortraitUrl: data.data.personPortraitUrl,
  132. address: data.data.postalAddress,
  133. postcode: data.data.postcode,
  134. lifePhotoList: theArr
  135. });
  136. }
  137. }.bind(this),
  138. }).always(function () {
  139. this.props.spinState(false);
  140. }.bind(this));
  141. },
  142. getInitialState() {
  143. return {
  144. loading: false,
  145. livePicUrlArr: [],
  146. lifePhotoList: []
  147. };
  148. },
  149. handleSubmit(e) {
  150. e.preventDefault();
  151. this.props.form.validateFields((err, values) => {
  152. //lifePhotoUrl
  153. let livePicArr = [];
  154. this.state.lifePhotoList.map(function (item) {
  155. if ( item.response && item.response.data && item.response.data.length ){
  156. livePicArr.push(item.response.data);
  157. }
  158. });
  159. let lifePhotoUrl = livePicArr.join(",");
  160. if (!err) {
  161. this.props.spinState(true);
  162. $.ajax({
  163. method: "POST",
  164. dataType: "json",
  165. crossDomain: false,
  166. url: globalConfig.context + "/api/user/userInfo",
  167. data: {
  168. "id": this.state.id,
  169. "nickname": values.nickname,
  170. "residenceProvince": values.theAddress[0],
  171. "residenceCity": values.theAddress[1],
  172. "residenceArea": values.theAddress[2],
  173. "personPortraitUrl": this.state.avatarUrlData,
  174. "lifePhotoUrl": lifePhotoUrl,
  175. "personalProfile": values.intro,
  176. "email": values.email,
  177. "fixedTelArea": this.state.fixTelArea,
  178. "fixedTel": this.state.fixTel,
  179. "fixedTelExtension": this.state.fixTelExtension,
  180. "qq": values.qq,
  181. "postalAddress": values.address,
  182. "postcode": values.postcode
  183. }
  184. }).done(function (data) {
  185. if (!data.error.length) {
  186. message.success('保存成功!');
  187. this.getData();
  188. } else {
  189. message.warning(data.error[0].message);
  190. }
  191. }.bind(this)).always(function () {
  192. this.props.spinState(false);
  193. }.bind(this));
  194. }
  195. });
  196. },
  197. avatarUrl(e) {
  198. this.state.avatarUrlData = e;
  199. },
  200. livePicFileList(e) {
  201. this.state.lifePhotoList = e;
  202. },
  203. componentWillMount() {
  204. this.getData();
  205. },
  206. fixTelAreaChange(e) {
  207. this.setState({
  208. fixTelArea: e.target.value
  209. });
  210. },
  211. fixTelChange(e) {
  212. this.setState({
  213. fixTel: e.target.value
  214. });
  215. },
  216. fixTelExtensionChange(e) {
  217. this.setState({
  218. fixTelExtension: e.target.value
  219. });
  220. },
  221. render() {
  222. const { getFieldDecorator } = this.props.form;
  223. const formItemLayout = {
  224. labelCol: { span: 3 },
  225. wrapperCol: { span: 12 },
  226. };
  227. const _me = this;
  228. return (
  229. <Form horizontal onSubmit={this.handleSubmit} className="person-form">
  230. <FormItem
  231. {...formItemLayout}
  232. label="社区昵称"
  233. >
  234. {getFieldDecorator('nickname', {
  235. initialValue: this.state.nickname || null
  236. })(
  237. <Input />
  238. )}
  239. </FormItem>
  240. <FormItem
  241. {...formItemLayout}
  242. label="居住地"
  243. >
  244. {getFieldDecorator('theAddress', {
  245. initialValue: this.state.theAddress || []
  246. })(
  247. <Cascader options={areaSelect()} />
  248. )}
  249. </FormItem>
  250. <FormItem
  251. {...formItemLayout}
  252. label="个人头像"
  253. labelCol={{ span: 3 }}
  254. wrapperCol={{ span: 21 }}
  255. >
  256. {getFieldDecorator('avatar')(
  257. <Avatar urlData={this.avatarUrl} name='personPortrait' picUrl={this.state.personPortraitUrl} />
  258. )}
  259. </FormItem>
  260. <div className="set-explain">
  261. <p>请上传清晰的个人身份证正反面原件照片/扫描件 (不能截图、图片内容要求完整 ),</p>
  262. <p>要求2M 以下的jpg、jpeg格式的图片。该资料不会公开展示,仅作为审核材料使用。</p>
  263. </div>
  264. <FormItem
  265. labelCol={{ span: 3 }}
  266. wrapperCol={{ span: 21 }}
  267. label="生活照"
  268. >
  269. {getFieldDecorator('livePic')(
  270. <PicturesWall
  271. domId={'person1'}
  272. fileList={this.livePicFileList}
  273. lifePhotoList={this.state.lifePhotoList}
  274. />
  275. )}
  276. </FormItem>
  277. <FormItem
  278. labelCol={{ span: 3 }}
  279. wrapperCol={{ span: 20 }}
  280. label="个人简介"
  281. >
  282. {getFieldDecorator('intro', {
  283. initialValue: this.state.intro || null
  284. })(
  285. <Input type="textarea"
  286. placeholder="全面介绍自己,让商友更深入了解您,内容长度不超过1000个字。"
  287. rows={6} />
  288. )}
  289. <p>还可输入{
  290. (() => {
  291. if (_me.props.form.getFieldValue('intro') && _me.props.form.getFieldValue('intro').length) {
  292. return 1000 - _me.props.form.getFieldValue('intro').length;
  293. } else {
  294. return 1000;
  295. }
  296. })()
  297. }字/1000</p>
  298. </FormItem>
  299. <FormItem
  300. {...formItemLayout}
  301. label="电子邮箱"
  302. hasFeedback
  303. >
  304. {getFieldDecorator('email', {
  305. rules: [{
  306. type: 'email', message: '请输入正确的邮箱地址!',
  307. }],
  308. initialValue: this.state.email || null
  309. })(
  310. <Input />
  311. )}
  312. </FormItem>
  313. <FormItem
  314. {...formItemLayout}
  315. label="固定电话"
  316. >
  317. {getFieldDecorator('telephone')(
  318. <p>
  319. <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} />
  320. </p>
  321. )}
  322. </FormItem>
  323. <FormItem
  324. {...formItemLayout}
  325. label="QQ"
  326. >
  327. {getFieldDecorator('qq', {
  328. initialValue: this.state.qq || null
  329. })(
  330. <Input />
  331. )}
  332. </FormItem>
  333. <FormItem
  334. {...formItemLayout}
  335. label="通讯地址"
  336. >
  337. {getFieldDecorator('address', {
  338. initialValue: this.state.address || null
  339. })(
  340. <Input />
  341. )}
  342. </FormItem>
  343. <FormItem
  344. {...formItemLayout}
  345. label="邮编"
  346. >
  347. {getFieldDecorator('postcode', {
  348. initialValue: this.state.postcode || null
  349. })(
  350. <Input />
  351. )}
  352. </FormItem>
  353. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  354. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  355. </FormItem>
  356. </Form >
  357. );
  358. },
  359. }));
  360. const Person = React.createClass({
  361. getInitialState() {
  362. return {
  363. loading: false
  364. };
  365. },
  366. spinChange(e) {
  367. this.setState({
  368. loading: e
  369. });
  370. },
  371. render() {
  372. return (
  373. <Spin spinning={this.state.loading} className='spin-box'>
  374. <div className="set-person">
  375. <div className="acc-detail">
  376. <p className="acc-title">个人资料</p>
  377. <PersonFrom spinState={this.spinChange} />
  378. </div>
  379. </div>
  380. </Spin>
  381. )
  382. }
  383. });
  384. export default Person;