import { _ as _extends } from '../_rollupPluginBabelHelpers-736b301a.js';
import React__default, { Component } from 'react';
import { Radio, InputNumber, Form, Select, message, Button, Input } from 'antd';
import Modal from '../Modal/index.js';
import { BaseStore, Service, LMConfig } from '@zenview/micro-basic-library';
import { cache } from '@zenview/micro-utils';

const RadioGroup$1 = Radio.Group;
class numberSelection extends Component {
  constructor(...args) {
    super(...args);
    this.state = {
      radioValue: 1,
      // 类型选择 1-全时 2-自定义
      value: this.props.value || []
    };
    this.onChangeRadioValue = e => {
      this.props.ChangeExportType(e.target.value);
      this.onOk(e.target.value === 1 ? 1000 : '');
      this.setState({
        radioValue: e.target.value
      });
    };
    this.onOk = e => {
      const {
        onChange
      } = this.props;
      onChange && onChange(e);
    };
    this.onChange = e => {
      this.onOk(e);
    };
  }
  componentDidMount() {
    this.state.radioValue === 1 && this.onOk(1000);
  }
  render() {
    const {
      radioValue
    } = this.state;
    return /*#__PURE__*/React__default.createElement("div", {
      className: "form-group-item-content capture_time"
    }, /*#__PURE__*/React__default.createElement(RadioGroup$1, {
      onChange: this.onChangeRadioValue,
      value: radioValue
    }, /*#__PURE__*/React__default.createElement(Radio, {
      value: 1
    }, "\u5168\u90E8"), /*#__PURE__*/React__default.createElement(Radio, {
      value: 2,
      style: {
        marginLeft: '16px'
      }
    }, "\u81EA\u5B9A\u4E49")), /*#__PURE__*/React__default.createElement("br", null), radioValue === 2 && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, "\u5BFC\u51FA\u524D ", /*#__PURE__*/React__default.createElement(InputNumber, {
      placeholder: "\u8BF7\u8F93\u5165\u5BFC\u51FA\u6570\u91CF",
      className: "export-number",
      step: 1,
      min: 1,
      max: this.props.maxValue,
      onChange: this.onChange
    }), " \u6761\u6570\u636E"));
  }
}

const RadioGroup = Radio.Group;
const {
  TextArea
} = Input;
const FormItem = Form.Item;
const Option = Select.Option;
function fromLocaltype() {
  const fromLocaltype = [{
    label: '开车打电话历史告警',
    value: '101531',
    exportType: 'drivephone'
  }, {
    label: '未系安全带历史告警',
    value: '101532',
    exportType: 'nosafetybelt'
  }, {
    label: '套牌车分析历史告警',
    value: '101533',
    exportType: 'platevehicleanalyse'
  }, {
    label: '机动车以图搜图',
    value: '1',
    exportType: 'vehicle'
  }, {
    label: '非机动车以图搜图',
    value: '2',
    exportType: 'nonvehicle'
  }, {
    label: '人脸以图搜图',
    value: '3',
    exportType: LMConfig.BSConfig.goFeatureSearch ? 'facesByIndexServer' : 'faceByAidAndVio'
  }, {
    label: '人体以图搜图',
    value: '4',
    exportType: 'body'
  }, {
    label: '遮阳板监测',
    value: '5',
    exportType: 'dunvisor'
  }, {
    label: '未系全带',
    value: '6',
    exportType: 'nosafetybelt'
  }, {
    label: '开车打电话',
    value: '7',
    exportType: 'carphone'
  }, {
    label: '伴随人员分析',
    value: '8',
    exportType: 'followPerson'
  }, {
    label: '人脸碰撞',
    value: '9',
    exportType: 'personCollision'
  }, {
    label: '车辆碰撞',
    value: '10',
    exportType: 'vehicleCollision'
  }];
  return fromLocaltype;
}
class DownloadTools extends React__default.Component {
  constructor(props) {
    super(props);
    this.formRef = /*#__PURE__*/React__default.createRef();
    //打开导出面板
    this.onClick = () => {
      this.setState({
        visible: true
      });
    };
    this.ChangeExportType = e => {
      this.exportType = e;
    };
    //提交导出结果
    this.onSubmit = () => {
      let {
        option,
        total = 0
      } = this.props;
      if (this.exportType !== 2 && total && total > 1000) {
        message.warn('最多导出1000条');
        return false;
      }
      option.offset = 0;
      if (this.exportType === 1) {
        option.limit = 1000;
      }
      this.formRef.current.validateFields().then(values => {
        if (values.listNumber > 1000) {
          message.warn('最多导出1000条');
          return false;
        }
        let options = {
          bizJson: {
            exportType: this.fromLocaltype.filter(item => item.label === values.fromLocal)[0].exportType,
            queryCondition: option,
            needPic: values.isHasPic,
            limit: values.listNumber || total,
            operationCenterId: BaseStore.app.userInfo.operationCenterId,
            organizationId: BaseStore.app.userInfo.organizationId
          },
          flowKey: 'imageExport',
          remark: values.reason || ''
        };
        Service.$http({
          headers: {
            Authorization: cache.getCache('token', 'session')
          },
          method: 'post',
          url: `/api/gam/workflow/v1/createFlow`,
          data: options
        }).then(res => {
          res.code === 0 ? message.success('提交成功') : message.error(res.message);
          this.onClose();
        });
      });
    };
    //取消导出申请
    this.onClose = () => {
      this.setState({
        visible: !this.state.visible
      });
    };
    this.fromLocaltype = props.fromLocaltype || fromLocaltype();
    this.state = {
      visible: false //控制导出的显示隐藏
    };
    this.exportType = 1;
  }
  render() {
    var _BSConfig$microServic;
    const {
      visible
    } = this.state;
    const BSConfig = LMConfig.BSConfig || {};
    let {
      fromLocal,
      total = 1000
    } = this.props;
    const formItemLayout = {
      labelCol: {
        span: 5
      },
      wrapperCol: {
        span: 18
      }
    };
    return (_BSConfig$microServic = BSConfig.microService) !== null && _BSConfig$microServic !== void 0 && _BSConfig$microServic.approval ? /*#__PURE__*/React__default.createElement("span", {
      className: "download-tools-box"
    }, /*#__PURE__*/React__default.createElement(Button, {
      type: "primary",
      onClick: this.onClick
    }, "\u5BFC\u51FA"), /*#__PURE__*/React__default.createElement(Modal, {
      visible: visible,
      title: '导出申请',
      onOk: this.onSubmit,
      onCancel: () => this.onClose(),
      className: "preset-name",
      okText: '提交'
    }, /*#__PURE__*/React__default.createElement(Form, {
      ref: this.formRef
    }, /*#__PURE__*/React__default.createElement(FormItem, _extends({
      label: "\u5BFC\u51FA\u6570\u91CF",
      name: "listNumber"
      // initialValue={1000}
      ,
      rules: [{
        required: true,
        message: '导出数量必填并且不能大于1000'
      }, {
        validator: (_, value) => value > 1000 ? Promise.reject('导出数量不能大于1000') : Promise.resolve()
      }]
    }, formItemLayout), /*#__PURE__*/React__default.createElement(numberSelection, {
      ChangeExportType: this.ChangeExportType,
      maxValue: total
    })), /*#__PURE__*/React__default.createElement(FormItem, _extends({
      label: "\u5BFC\u51FA\u56FE\u7247",
      name: "isHasPic",
      initialValue: true,
      rules: [{
        required: true,
        message: '请选择是否导出图片'
      }]
    }, formItemLayout), /*#__PURE__*/React__default.createElement(RadioGroup, null, /*#__PURE__*/React__default.createElement(Radio, {
      value: true
    }, "\u662F"), /*#__PURE__*/React__default.createElement(Radio, {
      value: false,
      style: {
        marginLeft: '16px'
      }
    }, "\u5426"))), /*#__PURE__*/React__default.createElement(FormItem, _extends({
      label: "\u5BFC\u51FA\u7C7B\u578B",
      name: "fileType",
      initialValue: "Excel\u6587\u4EF6",
      rules: [{
        required: true,
        message: '请选择导出类型'
      }]
    }, formItemLayout), /*#__PURE__*/React__default.createElement(Select, {
      style: {
        width: '100%'
      },
      disabled: true,
      placeholder: "\u8BF7\u9009\u62E9\u7C7B\u578B",
      showSearch: true,
      allowClear: true,
      className: "nation-select",
      filterOption: (input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
    }, /*#__PURE__*/React__default.createElement(Option, {
      value: "Excel\u6587\u4EF6"
    }, "Excel\u6587\u4EF6"), /*#__PURE__*/React__default.createElement(Option, {
      value: "PDF\u6587\u4EF6"
    }, "PDF\u6587\u4EF6"))), /*#__PURE__*/React__default.createElement(FormItem, _extends({
      label: "\u6240\u5728\u6A21\u5757",
      name: "fromLocal",
      required: true,
      initialValue: this.fromLocaltype.filter(item => item.value === fromLocal)[0].label
    }, formItemLayout), /*#__PURE__*/React__default.createElement(Input, {
      disabled: true
    })), /*#__PURE__*/React__default.createElement(FormItem, _extends({
      label: "\u5BFC\u51FA\u539F\u56E0",
      name: "reason",
      rules: [{
        required: false,
        message: '请输入导出原因'
      }, {
        max: 50,
        message: '最大长度为50'
      }]
    }, formItemLayout), /*#__PURE__*/React__default.createElement(TextArea, {
      autoSize: {
        minRows: 6,
        maxRows: 6
      }
    }))))) : null;
  }
}

export { DownloadTools as default, fromLocaltype };
//# sourceMappingURL=index.js.map
