import React, {Component} from 'react'
|
import { is, fromJS } from 'immutable'
|
import { Modal, notification } from 'antd'
|
import moment from 'moment'
|
|
import Api from '@/api'
|
import Utils from '@/utils/utils.js'
|
import Resetpwd from './resetpwd'
|
import MKEmitter from '@/utils/events.js'
|
import './index.scss'
|
|
class ResetPassword extends Component {
|
state = {
|
visible: false,
|
loading: false,
|
type: 'account',
|
okText: window.GLOB.dict['ok'] || '确定',
|
dict: window.GLOB.dict,
|
smsId: '',
|
mob: '',
|
code: ''
|
}
|
|
callback = null
|
|
componentDidMount() {
|
MKEmitter.addListener('resetpassword', this.resetpassword)
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
componentWillUnmount() {
|
MKEmitter.removeListener('resetpassword', this.resetpassword)
|
}
|
|
resetpassword = (callback) => {
|
this.callback = callback
|
this.setState({
|
visible: true,
|
loading: false,
|
type: 'account',
|
okText: window.GLOB.dict['ok'] || '确定',
|
mob: '',
|
code: '',
|
smsId: sessionStorage.getItem('mk_sms_id') || ''
|
})
|
}
|
|
resetPwdSubmit = () => {
|
const { type, dict } = this.state
|
|
if (type === 'account') {
|
this.formRef.handleConfirm().then(res => {
|
this.setState({
|
loading: true
|
})
|
|
let _param = {
|
func: 's_PwdUpt',
|
LText: `select '${res.originpwd}','${res.password}'`
|
}
|
|
if (window.GLOB.execType === 'x') {
|
_param.exec_type = 'x'
|
}
|
|
_param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
_param.LText = Utils.formatOptions(_param.LText, _param.exec_type)
|
_param.secretkey = Utils.encrypt(window.GLOB.execType === 'x' ? '' : _param.LText, _param.timestamp)
|
|
Api.getSystemConfig(_param).then(result => {
|
if (result.status) {
|
this.setState({
|
visible: false,
|
loading: false
|
})
|
notification.success({
|
top: 92,
|
message: dict['re_login'] || '修改成功,请重新登录。',
|
duration: 2
|
})
|
this.callback && this.callback()
|
} else {
|
this.setState({
|
loading: false
|
})
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
})
|
}, () => {})
|
} else if (type === 'mob') {
|
this.formRef.handleConfirm().then(res => {
|
if (!/^1[3456789]\d{9}$/.test(res.phone)) {
|
notification.warning({
|
top: 92,
|
message: dict['phone_error'] || '手机号格式错误,请重填!',
|
duration: 5
|
})
|
return
|
}
|
|
this.setState({
|
mob: res.phone,
|
type: 'code'
|
})
|
}, () => {})
|
} else if (type === 'code') {
|
this.formRef.handleConfirm().then(res => {
|
this.setState({
|
code: res.vercode,
|
type: 'phonepwd',
|
okText: dict['ok'] || '确定'
|
})
|
}, () => {})
|
} else if (type === 'phonepwd') {
|
this.formRef.handleConfirm().then(res => {
|
this.setState({
|
loading: true
|
})
|
|
let _param = {
|
func: 's_PwdUpt',
|
LText: `select '','${res.password}'`,
|
mob: this.state.mob,
|
check_code: this.state.code
|
}
|
|
if (window.GLOB.execType === 'x') {
|
_param.exec_type = 'x'
|
}
|
|
_param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
_param.LText = Utils.formatOptions(_param.LText, _param.exec_type)
|
_param.secretkey = Utils.encrypt(window.GLOB.execType === 'x' ? '' : _param.LText, _param.timestamp)
|
|
Api.getSystemConfig(_param).then(result => {
|
if (result.status) {
|
this.setState({
|
visible: false,
|
loading: false
|
})
|
notification.success({
|
top: 92,
|
message: dict['re_login'] || '修改成功,请重新登录。',
|
duration: 2
|
})
|
this.callback && this.callback()
|
} else {
|
this.setState({
|
loading: false
|
})
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
})
|
}, () => {})
|
}
|
}
|
|
render() {
|
const { visible, loading, okText, type, mob, smsId, dict } = this.state
|
|
return (
|
<Modal
|
title={dict['ch_pwd'] || '修改密码'}
|
wrapClassName="reset-password-modal"
|
visible={visible}
|
maskClosable={false}
|
onOk={this.resetPwdSubmit}
|
onCancel={() => { this.setState({ visible: false })}}
|
okText={okText}
|
cancelText={dict['cancel'] || '取消'}
|
confirmLoading={loading}
|
destroyOnClose
|
>
|
<Resetpwd type={type} mob={mob} smsId={smsId} wrappedComponentRef={(inst) => this.formRef = inst} resetPwdSubmit={this.resetPwdSubmit}/>
|
{type === 'account' && smsId ? <div className="forget-pwd"><span onClick={() => this.setState({type: 'mob', okText: dict['next'] || '下一步'})}>{dict['forgot_pwd'] || '忘记密码?'}</span></div> : null}
|
</Modal>
|
)
|
}
|
}
|
|
export default ResetPassword
|