/**
* v_register.js
* Version: 0.1
* User: wy
* Date: 2017-09-06
* Copyright(c)  2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 注册页面
*/

import {iot, uPublic, uComponents} from '../../public/public.js';

iot.ready(init);
function init() {
    //通用 input、按钮、dialog、loading组件
    uPublic.componentsInit(['u-text','u-button','u-dialog','u-loading']);
    const app = new Vue({
        data:{ 
            numberTel: null,
            textCode: null,
            codeDisabledFlag: false,
            textPassword: null,  
            textErrorTip: null,
            //配置组件
            componentsConfig: initComponentsConfig()     
        },
        mounted(){           
        },
        methods:{
            getCodeDisabledFlag(){
                return this.codeDisabledFlag;
            },
            setCodeDisabledFlag(boolean){
                this.codeDisabledFlag = boolean;
            },       
            onTelChange(number){
                telChange(this,number);            
            },
            onCodeChange(text){
                codeChange(this,text);            
            },      
            onPasswordChange(text){
                passwordChange(this,text);            
            },              
            //tap <
            onBackTap(){
                backTap();
            },
            //tap 获取验证码
            onCodeButtonTap(){
                codeButtonTap(this);
            },        
            //tap 注册
            onRegisterButtonTap(){
                registerButtonTap();
            }                      
        }   
    }).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {
    return {
        telInput: {
            initParam: {
                class: 'custom-text',
                icon: '&#xe6e8;',
                placeholder: Vue.t('register.telInputTip'),
                maxlength: 11,
                minlength: 11
            }
        },
        codeInput: {
            initParam: {
                class: 'custom-code-text',
                icon: '&#xe805;',
                placeholder: Vue.t('register.codeInputTip')
            }
        },
        //获取验证码 button 参数
        codeButton: {   
            initParam: {
                class: 'custom-code-button',
                text: Vue.t('btn.getCode')
            }
        },
        passwordInput: {
            initParam: {
                class: 'custom-password-text',
                icon: '&#xe64d;',
                placeholder: Vue.t('register.passwordInputTip'),
                type: 'password',
                maxlength: 6,
                minlength: 6
            }
        },
        //注册 button 参数
        registerButton: {   
            initParam: {
                class: 'custom-button',
                text: Vue.t('btn.register')
            }
        },       
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        }                
    }
}

function telChange(self,number){
    self.numberTel = number;
    console.log('telChange: ' + self.numberTel);
}

function codeChange(self,text){
    self.textCode = text;
    console.log('codeChange: ' + self.textCode);
}

//tap 获取验证码
function codeButtonTap(self){
    self.setCodeDisabledFlag(true);
}

function passwordChange(self,text){
    self.textPassword = text;
    console.log('passwordChange: ' + self.textPassword);
}

//tap <
function backTap(){
    iot.navigator.back();
}

//tap 注册
function registerButtonTap(){
    iot.navigator.openWindow({
        url: '../device/index.html',
        id: 'device'
    });
}