(function(KDApi,$){

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

    MyComponent.prototype = {
        _setModel: function(model) {
            this.model = model;
        },
        init:function(props){
          setHtml(this.model,props);
        },
        update:function(props){
        },
        destoryed:function(){
        }

    }

    var setHtml = function(model,props){
        KDApi.loadFile('./css/send_sms.css',model,() => {
            KDApi.templateFilePath('./html/send_sms.html',model,null).then(result => {
                model.dom.innerHTML = result
                initEvent(model,props);
            })
        })                
    }
    var initEvent = function(model,props){
		$('#send_sms', model.dom).click(function(){
			// 60时秒后重新显示发送按钮 
			waitTime(60);
			// 调用发送短信接口
            model.invoke('sendSms',"");

        })
    }   
	
	var waitTime = function waitTime(time) {
		
		var wait_time = time;
		
		// 发送按钮
		var send_sms = document.getElementById("send_sms");
		send_sms.style.display= 'none';
		// 倒计时提示
		var resend = document.getElementById("resend");
		resend.style.display= '';
		// 重新发送倒计时
		var resend_time = document.getElementById("resend_time");
		// 等待时间
		resend_time.innerHTML=wait_time;
		if (wait_time == 0) {
			resend.style.display= 'none';
			send_sms.style.display= '';
		} else {
			wait_time--;
			setTimeout(function() {
				waitTime(wait_time)
			}, 1000)
		}
	}
		
    KDApi.register('send_sms', MyComponent)
})(window.KDApi,jQuery);