import _Message from "@alifd/next/es/message";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import * as React from 'react';
import { Component } from 'react';
import style from "./index.module.scss";
import { writePrizeAddress } from "../../../api/base";

// interface AddressComponentType {
//   touchState?: boolean
// }
// type touchStateType = boolean;
var AddressComponent = /*#__PURE__*/function (_Component) {
  _inheritsLoose(AddressComponent, _Component);
  function AddressComponent(props) {
    var _this;
    _this = _Component.call(this, props) || this;
    _this.nocheckName = function (e) {
      // 获取数据
      var value = e.target.value;
      _this.checkname(e);
      // 受控模式赋值
      _this.setState({
        username: value
      });
    };
    _this.nocheckPhone = function (e) {
      // 获取数据
      var value = e.target.value;
      // 受控模式赋值
      _this.setState({
        phone: value
      });
      _this.checkphone(e);
    };
    _this.nocheckEmail = function (e) {
      // 获取数据
      var value = e.target.value;
      // 受控模式赋值
      _this.setState({
        email: value
      });
      _this.checkemail(e);
    };
    _this.checkname = function (e) {
      // 获取数据
      var value = e.target.value;
      // 受控模式赋值
      _this.setState({
        username: value
      });
      // 校验数据
      if (value.length > 10 && value.length === 0) {
        _this.setState({
          usernameMsg: '*长度必须<10',
          mustName: true
        });
        // console.log("eeeee", e.target)
      } else {
        _this.setState({
          mustName: false
        });
      }
    };
    _this.checkphone = function (e) {
      // 获取数据
      var value = e.target.value;
      // 受控模式赋值
      _this.setState({
        phone: value
      });
      // 校验数据
      if (!value.match(/^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/)) {
        _this.setState({
          phoneMsg: '*请输入正确的号码',
          mustPhone: true
        });
      } else {
        _this.setState({
          mustPhone: false
        });
      }
    };
    _this.checkemail = function (e) {
      // 获取数据
      var value = e.target.value;
      // 受控模式赋值
      _this.setState({
        email: value
      });
      // 校验数据
      // if (!value.match(/^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,5}$/)) {
      // 改成收件地址
      if (value.length === 0) {
        _this.setState({
          // emailMsg: '*请输入正确的邮箱号码',
          emailMsg: '*请输入收件地址',
          mustEmail: true
        });
      } else {
        _this.setState({
          mustEmail: false
        });
      }
    };
    _this.handleSubmit = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
      var obj, _yield$writePrizeAddr, code;
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              if (!(_this.state.mustName || _this.state.mustPhone || _this.state.mustEmail)) {
                _context.next = 4;
                break;
              }
              return _context.abrupt("return", _Message.error('您填写的信息不符合要求,请修改后提交'));
            case 4:
              obj = {
                a1: _this.state.drawMessage,
                // 71
                b: _this.state.activityId,
                d: _this.state.singerID,
                i: _this.state.username,
                // 收货人姓名
                j: _this.state.email,
                // 收货地址
                m: _this.state.phone // 收货人手机
              }; // console.log("this.state.drawMessage", this.state.drawMessage)
              _context.next = 7;
              return writePrizeAddress(obj);
            case 7:
              _yield$writePrizeAddr = _context.sent;
              code = _yield$writePrizeAddr.code;
              if (!(code === 200)) {
                _context.next = 12;
                break;
              }
              // 关闭弹窗
              _this.touchStart();
              return _context.abrupt("return", _Message.success('小主: 您的地址已提交成功啦，稍后我们的工作人员将会与您联系。'));
            case 12:
            case "end":
              return _context.stop();
          }
        }
      }, _callee);
    }));
    _this.handleTip = function (placeholder) {
      return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
        className: style.warinTip
      }), {
        placeholder: placeholder
      });
    };
    _this.state = {
      // ...props.data,
      username: '',
      phone: '',
      email: '',
      usernameMsg: '',
      phoneMsg: '',
      emailMsg: '',
      touchState: false,
      mustName: true,
      mustPhone: true,
      mustEmail: true
    };
    return _this;
  }

  // eslint-disable-next-line react/no-deprecated
  var _proto = AddressComponent.prototype;
  _proto.componentWillReceiveProps = function componentWillReceiveProps(props) {
    this.setState({
      touchState: props.touchState,
      drawMessage: props.drawMessage,
      activityId: props.activityId,
      singerID: props.singerID
    });
  };
  _proto.touchStart = function touchStart() {
    // this.setState({
    //   touchState: !touchState
    // })
    this.setState(function (prevState) {
      return {
        touchState: !prevState.touchState
      };
    });
  };
  _proto.render = function render() {
    // 获取数据和错误信息
    // const { username, phone, email usernameMsg, phoneMsg, emailMsg } = this.state;
    var _this$state = this.state,
      username = _this$state.username,
      phone = _this$state.phone,
      email = _this$state.email,
      usernameMsg = _this$state.usernameMsg,
      phoneMsg = _this$state.phoneMsg,
      emailMsg = _this$state.emailMsg;
    return /*#__PURE__*/React.createElement("div", null, this.state.touchState ? /*#__PURE__*/React.createElement("div", {
      className: style.ThePage
    }, /*#__PURE__*/React.createElement("div", {
      className: style.ThePage
    }, /*#__PURE__*/React.createElement("div", {
      className: style.whiteBox
    }, /*#__PURE__*/React.createElement("div", {
      className: style.header
    }, /*#__PURE__*/React.createElement("div", {
      className: style.img
    }, /*#__PURE__*/React.createElement("div", {
      className: style['header-text']
    }, /*#__PURE__*/React.createElement("div", null, "\u586B\u5199\u4FE1\u606F"), /*#__PURE__*/React.createElement("div", null, "\u8BF7\u8BA4\u771F\u586B\u5199\u4EE5\u4E0B\u4FE1\u606F \u4EE5\u4FBF\u5956\u54C1\u53D1\u653E")), /*#__PURE__*/React.createElement("div", {
      className: style['header-icon'],
      onClick: this.touchStart.bind(this)
    }))), /*#__PURE__*/React.createElement("div", {
      className: style['input-style']
    }, /*#__PURE__*/React.createElement("div", {
      className: style['form-style']
    }, /*#__PURE__*/React.createElement("form", null, /*#__PURE__*/React.createElement("div", {
      className: style['item-Style']
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        margin: '0 1em'
      }
    }, "\u59D3\u540D\uFF1A"), /*#__PURE__*/React.createElement("input", {
      value: username,
      onChange: this.nocheckName
    })), /*#__PURE__*/React.createElement("div", {
      className: style['item-Style']
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        margin: '0 1em'
      }
    }, "\u8054\u7CFB\u7535\u8BDD:"), /*#__PURE__*/React.createElement("input", {
      value: phone,
      onChange: this.nocheckPhone
    })), /*#__PURE__*/React.createElement("div", {
      className: style['item-Style']
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        margin: '0 1em'
      }
    }, "\u5730\u5740:"), /*#__PURE__*/React.createElement("input", {
      value: email,
      onChange: this.nocheckEmail
    }))), /*#__PURE__*/React.createElement("div", {
      className: style.btn
    }, /*#__PURE__*/React.createElement("button", {
      type: "submit",
      onClick: this.handleSubmit,
      className: style['submit-btn']
    }, "\u63D0\u4EA4"))))))) : /*#__PURE__*/React.createElement("div", null));
  };
  return AddressComponent;
}(Component);
AddressComponent.displayName = 'AddressComponent';
export { AddressComponent as default };