/**
* v_unlockInfo.js
* Version: 0.1
* User: wy
* Date: 2017-10-09
* 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-swipe-list','u-dialog','u-loading']);
    const app = new Vue({
        data:{                                   
            //配置组件
            componentsConfig: initComponentsConfig()   
        },
        mounted(){           
        },
        methods:{
            //tap <
            onBackTap(){
                backTap();
            },
            //tap 添加
            onAddTap(){
                addTap();
            },
            //tap list row btn 
            onUnlockInfoListButtonTap(value, buttonValue){
                unlockInfoListButtonTap(this, value, buttonValue);
            }                         
        }   
    }).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {
    return {
        unlockInfoList: {
            initParam: {
                class: 'custom-swipe-list',
                list: [
                    {title: '指纹1', subtitle: 'ID:123456', buttons: [{'text': Vue.t('unlockInfo.setHijack')},{'text': Vue.t('unlockInfo.cancelAssociated')}]},
                    {title: '指纹2', subtitle: 'ID:123456', buttons: [{'text': Vue.t('unlockInfo.setHijack')},{'text': Vue.t('unlockInfo.cancelAssociated')}]},
                    {title: '劫持指纹1', subtitle: 'ID:123456', buttons: [{'text': Vue.t('unlockInfo.cancelHijack')},{'text': Vue.t('unlockInfo.cancelAssociated')}]}
                ],
                tip: Vue.t('unlockInfo.noInfoTip')
            }
        },
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        }               
    }
}

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

//tap 添加 
function addTap(){
    iot.navigator.openWindow({
        url: './addUnlockInfo.html',
        id: 'addUnlockInfo'
    });
}

function unlockInfoListButtonTap(self, value, buttonValue) {
    //设为劫持&取消劫持
    if(buttonValue == '0'){
        uComponents.openConfirm(self, Vue.t('unlockInfo.setHijackTip'), 
                               {text: Vue.t('dialog.cancel'), callback: function () {}},
                               {text: Vue.t('dialog.confirm'), callback: function () {}}
        ); 
    }
    //取消关联
    else if(buttonValue == '1'){
        uComponents.openConfirm(self, Vue.t('unlockInfo.cancelAssociatedTip'), 
                               {text: Vue.t('dialog.cancel'), callback: function () {}},
                               {text: Vue.t('dialog.confirm'), callback: function () {}}
        ); 
    }
}