webpackJsonp([17],{

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

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

var _public = __webpack_require__(4);

_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-dialog', 'u-loading', 'u-button']);
    _public.uPublic.closeSlideBack();
    var app = new Vue({
        data: {
            //配置组件
            componentsConfig: initComponentsConfig(),
            clientId: null,
            showLoginButtonFlag: true
        },
        mounted: function mounted() {
            if (window.iotDebug) {
                iotDebug.push('start: Debug');
            }
            var clientInfo = plus.push.getClientInfo();
            this.setClientId(clientInfo.clientid);
            var self = this;
            if (plus.os.name == 'Android') {
                _public.iot.permission.checkPermission(['READ_EXTERNAL_STORAGE'], function (res) {
                    console.log('success', res);
                    loginButtonTap(self);
                }, function (err) {
                    console.log('error', err);
                });
            } else {
                loginButtonTap(self);
            }
        },

        methods: {
            getShowLoginButtonFlag: function getShowLoginButtonFlag() {
                return this.showLoginButtonFlag;
            },
            setShowLoginButtonFlag: function setShowLoginButtonFlag(flag) {
                this.showLoginButtonFlag = flag;
            },
            onLoginButtonTap: function onLoginButtonTap() {
                loginButtonTap(this);
            },
            getClientId: function getClientId() {
                return this.clientId;
            },
            setClientId: function setClientId(id) {
                this.clientId = id;
            }
        }
    }).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {
    return {
        //登录 button 参数
        loginButton: {
            initParam: {
                class: 'custom-guide-button',
                text: Vue.t('btn.guideLogin')
            }
        },
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        }
    };
}

function loginButtonTap(self) {
    _public.uComponents.showLoading(self);
    //	if(window.iotDebug){
    //      iotDebug.push('start: initSDSLogin');
    //  }
    //	window.SDSPlugin.login({},(res)=>{
    //		console.log(res);
    //		var data = uPublic.checkResponseData(res.data);
    //	    if(data){
    //	    	cloudsLogin(self, data.UserID);
    //	    }
    //	},(err)=>{
    //		console.log(err);
    //	})
    _public.iot.business.sds.login({
        data: {
            userinfo: {}
        },
        success: function success(response) {
            //	    	alert(JSON.stringify(response));
            console.log(response);
            if (window.iotDebug) {
                iotDebug.push('end: SDSloginSuccees');
            }
            //			alert(JSON.stringify(response)); 
            var data = _public.uPublic.checkResponseData(response.data);
            if (data) {
                self.setShowLoginButtonFlag(false);
                if (data.hasOwnProperty('UserID')) {
                    console.log("sds登陆成功了");
                    cloudsLogin(self, data.UserID);
                }
            } else {}
        },
        error: function error(_error) {
            console.log(_error);
            //	    	alert(JSON.stringify(error));
            if (window.iotDebug) {
                iotDebug.push('end: sds登陆失败' + JSON.stringify(_error));
            }
            if (window.iotDebug) {
                iotDebug.upload(_public.iot, 'sds登陆失败');
            }
        },
        complete: function complete() {
            _public.uComponents.hideLoading(self);
        }
    });
}

function cloudsLogin(self, id) {
    _public.uComponents.showLoading(self);
    if (window.iotDebug) {
        iotDebug.push('start: cloudsLogin');
    }
    _public.iot.business.user.simpleLogin({
        data: {
            username: id,
            clienId: self.getClientId()
        },
        success: function success(response) {
            if (window.iotDebug) {
                iotDebug.push('end: cloudsLogin');
            }
            if (window.iotDebug) {
                iotDebug.upload(_public.iot, '登陆流程时间');
            }
            _public.iot.navigator.openWindow({
                url: '../device/index.html',
                id: 'device'
            });
            plus.navigator.closeSplashscreen();
        },
        error: function error(_error2) {
            console.log(_error2);
            if (window.iotDebug) {
                iotDebug.push('end: 云端登陆失败' + JSON.stringify(_error2));
            }
            if (window.iotDebug) {
                iotDebug.upload(_public.iot, '云端登陆失败');
            }
            _public.uPublic.openRequestErrorAlert(self);
        },
        complete: function complete() {
            //			uComponents.hideLoading(self);
        }
    });
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2)["default"]))

/***/ }),

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

module.exports = __webpack_require__(218);


/***/ })

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