webpackJsonp([9],{

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

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

var _regenerator = __webpack_require__(10);

var _regenerator2 = _interopRequireDefault(_regenerator);

var _public = __webpack_require__(6);

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } /**
                                                                                                                                                                                                                  * v_doorlockUsers.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() {
	//通用 按钮、dialog、loading组件
	_public.uPublic.componentsInit(['u-button', 'u-dialog', 'u-loading']);
	var opener = plus.webview.currentWebview().opener();
	if (opener.id == 'addUser') {
		setTimeout(function () {
			plus.webview.close(opener, "none", 0, {});
		}, 500);
	}
	var app = new Vue({
		data: {
			userInfo: {},
			bindShowFlag: true,
			unbindShowFlag: false,
			//          stateShowFlag: false,
			guideShowFlag: false,
			guideStep1ShowFlag: false,
			guideStep2ShowFlag: false,
			guideStep3ShowFlag: false,
			guideStep4ShowFlag: false,
			//配置组件
			componentsConfig: initComponentsConfig(),
			extras: {},
			imageSrc: '../../resources/image/green_unbindSuccess_icon.png',
			//          textBindTip: Vue.t('doorlockUser.unbindSuccess'),
			role: null,
			info: null,
			isFirstAddUser: true
		},
		mounted: function mounted() {
			this.extras = _public.iot.navigator.getExtras();
			this.role = this.extras.role;
			var self = this;
			window.addEventListener('returnPage', function (event) {
				console.log("returnPage");
				_public.iot.navigator.fire(plus.webview.getWebviewById('doorlockUsers'), 'returnPage', {});
				getUserInfo(self);
			});
			getUserInfo(this);
			var opener = plus.webview.currentWebview().opener();
			if (opener.id == 'addUser') {
				self.isFirstAddUser = true;
			} else {
				self.isFirstAddUser = false;
			}
		},

		methods: {
			getBindShowFlag: function getBindShowFlag() {
				return this.bindShowFlag;
			},
			setBindShowFlag: function setBindShowFlag(boolean) {
				this.bindShowFlag = boolean;
			},
			getUnbindShowFlag: function getUnbindShowFlag() {
				return this.unbindShowFlag;
			},
			setUnbindShowFlag: function setUnbindShowFlag(boolean) {
				this.unbindShowFlag = boolean;
			},

			//          getStateShowFlag(){
			//              return this.stateShowFlag;
			//          },
			//          setStateShowFlag(boolean){
			//              this.stateShowFlag = boolean;
			//          },
			getGuideShowFlag: function getGuideShowFlag() {
				return this.guideShowFlag;
			},
			setGuideShowFlag: function setGuideShowFlag(boolean) {
				this.guideShowFlag = boolean;
			},
			getGuideStep1ShowFlag: function getGuideStep1ShowFlag() {
				return this.guideStep1ShowFlag;
			},
			setGuideStep1ShowFlag: function setGuideStep1ShowFlag(boolean) {
				this.guideStep1ShowFlag = boolean;
			},
			getGuideStep2ShowFlag: function getGuideStep2ShowFlag() {
				return this.guideStep2ShowFlag;
			},
			setGuideStep2ShowFlag: function setGuideStep2ShowFlag(boolean) {
				this.guideStep2ShowFlag = boolean;
			},
			getGuideStep3ShowFlag: function getGuideStep3ShowFlag() {
				return this.guideStep3ShowFlag;
			},
			setGuideStep3ShowFlag: function setGuideStep3ShowFlag(boolean) {
				this.guideStep3ShowFlag = boolean;
			},
			getGuideStep4ShowFlag: function getGuideStep4ShowFlag() {
				return this.guideStep4ShowFlag;
			},
			setGuideStep4ShowFlag: function setGuideStep4ShowFlag(boolean) {
				this.guideStep4ShowFlag = boolean;
			},
			setImageSrc: function setImageSrc(src) {
				this.imageSrc = src;
			},

			//          setTextBindTip(tip){
			//          	this.textBindTip = tip;
			//          },
			getInfo: function getInfo() {
				return this.info;
			},
			setInfo: function setInfo(object) {
				this.info = object;
			},

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

			//tap 邀请绑定
			onBindButtonTap: function onBindButtonTap() {
				bindButtonTap(this);
			},

			//tap 解绑
			onUnbindButtonTap: function onUnbindButtonTap() {
				unbindButtonTap(this);
			},

			//tap 绑定开锁信息
			onBindUnlockInfoTap: function onBindUnlockInfoTap() {
				bindUnlockInfoTap(this);
			},

			//tap 编辑用户昵称
			onEditNameTap: function onEditNameTap() {
				editNameTap(this);
			},

			//tap 历史开门记录
			onOpendoorRecordTap: function onOpendoorRecordTap() {
				opendoorRecordTap(this);
			},

			//tap 删除该用户
			onDeleteUserButtonTap: function onDeleteUserButtonTap() {
				deleteUserButtonTap(this);
			},

			//          onUnbindStateDialogTap(){
			//              unbindStateDialogTap(this);
			//          },
			//tap 下一步
			onNextButtonTap: function onNextButtonTap() {
				nextButtonTap(this);
			},

			//tap 我知道了
			onISeeButtonTap: function onISeeButtonTap() {
				iSeeButtonTap(this);
			}
		}
	}).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {
	var _ref;

	return _ref = {
		//绑定 button 参数
		bindButton: {
			initParam: {
				class: 'custom-unbind-button',
				text: Vue.t('doorlockUser.inviteBind')
			}
		},
		//解绑 button 参数
		unbindButton: {
			initParam: {
				class: 'custom-unbind-button',
				text: Vue.t('btn.unbind')
			}
		}
	}, _defineProperty(_ref, 'unbindButton', {
		initParam: {
			class: 'custom-unbind-button',
			text: Vue.t('btn.unbind')
		}
	}), _defineProperty(_ref, 'unbindButton', {
		initParam: {
			class: 'custom-unbind-button',
			text: Vue.t('btn.unbind')
		}
	}), _defineProperty(_ref, 'deleteUserButton', {
		initParam: {
			class: 'custom-button',
			text: Vue.t('btn.deleteUser')
		}
	}), _defineProperty(_ref, 'nextButton', {
		initParam: {
			class: 'custom-dialog-button',
			text: Vue.t('btn.next')
		}
	}), _defineProperty(_ref, 'iSeeButton', {
		initParam: {
			class: 'custom-dialog-button',
			text: Vue.t('btn.iSee')
		}
	}), _defineProperty(_ref, 'dialog', {
		initParam: {
			class: 'custom-dialog'
		}
	}), _defineProperty(_ref, 'loading', {
		initParam: {
			class: 'custom-loading'
		}
	}), _ref;
}

//判断是否第一次添加用户
function checkFirstAddUser(self) {
	_public.iot.storage.getMap('isFirstAddUser', function (res) {
		if (res) {} else {
			//显示引导动画
			showGuide(self);
		}
	}, function () {
		//显示 引导动画
		showGuide(self);
	});
}

//显示动画
function showGuide(self) {
	var time;
	return _regenerator2.default.async(function showGuide$(_context) {
		while (1) {
			switch (_context.prev = _context.next) {
				case 0:
					self.setGuideShowFlag(true);
					time = null;

					console.log(self.userInfo.role);

					if (!(self.userInfo.role == 0)) {
						_context.next = 20;
						break;
					}

					_context.prev = 4;
					_context.next = 7;
					return _regenerator2.default.awrap(sleep(500));

				case 7:
					time = _context.sent;
					self.setGuideStep3ShowFlag(true);
					_context.next = 11;
					return _regenerator2.default.awrap(sleep(500));

				case 11:
					time = _context.sent;

					self.setGuideStep4ShowFlag(true);
					_context.next = 18;
					break;

				case 15:
					_context.prev = 15;
					_context.t0 = _context['catch'](4);

					console.log(_context.t0);

				case 18:
					_context.next = 34;
					break;

				case 20:
					_context.prev = 20;
					_context.next = 23;
					return _regenerator2.default.awrap(sleep(500));

				case 23:
					time = _context.sent;

					self.setGuideStep1ShowFlag(true);

					_context.next = 27;
					return _regenerator2.default.awrap(sleep(500));

				case 27:
					time = _context.sent;

					self.setGuideStep2ShowFlag(true);
					_context.next = 34;
					break;

				case 31:
					_context.prev = 31;
					_context.t1 = _context['catch'](20);

					console.log(_context.t1);

				case 34:
				case 'end':
					return _context.stop();
			}
		}
	}, null, this, [[4, 15], [20, 31]]);
}

function nextGuide(self) {
	var time;
	return _regenerator2.default.async(function nextGuide$(_context2) {
		while (1) {
			switch (_context2.prev = _context2.next) {
				case 0:
					_context2.prev = 0;
					_context2.next = 3;
					return _regenerator2.default.awrap(sleep(500));

				case 3:
					time = _context2.sent;
					self.setGuideStep3ShowFlag(true);
					_context2.next = 7;
					return _regenerator2.default.awrap(sleep(500));

				case 7:
					time = _context2.sent;

					self.setGuideStep4ShowFlag(true);
					_context2.next = 14;
					break;

				case 11:
					_context2.prev = 11;
					_context2.t0 = _context2['catch'](0);

					console.log(_context2.t0);

				case 14:
				case 'end':
					return _context2.stop();
			}
		}
	}, null, this, [[0, 11]]);
}

function sleep(time) {
	return new Promise(function (resolve, reject) {
		setTimeout(function () {
			resolve(time);
		}, time);
	});
}

function getUserInfo(self) {
	_public.uComponents.showLoading(self);
	_public.iot.business.api.sendCustom('lock/getUserInfo', {
		data: {
			rel_id: self.extras.id,
			device_id: self.extras.lockId
		},
		success: function success(response) {
			var data = _public.uPublic.checkResponseData(response.data);
			console.log(data);
			if (data) {
				if (data.user_id != self.extras) {
					_public.iot.navigator.fire(plus.webview.getWebviewById('doorlockUsers'), 'returnPage', {});
				}
				self.setInfo(data);
				setUserInfo(self, data);
				if (self.role == 0) {
					checkFirstAddUser(self);
				}
			} else {}
		},
		error: function error(_error) {
			console.log(_error);
			//			if(window.iotDebug){
			//              iotDebug.push('end: 获取用户信息'+JSON.stringify(error));
			//         	}
			//	    	if (window.iotDebug) {
			//              iotDebug.upload(iot,'获取用户信息');
			//          }
			_public.uPublic.openRequestErrorAlert(self);
		},
		complete: function complete() {
			_public.uComponents.hideLoading(self);
		}
	});
}

//设置用户信息
function setUserInfo(self, data) {
	self.userInfo = {
		imgClass: data.role == 0 ? 'userInfo-image-admin' : data.user_id == null ? 'userInfo-image-unbind' : 'userInfo-image-bind',
		role: data.role,
		title: data.nickname,
		subtitle: ''
	};
	self.setBindShowFlag(data.user_id ? false : true);
	self.setUnbindShowFlag(data.user_id ? true : false);
}

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

//tap 编辑用户昵称
function editNameTap(self) {
	if (!self.role && !self.isFirstAddUser) {
		_public.iot.navigator.openWindow({
			url: './editName.html',
			id: 'editName',
			extras: {
				id: self.getInfo().id,
				nickname: self.getInfo().nickname,
				deviceId: self.getInfo().device_id,
				role: self.extras.role
			}
		});
	}
}

//tap 邀请绑定
function bindButtonTap(self) {
	checkUser(self, function (data) {
		if (data.auids) {
			_public.uComponents.openAlert(self, Vue.t('doorlockUser.bindedTip'), {
				text: Vue.t('dialog.confirm'), callback: function callback() {
					self.setInfo(data);
					setUserInfo(self, data);
				}
			});
		} else {
			_public.iot.navigator.openWindow({
				url: './inviteBind.html',
				id: 'inviteBind',
				extras: {
					uuid: self.extras.uuid,
					id: self.extras.id,
					deviceId: self.getInfo().device_id,
					lockId: self.extras.lockId
				}
			});
		}
	});
}

//tap 解绑
function unbindButtonTap(self) {
	_public.uComponents.openConfirm(self, Vue.t('doorlockUser.unbindDialogTip'), { text: Vue.t('dialog.cancel'), callback: function callback() {} }, { text: Vue.t('dialog.unbind'), callback: function callback() {
			_public.iot.business.sds.unbindByManager({
				data: {
					uuid: self.extras.uuid,
					destAuid: self.info.auids
				},
				success: function success(response) {
					console.log(response);
					_public.iot.business.api.sendCustom('lock/unbindUser', {
						data: {
							user_id: self.getInfo().user_id,
							device_sn: self.getInfo().device_id,
							device_id: self.extras.lockId
						},
						success: function success(response) {
							console.log(response);
							_public.iot.navigator.fire(plus.webview.getWebviewById('doorlockUsers'), 'returnPage', {});
							//				    		self.setStateShowFlag(true);
							_public.uComponents.openAlert(self, Vue.t('doorlockUser.unbindSuccess'), {
								text: Vue.t('dialog.confirm'), callback: function callback() {
									getUserInfo(self);
								}
							});
						},
						error: function error(_error2) {
							console.log(_error2);
							//					    	uPublic.openRequestErrorAlert(self);
							//				    		self.setImageSrc('../../resources/image/green_unbindFail_icon.png');
							//				    		self.setTextBindTip(Vue.t('doorlockUser.unbindFailue'));
							//				    		self.setStateShowFlag(true);
							_public.uComponents.openAlert(self, Vue.t('doorlockUser.unbindFailue'), {
								text: Vue.t('dialog.confirm'), callback: function callback() {}
							});
						},
						complete: function complete() {
							_public.uComponents.hideLoading(self);
						}
					});
				},
				error: function error(_error3) {
					console.log(_error3);
					_public.uPublic.openRequestErrorAlert(self);
					//		        	self.setImageSrc('../../resources/image/green_unbindFail_icon.png');
					//		    		self.setTextBindTip(Vue.t('doorlockUser.unbindFailue'));
					//		    		self.setStateShowFlag(true);
					_public.uComponents.openAlert(self, Vue.t('doorlockUser.unbindSuccess'), {
						text: Vue.t('dialog.confirm'), callback: function callback() {
							getUserInfo(self);
						}
					});
				},
				complete: function complete() {}
			});
		} });
}

//function unbindStateDialogTap(self){
//  self.setStateShowFlag(false);
//  self.setBindShowFlag(true);
//  self.setUnbindShowFlag(false);
//  self.userInfo.image = '../../resources/image/gray_unbindHead_icon.png';
//}

//tap 绑定开锁信息
function bindUnlockInfoTap(self) {
	_public.iot.navigator.openWindow({
		url: './unlockInfo.html',
		id: 'unlockInfo',
		extras: {
			id: self.extras.id,
			userId: self.getInfo().user_id,
			deviceId: self.getInfo().device_id,
			lockId: self.extras.lockId,
			role: self.extras.role
		}
	});
}

//tap 历史开门记录
function opendoorRecordTap(self) {
	if (!self.isFirstAddUser) {
		_public.iot.navigator.openWindow({
			url: '../device/opendoorRecord.html',
			id: 'opendoorRecord',
			extras: {
				relId: self.extras.id,
				deviceId: self.getInfo().device_id
			}
		});
	}
}

//tap 删除该用户
function deleteUserButtonTap(self) {
	_public.uComponents.openConfirm(self, Vue.t('doorlockUser.deleteUserDialogTip'), { text: Vue.t('dialog.cancel'), callback: function callback() {} }, { text: Vue.t('dialog.delete'), callback: function callback() {
			deleteUser(self);
		} });
}

//tap 下一步
function nextButtonTap(self) {
	self.setGuideStep1ShowFlag(false);
	self.setGuideStep2ShowFlag(false);
	nextGuide(self);
}

//tap 我知道了
function iSeeButtonTap(self) {
	self.setGuideShowFlag(false);
	_public.iot.storage.setMap('isFirstAddUser', true, function () {}, function (err) {});
}

//删除用户
function deleteUser(self) {
	_public.uComponents.showLoading(self);
	//确认该用户是否被绑定
	checkUser(self, function (data) {
		self.setInfo(data);
		//判断该用户是否绑定
		if (self.info.auids) {
			_public.iot.business.sds.unbindByManager({
				data: {
					uuid: self.extras.uuid,
					destAuid: self.info.auids
				},
				success: function success(response) {
					deleteCloudeUser(self);
				},
				error: function error(_error4) {
					console.log(_error4);
					_public.uComponents.openAlert(self, Vue.t('doorlockUser.deleteFailure'), {
						text: Vue.t('btn.confirm'), callback: function callback() {}
					});
				},
				complete: function complete() {}
			});
		} else {
			deleteCloudeUser(self);
		}
	});
}

function checkUser(self, callback) {
	_public.iot.business.api.sendCustom('lock/getUserInfo', {
		data: {
			rel_id: self.extras.id,
			device_id: self.extras.lockId
		},
		success: function success(response) {
			var data = _public.uPublic.checkResponseData(response.data);
			console.log(data);
			if (data) {
				if (data.user_id != self.extras) {
					_public.iot.navigator.fire(plus.webview.getWebviewById('doorlockUsers'), 'returnPage', {});
				}
				callback(data);
			} else {}
		},
		error: function error(_error5) {
			console.log(_error5);
			_public.uPublic.openRequestErrorAlert(self);
		},
		complete: function complete() {}
	});
}

function deleteCloudeUser(self) {
	_public.iot.business.api.sendCustom('lock/delLockUser', {
		data: {
			rel_id: self.extras.id,
			user_id: self.getInfo().user_id,
			device_sn: self.getInfo().device_id,
			device_id: self.extras.lockId
		},
		success: function success(response) {
			console.log(response);
			if (response.data.success) {
				_public.iot.navigator.fire(plus.webview.getWebviewById('doorlockUsers'), 'returnPage', {});
				_public.uComponents.openAlert(self, Vue.t('doorlockUser.deleteSuccess'), {
					text: Vue.t('btn.confirm'), callback: function callback() {
						_public.iot.navigator.aback();
					}
				});
			}
		},
		error: function error(_error6) {
			console.log(_error6);
			_public.uComponents.openAlert(self, Vue.t('doorlockUser.deleteFailure'), {
				text: Vue.t('btn.confirm'), callback: function callback() {}
			});
		},
		complete: function complete() {
			_public.uComponents.hideLoading(self);
		}
	});
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)["default"], __webpack_require__(14)))

/***/ }),

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

module.exports = __webpack_require__(190);


/***/ })

},[300]);
//# sourceMappingURL=doorlockUser.js.map