"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));

require("regenerator-runtime/runtime");

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));

require("./Questionnaire.css");

var _Modal = _interopRequireDefault(require("../Modal"));

var _Rate = _interopRequireDefault(require("../Rate"));

var _Button = _interopRequireDefault(require("../Button"));

var _Nps = _interopRequireDefault(require("./Nps"));

var _Input = _interopRequireDefault(require("../Input"));

var _confim = _interopRequireDefault(require("../confim"));

var _component = require("../_utils/component");

var _vm2 = _interopRequireDefault(require("./vm"));

var _vueNormalizeComponent = _interopRequireDefault(require("../_utils/vue-normalize-component.js"));

/* script */
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
var Textarea = _Input.default.Textarea;
var __vue_script__ = {
  name: (0, _component.createComponentName)('questionnaire'),
  components: {
    Modal: _Modal.default,
    Nps: _Nps.default,
    Rate: _Rate.default,
    Button: _Button.default,
    Textarea,
    GdInput: _Input.default
  },
  mixins: [_component.componentMixin],
  props: {
    onCancel: {
      type: Function
    },
    afterClose: {
      type: Function
    },
    // 居中
    centered: {
      type: Boolean,
      default: true
    },
    visible: {
      type: Boolean,
      default: false
    },
    onOk: {
      type: Function
    }
  },

  data() {
    return {
      vm: new _vm2.default(),
      loading: false,
      error: false
    };
  },

  methods: {
    getInfo(postion) {
      return this.vm.getInfo(postion, '123489');
    },

    onError(e) {
      var _this = this;

      var promise = _confim.default.error({
        title: '提交失败',
        subTitle: e.message,
        okText: '重新提交',
        onOk: function () {
          var _onOk = (0, _asyncToGenerator2.default)(
          /*#__PURE__*/
          _regenerator.default.mark(function _callee() {
            var res;
            return _regenerator.default.wrap(function _callee$(_context) {
              while (1) {
                switch (_context.prev = _context.next) {
                  case 0:
                    promise.vm.update({
                      okText: '提交中...'
                    });
                    _context.next = 3;
                    return _this.vm.submit(e).then(function () {
                      _this.onSuccess();

                      return true;
                    }).catch(function (e) {
                      promise.vm.update({
                        subTitle: e.message
                      });
                      return false;
                    });

                  case 3:
                    res = _context.sent;
                    promise.vm.update({
                      okText: '重新提交'
                    });
                    return _context.abrupt("return", res);

                  case 6:
                  case "end":
                    return _context.stop();
                }
              }
            }, _callee, this);
          }));

          function onOk() {
            return _onOk.apply(this, arguments);
          }

          return onOk;
        }()
      });

      return promise;
    },

    onSuccess() {
      return _confim.default.success({
        title: '提交成功',
        subTitle: '感谢你的评价',
        time: 1000
      });
    },

    onSubmit(e) {
      var _this2 = this;

      return (0, _asyncToGenerator2.default)(
      /*#__PURE__*/
      _regenerator.default.mark(function _callee4() {
        return _regenerator.default.wrap(function _callee4$(_context4) {
          while (1) {
            switch (_context4.prev = _context4.next) {
              case 0:
                e.preventDefault();

                if (!(_this2.vm.feedback.length > 500 || _this2.vm.contact.length > 30)) {
                  _context4.next = 6;
                  break;
                }

                _this2.error = true;
                clearTimeout(_this2.timer);
                _this2.timer = setTimeout(function () {
                  _this2.error = false;
                }, 2000);
                return _context4.abrupt("return");

              case 6:
                _this2.loading = true;
                _context4.next = 9;
                return _this2.vm.submit().then(
                /*#__PURE__*/
                (0, _asyncToGenerator2.default)(
                /*#__PURE__*/
                _regenerator.default.mark(function _callee2() {
                  return _regenerator.default.wrap(function _callee2$(_context2) {
                    while (1) {
                      switch (_context2.prev = _context2.next) {
                        case 0:
                          _this2.loading = false;
                          _this2.visible = false;
                          _context2.next = 4;
                          return _this2.onSuccess();

                        case 4:
                          _this2.onOk();

                        case 5:
                        case "end":
                          return _context2.stop();
                      }
                    }
                  }, _callee2, this);
                }))).catch(
                /*#__PURE__*/
                function () {
                  var _ref2 = (0, _asyncToGenerator2.default)(
                  /*#__PURE__*/
                  _regenerator.default.mark(function _callee3(e) {
                    return _regenerator.default.wrap(function _callee3$(_context3) {
                      while (1) {
                        switch (_context3.prev = _context3.next) {
                          case 0:
                            _this2.visible = false;
                            _this2.loading = false;
                            _context3.next = 4;
                            return _this2.onError(e);

                          case 4:
                            _this2.onCancel();

                          case 5:
                          case "end":
                            return _context3.stop();
                        }
                      }
                    }, _callee3, this);
                  }));

                  return function (_x) {
                    return _ref2.apply(this, arguments);
                  };
                }());

              case 9:
              case "end":
                return _context4.stop();
            }
          }
        }, _callee4, this);
      }))();
    }

  }
};
/* template */

var __vue_render__ = function __vue_render__() {
  var _vm = this;

  var _h = _vm.$createElement;

  var _c = _vm._self._c || _h;

  return _c("Modal", {
    class: _vm.bem("modal"),
    attrs: {
      visible: _vm.visible,
      onCancel: _vm.onCancel,
      afterClose: _vm.afterClose,
      maskClosable: false,
      keyborad: false,
      width: "872px"
    }
  }, [_c("form", {
    class: _vm.bem(),
    on: {
      submit: _vm.onSubmit
    }
  }, [_c("img", {
    attrs: {
      src: require("./assets/slidebar.png"),
      alt: "slidebar"
    }
  }), _vm._v(" "), _c("div", {
    class: _vm.bem("content")
  }, [_c("div", {
    class: _vm.bem("label")
  }, [_c("span", {
    class: _vm.bem("tag")
  }, [_c("div", [_vm._v("必填")])]), _vm._v("\n                请评价本次编辑体验：\n            ")]), _vm._v(" "), _c("Rate", {
    class: _vm.bem("rate"),
    model: {
      value: _vm.vm.rate,
      callback: function callback($$v) {
        _vm.$set(_vm.vm, "rate", $$v);
      },
      expression: "vm.rate"
    }
  }), _vm._v(" "), _c("div", {
    class: _vm.bem("label")
  }, [_c("span", {
    class: _vm.bem("tag")
  }, [_c("div", [_vm._v("必填")])]), _vm._v("\n                你愿意把“稿定设计”推荐给你的朋友吗？\n            ")]), _vm._v(" "), _c("nps", {
    class: _vm.bem("nps"),
    model: {
      value: _vm.vm.nps,
      callback: function callback($$v) {
        _vm.$set(_vm.vm, "nps", $$v);
      },
      expression: "vm.nps"
    }
  }), _vm._v(" "), _c("div", {
    class: _vm.bem("feedback")
  }, [_c("Textarea", {
    attrs: {
      placeholder: "你给出这个分数的原因？说说你的建议"
    },
    model: {
      value: _vm.vm.feedback,
      callback: function callback($$v) {
        _vm.$set(_vm.vm, "feedback", $$v);
      },
      expression: "vm.feedback"
    }
  }), _vm._v(" "), _c("transition", {
    attrs: {
      name: "gd-fade"
    }
  }, [_vm.error && _vm.vm.feedback.length > 500 ? _c("div", {
    class: _vm.bem("error")
  }, [_vm._v("输入字数已超出限制  " + _vm._s(_vm.vm.feedback.length) + "/500")]) : _vm._e()])], 1), _vm._v(" "), _c("div", {
    class: _vm.bem("contact")
  }, [_c("GdInput", {
    attrs: {
      placeholder: "你的联系方式？"
    },
    model: {
      value: _vm.vm.contact,
      callback: function callback($$v) {
        _vm.$set(_vm.vm, "contact", $$v);
      },
      expression: "vm.contact"
    }
  }), _vm._v(" "), _c("transition", {
    attrs: {
      slot: "append",
      name: "gd-fade"
    },
    slot: "append"
  }, [_vm.error && _vm.vm.contact.length > 30 ? _c("div", {
    class: _vm.bem("error")
  }, [_vm._v("输入字数已超出限制  " + _vm._s(_vm.vm.contact.length) + "/30")]) : _vm._e()])], 1), _vm._v(" "), _c("div", {
    class: _vm.bem("footer")
  }, [_c("Button", {
    attrs: {
      type: "primary",
      disabled: !_vm.vm.canSubmit,
      loading: _vm.loading
    }
  }, [_vm._v(_vm._s(_vm.loading ? "提交评价中..." : "提交评价"))])], 1)], 1)])]);
};

var __vue_staticRenderFns__ = [];
__vue_render__._withStripped = true;
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = undefined;
/* module identifier */

var __vue_module_identifier__ = undefined;
/* functional template */

var __vue_is_functional_template__ = false;
/* component normalizer */

/* style inject */

/* style inject SSR */
var _default = (0, _vueNormalizeComponent.default)({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);

exports.default = _default;