webpackJsonp([25],{

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

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

var _public = __webpack_require__(4);

_public.iot.ready(init); /**
                         * v_scanCodeAdd.js
                         * Version: 0.1
                         * User: wy
                         * Date: 2017-09-07
                         * Copyright(c)  2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
                         * 扫描绑定设备页面
                         */

function init() {
				//通用 dialog、loading组件
				_public.uPublic.componentsInit(['u-dialog', 'u-loading']);
				var app = new Vue({
								data: {
												//配置组件
												componentsConfig: initComponentsConfig()
								},
								mounted: function mounted() {
												var self = this;
												if (plus.os.name == 'Android') {
																_public.iot.permission.checkPermission(['CAMERA'], function (res) {
																				console.log('success', res);
																				openScanCode(self);
																}, function (err) {
																				console.log('error', err);
																});
												} else {
																openScanCode(self);
												}
								},

								methods: {
												//tap <
												onBackTap: function onBackTap() {
																backTap();
												}
								}
				}).$mount('#app');
}

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

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

function openScanCode(self) {
				_public.iot.utils.scanBarcode({
								data: {
												id: 'bcid',
												styles: {
																frameColor: '#00ffff',
																scanbarColor: '#00ffff',
																background: '#242b35'
												}
								},
								success: function success(response) {
												console.log(response);
												var data = _public.uPublic.checkResponseData(response.data);
												if (data) {
																//扫描成功
																var result = JSON.parse(data.result);
																var qrKey = result.qrKey;
																var lockId = result.lockId;
																var relId = result.relId;
																//绑定设备
																_public.iot.business.sds.scanqr({
																				data: {
																								qrKey: qrKey
																				},
																				success: function success(response) {
																								console.log(response);
																								var data = _public.uPublic.checkResponseData(response.data);
																								if (data) {
																												//云端绑定
																												deviceBind(self, lockId, relId);
																								} else {}
																				},
																				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('addDevice.bindFailure'), {
																												text: Vue.t('dialog.confirm'), callback: function callback() {}
																								});
																				}
																});
												} else {}
								},
								error: function error(_error2) {
												//请求失败
												console.log(_error2);
												//  		if(window.iotDebug){
												//              iotDebug.push('end: 扫描失败'+JSON.stringify(error));
												//         	}
												//	    	if (window.iotDebug) {
												//              iotDebug.upload(iot,'扫描失败');
												//          }
												_public.uPublic.openRequestErrorAlert(self);
								}
				});
}

function deviceBind(self, lockId, relId) {
				_public.iot.business.api.sendCustom('lock/bindUser', {
								data: {
												device_id: lockId,
												rel_id: relId,
												//		    mac: parameters.mac,
												nickname: ''
								},
								success: function success(response) {
												console.log(response);
												var data = response.data;
												if (data.success) {
																_public.uComponents.openAlert(self, Vue.t('addDevice.bindSuccess'), {
																				text: Vue.t('dialog.confirm'), callback: function callback() {
																								_public.iot.navigator.openWindow({
																												url: '../device/index.html',
																												id: 'device'
																								});
																				}
																});
												}
								},
								error: function error(_error3) {
												console.log(_error3);
												//	    	if(window.iotDebug){
												//              iotDebug.push('end: 云端绑定失败'+JSON.stringify(error));
												//         	}
												//	    	if (window.iotDebug) {
												//              iotDebug.upload(iot,'云端绑定失败');
												//          }
												_public.uComponents.openAlert(self, Vue.t('addDevice.bindFailure'), {
																text: Vue.t('dialog.confirm'), callback: function callback() {}
												});
								},
								complete: function complete() {}
				});
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2)["default"]))

/***/ }),

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

module.exports = __webpack_require__(198);


/***/ })

},[299]);
//# sourceMappingURL=scanCodeAdd.js.map