webpackJsonp([21],{

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

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

var _config = __webpack_require__(9);

var _config2 = _interopRequireDefault(_config);

var _public = __webpack_require__(4);

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

/**
* v_addUser.js
* Version: 0.1
* User: wy
* Date: 2017-10-09
* Copyright(c)  2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 添加用户页面
*/

_public.iot.ready(init);
function init() {
    //通用 input、按钮、dialog、loading组件
    _public.uPublic.componentsInit(['u-text', 'u-button', 'u-dialog', 'u-loading']);
    _public.uPublic.closeSlideBack();
    var app = new Vue({
        data: {
            textName: null,
            textErrorTip: null,
            //配置组件
            componentsConfig: initComponentsConfig(),
            extras: {}
        },
        mounted: function mounted() {
            this.extras = _public.iot.navigator.getExtras();
            console.log(this.extras);
        },

        methods: {
            getTextName: function getTextName() {
                return this.textName;
            },
            setTextName: function setTextName(text) {
                this.textName = text;
            },
            getTextErrorTip: function getTextErrorTip() {
                return this.textErrorTip;
            },
            setTextErrorTip: function setTextErrorTip(tip) {
                this.textErrorTip = tip;
            },

            //tap <
            onBackTap: function onBackTap() {
                backTap();
            },
            onNameChange: function onNameChange(text) {
                nameChange(this, text);
            },

            //tap 确定
            onConfirmButtonTap: function onConfirmButtonTap() {
                confirmButtonTap(this);
            }
        }
    }).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {
    return {
        nameInput: {
            initParam: {
                class: 'custom-text',
                icon: '&#xe6b0;',
                placeholder: Vue.t('addUser.nameInputTip'),
                maxlength: _config2.default.input.maxlength
            }
        },
        //确定 button 参数
        confirmButton: {
            initParam: {
                class: 'custom-button',
                text: Vue.t('btn.confirm')
            }
        },
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        }
    };
}

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

function nameChange(self, text) {
    self.textName = text;
    self.setTextErrorTip(null);
    console.log('nameChange: ' + self.textName);
}

//tap 确定
function confirmButtonTap(self) {
    if (self.getTextName() == null || self.getTextName().trim() == '') {
        self.setTextErrorTip(Vue.t('addUser.error.nameCanNotEmpty'));
    } else {
        _public.uComponents.showLoading(self);
        _public.iot.business.api.sendCustom('lock/addLockUser', {
            data: {
                device_id: self.extras.deviceId,
                nickname: self.getTextName()
            },
            success: function success(response) {
                console.log(response);
                if (response.data.id) {
                    _public.uComponents.openAlert(self, Vue.t('addUser.addUserSuccess'), {
                        text: Vue.t('btn.confirm'), callback: function callback() {
                            console.log("添加用户成功");
                            //跳转到门锁用户界面
                            _public.iot.navigator.openWindow({
                                url: './doorlockUser.html',
                                id: 'doorlockUser',
                                extras: {
                                    id: response.data.id,
                                    lockId: self.extras.lockId,
                                    uuid: self.extras.uuid,
                                    role: self.extras.role
                                }
                            });
                        }
                    });
                }
            },
            error: function error(_error) {
                console.log(_error);
                //				if(window.iotDebug){
                //	                iotDebug.push('end: 添加用户成功'+JSON.stringify(error));
                //	           	}
                //		    	if (window.iotDebug) {
                //	                iotDebug.upload(iot,'添加用户失败');
                //	            }
                _public.uComponents.openAlert(self, Vue.t('addUser.addUserFailure'), {
                    text: Vue.t('btn.confirm'), callback: function callback() {
                        console.log("添加用户失败");
                    }
                });
            },
            complete: function complete() {
                _public.uComponents.hideLoading(self);
            }
        });
    }
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2)["default"]))

/***/ }),

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

module.exports = __webpack_require__(211);


/***/ })

},[312]);
//# sourceMappingURL=addUser.js.map