|
|
|
@ -2,69 +2,84 @@ import React from "react"; |
|
|
|
|
import {Button, Col, Container, Form, FormControl, Image, Row} from "react-bootstrap"; |
|
|
|
|
import {UserEdit, UserType} from "../entity"; |
|
|
|
|
import {Input} from "../ui/InputGroup"; |
|
|
|
|
|
|
|
|
|
import {API, JSONResponse, Method, prefix, request} from "../interface"; |
|
|
|
|
import { |
|
|
|
|
EmptyBodyTransform, |
|
|
|
|
FindUserInfo, |
|
|
|
|
FindUserInfoTransform, |
|
|
|
|
ModifyPwdMessage, |
|
|
|
|
ModifyPwdTransform, |
|
|
|
|
SimpleMessage |
|
|
|
|
} from "../result"; |
|
|
|
|
import {MyDialog} from "../ui/MyDialog"; |
|
|
|
|
import {Address} from "../ui/Address"; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 个人信息 |
|
|
|
|
*/ |
|
|
|
|
export class MyInfo extends React.Component< |
|
|
|
|
{ |
|
|
|
|
userId:string; |
|
|
|
|
isOwn:boolean; |
|
|
|
|
ownUserId:string; |
|
|
|
|
userId?:string; |
|
|
|
|
isMyFriend:boolean; |
|
|
|
|
isAdd:boolean; |
|
|
|
|
//更新用户信息回调
|
|
|
|
|
onUserUpdate?:Function; |
|
|
|
|
}, UserEdit>{ |
|
|
|
|
|
|
|
|
|
private ages:Array<number> |
|
|
|
|
|
|
|
|
|
constructor(props: Readonly<any>) { |
|
|
|
|
super(props); |
|
|
|
|
|
|
|
|
|
this.ages=this.createAge() |
|
|
|
|
|
|
|
|
|
this.state={ |
|
|
|
|
userType: "", |
|
|
|
|
//用户ID
|
|
|
|
|
userId:"", |
|
|
|
|
//用户姓名
|
|
|
|
|
name:"", |
|
|
|
|
//用户年龄
|
|
|
|
|
age:0, |
|
|
|
|
//用户电话
|
|
|
|
|
mobile:0, |
|
|
|
|
//用户邮箱
|
|
|
|
|
email:"", |
|
|
|
|
address:"", |
|
|
|
|
//地点
|
|
|
|
|
serviceAddress:"", |
|
|
|
|
//个人简介
|
|
|
|
|
info:"", |
|
|
|
|
//性别
|
|
|
|
|
sex:"男", |
|
|
|
|
//头像
|
|
|
|
|
headImg:"", |
|
|
|
|
contentEditable:false, |
|
|
|
|
modifyPassword:false, |
|
|
|
|
oldPassword:"", |
|
|
|
|
newPassword:"", |
|
|
|
|
confirmNewPwd:"" |
|
|
|
|
confirmNewPwd:"", |
|
|
|
|
result:null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createAge(){ |
|
|
|
|
let age=[] |
|
|
|
|
for(let i=18;i<100;i++){ |
|
|
|
|
age.push(i) |
|
|
|
|
} |
|
|
|
|
return age |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 加载用户信息 |
|
|
|
|
*/ |
|
|
|
|
loadInfo(){ |
|
|
|
|
this.setState({ |
|
|
|
|
headImg:"logo512.png", |
|
|
|
|
userId:"admin", |
|
|
|
|
name:"张三", |
|
|
|
|
age:Math.ceil(Math.random()*100)+1, |
|
|
|
|
mobile:1234567879, |
|
|
|
|
email:"admin@qq.com", |
|
|
|
|
serviceAddress:"上海高新区", |
|
|
|
|
info:"个人简介", |
|
|
|
|
userType:UserType.help.toString() |
|
|
|
|
|
|
|
|
|
let that=this |
|
|
|
|
|
|
|
|
|
request(API.account.find+"/"+this.props.userId,Method.GET, {},new FindUserInfoTransform(),function(res:FindUserInfo){ |
|
|
|
|
switch (res.customResult) { |
|
|
|
|
case SimpleMessage.fail: |
|
|
|
|
that.setState({ |
|
|
|
|
result:<h3 className="text-danger text-center">获取用户信息失败,请联系管理员</h3> |
|
|
|
|
});break |
|
|
|
|
case SimpleMessage.ok: |
|
|
|
|
that.setState({ |
|
|
|
|
headImg:res.info?.headImg, |
|
|
|
|
userId:res.info?.userId, |
|
|
|
|
name:res.info?.name, |
|
|
|
|
age:res.info?.age, |
|
|
|
|
mobile:res.info?.mobile, |
|
|
|
|
email:res.info?.email, |
|
|
|
|
serviceAddress:res.info?.serviceAddress, |
|
|
|
|
info:res.info?.info, |
|
|
|
|
userType:res.info?.userType, |
|
|
|
|
sex:res.info?.sex |
|
|
|
|
});break |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -97,6 +112,28 @@ export class MyInfo extends React.Component< |
|
|
|
|
this.setState({ |
|
|
|
|
modifyPassword:false |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
let that=this |
|
|
|
|
|
|
|
|
|
request(API.account.updatePwd,Method.POST, { |
|
|
|
|
newPassword:this.state.newPassword, |
|
|
|
|
oldPassword:this.state.oldPassword |
|
|
|
|
},new ModifyPwdTransform(),function (res:JSONResponse<ModifyPwdMessage>) { |
|
|
|
|
switch (res.customResult) { |
|
|
|
|
case ModifyPwdMessage.fail: |
|
|
|
|
that.setState({ |
|
|
|
|
result:<h3 className="text-danger text-center">修改密码失败,请联系管理员</h3> |
|
|
|
|
});break |
|
|
|
|
case ModifyPwdMessage.pwd_fail: |
|
|
|
|
that.setState({ |
|
|
|
|
result:<h3 className="text-danger text-center">修改密码失败,原密码错误</h3> |
|
|
|
|
});break |
|
|
|
|
case ModifyPwdMessage.ok: |
|
|
|
|
that.setState({ |
|
|
|
|
result:<h3 className="text-info text-center">修改密码成功</h3> |
|
|
|
|
});break |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -107,10 +144,34 @@ export class MyInfo extends React.Component< |
|
|
|
|
contentEditable:false |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if(this.props.onUserUpdate) { |
|
|
|
|
this.props.onUserUpdate({userType: this.state.userType}) |
|
|
|
|
} |
|
|
|
|
console.debug(this.state) |
|
|
|
|
let that=this |
|
|
|
|
|
|
|
|
|
request(API.account.update,Method.POST, { |
|
|
|
|
headImg:this.state.headImg||"", |
|
|
|
|
name:this.state.name||"", |
|
|
|
|
age:this.state.age+""||"", |
|
|
|
|
mobile:this.state.mobile+""||"", |
|
|
|
|
email:this.state.email||"", |
|
|
|
|
serviceAddress:this.state.serviceAddress||"", |
|
|
|
|
info:this.state.info||"", |
|
|
|
|
userType:this.state.userType||"", |
|
|
|
|
sex:this.state.sex||"" |
|
|
|
|
},new EmptyBodyTransform(),function (res:JSONResponse<SimpleMessage>) { |
|
|
|
|
switch (res.customResult) { |
|
|
|
|
case SimpleMessage.fail: |
|
|
|
|
that.setState({ |
|
|
|
|
result:<h3 className="text-danger text-center">更新信息失败,请联系管理员</h3> |
|
|
|
|
});break |
|
|
|
|
case SimpleMessage.ok: |
|
|
|
|
that.loadInfo(); |
|
|
|
|
//TODO 更新用户身份
|
|
|
|
|
that.setState({ |
|
|
|
|
result:<h3 className="text-info text-center">更新信息成功</h3> |
|
|
|
|
}) |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -132,22 +193,26 @@ export class MyInfo extends React.Component< |
|
|
|
|
render() { |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<Container> |
|
|
|
|
<Container className="overflow-auto"> |
|
|
|
|
<Row> |
|
|
|
|
<Col className="p-3"> |
|
|
|
|
<Image className="chat-headImg" src={this.state.headImg}/> |
|
|
|
|
<Col className="p-3 text-center"> |
|
|
|
|
<Image className="chat-headImg" src={this.state.headImg?prefix.image+this.state.headImg:""}/> |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
{/*TODO 表单校验*/} |
|
|
|
|
<Row> |
|
|
|
|
<Col className="border-info border p-3 text-center">{this.state.userId}</Col> |
|
|
|
|
<Col className="border-info border p-3 d-flex justify-content-center align-items-center"> |
|
|
|
|
{this.state.userId} |
|
|
|
|
</Col> |
|
|
|
|
<Col className="border-info border p-3 text-center"> |
|
|
|
|
{this.state.contentEditable? |
|
|
|
|
<FormControl value={this.state.name} onChange={(e)=>this.setState({name:e.target.value})}/> |
|
|
|
|
:this.state.name}</Col> |
|
|
|
|
<Col className="border-info border p-3 text-center"> |
|
|
|
|
{this.state.contentEditable? |
|
|
|
|
<FormControl value={this.state.age} type={"number"} onChange={(e)=>this.setState({age:+e.target.value})}/> |
|
|
|
|
<FormControl as={"select"} value={this.state.age} onChange={(e)=>this.setState({age:+e.target.value})}> |
|
|
|
|
{this.ages.map(value=><option key={value} value={value}>{value}</option>)} |
|
|
|
|
</FormControl> |
|
|
|
|
:this.state.age}</Col> |
|
|
|
|
</Row> |
|
|
|
|
<Row> |
|
|
|
@ -163,18 +228,24 @@ export class MyInfo extends React.Component< |
|
|
|
|
</Col> |
|
|
|
|
<Col className="border-info border p-3 text-center"> |
|
|
|
|
{this.state.contentEditable? |
|
|
|
|
<FormControl value={this.state.userType} as={"select"} onChange={(e)=>this.setState({userType:e.target.value})}> |
|
|
|
|
<option value={UserType.help}>服务发起者</option> |
|
|
|
|
<option value={UserType.seekHelp}>服务接受者</option> |
|
|
|
|
</FormControl>: |
|
|
|
|
this.state.userType===UserType.help?"等待接受帮助":"等待前往帮助"} |
|
|
|
|
<FormControl value={this.state.sex} as={"select"} onChange={event => this.setState({sex:event.target.value})}> |
|
|
|
|
<option value={"man"}>男</option> |
|
|
|
|
<option value={"women"}>女</option> |
|
|
|
|
</FormControl>:this.state.sex==='man'?"男":"女"} |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
<Row> |
|
|
|
|
<Col className="border-info border p-3 text-center"> |
|
|
|
|
{this.state.contentEditable? |
|
|
|
|
<FormControl value={this.state.serviceAddress} onChange={(e)=>this.setState({serviceAddress:e.target.value})}/> |
|
|
|
|
:this.state.serviceAddress} |
|
|
|
|
<Address col={12} value={this.state.serviceAddress} onChange={(value:string)=>this.setState({serviceAddress:value})}/>:this.state.serviceAddress} |
|
|
|
|
</Col> |
|
|
|
|
<Col className="border-info border p-3 text-center"> |
|
|
|
|
{this.state.contentEditable? |
|
|
|
|
<FormControl value={this.state.userType} as={"select"} onChange={(e)=>this.setState({userType:e.target.value})}> |
|
|
|
|
<option value={UserType.seekHelp}>服务发起者</option> |
|
|
|
|
<option value={UserType.help}>服务接受者</option> |
|
|
|
|
</FormControl>: |
|
|
|
|
this.state.userType===UserType.help?"等待前往帮助":"等待接受帮助"} |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
<Row> |
|
|
|
@ -223,6 +294,9 @@ export class MyInfo extends React.Component< |
|
|
|
|
</Row> |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
<MyDialog content={this.state.result} open={this.state.result!==null} titleId="myinfo-dialog" menuName="用户提示" onClose={()=>this.setState({ |
|
|
|
|
result:null |
|
|
|
|
})}/> |
|
|
|
|
</Container> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|