/**
* 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:{            
            //配置组件
            componentsConfig: initComponentsConfig()     
        },
        mounted(){           
        },
        methods:{
            //tap <
            onBackTap(){
                backTap();
            },       
            //tap +
            onAddTap(){
                addTap();
            },
            //tap list row device
            onDoorlockListTap(){
                doorlockListTap();
            },
            //tap list row button
            onDoorlockListButtonTap(value, buttonValue){
                doorlockListButtonTap(this, value, buttonValue);
            },
            //tap 退出系统
            onLogoutButtonTap(){
                logoutButtonTap(this);
            }                    
        }   
    }).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {
    return {
        doorlockList: {
            initParam: {
                class: '',
                list: [{value: 1,'leftImage': '../../resources/image/device.png','title': '门锁-001','buttons': [{'icon': '&#xe728;'},{'icon': '&#xe61b;'},{'icon': '&#xe63e;'},{'icon': '&#xe742;'}]},
                       {value: 2,'leftImage': '../../resources/image/device.png','title': '门锁-002','buttons': [{'icon': '&#xe728;'},{'icon': '&#xe61b;'},{'icon': '&#xe63e;'},{'icon': '&#xe742;'}]},
                       {value: 3,'leftImage': '../../resources/image/device.png','title': '门锁-003','buttons': [{'icon': '&#xe728;'},{'icon': '&#xe61b;'},{'icon': '&#xe63e;'},{'icon': '&#xe742;'}]},
                       {value: 4,'leftImage': '../../resources/image/device.png','title': '门锁-004','buttons': [{'icon': '&#xe728;'},{'icon': '&#xe61b;'},{'icon': '&#xe63e;'},{'icon': '&#xe742;'}]},
                       {value: 5,'leftImage': '../../resources/image/device.png','title': '门锁-005','buttons': [{'icon': '&#xe728;'},{'icon': '&#xe61b;'},{'icon': '&#xe63e;'},{'icon': '&#xe742;'}]}],
                tip: Vue.t('doorlockManage.noDeviceTip')  
            }
        },
        //退出系统 button 参数
        logoutButton: {   
            initParam: {
                class: 'custom-button',
                text: Vue.t('btn.logout')
            }
        }, 
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        }                
    }
}

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

//tap +
function addTap(){
    iot.navigator.openWindow({
        url: '../addDevice/',
        id: 'addDevice'
    });
}

//tap list row device
function doorlockListTap(){
    iot.navigator.openWindow({
        url: '../device/',
        id: 'device'
    });
}

//tap list row button
function doorlockListButtonTap(self, value, buttonValue) {
    //tap 修改名称
    if(buttonValue == '0'){
        iot.navigator.openWindow({
            url: './editName.html',
            id: 'editName'
        });
    }
    //tap 生成绑定二维码
    else if(buttonValue == '1'){
        iot.navigator.openWindow({
            url: './qrcode.html',
            id: 'qrcode'
        });
    }
    //tap ID-姓名绑定
    else if(buttonValue == '2'){
        iot.navigator.openWindow({
            url: '../bindUser/',
            id: 'bindUser'
        });
    }
    //tap 删除门锁
    else if(buttonValue == '3'){
        uComponents.openConfirm(self, Vue.t('doorlockManage.deleteDialogTip', ['门锁-001']),
                               {text: Vue.t('dialog.cancel'), callback: function () {}},
                               {text: Vue.t('dialog.confirm'), callback: function () {}}
        );
    }
}

//tap 退出系统
function logoutButtonTap(self){
    uComponents.openConfirm(self, Vue.t('doorlockManage.logoutDialogTip'), 
                           {text: Vue.t('dialog.cancel'), callback: function () {}}, 
                           {text: Vue.t('dialog.confirm'), callback: function () {
                                iot.navigator.openWindow({
                                    url: '../login/login.html',
                                    id: 'login'
                                });                             
                           }}
    );  
}