webpackJsonp([22],{

/***/ 207:
/***/ (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_editName.js
* Version: 0.1
* User: wy
* Date: 2017-09-06
* 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: _public.iot.navigator.getExtras().nickname,
            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;
            },
            setTextErrorTip: function setTextErrorTip(text) {
                this.textErrorTip = text;
            },
            onNameChange: function onNameChange(text) {
                nameChange(this, text);
            },

            //tap <
            onBackTap: function onBackTap() {
                backTap();
            },

            //tap 保存
            onSaveTap: function onSaveTap() {
                saveTap(this);
            }
        }
    }).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {
    return {
        nameInput: {
            initParam: {
                class: 'custom-editName-text',
                placeholder: Vue.t('editName.nameInputTip'),
                maxlength: _config2.default.input.maxlength
            }
        },
        //保存 button 参数
        saveButton: {
            initParam: {
                class: 'custom-button',
                text: Vue.t('btn.save')
            }
        },
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        }
    };
}

function alert() {
    alert('aaa');
}

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

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

//tap 保存
function saveTap(self) {
    if (self.getTextName() == null || self.getTextName().trim() == '') {
        self.setTextErrorTip(Vue.t('editName.error.nameCanNotBeBlank'));
    } else {
        _public.uComponents.showLoading(self);
        _public.iot.business.device.setName({
            data: {
                device_id: self.extras.lockId,
                device_name: self.getTextName()
            },
            success: function success(response) {
                console.log(response);
                var data = _public.uPublic.checkResponseData(response.data);
                if (data) {
                    _public.uComponents.openAlert(self, Vue.t('editName.editNameSuccess'), {
                        text: Vue.t('btn.confirm'), callback: function callback() {
                            _public.iot.navigator.fire(plus.webview.currentWebview().opener(), 'returnPage', {});
                            console.log('returnPage');
                            _public.iot.navigator.back();
                        }
                    });
                }
            },
            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('editName.editNameFailue'), {
                    text: Vue.t('btn.confirm'), callback: function callback() {
                        var opener = plus.webview.currentWebview().opener();
                        _public.iot.navigator.back();
                    }
                });
            },
            complete: function complete() {
                _public.uComponents.hideLoading(self);
            }
        });
    }
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2)["default"]))

/***/ }),

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

module.exports = __webpack_require__(207);


/***/ })

},[308]);
//# sourceMappingURL=editName.js.map