import React, { Component } from 'react';
import {
  WeaInput,
} from 'ecCom';

// 固定值
export default class FixedValue extends Component {
  render() {
    const {
      record,
    } = this.props;

    return (
      <WeaInput
        ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@0nerjb`}
        value={record.customsql}
        style={{width: 200}}
        onChange={this.handleChangeValue}
      />
    )
  }

  // 固定值变化时传值
  handleChangeValue = (value) => {
    const {
      record,
      datas=[],
      onChange,
    } = this.props;

    let changeAfterDatas = datas && datas.map(data => {
      if(data.fieldid === record.fieldid) {
        data.customsql = value;
      }
      return data;
    })

    // 调用父组件中的onchange方法改变值
    if(onChange && typeof(onChange) === "function") {
      onChange(changeAfterDatas);
    }
  }
}
