/**
* v_index.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() {
    //通用 按钮、dialog、loading组件
    uPublic.componentsInit(['u-button','u-dialog','u-loading']);
    //项目 list组件
    uPublic.componentsExtend(['grid-list']);
    const app = new Vue({
        data:{   
            textDoorlock: '智能指纹锁1',
            stateShowFlag: false,  
            //配置组件
            componentsConfig: initComponentsConfig()     
        },
        mounted(){           
        },
        methods:{
            getStateShowFlag(){
                return this.stateShowFlag;
            },
            setStateShowFlag(boolean){
                this.stateShowFlag = boolean;
            },           
            //tap <
            onBackTap(){
                backTap();
            },
            onEditNameTap(){
                editNameTap();
            },
            //tap 解绑门锁
            onUnbindDoorlockButtonTap(){
                unbindDoorlockButtonTap(this);
            },
            onUnbindStateDialogTap(){
                unbindStateDialogTap(this);
            },                             
        }   
    }).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {
    return {
        //解绑门锁 button 参数
        unbindDoorlockButton: {   
            initParam: {
                class: 'custom-button',
                text: Vue.t('btn.unbindDoorlock')
            }
        }, 
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        }                
    }
}

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

function editNameTap(){
    iot.navigator.openWindow({
        url: './editName.html',
        id: 'editName'
    });    
}

//tap 解绑门锁
function unbindDoorlockButtonTap(self){
    uComponents.openConfirm(self, Vue.t('doorlockManage.unbindDialogTip'), 
                           {text: Vue.t('dialog.cancel'), callback: function () {}}, 
                           {text: Vue.t('dialog.unbind'), callback: function () {
                                self.setStateShowFlag(true);
                           }}
    );  
}

function unbindStateDialogTap(self){
    self.setStateShowFlag(false);
}