webpackJsonp([11],{

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

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

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);

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

_public.iot.ready(init); /**
                         * v_addUnlockInfo.js
                         * Version: 0.1
                         * User: wy
                         * Date: 2017-10-09
                         * Copyright(c)  2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
                         * 绑定开锁信息页面
                         */

function init() {
    //通用 select、开关、按钮、dialog、loading组件
    _public.uPublic.componentsInit(['u-select', 'u-switch', 'u-button', 'u-dialog', 'u-loading']);
    _public.uPublic.closeSlideBack();
    var app = new Vue({
        data: {
            recordSelectIndex: 0,
            openId: null,
            mode: 1,
            recordSelectList: [],
            waysOpenDoor: [],
            selectedMode: 1,
            valueSetHijack: 0,
            guideShowFlag: false,
            guideStep1ShowFlag: false,
            guideStep2ShowFlag: false,
            guideStep3ShowFlag: false,
            guideStep4ShowFlag: false,
            guideStep5ShowFlag: false,
            guideStep6ShowFlag: false,
            //配置组件
            componentsConfig: initComponentsConfig(),
            extras: {}
        },
        mounted: function mounted() {
            this.extras = _public.iot.navigator.getExtras();
            console.log(this.extras);
            var self = this;
            for (var i = 1; _config2.default.openDoorWay.hasOwnProperty(i); i++) {
                self.waysOpenDoor.push({
                    mode: i,
                    text: Vue.t('unlockInfo.' + _config2.default.openDoorWay[i] + '')
                });
            }
            resolve(this);
        },

        methods: {
            getRecordSelectIndex: function getRecordSelectIndex() {
                return this.recordSelectIndex;
            },
            setRecordSelectIndex: function setRecordSelectIndex(index) {
                this.recordSelectIndex = index;
            },
            getOpenId: function getOpenId() {
                return this.openId;
            },
            setOpenId: function setOpenId(id) {
                this.openId = id;
            },
            getMode: function getMode() {
                return this.mode;
            },
            setMode: function setMode(mode) {
                this.mode = mode;
            },
            getRecordSelectList: function getRecordSelectList() {
                return this.recordSelectList;
            },
            setRecordSelectList: function setRecordSelectList(list) {
                this.recordSelectList = list;
            },
            getSelectedMode: function getSelectedMode() {
                return this.selectedMode;
            },
            setSelectedMode: function setSelectedMode(mode) {
                this.selectedMode = mode;
            },
            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;
            },
            getGuideStep5ShowFlag: function getGuideStep5ShowFlag() {
                return this.guideStep5ShowFlag;
            },
            setGuideStep5ShowFlag: function setGuideStep5ShowFlag(boolean) {
                this.guideStep5ShowFlag = boolean;
            },
            getGuideStep6ShowFlag: function getGuideStep6ShowFlag() {
                return this.guideStep6ShowFlag;
            },
            setGuideStep6ShowFlag: function setGuideStep6ShowFlag(boolean) {
                this.guideStep6ShowFlag = boolean;
            },

            //tap <
            onBackTap: function onBackTap() {
                backTap();
            },
            onRecordSelectChange: function onRecordSelectChange(value) {
                recordSelectChange(this, value);
            },

            //tap 添加
            onAddButtonTap: function onAddButtonTap() {
                addButtonTap(this);
            },
            onSelectOpenDoorModeTap: function onSelectOpenDoorModeTap(index) {
                selectOpenDoorModeTap(this, index);
            },

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

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

//配置组件参数
function initComponentsConfig() {
    return {
        recordSelect: {
            initParam: {
                class: 'custom-select',
                list: [],
                pagesize: Number.MAX_VALUE,
                tip: Vue.t('addUnlockInfo.noRecordTip')
            }
        },
        //设为劫持指纹
        setHijackSwitch: {
            initParam: {
                class: 'custom-setHijack-switch',
                text: Vue.t('addUnlockInfo.setHijackSwitch')
            }
        },
        //添加 button 参数
        addButton: {
            initParam: {
                class: 'custom-button',
                text: Vue.t('btn.add')
            }
        },
        //下一步 button 参数
        nextButton: {
            initParam: {
                class: 'custom-dialog-button',
                text: Vue.t('btn.next')
            }
        },
        //我知道了 button 参数
        iSeeButton: {
            initParam: {
                class: 'custom-dialog-button',
                text: Vue.t('btn.iSee')
            }
        },
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        }
    };
}

function resolve(self) {
    getTodayReccordByMode(self, self.getSelectedMode());
    _public.iot.storage.getMap('isFristAddUnlockInfo', 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);
                    _context.prev = 1;
                    _context.next = 4;
                    return _regenerator2.default.awrap(sleep(500));

                case 4:
                    time = _context.sent;

                    self.setGuideStep1ShowFlag(true);

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

                case 8:
                    time = _context.sent;

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

                case 12:
                    _context.prev = 12;
                    _context.t0 = _context['catch'](1);

                    console.log(_context.t0);

                case 15:
                case 'end':
                    return _context.stop();
            }
        }
    }, null, this, [[1, 12]]);
}

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

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]]);
}

//tap 下一步
function nextStepButtonTap(self) {
    self.setGuideStep3ShowFlag(false);
    self.setGuideStep4ShowFlag(false);
    nextStepGuide(self);
}

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

                case 3:
                    time = _context3.sent;

                    self.setGuideStep5ShowFlag(true);

                    _context3.next = 7;
                    return _regenerator2.default.awrap(sleep(500));

                case 7:
                    time = _context3.sent;

                    self.setGuideStep6ShowFlag(true);
                    _context3.next = 14;
                    break;

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

                    console.log(_context3.t0);

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

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

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

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

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

//
function recordSelectChange(self, value) {
    console.log(value);
    self.recordSelectIndex = value;
    console.log('recordSelectChange:' + self.recordSelectIndex);
    for (var i = 0; i < self.getRecordSelectList().length; i++) {
        if (self.recordSelectIndex == self.getRecordSelectList()[i].id) {
            self.setOpenId(parseInt(self.getRecordSelectList()[i].openId));
        }
    }
}

//tap 添加 
function addButtonTap(self) {
    if (self.getOpenId()) {
        _public.uComponents.showLoading(self);
        _public.iot.business.api.sendCustom('lock/bindOpenLog', {
            data: {
                device_id: self.extras.deviceId,
                mode: self.getMode(),
                openId: self.getOpenId(),
                rel_id: self.extras.id
            },
            success: function success(response) {
                console.log(response);
                if (response.data.success) {
                    _public.uComponents.openAlert(self, Vue.t('addUnlockInfo.addInfoSuccess'), {
                        text: Vue.t('dialog.confirm'), callback: function callback() {
                            _public.iot.navigator.fire(plus.webview.currentWebview().opener(), 'returnPage', {});
                            _public.iot.navigator.back();
                        }
                    });
                } 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(vmObj, Vue.t('addUnlockInfo.addInfoFailue'), {
                    text: Vue.t('dialog.confirm'), callback: function callback() {}
                });
            },
            complete: function complete() {
                _public.uComponents.hideLoading(self);
            }
        });
        setTimeout(function () {
            _public.uComponents.openAlert(vmObj, Vue.t('addUnlockInfo.addInfoFailue'), {
                text: Vue.t('dialog.confirm'), callback: function callback() {}
            });
            _public.uComponents.hideLoading(self);
        }, _config2.default.wifi_add_timeout);
    }
}

function selectOpenDoorModeTap(self, index) {
    self.setSelectedMode(index);
    self.setMode(index);
    getTodayReccordByMode(self, index);
}

function getTodayReccordByMode(self, mode) {
    _public.uComponents.showLoading(self);
    _public.iot.business.api.sendCustom('lock/getUnbindOpen', {
        data: {
            mode: self.getSelectedMode(),
            device_id: self.extras.deviceId
        },
        success: function success(response) {
            console.log(response);
            var data = response.data;
            self.setRecordSelectList(data);
            var list = [];
            for (var i = 0; i < data.length; i++) {
                list[i] = {
                    value: data[i].id,
                    title: (0, _moment2.default)(data[i].time).format("HH:mm"),
                    subtitle: 'ID:' + data[i].openId
                };
            }
            if (data.length) {
                self.setRecordSelectIndex(data[0].id);
                for (var _i = 0; _i < self.getRecordSelectList().length; _i++) {
                    if (self.recordSelectIndex == self.getRecordSelectList()[_i].id) {
                        self.setOpenId(parseInt(self.getRecordSelectList()[_i].openId));
                    }
                }
            }
            _public.uComponents.changeSelectList(self, list);
        },
        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);
        },
        complete: function complete() {
            _public.uComponents.hideLoading(self);
        }
    });
}

function setHijackTap(self, value) {
    if (value) {
        self.setMode(20);
    } else {
        self.setMode(2);
    }
    console.log(self.getMode());
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)["default"], __webpack_require__(14)))

/***/ }),

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

module.exports = __webpack_require__(188);


/***/ })

},[298]);
//# sourceMappingURL=addUnlockInfo.js.map