/**
* v_index.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-dialog','u-loading']);
    const app = new Vue({
        data:{ 
            userList: [{value: 1, role: 0, image: '../../resources/image/green_admin_icon.png', title: '我是个用户', subtitle: '管理员'},
                       {value: 2, role: 1, image: '../../resources/image/gray_unbindHead_icon.png', title: '我是个用户二号', subtitle: ''}],
            userListIndex: null,
            loadShowFlag: false,
            loadFlag: false,
            loadText: Vue.t('scroll.clickToLoadMore'),
            pagesize: 10,
            tip: Vue.t('userList.noUserTip'),          
            //配置组件
            componentsConfig: initComponentsConfig()   
        },
        mounted(){           
        },
        methods:{
            //tap <
            onBackTap(){
                backTap();
            },
            //tap +
            onAddUserTap(){
                addUserTap();
            },
            onSwipeLeftRow(index){
                swipeLeftRow(this, index);
            },
            onSwipeRightRow(){
                swipeRightRow(this);
            },
            onTapLoad(){
                tapLoad();
            },
            onTapUserList(index){
                tapUserList(this, index);
            },
            onTapButton(buttonIndex){
                tapButton(buttonIndex);
            }                  
        }   
    }).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {
    return {
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        }               
    }
}

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

//tap + 
function addUserTap(){
    iot.navigator.openWindow({
        url: './addUser.html',
        id: 'addUser'
    }); 
}

// 向左滑动用户列表，修改用户列表下标
function swipeLeftRow(self, index) {
    self.userListIndex = index;
}

// 向右滑动用户列表，修改用户列表下标
function swipeRightRow(self) {
    self.userListIndex = null;
}

// 点击组件列表 通知事件和当前点击列表下标
function tapUserList(self, listIndex) {
    if (self.userListIndex != null) {
        return;
    }
    iot.navigator.openWindow({
        url: './doorlockUsers.html',
        id: 'doorlockUsers'
    }); 
}

//点击加载更多
function tapLoad(){
    if (!self.loadFlag) {
        self.loadText = Vue.t('scroll.loading');
        self.loadFlag = true;
        //再次发送获取用户列表请求
    }
}

//点击按钮
function tapButton(buttonIndex){
    console.log(buttonIndex);
}