/**
* 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-carousel','u-marquee','u-switch','u-button','u-dialog','u-loading']);
    const app = new Vue({
        data:{ 
            //开门记录
            valueOpendoorRecord: 1,
            //安全报警
            valueSecurityAlarm: 1,
            //门锁用户
            valueDoorlockUser: 1,
            //远程开门
            valueRemoteOpendoor: 1,
            //劫持报警
            valueHijackAlarm: 1,
            //门锁管理
            valueDoorlockManage: 1,
            activeFlag: true,
            followShowFlag: false,
            doorbellShowFlag: true,
            bindDoorlockShowFlag: false,
            //配置组件
            componentsConfig: initComponentsConfig()
        },
        mounted(){
        },
        methods:{
            getValueOpendoorRecord(){
                return this.valueOpendoorRecord;
            },
            setValueOpendoorRecord(value){
                this.valueOpendoorRecord = value;
            },
            getValueSecurityAlarm(){
                return this.valueSecurityAlarm;
            },
            setValueSecurityAlarm(value){
                this.valueSecurityAlarm = value;
            },
            getValueRemoteOpendoor(){
                return this.valueRemoteOpendoor;
            },
            setValueRemoteOpendoor(value){
                this.valueRemoteOpendoor = value;
            },
            getValueHijackAlarm(){
                return this.valueHijackAlarm;
            },
            setValueHijackAlarm(value){
                this.valueHijackAlarm = value;
            }, 
            getFollowShowFlag(){
                return this.followShowFlag;
            },
            setFollowShowFlag(boolean){
                this.followShowFlag = boolean;
            },
            onMyInfoTap(){
                myInfoTap();
            },                  
            //tap 门锁管理
            onDoorlockManageTap(){
                doorlockManageTap();
            },
            //tap 开门记录
            onOpendoorRecordTap(){
                opendoorRecordTap();
            }, 
            //tap 安全报警
            onSecurityAlarmTap(){
                securityAlarmTap();
            },
            //tap 门锁用户
            onDoorlockUserTap(){
                doorlockUserTap();
            },
            //tap 远程开门
            onRemoteOpendoorTap(){
                remoteOpendoorTap();
            },
            //tap 劫持报警
            onHijackAlarmTap(){
                hijackAlarmTap();
            },
            //tap 保存二维码到相册
            onSaveQRcodeButtonTap(){
                saveQRcodeButtonTap();
            },
            //tap 稍后关注
            onLaterFollowTap(){
                laterFollowTap(this);
            },
            onBindDoorlockTap(){
                bindDoorlockTap();
            }                    
        }   
    }).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {   
    return {
        //图片轮播
        carousel: {
            initParam: {
                class:'custom-carousel',
                list:  [{image: '../../resources/image/image1.png'},
                        {image: '../../resources/image/image2.png'},
                        {image: '../../resources/image/image3.png'}],
                auto: true,
                autoTime: 2000,
                loop: true
            }
        },
        marquee: {
            initParam: {
                class: "custom-marquee",
                text: "2017.08.02 18:45 宝贝指纹开门<br>2017.08.02 18:45 宝贝指纹开门<br>2017.08.02 18:45 宝贝指纹开门"
            }
        },
        //开门记录switch 参数
        opendoorRecordSwitch: {
            initParam: {
                class: 'custom-switch',
                text: Vue.t('device.opendoorRecord'),
                autoChange: false
            }
        },
        //安全报警switch 参数
        securityAlarmSwitch: {
            initParam: {
                class: 'custom-switch',
                text: Vue.t('device.securityAlarm'),
                autoChange: false
            }
        },
        doorlockUserSwitch: {
            initParam: {
                class: 'custom-switch',
                text: Vue.t('device.doorlockUser'),
                autoChange: false
            }
        },
        //远程开门switch 参数
        remoteOpendoorSwitch: {
            initParam: {
                class: 'custom-switch',
                text: Vue.t('device.remoteOpendoor'),
                autoChange: false
            }
        },
        //劫持报警switch 参数
        hijackAlarmSwitch: {
            initParam: {
                class: 'custom-switch',
                text: Vue.t('device.hijackAlarm'),
                autoChange: false
            }
        },
        doorlockManageSwitch: {
            initParam: {
                class: 'custom-switch',
                text: Vue.t('device.doorlockManage'),
                autoChange: false
            }
        },
        //确定 button 参数
        saveQRcodeButton: {   
            initParam: {
                class: 'custom-button',
                text: Vue.t('btn.saveQRcode')
            }
        },
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        }                
    }
}

function myInfoTap(){
    iot.navigator.openWindow({
        url: '../myInfo/',
        id: 'myInfo'
    });  
}

//tap 门锁管理
function doorlockManageTap(){
    iot.navigator.openWindow({
        url: '../doorlockManage/',
        id: 'doorlockManage'
    });
}

//tap 开门记录
function opendoorRecordTap(){
    iot.navigator.openWindow({
        url: './opendoorRecord.html',
        id: 'opendoorRecord'
    });
}

//tap 安全报警
function securityAlarmTap(){
    iot.navigator.openWindow({
        url: './alarmInfo.html',
        id: 'alarmInfo'
    });
}

//tap 门锁用户
function doorlockUserTap(){
    iot.navigator.openWindow({
        url: '../doorlockUsers/',
        id: 'doorlockUsers'
    });
}

//tap 远程开门
function remoteOpendoorTap(){
    iot.navigator.openWindow({
        url: './remoteOpendoor.html',
        id: 'remoteOpendoor'
    });    
}

//tap 劫持报警
function hijackAlarmTap(){
    iot.navigator.openWindow({
        url: './hijackRecord.html',
        id: 'hijackRecord'
    });
}

//tap 保存二维码到相册
function saveQRcodeButtonTap(){
    alert('保存二维码到相册');
}

//tap 稍后关注
function laterFollowTap(self){
    self.setFollowShowFlag(false);
}

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