(function(KDApi,$){

    function MyComponent(model){
        this._setModel(model);
    }

    MyComponent.prototype = {
        _setModel: function(model) {
            this.model = model;
        },
        init:function(props){
          setHtml(this.model,props);
		  // 每隔1分钟刷新验证码
		  setInterval(this.model, 60000);
        },
        update:function(props){
		  $(".vCode").attr("value", props.data.authCode)
		  $("#verifycode").attr("src", props.data.content)
        },
        destoryed:function(){
        }

    }
	/**
	 * 定时刷新验证码
	 */
	var setInterval = function(model, timeout) {
		
        window.setInterval(() => {
            model.invoke('validateCode',"");
        }, timeout);
    }

    var setHtml = function(model,props){
        KDApi.loadFile('./css/validate_code.css',model,() => {
            KDApi.templateFilePath('./html/validate_code.art',model,null).then(result => {
                model.dom.innerHTML = result
                console.log(result);
                initEvent(model,props);
            })
        })                
    }
    var initEvent = function(model,props){
		$('.validate_code', model.dom).click(function(){
            model.invoke('validateCode',"");
        })
		
		model.invoke('validateCode',"");
    }    
    KDApi.register('validate_code', MyComponent)
})(window.KDApi,jQuery);