/**
* r_userList.vue
* Version: 0.1
* User: wy
* Date: 2017-09-07
* Copyright(c)  2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 用户列表页面
*/
<template>
    <div>
        <div class="header">
            <v-touch tag="span" class="header-left icon" v-on:tap="onBackTap">&#xe611;</v-touch>   
            <p>{{ $t('title.userList') }}</p>
        </div>
        <u-swipe-list ref="uswipelist" :init-param="componentsConfig.userList.initParam"
    v-on:u-swipe-list-button-tap="onUserListButtonTap(arguments[0],arguments[1])"></u-swipe-list>
        <u-dialog ref="udialog" :init-param="componentsConfig.dialog.initParam"></u-dialog>
        <u-loading ref="uloading" :init-param="componentsConfig.loading.initParam"></u-loading>
    </div>
</template>  

<script>
    import {iot, uPublic, uComponents} from '../../public/public.js';
    //通用 侧滑列表、dialog、loading组件
    uPublic.componentsInit(['u-swipe-list','u-dialog','u-loading']);    
    export default {
        data (){
            return {
                //配置组件
                componentsConfig: initComponentsConfig(),
                pageFrom: null
            }
        },
        beforeRouteEnter (to, from, next) {
            //alert('beforeRouteEnter 路由userList');
            next(vm => {
                resolve(vm, to);
            })
        },
        beforeRouteUpdate (to, from, next) {
            //alert('beforeRouteUpdate 路由userList');
        },
        mounted(){            
        },      
        methods:{
            getPageFrom(){
                return this.pageFrom;
            },
            setPageFrom(string){
                this.pageFrom = string;
            },        
            //tap <      
            onBackTap(){
                backTap(this);
            },
            //tap list row delete 
            onUserListButtonTap(value, buttonValue){
                userListButtonTap(this, value, buttonValue);
            }
        }               
    }

    //配置组件参数
    function initComponentsConfig(){
        let title = Vue.t('userList.name', ['迷失者']);
        let subtitle = Vue.t('userList.id', [1,1,1]);
        return {
            userList: {
                initParam: {
                    class: 'custom-swipe-list',
                    list: [
                        {value: 1, image: '../../resources/image/white_head_icon.png', title: '姓名：迷失者', subtitle: subtitle, buttons: [{"text": ""}]},
                        {value: 2, image: '../../resources/image/white_head_icon.png', title: '姓名：漫步者', subtitle: subtitle, buttons: [{"text": ""}],},
                        {value: 3, image: '../../resources/image/white_head_icon.png', title: '姓名：太空旅行者', subtitle: subtitle, buttons: [{"text": ""}],},
                        {value: 4, image: '../../resources/image/white_head_icon.png', title: '姓名：探索迷失者', subtitle: subtitle, buttons: [{"text": ""}],},
                        {value: 5, image: '../../resources/image/white_head_icon.png', title: '姓名：麻麻272', subtitle: subtitle, buttons: [{"text": ""}],},
                        {value: 6, image: '../../resources/image/white_head_icon.png', title: '姓名：代号小黄人', subtitle: subtitle, buttons: [{"text": ""}],}
                    ],
                    tip: Vue.t('userList.noUserTip')
                }
            },
            dialog: {
                initParam: {
                    class: 'custom-dialog'
                }
            },         
            loading: {
                initParam: {
                    class: 'custom-loading'
                }
            }
        }
    }

    //tap <
    function backTap(self){  
        if(self.getPageFrom() == 'bindUser'){
            self.$router.go(-3);
        }     
        else{
            self.$router.go(-1);
        } 
    }       

    function resolve(self, to) {
        let query = to.query;
        self.setPageFrom(query.pageName);
    }

    //tap list row delete 
    function userListButtonTap(self, value, buttonValue) {
        if(buttonValue == '0'){
            uComponents.openConfirm(self, '确认删除用户xxx吗？', 
                                   {text: Vue.t('dialog.cancel'), callback: function () {}},
                                   {text: Vue.t('dialog.confirm'), callback: function () {}}
            ); 
        }
    }  
</script>