import _Message from "@alifd/next/es/message";
import { useState } from 'react';
import cosUpload from "../../../module/axios/cosUpload";
import style from "../index.module.scss";
function FormUpload(props) {
  // eslint-disable-next-line react/prop-types
  var className = props.className,
    option = props.option,
    onChange = props.onChange;
  var _useState = useState(''),
    imageUrl = _useState[0],
    setImageUrl = _useState[1];
  var onUploadChange = function onUploadChange(e) {
    var file = e === null || e === void 0 ? void 0 : e.target.files[0];
    cosUpload(file, {
      pathDir: 'xtForm',
      reName: true
    }).then(function (_ref) {
      var code = _ref.code,
        data = _ref.data,
        msg = _ref.msg;
      if (code === '0000') {
        option && Object.assign(option, {
          image: data.ossPath
        });
        onChange && onChange(data.ossPath);
        setImageUrl(data.ossPath);
        _Message.success('上传成功');
      } else _Message.error(msg);
    });
  };
  var onClose = function onClose() {
    setImageUrl('');
    option && Object.assign(option, {
      image: ''
    });
    onChange && onChange('');
  };
  return /*#__PURE__*/React.createElement("div", {
    className: style['form-upload-content'] + " " + (className !== null && className !== void 0 ? className : '')
  }, imageUrl ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("img", {
    src: imageUrl
  }), /*#__PURE__*/React.createElement("span", {
    className: style['form-upload-close'] + " xiatu-rich xt-del",
    onClick: onClose
  })) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("input", {
    type: "file",
    accept: ".jpg,.jpeg,.png,.gif",
    onChange: onUploadChange
  }), /*#__PURE__*/React.createElement("span", {
    className: "xiatu-rich xt-gongjulan-xinzeng-chatu"
  }), /*#__PURE__*/React.createElement("span", {
    className: "form-upload-text"
  }, "\u4E0A\u4F20\u56FE\u7247")));
}
export default FormUpload;