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