/**
* v_remoteOpendoor.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-commstatus-loading','u-dialog','u-loading']);
    const app = new Vue({
        data:{  
            textPassword: null,  
            textErrorTip: null,
            textLoading: 'loading...',
            status: 0,       
            //配置组件
            componentsConfig: initComponentsConfig()     
        },
        mounted(){           
        },
        methods:{
            getTextLoading(){
                return this.textLoading;
            },
            setTextLoading(text){
                this.textLoading = text;
            },
            getStatus(){
                return this.status;
            },
            setStatus(value){
                this.status = value;
            },
            onPasswordChange(text){
                passwordChange(this,text);            
            },
            onPasswordChange(text){
                passwordChange(this,text);            
            },      
            //tap <
            onBackTap(){
                backTap();
            },
            //tap 确定
            onConfirmButtonTap(){
                confirmButtonTap(this);
            },
            //tap loading button
            onCommstatusLoadingButtonTap(){
                commstatusLoadingButtonTap(this);
            }                  
        } 
    }).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {
    return {
        passwordInput: {
            initParam: {
                class: 'custom-text',
                icon: '&#xe64d;',
                placeholder: Vue.t('remoteOpendoor.passwordInputTip')
            }
        },
        //确定 button 参数
        confirmButton: {   
            initParam: {
                class: 'custom-button',
                text: Vue.t('btn.confirm')
            }
        },
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        },
        ucommstatusloading: {
            initParam: {
                class: 'custom-commstatus-loading',
                buttonText: Vue.t('btn.confirm')
            }
        }                
    }
}

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

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

//tap 确定
function confirmButtonTap(self){
    uComponents.showCommstatusloading(self);
    setTimeout(function(){
        self.setTextLoading(Vue.t('commstatusLoading.connectSuccess'));
        setTimeout(function(){
            //绑定成功
            self.setStatus(1);
            self.setTextLoading(Vue.t('commstatusLoading.bindSuccess'));
            //绑定失败
            //self.setStatus(2);
            //self.setTextLoading(Vue.t('commstatusLoading.bindFailed'));
            //uComponents.changeCommstatusButtonText(self,Vue.t('btn.reBound'));
        },3000);
    },3000);
}

//tap loading button
function commstatusLoadingButtonTap(self) {
    //绑定成功
    uComponents.hideCommstatusloading(self);
    iot.navigator.back();
    //绑定失败
    //uComponents.hideCommstatusloading(self);
}