/* @author:李霆 @update:2018/05/29 @descript:复制粘贴,拿起来就是干!! */ import React from 'react'; import ajax from 'jquery/src/ajax/xhr.js'; import $ from 'jquery/src/ajax'; import { Row, Col, Form, Button, Spin, message, Modal, Input } from 'antd'; import './account.less'; const FormItem = Form.Item; class Account extends React.Component { constructor(props) { super(props); this.state = { loading: false, visible: false, editState: false, name: 'liting', followTime: '2010/09/18', contactMobile: '18320747565' }; } loadData() { this.setState({ loading: true }); $.ajax({ method: 'post', dataType: 'json', crossDomain: false, url: globalConfig.context + '/api/admin/customer/shuju', data: {}, success: function(data) { if (data.error.length || data.data == '') { if (data.error && data.error.length) { message.warning(data.error[0].message); } } else { this.setState({ id: data.data.id, name: data.data.name, photo: data.data.photo, email: data.data.email, nickname: data.data.nickname, accountData: data.data }); } }.bind(this) }).always( function() { this.setState({ loading: false }); }.bind(this) ); } //修改密码 passFun() { this.setState({ visible: true, password: '', repeatPass: '' }); } //企业认证 companyFun() {} //个人认证 personFun() {} //修改密码 passSubmit() { if (!this.state.name) { message.warning('请填写昵称!'); return; } if (!this.state.password) { message.warning('请填写新密码!'); return; } if (this.state.password !== this.state.repeatPass) { message.warning('两次输入的密码不一致!'); } this.setState({ loading: true }); $.ajax({ method: 'POST', dataType: 'json', crossDomain: false, url: globalConfig.context + '/api/user/mobile', data: { mobile: this.state.mobile, mobileCode: this.state.mcode, password: this.state.password, name: this.state.name } }).done( function(data) { if (!data.error.length) { this.setState({ visible: false }); message.success('修改成功!'); this.loadData(); } else { message.warning(data.error[0].message); } }.bind(this) ); } handleOk() { this.passSubmit(); } handleCancel() { this.setState({ visible: false }); } //单个修改 btnFun(item) { switch (item) { case 1: this.setState({ editName: true }); setTimeout(()=>{this.refs.name.focus()},10) break; case 2: this.setState({ editPhoto: true }); setTimeout(()=>{this.refs.photo.focus()},10) break; case 3: this.setState({ editEmail: true }); setTimeout(()=>{this.refs.email.focus()},10) break; case 4: this.setState({ editNickname: true }); setTimeout(()=>{this.refs.nickname.focus()},10) break; } this.enterFun(item); } //保存单个修改 saveFun(item) { $.ajax({ method: 'POST', dataType: 'json', crossDomain: false, url: globalConfig.context + '/api/user/mobile', data: { id: this.state.id, name: this.state.name, photo: this.state.photo, email: this.state.email, nickname: this.state.nickname } }).done( function(data) { if (!data.error.length) { this.setState({ visible: false }); message.success('修改成功!'); switch (item) { case 1: this.setState({ editName: false }); break; case 2: this.setState({ editPhoto: false }); break; case 3: this.setState({ editEmail: false }); break; case 4: this.setState({ editNickname: false }); break; } this.loadData(); } else { message.warning(data.error[0].message); } }.bind(this) ); } //按下键盘回车键时保存 enterFun(item) { if(item){ document.onkeydown=function(e){ //对整个页面文档监听回车键 var keyNum=window.event ? e.keyCode :e.which; if(keyNum==13){ this.saveFun(item); } }.bind(this) } } componentWillMount(){ this.loadData(); } render() { const formItemLayout = { labelCol: { span: 8 }, wrapperCol: { span: 10 } }; const formItemLayoutBtn = { labelCol: { span: 8 }, wrapperCol: { span: 6 } }; const accountData = this.state.account || []; return (