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

const {getLabel} = WeaLocaleProvider;

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

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

  // 校验db是否设置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.db_field_title) {
        showMsg = true;
      }
    }

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

    return showMsg;
  }
}