webpackJsonp([3],{

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

"use strict";


Object.defineProperty(exports, "__esModule", {
    value: true
});
var projectMethods = {};

projectMethods.changeList = function (vmObj, list) {
    vmObj.$refs.list.changeList(list);
};

exports.default = projectMethods;

/***/ }),

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

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

var _regenerator = __webpack_require__(10);

var _regenerator2 = _interopRequireDefault(_regenerator);

var _moment = __webpack_require__(0);

var _moment2 = _interopRequireDefault(_moment);

var _config = __webpack_require__(9);

var _config2 = _interopRequireDefault(_config);

var _public = __webpack_require__(6);

var _components = __webpack_require__(18);

var _components2 = _interopRequireDefault(_components);

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

var PAGE_SIZE = 10; /**
                    * v_opendoorRecord.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() {
	//通用 list、dialog、loading组件
	_public.uPublic.componentsInit(['u-list', 'u-dialog', 'u-loading']);
	_public.uPublic.componentsExtend(['list']);
	_public.uPublic.closeSlideBack();
	var app = new Vue({
		data: {
			//配置组件
			componentsConfig: initComponentsConfig(),
			list: [],
			startId: 0,
			deviceId: null,
			userInfo: [],
			flag: true,
			noticeTipShowFlag: false
		},
		mounted: function mounted() {
			var _this = this;

			_public.uComponents.showLoading(this);
			this.noticeTipShowFlag = !_public.iot.native.isNotifycationOpen();
			resolve(this);
			window.addEventListener('returnPage', function () {
				_this.noticeTipShowFlag = !_public.iot.native.isNotifycationOpen();
			});
		},

		methods: {
			getList: function getList() {
				return this.list;
			},
			setList: function setList(list) {
				this.list = list;
			},
			getStartId: function getStartId() {
				return this.startId;
			},
			setStartId: function setStartId(id) {
				this.startId = id;
			},
			getDeviceId: function getDeviceId() {
				return this.deviceId;
			},
			getUserInfo: function getUserInfo() {
				return this.userInfo;
			},
			setUserInfo: function setUserInfo(info) {
				this.userInfo = info;
			},
			setDeviceId: function setDeviceId(id) {
				this.deviceId = id;
			},
			onListLoad: function onListLoad() {
				listLoad(this);
			},
			onRefreshFresh: function onRefreshFresh() {
				refreshFresh(this);
			},
			onNotifycationSetting: function onNotifycationSetting() {
				notifycationSetting();
			},

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

//配置组件参数
function initComponentsConfig() {
	return {
		opendoorRecordList: {
			initParam: {
				class: 'custom-list',
				list: [],
				tip: Vue.t('opendoorRecord.noRecordTip'),
				pagesize: PAGE_SIZE,
				pullup: true
			}
		},
		dialog: {
			initParam: {
				class: 'custom-dialog'
			}
		},
		loading: {
			initParam: {
				class: 'custom-loading'
			}
		}
	};
}

//调用接口获取开门记录
function resolve(self) {
	console.log("in");
	//	uComponents.showLoading(self);
	self.setDeviceId(_public.iot.navigator.getExtras().deviceId);
	console.log(_public.iot.navigator.getExtras());
	if (_public.iot.navigator.getExtras().relId) {
		getPersonalHistory(self, _public.iot.navigator.getExtras().relId);
	} else {
		getHistoryRecord(self);
	}
}

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

//重写mui.back
//mui.back = function(){
//  iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
//  console.log("fire");
//	iot.navigator.back();
//}

//tap 点击加载更多
function listLoad(self) {
	resolve(self);
}

//获取历史记录（整个设备）
function getHistoryRecord(self) {
	var _this2 = this;

	_public.iot.business.api.sendCustom('lock/getHistoryRecord', {
		data: {
			device_id: self.getDeviceId(),
			action: 0,
			start_id: self.getStartId(),
			page_size: PAGE_SIZE
		},
		success: function success(response) {
			var data, record;
			return _regenerator2.default.async(function success$(_context) {
				while (1) {
					switch (_context.prev = _context.next) {
						case 0:
							setListData(self, response);

							if (!self.flag) {
								_context.next = 8;
								break;
							}

							data = _public.uPublic.checkResponseData(response.data);

							if (!(data && data.record.length > 0)) {
								_context.next = 8;
								break;
							}

							record = data.record;
							_context.next = 7;
							return _regenerator2.default.awrap(_public.uPublic.upDateRead('open', (0, _moment2.default)(record[0].time).unix()));

						case 7:
							self.flag = _context.sent;

						case 8:
						case 'end':
							return _context.stop();
					}
				}
			}, null, _this2);
		},
		error: function error(_error) {
			console.log(_error);
			_public.uPublic.openRequestErrorAlert(self);
		},
		complete: function complete() {
			_public.uComponents.hideLoading(self);
		}
	});
}

//获取个人历史记录
function getPersonalHistory(self, id) {
	_public.iot.business.api.sendCustom('lock/getPersonalHistory', {
		data: {
			device_id: self.getDeviceId(),
			rel_id: id,
			action: 0,
			start_id: self.getStartId(),
			page_size: PAGE_SIZE
		},
		success: function success(response) {
			setListData(self, response);
		},
		error: function error(_error2) {
			console.log(_error2);
			_public.uPublic.openRequestErrorAlert(self);
		},
		complete: function complete() {
			_public.uComponents.hideLoading(self);
		}
	});
}

//设置历史记录渲染列表
function setListData(self, response) {
	var data = _public.uPublic.checkResponseData(response.data);
	if (data) {
		console.log(data);
		var list = [];
		var record = data.record;
		if (data.hasOwnProperty('info')) {
			self.setUserInfo(data.info);
		}
		for (var i = 0; i < record.length; i++) {
			list[i] = {
				value: record[i].openId,
				title: record[i].mode == 30 || record[i].mode == 5 ? '' : "ID:" + record[i].openId,
				//				leftImage: '../../resources/image/green_opendoor'+record[i].mode+'_icon.png',
				imgClass: 'u-list-left-bg-image_' + record[i].mode,
				subtitle: Vue.t('opendoorRecord.' + _config2.default.openDoorMode[record[i].mode] + ''),
				rightText: (0, _moment2.default)(record[i].time).format("YYYY.MM.DD HH:mm:ss")
			};
			for (var j = 0; j < self.getUserInfo().length; j++) {
				if (record[i].openId == self.getUserInfo()[j].openId && record[i].mode == self.getUserInfo()[j].mode) {
					if (self.getUserInfo()[j].nickname != null) {
						list[i].title = self.getUserInfo()[j].nickname;
					}
				}
			}
		}
		self.setList(self.getList().concat(list));
		if (record.length > 0) {
			self.setStartId(record[record.length - 1].id);
		}
		//更新列表数据
		_components2.default.changeList(self, self.getList());
		console.log("in");
	} else {}
}

//ios跳转到系统设置页面
//android跳转到通知页面
function notifycationSetting() {
	if (plus.os.name == 'Android') {
		_public.iot.navigator.openWindow({
			url: './notify.html',
			id: 'notify',
			styles: {
				popGesture: 'none'
			}
		});
	} else {
		_public.iot.native.toNotifycationSetting();
	}
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)["default"]))

/***/ }),

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

module.exports = __webpack_require__(186);


/***/ })

},[296]);
//# sourceMappingURL=opendoorRecord.js.map