/*
 * Creater:     shizi
 * CreateDate:  2022/03/31
 * Describe：   单位设置
 * */
import React, { Component } from 'react';
import DynamicRenderingForm from 'pages/common/DynamicRenderingForm';
import '../style/new-drug.less';

class UnitSetting extends Component {
  componentDidMount() {
    this.props.onRef && this.props.onRef(this);
  }

  // 表单赋值
  setFieldsValue = (values) => {
    this.formRef && this.formRef.setFieldsValue(values);
  }

  // 获取表单单个字段的值
  getFieldValue = (dataIndex) => {
    let value = this.formRef && this.formRef.getFieldValue(dataIndex);
    return value;
  }

  // 获取数据
  getFieldsValue = () => {
    let medObj = this.formRef && this.formRef.getFieldsValue() || {}
    return medObj;
  }

  // 保存
  handleSave = () => {
    let medObj = this.formRef && this.formRef.handleSave() || {}
    return medObj;
  }

  // 重置
  resetFields = () => {
    this.formRef && this.formRef.resetFields();
  }

  render() {
    let { title, desc, result, rowData, formData } = this.props;
    return (
      <div className='inventory-item'>
        <div className='inventory-item-header'>
          <div className='inventory-item-header-title'>
            {title}<span style={{ display: desc ? 'inline-block' : 'none' }}>（{desc}）</span>
          </div>
          <div style={{ display: result ? 'inline-block' : 'none' }} className='inventory-item-header-desc'>
            预览：{result}
          </div>
        </div>
        <DynamicRenderingForm
          formItemCol={{ labelCol: 8, wrapperCol: 16 }}
          rowData={rowData}
          formData={formData}
          onRef={ref => this.formRef = ref}
        />
      </div>
    )
  }
};

export default UnitSetting;