webpackJsonp([11],{

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

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

var _config = __webpack_require__(127);

var _config2 = _interopRequireDefault(_config);

var _public = __webpack_require__(4);

var _components = __webpack_require__(244);

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

_public.iot.ready(init); /**
                         * v_index.js
                         * Version: 0.1
                         * User: wy
                         * Date: 2017-09-06
                         * Copyright(c)  2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
                         * 门锁管理页面
                         */

function init() {
    //通用 按钮、dialog、loading组件
    _public.uPublic.componentsInit(['u-button', 'u-dialog', 'u-loading', 'u-switch']);
    //项目 list组件
    _public.uPublic.componentsExtend(['grid-list']);
    var app = new Vue({
        data: {
            //配置组件
            componentsConfig: initComponentsConfig(),
            //提示框是否显示
            stateShowFlag: false,
            //我的门锁
            doorlock: null,
            //提示框显示文字
            showMsg: '',
            textNickname: null,
            extras: {},
            unbindSucceess: false,
            valueDoorbell: true,
            valueAlarm: true,
            valueOpendoor: true
        },
        mounted: function mounted() {
            this.extras = _public.iot.navigator.getExtras();
            console.log(this.extras);
            //获取门锁
            getDoorlockInfo(this);
            //监听returnPage返回事件，重新获取最新数据
            var self = this;
            window.addEventListener('returnPage', function (event) {
                console.log("returnPage");
                getDoorlockInfo(self);
            });
        },

        methods: {
            getStateShowFlag: function getStateShowFlag() {
                return this.stateShowFlag;
            },
            setStateShowFlag: function setStateShowFlag(flag) {
                this.stateShowFlag = flag;
            },
            getDoorlock: function getDoorlock() {
                return this.doorlock;
            },
            setDoorlock: function setDoorlock(obj) {
                this.doorlock = obj;
            },
            getShowMsg: function getShowMsg() {
                return this.showMsg;
            },
            setShowMsg: function setShowMsg(msg) {
                this.showMsg = msg;
            },
            getTextNickname: function getTextNickname() {
                return this.textNickname;
            },
            setTextNickname: function setTextNickname(text) {
                this.textNickname = text;
            },
            getUnbindSucceess: function getUnbindSucceess() {
                return this.unbindSucceess;
            },
            setUnbindSucceess: function setUnbindSucceess(bool) {
                this.unbindSucceess = bool;
            },

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

            //tap 修改设备昵称
            onEditNameTap: function onEditNameTap() {
                editNameTap(this);
            },

            //tap 解绑门锁
            onUnbindDoorlockButtonTap: function onUnbindDoorlockButtonTap() {
                unbindDoorlockButtonTap(this);
            },

            //tap 隐藏提示框
            onUnbindStateDialogTap: function onUnbindStateDialogTap() {
                unbindStateDialogTap(this);
            }
        }
    }).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {
    return {
        unbindDoorlockButton: {
            initParam: {
                class: 'custom-button',
                text: Vue.t('btn.unbindDoorlock')
            }
        },
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        },
        doorbellSwitch: {
            initParam: {
                class: 'custom-switch'
            }
        },
        alarmSwitch: {
            initParam: {
                class: 'custom-switch'
            }
        },
        opendoorSwitch: {
            initParam: {
                class: 'custom-switch'
            }
        }
    };
}

function getDoorlockInfo(self) {
    _public.uComponents.showLoading(self);
    var productId = _config2.default.mode.substr(_config2.default.mode_type.length, 6);
    _public.iot.business.api.send('device/getList', {
        data: {
            sds: false,
            device_id: self.extras.deviceId,
            product_id: productId,
            parent_id: 0,
            start_id: 0,
            number: 10
        },
        success: function success(response) {
            console.log(response);
            var data = _public.uPublic.checkResponseData(response.data);
            if (data) {
                self.setDoorlock(response.data[0]);
                self.setTextNickname(self.getDoorlock().nickname);
                console.log(self.getDoorlock());
            }
        },
        error: function error(_error) {
            //请求失败
            _public.uPublic.openRequestErrorAlert(self);
            console.log(_error);
        },
        complete: function complete() {
            _public.uComponents.hideLoading(self);
        }
    }, true);
}

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

//tap 修改设备昵称
function editNameTap(self) {
    _public.iot.navigator.openWindow({
        url: './editName.html',
        id: 'editName',
        extras: {
            deviceId: self.getDoorlock().id,
            nickname: self.getTextNickname()
        }
    });
}

//tap 解绑门锁
function unbindDoorlockButtonTap(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.uComponents.showLoading(self);
            _public.iot.business.sds.unbindDevice({
                data: {
                    uuid: self.extras.uuid
                },
                success: function success(response) {
                    console.log(response);
                    unbind(self);
                },
                error: function error(_error2) {
                    console.log(_error2);
                },
                complete: function complete() {}
            });
        } });
}

//tap 隐藏提示框
function unbindStateDialogTap(self) {
    self.setStateShowFlag(false);
    if (self.getUnbindSucceess) {
        _public.iot.navigator.openWindow({
            url: '../device/index.html',
            id: 'device'
        });
    }
}

function unbind(self) {
    _public.iot.business.api.sendCustom('lock/unbind', {
        data: {
            device_sn: self.getDoorlock().device_id,
            device_id: self.getDoorlock().id
        },
        success: function success(response) {
            console.log(response);
            self.setStateShowFlag(true);
            self.setShowMsg(Vue.t('doorlockUser.unbindSuccess'));
            self.setUnbindSucceess(true);
        },
        error: function error(_error3) {
            console.log(_error3);
            self.setStateShowFlag(false);
            self.setShowMsg(Vue.t('doorlockUser.unbindFailue'));
            self.setUnbindSucceess(false);
        },
        complete: function complete() {
            _public.uComponents.hideLoading(self);
        }
    });
}

function unbindUser(self) {
    _public.iot.business.api.sendCustom('lock/unbindUser', {
        data: {
            rel_id: self.getDoorlock().id,
            device_id: self.getDoorlock().device_id,
            user_id: self.getDoorlock().user_device_id
        },
        success: function success(response) {
            self.setStateShowFlag(true);
            self.setShowMsg(Vue.t('doorlockUser.unbindSuccess'));
            self.setUnbindSucceess(true);
        },
        error: function error(_error4) {
            console.log(_error4);
            self.setStateShowFlag(false);
            self.setShowMsg(Vue.t('doorlockUser.unbindFailue'));
            self.setUnbindSucceess(false);
        },
        complete: function complete() {
            _public.uComponents.hideLoading(self);
        }
    });
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2)["default"]))

/***/ }),

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

"use strict";


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

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

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

exports.projectMethods = projectMethods;

/***/ }),

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

module.exports = __webpack_require__(208);


/***/ })

},[306]);
//# sourceMappingURL=index.js.map