"use strict";

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

var WatchLiveLogin = React.createClass({ displayName: "WatchLiveLogin",
    mixins: [MyReactMixin],
    getInitialState: function getInitialState() {
        var initParam = this.getInitParam();
        return {
            param: initParam,
            showMask: false,
            mobile: "",
            mobileMsg: null,
            mobileDisable: false,
            smsCode: "",
            smsCodeMsg: null
        };
    },
    componentDidMount: function componentDidMount() {
        $.subscribe("WatchLiveLogin.showUserAuthentication", this.showUserAuthentication);
        $.subscribe("WatchLiveLogin.hideUserAuthentication", this.hideUserAuthentication);
    },

    showUserAuthentication: function showUserAuthentication() {
        this.setState({ showMask: true });
    },

    hideUserAuthentication: function hideUserAuthentication() {
        this.setState({
            showMask: false,
            mobile: "",
            mobileMsg: null,
            mobileDisable: false,
            smsCode: "",
            smsCodeMsg: null
        });
    },

    handleInputChange: function handleInputChange(event) {
        var target = event.target;
        var value = target.type === 'checkbox' ? target.checked : target.value;
        var name = target.name;
        this.setState(_defineProperty({}, name, value));
    },

    sendSmsCode: function sendSmsCode() {
        var that = this;
        //验证手机号的是否正确
        if (emptyStr(this.state.mobile)) {
            this.setState({ mobileMsg: i18n.invite.NotNull });
            return false;
        }
        var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
        var mailreg = /^(\w+([-.][A-Za-z0-9]+)*){3,18}@\w+([-.][A-Za-z0-9]+)*\.\w+([-.][A-Za-z0-9]+)*$/;
        console.log(myreg.test(this.state.mobile), mailreg.test(this.state.mobile));
        if (!myreg.test(this.state.mobile) && !mailreg.test(this.state.mobile)) {
            this.setState({ mobileMsg: i18n.changeCellphone.formatError });
            return false;
        }
        //验证是否为活动参会者手机号
        $.post("/api/v2/fileDownload/sendAttendeeLoginCode/" + this.state.param.eventId, {
            content: this.state.mobile,
            cellphone: this.state.mobile,
            email: this.state.mobile,
            eventId: this.state.param.eventId
        }, function (result) {
            if (result.retStatus === 200) {
                that.setState({ mobileMsg: null, mobileDisable: true });
            } else if (result.retStatus === 201) {
                that.setState({ mobileMsg: "该用户未报名，请先报名" });
            } else {
                alertWarningTips(result.respObject);
            }
        }, "json");
    },

    authentification: function authentification() {
        var that = this;
        if (emptyStr(this.state.smsCode)) {
            this.setState({ smsCodeMsg: i18n.common.checkCodeNotEmptyTip });
            return false;
        }
        $.post("/api/v2/fileDownload/authentification/" + this.state.param.eventId, {
            mobile: this.state.mobile,
            content: this.state.mobile,
            smsCode: this.state.smsCode,
            type: 'LIVE',
            liveChannelId: getQueryVariable("live")
        }, function (result) {
            if (result.retStatus === 200) {
                that.hideUserAuthentication();
                alertSuccessTips(i18n.exExhibitor.success);
                $.publish("WatchLive.loadLivePlayUrl", param.liveChannelId ? param.liveChannelId : result.respObject.liveChannelId);
            } else if (result.retStatus === 201) {
                that.setState({ smsCodeMsg: "验证码错误" });
            } else {
                alertWarningTips(result.respObject);
            }
        }, "json");
    },

    render: function render() {
        var that = this;
        return React.createElement(LayerWrapper, { title: i18n.common.identityAuth, /*请先进行身份认证*/isShow: that.state.showMask, hide: that.hideUserAuthentication, width: "390px", marginTop: "20vh" }, React.createElement(FormBox.FormCon, { register: param.eventId == 6910985, confirm: that.authentification, confirmButton: i18n.siemensBri.login /*"登录"*/ }, React.createElement(FormLi.CommonFormLi, { title: i18n.attendeeDetail.attendeeCellphoneOrEmail, /*参会人员手机号*/required: true, errorMsg: this.state.mobileMsg }, React.createElement("div", { className: "clearfix" }, React.createElement("div", { className: "col-lg-8" }, React.createElement("div", { className: "input_box" }, React.createElement("input", { type: "text", name: "mobile", className: "input " + (this.state.mobileDisable && "unclickable"), value: this.state.mobile, onChange: this.handleInputChange, disabled: this.state.mobileDisable }))), React.createElement("div", { className: "col-lg-4" }, this.state.mobileDisable ? React.createElement("span", { className: "block button set sms_code_container unclickable" }, i18n.common.getCode /*获取验证码*/) : React.createElement("span", { className: "block button set sms_code_container", onClick: this.sendSmsCode }, i18n.common.getCode /*获取验证码*/)))), React.createElement(FormLi.CommonFormLi, { title: i18n.common.checkCode, /*手机验证码*/required: true, errorMsg: this.state.smsCodeMsg }, React.createElement("div", { className: "clearfix" }, React.createElement("div", null, React.createElement("div", { className: "input_box" }, React.createElement("input", { type: "text", className: "input", name: "smsCode", value: this.state.smsCode, onChange: this.handleInputChange })))))));
    }
});

$(function () {
    ReactDOM.render(React.createElement(WatchLiveLogin, null), document.getElementById('watch_live_login'));
});