import React, { Component } from 'react';
import {message} from 'antd';
import {WeaLocaleProvider} from 'ecCom';
import AttachmentFile from './index.js';

const {getLabel} = WeaLocaleProvider;

export default class Ftp extends Component {
  constructor(props) {
    super(props);
    props.getInstance && props.getInstance(this);
  }

  render() {
    return (
      <AttachmentFile ecId={`${this && this.props && this.props.ecId || ''}_AttachmentFile@alne32`} 
        filetype='1'
        record={this.props.record}
        datas={this.props.datas}
        otherParams={this.props.otherParams}
        onChange={this.props.onChange}
      />
    )  
  }

  // 校验ftp是否设置attachment_settings
  onSave = () => {
    const {
      record,
    } = this.props;
    let showMsg = false;

    if(record.attachment_settings) {
      let attachment_settings = {};

      try {
        attachment_settings = JSON.parse(record.attachment_settings);
      } catch(err){}

      if(attachment_settings.ftp_addr && attachment_settings.ftp_pwd && attachment_settings.ftp_username) {
        showMsg = true;
      }
    }

    if(!showMsg) {
      message.error(getLabel('0','请设置FTP附件转换规则的内容'));
    }

    return showMsg;
  }
}
