webpackJsonp([19],{

/***/ 172:
/***/ (function(module, exports, __webpack_require__) {

"use strict";
/* WEBPACK VAR INJECTION */(function(Vue) {

var _config = __webpack_require__(126);

var _config2 = _interopRequireDefault(_config);

var _public = __webpack_require__(2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
* v_index.js
* Version: 0.1
* User: zjx
* Date: 2017-09-29
* Copyright(c)  2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 门锁用户
*/
_public.iot.ready(init);
function init() {
    //通用 图片轮播、跑马灯、开关、按钮、dialog、loading组件
    _public.uPublic.componentsInit(['u-swipe-list', 'u-dialog', 'u-loading']);
    var app = new Vue({
        data: {
            //配置组件
            componentsConfig: initComponentsConfig(),
            //用户列表
            userList: [],
            userListIndex: null,
            loadShowFlag: false,
            loadFlag: false,
            loadText: 'loading',
            pagesize: 10,
            tip: '无数据',
            extras: {},
            userListData: [],
            startId: 0
        },
        mounted: function mounted() {
            this.extras = _public.iot.navigator.getExtras();
            //获取用户列表
            getUserList(this);
            //      	
        },

        methods: {
            getUserList: function getUserList() {
                return this.userList;
            },
            setUserList: function setUserList(list) {
                this.userList = list;
            },
            onBackTap: function onBackTap() {
                backTap();
            },
            onAddUserTap: function onAddUserTap() {
                addUserTap();
            },
            setLoadShowFlag: function setLoadShowFlag(number) {
                this.loadShowFlag = number >= this.pagesize;
            },
            getUserListData: function getUserListData() {
                return this.userListData;
            },
            setUserListData: function setUserListData(data) {
                this.userListData = data;
            },
            getStartId: function getStartId() {
                return this.startId;
            },
            setStartId: function setStartId(id) {
                this.startId = id;
            },
            onSwipeLeftRow: function onSwipeLeftRow(index) {
                swipeLeftRow(this, index);
            },
            onSwipeRightRow: function onSwipeRightRow() {
                swipeRightRow(this);
            },
            onTapLoad: function onTapLoad() {
                tapLoad();
            },
            onTapUserList: function onTapUserList(index) {
                _onTapUserList(this, index);
            },
            onTapButton: function onTapButton(buttonIndex) {
                tapButton(buttonIndex);
            },
            changeUserList: function changeUserList(list) {
                _changeUserList(this, list);
            }
        }

    }).$mount('#app');
}

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

//获取用户列表
function getUserList(self) {
    console.log(self.extras);
    _public.uComponents.showLoading(self);
    _public.iot.business.device.getUsers({
        data: {
            device_id: self.extras.deviceId
        },
        success: function success(response) {
            console.log(response);
            var data = [{ id: 2,
                device_id: 'B0F89310D509',
                user_id: 2,
                role: 0,
                nickname: '用户1',
                username: '测试1' }, { id: 3,
                device_id: 'B0F89310D509',
                user_id: 1,
                role: 1,
                nickname: '用户2',
                username: '测试2' }, { id: 4,
                device_id: 'B0F89310D509',
                user_id: null,
                role: 1,
                nickname: '用户3' }, { id: 5,
                device_id: 'B0F89310D509',
                user_id: null,
                role: 1,
                nickname: '用户4' }, { id: 6,
                device_id: 'B0F89310D509',
                user_id: null,
                role: 1,
                nickname: '用户5' }];

            //	    	let data = uPublic.checkResponseData(response.data);
            console.log(data);
            if (data) {
                var list = [];
                for (var i = 0; i < data.length; i++) {
                    list[i] = {
                        value: data[i].id,
                        role: data[i].role,
                        image: data[i].role == 0 ? '../../resources/image/green_admin_icon.png' : data[i].user_id == null ? '../../resources/image/gray_unbindHead_icon.png' : '../../resources/image/green_bindhead_icon.png',
                        title: data[i].nickname,
                        subtitle: data[i].username
                    };
                }

                self.setUserListData(self.getUserList().concat(data));
                self.setUserList(self.getUserList().concat(list));
                console.log(self.getUserList());
                if (data.length > 0) {
                    self.setStartId(data[data.length - 1].id);
                }
            }
        },
        error: function error(_error) {
            console.log(_error);
            //	    	uPublic.openRequestErrorAlert(self);
        },
        complete: function complete() {
            _public.uComponents.hideLoading(self);
        }
    });
}

//返回上一页
function backTap() {
    _public.iot.navigator.back();
}

//添加用户
function addUserTap() {
    _public.iot.navigator.openWindow({
        url: '../doorlockUsers/addUser.html',
        id: 'addUser'
    });
}

// 向左滑动用户列表，修改用户列表下标
function swipeLeftRow(self, index) {
    self.userListIndex = index;
}
// 向右滑动用户列表，修改用户列表下标
function swipeRightRow(self) {
    self.userListIndex = null;
}
// 点击组件列表 通知事件和当前点击列表下标
function _onTapUserList(self, listIndex) {
    _public.iot.navigator.openWindow({
        url: './doorlockUser.html',
        id: 'doorlockUser',
        extras: {
            id: self.getUserListData()[listIndex].id,
            userId: self.getUserListData()[listIndex].user_id,
            nickname: self.getUserListData()[listIndex].nickname,
            username: self.getUserListData()[listIndex].username,
            deviceId: self.getUserListData()[listIndex].device_id,
            role: self.getUserListData()[listIndex].role,
            uuid: self.extras.uuid
        }
    });
    if (self.userListIndex != null) {
        self.userListIndex = null;
    }
}
//点击加载更多
function tapLoad() {
    if (!self.loadFlag) {
        self.loadText = 'loading';
        self.loadFlag = true;
        //再次发送获取用户列表请求
    }
}

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

// 修改userList列表
function _changeUserList(self, list) {
    self.setLoadShowFlag(list.length - self.swipeList.length);
    self.userList = list;
    self.$nextTick(function () {
        self.loadText = '点击加载更多';
        self.loadFlag = false;
    });
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)["default"]))

/***/ }),

/***/ 273:
/***/ (function(module, exports, __webpack_require__) {

module.exports = __webpack_require__(172);


/***/ })

},[273]);
//# sourceMappingURL=index.js.map