/**
* 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-switch','u-button','u-dialog','u-loading']);
    //项目 list组件
    uPublic.componentsExtend(['grid-list']);
    const app = new Vue({
        data:{   
            textDoorlock: '智能指纹锁1',
            stateShowFlag: false, 
            //门铃消息推送 switch
            valueDoorbell: 1,   
            //报警消息推送 switch
            valueAlarm: 0,   
            //开门消息推送 switch
            valueOpendoor: 1,  
            //配置组件
            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 {
        //门铃消息推送 switch 参数
        doorbellSwitch: {
            initParam: {
                class: 'custom-switch'
            }
        },
        //报警消息推送 switch 参数
        alarmSwitch: {
            initParam: {
                class: 'custom-switch'
            }
        },
        //开门消息推送 switch 参数
        opendoorSwitch: {
            initParam: {
                class: 'custom-switch'
            }
        },
        //解绑门锁 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);
}