diff --git a/public/react/src/modules/user/account/AccountBasicEdit.js b/public/react/src/modules/user/account/AccountBasicEdit.js index 9d6b4706c..7463fa632 100644 --- a/public/react/src/modules/user/account/AccountBasicEdit.js +++ b/public/react/src/modules/user/account/AccountBasicEdit.js @@ -1,570 +1,570 @@ -import React, { Component } from 'react'; - -import { SnackbarHOC, getImageUrl, City } from 'educoder'; -import { Form, Button, Input, Radio, Select, Tooltip, Icon } from 'antd' -import ApplyForAddOrgModal from '../modal/ApplyForAddOrgModal' -import ApplyForAddChildOrgModal from '../modal/ApplyForAddChildOrgModal' -import axios from 'axios' - -const RadioGroup = Radio.Group; -const Option = Select.Option; - -const map={"teacher":"教师", "student":"学生", "professional":"专业人士"} -class AccountBasic extends Component { - constructor(props){ - super(props); - this.state={ - nameLength:0, - showRealName:true, - schoolList:undefined, - filterSchoolList:undefined, - school:undefined, - departments:undefined, - filterDepartments:undefined, - departmentsName:undefined, - identity:"teacher", - school_id:undefined, - department_id:undefined - } - } - - componentDidUpdate =(prevProps)=>{ - if(this.props.basicInfo && prevProps.basicInfo == undefined){ - this.setValue(this.props.basicInfo); - this.getSchoolList(this.props.basicInfo); - } - } - - componentDidMount = () =>{ - if(this.props.basicInfo){ - this.setValue(this.props.basicInfo); - this.getSchoolList(this.props.basicInfo); - } - } - - setValue=(basicInfo)=>{ - if(basicInfo){ - //if(basicInfo.nickname){ - this.setState({ - nameLength:basicInfo.nickname?basicInfo.nickname.length:0, - showRealName:basicInfo.show_realname, - identity:basicInfo.identity - }) - //} - this.props.form.setFieldsValue({ - nickname:basicInfo.nickname, - name:!basicInfo.show_realname ? this.hideRealName(basicInfo.name) : basicInfo.name, - student_No:basicInfo.student_id, - sex:String(basicInfo.gender), - job:map[basicInfo.identity], - org:basicInfo.school_name, - org2:basicInfo.department_name, - job1:basicInfo && basicInfo.identity=="teacher" ? basicInfo.technical_title:"教授", - job2:basicInfo && basicInfo.identity=="professional" ? basicInfo.technical_title:"企业管理者", - city:[basicInfo.location,basicInfo.location_city] - }) - } - } - - // 获取学校、单位 - getSchoolList=(basicInfo)=>{ - let url=`/schools/for_option.json`; - axios.get(url).then((result)=>{ - if(result){ - this.setState({ - schoolList:result.data.schools - }) - if(basicInfo && basicInfo.school_name){ - this.setState({ - school:basicInfo.school_name, - filterSchoolList:this.state.schoolList.filter(function(item){ - return item.name.indexOf(basicInfo.school_name)>-1; - }) - }) - this.getDepartments(basicInfo.school_name,false); - } - } - }).catch((error)=>{ - console.log(error); - }) - } - - // 输入昵称时change剩余的字数 - changeNickName=(e)=>{ - let num= 10 - parseInt(e.target.value.length); - this.setState({ - nameLength:num < 0 ? 0 : num - }) - } - - handleSubmit = () => { - this.props.form.validateFieldsAndScroll((err, values) => { - console.log(values); - let {basicInfo}=this.props; - if(!err){ - let url=`/users/accounts/${basicInfo.id}.json` - axios.put((url),{ - nickname:values.nickname, - name:values.name, - show_realname:this.state.showRealName, - gender:parseInt(values.sex), - location:values.city[0], - location_city:values.city[1], - identity:values.job=="教师"?"teacher":values.job=="学生"?"student":"professional", - technical_title:values.job1 || values.job2, - student_id:values.job=="学生" ? values.student_No : null, - school_id:this.state.school_id, - department_id:this.state.department_id - }).then((result)=>{ - if(result){ - this.props.getBasicInfo(); - } - }).catch((error)=>{ - console.log(error); - }) - } - }) - } - - // 隐藏或显示真实姓名 - showOrHide=(flag,name)=>{ - this.setState({ - showRealName:flag==true?false:true - }) - if(flag==true){ - this.hideRealName(name); - }else{ - this.props.form.setFieldsValue({ - name - }) - } - } - - // 将名字隐藏起来 - hideRealName=(name)=>{ - let len=parseInt(name.length)-1; - let str=""; - for(var i = 0; i < len; i++){ str += "*"; } - - name = name.substr(0,1)+str; - - this.props.form.setFieldsValue({ - name - }) - } - - // 过滤学校 - filterList=(e)=>{ - let arr=[]; - if(e){ - arr= this.state.schoolList.filter(function(item){ - return item.name.indexOf(e)>-1; - }); - this.props.form.setFieldsValue({ - org:e - }) - this.setState({ - school:e, - filterSchoolList:arr - }) - } - // else{ - // let {school}=this.state; - // arr= this.state.schoolList.filter(function(item){ - // return item.name.indexOf(school)>-1; - // }); - // } - } - //搜索部门 - searchDepartment=(e)=>{ - this.props.form.setFieldsValue({ - org2:e - }) - let arr = this.state.departments.filter(function(item){ - return item.name.indexOf(e) > -1 - }) - this.setState({ - filterDepartments:arr, - departmentsName:e - }) - } - - // 选择部门、学院 - changeDepartment=(e)=>{ - let arr=this.state.departments.filter(function(item){ - return item.name == e; - }); - this.setState({ - departmentsName:e, - department_id:arr[0].id - }) - } - - // 选择学校(获取对应学校的学院、部门) - changeList=(e)=>{ - this.getDepartments(e,true); - } - - getDepartments=(e,flag)=>{ - let arr=this.state.schoolList.filter(function(item){ - return item.name == e; - }); - // 保存选择的学校id - this.setState({ - school_id:arr[0].id, - school:e, - }) - let url=`/schools/${arr[0].id}/departments/for_option.json`; - axios.get(url).then((result)=>{ - if(result){ - this.setState({ - departments:result.data.departments, - filterDepartments:result.data.departments - }) - // 切换学校后,部门默认选择第一个 - if(result.data.departments && result.data.departments.length>0 && flag==true){ - this.props.form.setFieldsValue({ - org2:result.data.departments[0].name - }) - } - } - }).catch((error)=>{ - console.log(error); - }) - } - - // 切换职称 - changeJob=(e)=>{ - - this.setState({ - identity:e - }) - let {basicInfo}=this.props; - if(basicInfo){ - this.props.form.setFieldsValue({ - job1:basicInfo && basicInfo.identity=="teacher" ? basicInfo.technical_title:"教授", - job2:basicInfo && basicInfo.identity=="professional" ? basicInfo.technical_title:"企业管理者", - }) - } - } - - - showApplyForAddOrgModal = () => { - this.applyForAddOrgForm.setVisible(true) - } - showApplyForAddChildOrgModal = () => { - let{school,schoolList}=this.state; - let arr=schoolList.filter(function(item){ - return item.name == school; - }); - if(arr.length > 0){ - this.applyForAddChildOrgForm.setVisible(true) - }else{ - this.props.showNotification("请先选择正确的单位或者学校!"); - } - } - - render() { - let{ - nameLength, - showRealName, - filterSchoolList, - filterDepartments, - school, - school_id, - departmentsName, - identity - }=this.state; - const { getFieldDecorator } = this.props.form; - let{basicInfo}=this.props - - return ( -
- this.applyForAddOrgForm = form} schoolName={school} - {...this.props}> - this.applyForAddChildOrgForm = form} > - -
- -
基本信息
- -
- - {getFieldDecorator('nickname', { - rules: [{ - // initialValue: this.state.cityDefaultValue, - required: true, - message: '请输入您的昵称', - }], - })( - {String(nameLength)}/10 - }> - )} - - - - {getFieldDecorator('name', { - rules: [{ - // initialValue: this.state.cityDefaultValue, - required: true, - message: '请输入您的姓名', - }], - })( - this.showOrHide(showRealName,basicInfo.name)}> - }> - )} - { showRealName ? '(显示:平台将显示您的真实姓名)' : '(隐藏:平台将显示你的昵称)' } - - - - {getFieldDecorator('sex', { - rules: [{ - required: true, - message: '请选择性别', - }], - })( - - - - - )} - - - - - {getFieldDecorator('city', { - rules: [{ - type: 'array', - required: true, - message: '请先选择所在地', - }], - })( - - )} - -
- - {getFieldDecorator('job', { - rules: [{ - initialValue:"teacher", - required: true, - message: '请先选择职业', - }], - })( - - )} - - { - identity && identity=="student" && - - {getFieldDecorator('student_No', { - rules: [{ - required: true, - message: '请先输入学号', - }], - })( - - )} - - } - { - identity && identity=="teacher" && - - {getFieldDecorator('job1', { - rules: [{ - initialValue:"教授", - required: true, - message: '请先选择职称', - }], - })( - - )} - - } - { - identity && identity=="professional" && - - {getFieldDecorator('job2', { - rules: [{ - initialValue:"企业管理者", - required: true, - message: '请先选择职称', - }], - })( - - )} - - } -
- - - {getFieldDecorator('org', { - rules: [{ - // initialValue: this.state.cityDefaultValue, - // type: 'array', - required: true, - message: '请先选择学校/单位', - }], - })( - - )} - -
- {!filterSchoolList || (filterSchoolList && filterSchoolList.length==0 )&& - - 未找到包含“{school}”的高校, - 申请新增 - - } -
- - {getFieldDecorator('org2', { - rules: [{ - // initialValue: this.state.cityDefaultValue, - // type: 'array', - required: true, - message: '请先选择院系/部门', - }], - })( - - )} - -
- { - !filterDepartments || (filterDepartments && filterDepartments.length==0 )&& - - 未找到包含“{departmentsName}”的院系/部门, - 申请新增 - - } -
- - {/* htmlType="submit" */} - {/* -
*/} - - {/*
-
*/} -
-
-
* 我们确保你所提供的信息均处于严格保密状态,不会泄露
-
- ); - } -} -const WrappedAccountBasic = Form.create({ name: 'AccountBasic' })(AccountBasic); - -export default WrappedAccountBasic; +import React, { Component } from 'react'; + +import { SnackbarHOC, getImageUrl, City } from 'educoder'; +import { Form, Button, Input, Radio, Select, Tooltip, Icon } from 'antd' +import ApplyForAddOrgModal from '../modal/ApplyForAddOrgModal' +import ApplyForAddChildOrgModal from '../modal/ApplyForAddChildOrgModal' +import axios from 'axios' + +const RadioGroup = Radio.Group; +const Option = Select.Option; + +const map={"teacher":"教师", "student":"学生", "professional":"专业人士"} +class AccountBasic extends Component { + constructor(props){ + super(props); + this.state={ + nameLength:0, + showRealName:true, + schoolList:undefined, + filterSchoolList:undefined, + school:undefined, + departments:undefined, + filterDepartments:undefined, + departmentsName:undefined, + identity:"teacher", + school_id:undefined, + department_id:undefined + } + } + + componentDidUpdate =(prevProps)=>{ + if(this.props.basicInfo && prevProps.basicInfo == undefined){ + this.setValue(this.props.basicInfo); + this.getSchoolList(this.props.basicInfo); + } + } + + componentDidMount = () =>{ + if(this.props.basicInfo){ + this.setValue(this.props.basicInfo); + this.getSchoolList(this.props.basicInfo); + } + } + + setValue=(basicInfo)=>{ + if(basicInfo){ + //if(basicInfo.nickname){ + this.setState({ + nameLength:basicInfo.nickname?basicInfo.nickname.length:0, + showRealName:basicInfo.show_realname, + identity:basicInfo.identity + }) + //} + this.props.form.setFieldsValue({ + nickname:basicInfo.nickname, + name:!basicInfo.show_realname ? this.hideRealName(basicInfo.name) : basicInfo.name, + student_No:basicInfo.student_id, + sex:String(basicInfo.gender), + job:map[basicInfo.identity], + org:basicInfo.school_name, + org2:basicInfo.department_name, + job1:basicInfo && basicInfo.identity=="teacher" ? basicInfo.technical_title:"教授", + job2:basicInfo && basicInfo.identity=="professional" ? basicInfo.technical_title:"企业管理者", + city:[basicInfo.location,basicInfo.location_city] + }) + } + } + + // 获取学校、单位 + getSchoolList=(basicInfo)=>{ + let url=`/schools/for_option.json`; + axios.get(url).then((result)=>{ + if(result){ + this.setState({ + schoolList:result.data.schools + }) + if(basicInfo && basicInfo.school_name){ + this.setState({ + school:basicInfo.school_name, + filterSchoolList:this.state.schoolList.filter(function(item){ + return item.name.indexOf(basicInfo.school_name)>-1; + }) + }) + this.getDepartments(basicInfo.school_name,false); + } + } + }).catch((error)=>{ + console.log(error); + }) + } + + // 输入昵称时change剩余的字数 + changeNickName=(e)=>{ + let num= 10 - parseInt(e.target.value.length); + this.setState({ + nameLength:num < 0 ? 0 : num + }) + } + + handleSubmit = () => { + this.props.form.validateFieldsAndScroll((err, values) => { + console.log(values); + let {basicInfo}=this.props; + if(!err){ + let url=`/users/accounts/${basicInfo.id}.json` + axios.put((url),{ + nickname:values.nickname, + name:values.name, + show_realname:this.state.showRealName, + gender:parseInt(values.sex), + location:values.city[0], + location_city:values.city[1], + identity:values.job=="教师"?"teacher":values.job=="学生"?"student":"professional", + technical_title:values.job1 || values.job2, + student_id:values.job=="学生" ? values.student_No : null, + school_id:this.state.school_id, + department_id:this.state.department_id + }).then((result)=>{ + if(result){ + this.props.getBasicInfo(); + } + }).catch((error)=>{ + console.log(error); + }) + } + }) + } + + // 隐藏或显示真实姓名 + showOrHide=(flag,name)=>{ + this.setState({ + showRealName:flag==true?false:true + }) + if(flag==true){ + this.hideRealName(name); + }else{ + this.props.form.setFieldsValue({ + name + }) + } + } + + // 将名字隐藏起来 + hideRealName=(name)=>{ + let len=parseInt(name.length)-1; + let str=""; + for(var i = 0; i < len; i++){ str += "*"; } + + name = name.substr(0,1)+str; + + this.props.form.setFieldsValue({ + name + }) + } + + // 过滤学校 + filterList=(e)=>{ + let arr=[]; + if(e){ + arr= this.state.schoolList.filter(function(item){ + return item.name.indexOf(e)>-1; + }); + this.props.form.setFieldsValue({ + org:e + }) + this.setState({ + school:e, + filterSchoolList:arr + }) + } + // else{ + // let {school}=this.state; + // arr= this.state.schoolList.filter(function(item){ + // return item.name.indexOf(school)>-1; + // }); + // } + } + //搜索部门 + searchDepartment=(e)=>{ + this.props.form.setFieldsValue({ + org2:e + }) + let arr = this.state.departments.filter(function(item){ + return item.name.indexOf(e) > -1 + }) + this.setState({ + filterDepartments:arr, + departmentsName:e + }) + } + + // 选择部门、学院 + changeDepartment=(e)=>{ + let arr=this.state.departments.filter(function(item){ + return item.name == e; + }); + this.setState({ + departmentsName:e, + department_id:arr[0].id + }) + } + + // 选择学校(获取对应学校的学院、部门) + changeList=(e)=>{ + this.getDepartments(e,true); + } + + getDepartments=(e,flag)=>{ + let arr=this.state.schoolList.filter(function(item){ + return item.name == e; + }); + // 保存选择的学校id + this.setState({ + school_id:arr[0].id, + school:e, + }) + let url=`/schools/${arr[0].id}/departments/for_option.json`; + axios.get(url).then((result)=>{ + if(result){ + this.setState({ + departments:result.data.departments, + filterDepartments:result.data.departments + }) + // 切换学校后,部门默认选择第一个 + if(result.data.departments && result.data.departments.length>0 && flag==true){ + this.props.form.setFieldsValue({ + org2:result.data.departments[0].name + }) + } + } + }).catch((error)=>{ + console.log(error); + }) + } + + // 切换职称 + changeJob=(e)=>{ + + this.setState({ + identity:e + }) + let {basicInfo}=this.props; + if(basicInfo){ + this.props.form.setFieldsValue({ + job1:basicInfo && basicInfo.identity=="teacher" ? basicInfo.technical_title:"教授", + job2:basicInfo && basicInfo.identity=="professional" ? basicInfo.technical_title:"企业管理者", + }) + } + } + + + showApplyForAddOrgModal = () => { + this.applyForAddOrgForm.setVisible(true) + } + showApplyForAddChildOrgModal = () => { + let{school,schoolList}=this.state; + let arr=schoolList.filter(function(item){ + return item.name == school; + }); + if(arr.length > 0){ + this.applyForAddChildOrgForm.setVisible(true) + }else{ + this.props.showNotification("请先选择正确的单位或者学校!"); + } + } + + render() { + let{ + nameLength, + showRealName, + filterSchoolList, + filterDepartments, + school, + school_id, + departmentsName, + identity + }=this.state; + const { getFieldDecorator } = this.props.form; + let{basicInfo}=this.props + + return ( +
+ this.applyForAddOrgForm = form} schoolName={school} + {...this.props}> + this.applyForAddChildOrgForm = form} > + +
+ +
基本信息
+ +
+ + {getFieldDecorator('nickname', { + rules: [{ + // initialValue: this.state.cityDefaultValue, + required: true, + message: '请输入您的昵称', + }], + })( + {String(nameLength)}/10 + }> + )} + + + + {getFieldDecorator('name', { + rules: [{ + // initialValue: this.state.cityDefaultValue, + required: true, + message: '请输入您的姓名', + }], + })( + this.showOrHide(showRealName,basicInfo.name)}> + }> + )} + { showRealName ? '(显示:平台将显示您的真实姓名)' : '(隐藏:平台将显示你的昵称)' } + + + + {getFieldDecorator('sex', { + rules: [{ + required: true, + message: '请选择性别', + }], + })( + + + + + )} + + + + + {getFieldDecorator('city', { + rules: [{ + type: 'array', + required: true, + message: '请先选择所在地', + }], + })( + + )} + +
+ + {getFieldDecorator('job', { + rules: [{ + initialValue:"teacher", + required: true, + message: '请先选择职业', + }], + })( + + )} + + { + identity && identity=="student" && + + {getFieldDecorator('student_No', { + rules: [{ + required: true, + message: '请先输入学号', + }], + })( + + )} + + } + { + identity && identity=="teacher" && + + {getFieldDecorator('job1', { + rules: [{ + initialValue:"教授", + required: true, + message: '请先选择职称', + }], + })( + + )} + + } + { + identity && identity=="professional" && + + {getFieldDecorator('job2', { + rules: [{ + initialValue:"企业管理者", + required: true, + message: '请先选择职称', + }], + })( + + )} + + } +
+ + + {getFieldDecorator('org', { + rules: [{ + // initialValue: this.state.cityDefaultValue, + // type: 'array', + required: true, + message: '请先选择学校/单位', + }], + })( + + )} + +
+ {!filterSchoolList || (filterSchoolList && filterSchoolList.length==0 )&& + + 未找到包含“{school}”的高校, + 申请新增 + + } +
+ + {getFieldDecorator('org2', { + rules: [{ + // initialValue: this.state.cityDefaultValue, + // type: 'array', + required: true, + message: '请先选择院系/部门', + }], + })( + + )} + +
+ { + !filterDepartments || (filterDepartments && filterDepartments.length==0 )&& + + 未找到包含“{departmentsName}”的院系/部门, + 申请新增 + + } +
+ + {/* htmlType="submit" */} + {/* +
*/} + + {/*
+
*/} +
+
+
* 我们确保你所提供的信息均处于严格保密状态,不会泄露
+
+ ); + } +} +const WrappedAccountBasic = Form.create({ name: 'AccountBasic' })(AccountBasic); + +export default WrappedAccountBasic;