|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
import React from "react"; |
|
|
|
|
import {Button, Col, Container, Form, FormControl, Image, Row} from "react-bootstrap"; |
|
|
|
|
import {UserEdit, UserType} from "../entity"; |
|
|
|
|
import {User, UserEdit, UserType} from "../entity"; |
|
|
|
|
import {Input} from "../ui/InputGroup"; |
|
|
|
|
import {API, JSONResponse, Method, prefix, request} from "../interface"; |
|
|
|
|
import { |
|
|
|
@ -21,12 +21,14 @@ import {user_type_cookie} from "../account/PropCookie"; |
|
|
|
|
*/ |
|
|
|
|
export class MyInfo extends React.Component< |
|
|
|
|
{ |
|
|
|
|
//查看用户id
|
|
|
|
|
userId:string; |
|
|
|
|
//查看本人
|
|
|
|
|
isOwn:boolean; |
|
|
|
|
isMyFriend:boolean; |
|
|
|
|
//是否添加好友
|
|
|
|
|
isAdd:boolean; |
|
|
|
|
cookies?:Cookies; |
|
|
|
|
}, UserEdit>{ |
|
|
|
|
}, { userEdit:UserEdit,userInfo?:User,result:JSX.Element|null }>{ |
|
|
|
|
|
|
|
|
|
private ages:Array<number> |
|
|
|
|
|
|
|
|
@ -36,12 +38,14 @@ export class MyInfo extends React.Component< |
|
|
|
|
this.ages=this.createAge() |
|
|
|
|
|
|
|
|
|
this.state={ |
|
|
|
|
contentEditable:false, |
|
|
|
|
modifyPassword:false, |
|
|
|
|
oldPassword:"", |
|
|
|
|
newPassword:"", |
|
|
|
|
confirmNewPwd:"", |
|
|
|
|
result:null |
|
|
|
|
userEdit:{ |
|
|
|
|
contentEditable:false, |
|
|
|
|
modifyPassword:false, |
|
|
|
|
oldPassword:"", |
|
|
|
|
newPassword:"", |
|
|
|
|
confirmNewPwd:"", |
|
|
|
|
}, |
|
|
|
|
result:null, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -59,6 +63,9 @@ export class MyInfo extends React.Component< |
|
|
|
|
*/ |
|
|
|
|
loadInfo(){ |
|
|
|
|
|
|
|
|
|
if(!this.props.userId){ |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
let that=this |
|
|
|
|
|
|
|
|
|
request(API.account.find+"/"+this.props.userId,Method.GET, {},new FindUserInfoTransform(),function(res:FindUserInfo){ |
|
|
|
@ -69,17 +76,26 @@ export class MyInfo extends React.Component< |
|
|
|
|
});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, |
|
|
|
|
oldUserType:res.info?.userType |
|
|
|
|
userInfo:res.info, |
|
|
|
|
userEdit: { |
|
|
|
|
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, |
|
|
|
|
oldUserType:res.info?.userType, |
|
|
|
|
|
|
|
|
|
contentEditable:false, |
|
|
|
|
modifyPassword:false, |
|
|
|
|
oldPassword:"", |
|
|
|
|
newPassword:"", |
|
|
|
|
confirmNewPwd:"", |
|
|
|
|
} |
|
|
|
|
});break |
|
|
|
|
|
|
|
|
|
} |
|
|
|
@ -95,7 +111,7 @@ export class MyInfo extends React.Component< |
|
|
|
|
*/ |
|
|
|
|
openEdit(){ |
|
|
|
|
this.setState({ |
|
|
|
|
contentEditable:true |
|
|
|
|
userEdit:{...this.state.userEdit,...{contentEditable:true}} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -104,7 +120,7 @@ export class MyInfo extends React.Component< |
|
|
|
|
*/ |
|
|
|
|
openModifyPwd(){ |
|
|
|
|
this.setState({ |
|
|
|
|
modifyPassword:true |
|
|
|
|
userEdit:{...this.state.userEdit,...{ modifyPassword:true}} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -113,14 +129,14 @@ export class MyInfo extends React.Component< |
|
|
|
|
*/ |
|
|
|
|
modifyPwd(){ |
|
|
|
|
this.setState({ |
|
|
|
|
modifyPassword:false |
|
|
|
|
userEdit:{...this.state.userEdit,...{ modifyPassword:false}} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
let that=this |
|
|
|
|
|
|
|
|
|
request(API.account.updatePwd,Method.POST, { |
|
|
|
|
newPassword:this.state.newPassword, |
|
|
|
|
oldPassword:this.state.oldPassword |
|
|
|
|
newPassword:this.state.userEdit.newPassword, |
|
|
|
|
oldPassword:this.state.userEdit.oldPassword |
|
|
|
|
},new ModifyPwdTransform(),function (res:JSONResponse<ModifyPwdMessage>) { |
|
|
|
|
switch (res.customResult) { |
|
|
|
|
case ModifyPwdMessage.fail: |
|
|
|
@ -144,24 +160,24 @@ export class MyInfo extends React.Component< |
|
|
|
|
*/ |
|
|
|
|
doSave(){ |
|
|
|
|
this.setState({ |
|
|
|
|
contentEditable:false |
|
|
|
|
userEdit:{...this.state.userEdit,...{ contentEditable:false}} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
let that=this |
|
|
|
|
let isUpdateUserType=this.state.userType!==this.state.oldUserType |
|
|
|
|
let isUpdateUserType=this.state.userEdit.userType!==this.state.userEdit.oldUserType |
|
|
|
|
if(isUpdateUserType&&this.props.cookies){ |
|
|
|
|
this.props.cookies.set(user_type_cookie,this.state.userType) |
|
|
|
|
this.props.cookies.set(user_type_cookie,this.state.userEdit.userType) |
|
|
|
|
} |
|
|
|
|
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||"" |
|
|
|
|
headImg:this.state.userEdit.headImg||"", |
|
|
|
|
name:this.state.userEdit.name||"", |
|
|
|
|
age:this.state.userEdit.age+""||"", |
|
|
|
|
mobile:this.state.userEdit.mobile+""||"", |
|
|
|
|
email:this.state.userEdit.email||"", |
|
|
|
|
serviceAddress:this.state.userEdit.serviceAddress||"", |
|
|
|
|
info:this.state.userEdit.info||"", |
|
|
|
|
userType:this.state.userEdit.userType||"", |
|
|
|
|
sex:this.state.userEdit.sex||"" |
|
|
|
|
},new EmptyBodyTransform(),function (res:JSONResponse<SimpleMessage>) { |
|
|
|
|
switch (res.customResult) { |
|
|
|
|
case SimpleMessage.fail: |
|
|
|
@ -217,74 +233,96 @@ export class MyInfo extends React.Component< |
|
|
|
|
<Container className="overflow-auto"> |
|
|
|
|
<Row> |
|
|
|
|
<Col className="p-3 text-center"> |
|
|
|
|
<Image className="chat-headImg" src={this.state.headImg?prefix.image+this.state.headImg:""}/> |
|
|
|
|
<Image className="chat-headImg" src={this.state.userInfo?.headImg?prefix.image+this.state.userInfo.headImg:""}/> |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
{/*TODO 表单校验*/} |
|
|
|
|
<Row> |
|
|
|
|
<Col className="border-info border p-3 d-flex justify-content-center align-items-center"> |
|
|
|
|
{this.state.userId} |
|
|
|
|
{this.state.userInfo?.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> |
|
|
|
|
{this.state.userEdit.contentEditable? |
|
|
|
|
<FormControl value={this.state.userEdit.name} onChange={(e)=>this.setState({ |
|
|
|
|
userEdit:{...this.state.userEdit,...{ name:e.target.value}} |
|
|
|
|
})}/> |
|
|
|
|
:this.state.userInfo?.name}</Col> |
|
|
|
|
<Col className="border-info border p-3 text-center"> |
|
|
|
|
{this.state.contentEditable? |
|
|
|
|
<FormControl as={"select"} value={this.state.age} onChange={(e)=>this.setState({age:+e.target.value})}> |
|
|
|
|
{this.state.userEdit.contentEditable? |
|
|
|
|
<FormControl as={"select"} value={this.state.userEdit.age} onChange={(e)=>this.setState({ |
|
|
|
|
userEdit:{...this.state.userEdit,...{ age:+e.target.value}} |
|
|
|
|
})}> |
|
|
|
|
{this.ages.map(value=><option key={value} value={value}>{value}</option>)} |
|
|
|
|
</FormControl> |
|
|
|
|
:this.state.age}</Col> |
|
|
|
|
:this.state.userInfo?.age}</Col> |
|
|
|
|
</Row> |
|
|
|
|
<Row> |
|
|
|
|
<Col className="border-info border p-3 text-center"> |
|
|
|
|
{this.state.contentEditable? |
|
|
|
|
<FormControl value={this.state.mobile} type={"number"} onChange={(e)=>this.setState({mobile:+e.target.value})}/> |
|
|
|
|
:this.state.mobile} |
|
|
|
|
{this.state.userEdit.contentEditable? |
|
|
|
|
<FormControl value={this.state.userEdit.mobile} type={"number"} onChange={(e)=>this.setState({ |
|
|
|
|
userEdit:{...this.state.userEdit,...{ mobile:+e.target.value}} |
|
|
|
|
})}/> |
|
|
|
|
:this.state.userInfo?.mobile} |
|
|
|
|
</Col> |
|
|
|
|
<Col className="border-info border p-3 text-center"> |
|
|
|
|
{this.state.contentEditable? |
|
|
|
|
<FormControl value={this.state.email} onChange={(e)=>this.setState({email:e.target.value})}/> |
|
|
|
|
:this.state.email} |
|
|
|
|
{this.state.userEdit.contentEditable? |
|
|
|
|
<FormControl value={this.state.userEdit.email} onChange={(e)=>this.setState({ |
|
|
|
|
userEdit:{...this.state.userEdit,...{ email:e.target.value}} |
|
|
|
|
})}/> |
|
|
|
|
:this.state.userInfo?.email} |
|
|
|
|
</Col> |
|
|
|
|
<Col className="border-info border p-3 text-center"> |
|
|
|
|
{this.state.contentEditable? |
|
|
|
|
<FormControl value={this.state.sex} as={"select"} onChange={event => this.setState({sex:event.target.value})}> |
|
|
|
|
{this.state.userEdit.contentEditable? |
|
|
|
|
<FormControl value={this.state.userEdit.sex} as={"select"} onChange={event => this.setState({ |
|
|
|
|
userEdit:{...this.state.userEdit,...{ sex:event.target.value}} |
|
|
|
|
})}> |
|
|
|
|
<option value={"man"}>男</option> |
|
|
|
|
<option value={"women"}>女</option> |
|
|
|
|
</FormControl>:this.state.sex==='man'?"男":"女"} |
|
|
|
|
</FormControl>:this.state.userInfo?.sex==='man'?"男":"女"} |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
<Row> |
|
|
|
|
<Col className="border-info border p-3 text-center"> |
|
|
|
|
{this.state.contentEditable? |
|
|
|
|
<Address col={12} value={this.state.serviceAddress} onChange={(value:string)=>this.setState({serviceAddress:value})}/>:this.state.serviceAddress} |
|
|
|
|
{this.state.userEdit.contentEditable? |
|
|
|
|
<Address col={12} value={this.state.userEdit.serviceAddress} onChange={(value:string)=>this.setState({ |
|
|
|
|
userEdit:{...this.state.userEdit,...{ serviceAddress:value}} |
|
|
|
|
})}/>:this.state.userInfo?.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})}> |
|
|
|
|
{this.state.userEdit.contentEditable? |
|
|
|
|
<FormControl value={this.state.userEdit.userType} as={"select"} onChange={(e)=>this.setState({ |
|
|
|
|
userEdit:{...this.state.userEdit,...{ userType:e.target.value}} |
|
|
|
|
})}> |
|
|
|
|
<option value={UserType.seekHelp}>服务发起者</option> |
|
|
|
|
<option value={UserType.help}>服务接受者</option> |
|
|
|
|
</FormControl>: |
|
|
|
|
this.state.userType===UserType.help?"等待前往帮助":"等待接受帮助"} |
|
|
|
|
this.state.userInfo?.userType===UserType.help?"等待前往帮助":"等待接受帮助"} |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
<Row> |
|
|
|
|
<Col className="border-info border p-3 text-center my-info-desc"> |
|
|
|
|
{this.state.contentEditable? |
|
|
|
|
<FormControl value={this.state.info} as={"textarea"} onChange={(e)=>this.setState({info:e.target.value})}/> |
|
|
|
|
:this.state.info} |
|
|
|
|
{this.state.userEdit.contentEditable? |
|
|
|
|
<FormControl value={this.state.userEdit.info} as={"textarea"} onChange={(e)=>this.setState({ |
|
|
|
|
userEdit:{...this.state.userEdit,...{ info:e.target.value}} |
|
|
|
|
})}/> |
|
|
|
|
:this.state.userInfo?.info} |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
{this.state.modifyPassword? |
|
|
|
|
{this.state.userEdit.modifyPassword? |
|
|
|
|
<Row> |
|
|
|
|
<Col> |
|
|
|
|
<Form> |
|
|
|
|
<Input name="oldPassword" type={"password"} desc="旧密码" onChange={(value:string)=>this.setState({oldPassword:value})}/> |
|
|
|
|
<Input name="oldPassword" type={"password"} desc="旧密码" onChange={(value:string)=>this.setState({ |
|
|
|
|
userEdit:{...this.state.userEdit,...{ oldPassword:value}} |
|
|
|
|
})}/> |
|
|
|
|
|
|
|
|
|
<Input name="newPassword" type={"password"} desc="新密码" onChange={(value:string)=>this.setState({newPassword:value})}/> |
|
|
|
|
<Input name="newPassword" type={"password"} desc="新密码" onChange={(value:string)=>this.setState({ |
|
|
|
|
userEdit:{...this.state.userEdit,...{newPassword:value}} |
|
|
|
|
})}/> |
|
|
|
|
|
|
|
|
|
<Input name="confirmNewPwd" type={"password"} placeholder="请确认新密码" desc="新密码" onChange={(value:string)=>this.setState({confirmNewPwd:value})}/> |
|
|
|
|
<Input name="confirmNewPwd" type={"password"} placeholder="请确认新密码" desc="新密码" onChange={(value:string)=>this.setState({ |
|
|
|
|
userEdit:{...this.state.userEdit,...{confirmNewPwd:value}} |
|
|
|
|
})}/> |
|
|
|
|
</Form> |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
@ -294,19 +332,19 @@ export class MyInfo extends React.Component< |
|
|
|
|
{this.props.isOwn? |
|
|
|
|
<Row className="p-3"> |
|
|
|
|
<Col className="text-center"> |
|
|
|
|
{this.state.contentEditable? |
|
|
|
|
{this.state.userEdit.contentEditable? |
|
|
|
|
<Button variant={"primary"} onClick={()=>this.doSave()}>保存信息</Button>: |
|
|
|
|
<Button variant={"info"} onClick={()=>this.openEdit()} disabled={this.state.modifyPassword}>编辑信息</Button>} |
|
|
|
|
<Button variant={"info"} onClick={()=>this.openEdit()} disabled={this.state.userEdit.modifyPassword}>编辑信息</Button>} |
|
|
|
|
</Col> |
|
|
|
|
<Col className="text-center"> |
|
|
|
|
{this.state.modifyPassword? |
|
|
|
|
{this.state.userEdit.modifyPassword? |
|
|
|
|
<Button variant={"light"} onClick={()=>this.modifyPwd()}>确认</Button>: |
|
|
|
|
<Button variant={"light"} onClick={()=>this.openModifyPwd()} disabled={this.state.contentEditable}>修改密码</Button>} |
|
|
|
|
<Button variant={"light"} onClick={()=>this.openModifyPwd()} disabled={this.state.userEdit.contentEditable}>修改密码</Button>} |
|
|
|
|
</Col> |
|
|
|
|
</Row>: |
|
|
|
|
<Row className="p-3"> |
|
|
|
|
<Col className="text-center"> |
|
|
|
|
{this.props.isMyFriend?null:this.props.isAdd? |
|
|
|
|
{this.state.userInfo?.isMyFriend===undefined||this.state.userInfo.isMyFriend?null:this.props.isAdd? |
|
|
|
|
<Button variant={"primary"} onClick={()=>this.addFriend()}>添加好友</Button> |
|
|
|
|
: |
|
|
|
|
<Button variant={"primary"} onClick={()=>this.agreeFriend()}>同意</Button> |
|
|
|
|