content: /**
   * Created by Administrator on 2016/11/19 0019.
   */
  import React from 'react';
  import {render} from 'react-dom';
  import {Nav,NavTitle,NavLeft} from '../../assets/components/nav/nav.js';
  import Btn from '../../assets/components/btn/btn.js';
  import Formsy,{Form,Mixin} from "react-cmos-formsy";
  import { createStore, combineReducers } from 'redux';
  import { Provider,connect} from 'react-redux';
  import Layer from 'react-cmos-layer';
  import "../../assets/css/form.css";
  var messages={};
  function reducers(state, action) {
      switch (action.type) {
          case "GETERROR":
              return messages[action.name]?{error:action.error,message:messages[action.name]}:{error:false,message:""};
          case "SHOWR":
              return {error:false,message:""};
          default:
              return state
      }
  }
  //创建store
  var store = createStore(reducers,{error:'',message:''});
  
  var FormItem=React.createClass({
      mixins: [Mixin],
      focus:function(event){
          this.props.focus&&store.dispatch({type:"GETERROR",message:this.props.focus,name:this.props.name});
      },
      change:function(event){
          var _this=this,value=event.currentTarget.value;
          this.setValue(value,()=>{
              if(_this.isValidValue(value)){
                  store.dispatch({type:"SHOWR",name:_this.props.name,error:false})
              }else{
                  store.dispatch({type:"GETERROR",name:_this.props.name,error:true})
              }
          });
  
      },
      render:function(){
          messages[this.props.name]=this.getErrorMessage();
          return (
              <div className="form-item">
                  <label  htmlFor = { this.props.name }>{this.props.label}</label>
                  <input type="text"  name={this.props.name} onChange={this.change} defaultValue={this.state.value} onBlur={this.blur} onFocus={this.focus}/>
              </div>
              )
      }
  });
  var Pwd = React.createClass({
      getInitialState:function(){
          return {timeString:null}
      },
      submit:function(data, resetForm){
          console.log(arguments);
          let _this=this;
          this.refs.layer.loading("数据提交中...");
          setTimeout(function(){
              _this.refs.layer.close();
              _this.refs.layer.tips({
                  content: "密码修改成功",
                  time: 4,
                  close: function () {
                      _this.props.router.push('/');
                  }
              })
          },1000)
      },
      enableButton:function() {
          this.setState({ canSubmit: true });
      },
      disableButton:function() {
          this.setState({ canSubmit: false });
      },
      render: function () {
          return (
              <div>
                  <Nav>
                      <NavTitle>修改密码</NavTitle>
                      <NavLeft ></NavLeft>
                  </Nav>
                  <Form onValidSubmit={this.submit} onValid={this.enableButton} onInvalid={this.disableButton}>
                      <div className='form-items' onSubmit = { this.submit }>
                          <FormItem name='mobile' label='手机号'  validations={{isMobile:true}}  validationErrors={{isMobile:'请输入正确的手机号'}} focus="手机号为11为数字哟"></FormItem>
                          <FormItem name='code' label='验证码' validations={{isDigits:true,isLength:6}}  validationErrors={{isDigits:'验证码为纯数字',isLength:"验证码长度为6"}} focus="验证码为6为纯数字哟"></FormItem>
                          <FormItem name='pwd' label='原密码'  validations={{minLength:8}}  validationErrors={{minLength:"密码长度最少为8个字符"}} focus="忘记没密码可以通过手机号找回哟"></FormItem>
                          <FormItem name='newPwd' label='新密码'  validations={{minLength:8}}  validationErrors={{minLength:"密码长度最少为8个字符"}} focus="为了账号安全密码不要过于简单哟"></FormItem>
                          <div className={this.props.error?'error tips':'tips'}>{this.props.message}</div>
                          <div className="pd-15">
                              <Btn type='submit' block btnName={this.state.canSubmit?"primary":"default" }>提交</Btn>
                          </div>
                      </div>
                  </Form>
                  <Layer ref='layer'/>
              </div>
          )
      }
  });
  
  let PwdConnect=connect(function(state){
      return {
          error:state.error,
          message:state.message
      }
  })(Pwd);
  
  var PwdProvider = React.createClass({
      render:function(){
          return (
              <Provider store={store}>
                  <PwdConnect {...this.props}/>
              </Provider>
          )
      }
  });
  export default PwdProvider
  //render(<Log/>, document.getElementById('J_figureList'));