/**
* v_wifiAdd.js
* Version: 0.1
* User: wy
* Date: 2017-09-07
* Copyright(c)  2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 连接Wi-Fi页面
*/

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

iot.ready(init);
function init() {
    //通用 input、按钮、dialog、loading组件
    uPublic.componentsInit(['u-text','u-button','u-comm-loading','u-dialog','u-loading']);
    const app = new Vue({
        data:{     
            textPassword: null, 
            textErrorTip: null,      
            //配置组件
            componentsConfig: initComponentsConfig()   
        },
        mounted(){                 
        },
        methods:{
            onPasswordChange(text){
                passwordChange(this,text);            
            },            
            //tap <
            onBackTap(){
                backTap();
            },
            //tap 连接
            onConnectButtonTap(){
                connectButtonTap(this);    
            },
            //tap loading button
            onCommLoadingButtonTap(){
                commLoadingButtonTap(this);
            }                          
        }   
    }).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {
    return {
        passwordInput: {
            initParam: {
                class: 'custom-password-text',
                icon: '&#xe64d;',
                placeholder: Vue.t('wifiAdd.passwordInputTip'),
                type: 'password'
            }
        },
        //连接 button 参数
        connectButton: {   
            initParam: {
                class: 'custom-button',
                text: Vue.t('btn.connect')
            }
        }, 
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        },
        ucommloading: {
            initParam: {
                class: 'custom-comm-loading',
                buttonText: Vue.t('btn.confirm'),
                text: '密码确认中...',
                status: 0,  
            }
        }                        
    }
}

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

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

//tap 连接
function connectButtonTap(self){     
    uComponents.showCommLoading(self);
    setTimeout(function(){
        uComponents.changeCommLoadingStatusAndText(self,0,'门锁响应中...');
        setTimeout(function(){
            //绑定成功
            uComponents.changeCommLoadingStatusAndText(self,1,'远程开门成功');            
            //绑定失败
            //uComponents.changeCommLoadingStatusAndText(self,1,'远程开门失败');
            //uComponents.changeCommButtonText(self,'请尝试重试');
        },3000);
    },3000);
}

//tap loading button
function commLoadingButtonTap(self) {
    //绑定成功
    uComponents.hideCommLoading(self);
    iot.navigator.openWindow({
        url: '../device/',
        id: 'device'
    });
}