/*
 * Create:      柿子
 * CreateDate:  2022/09/06
 * Describe：   库房 - 出库 - 库存转移制单【弃用】
 * */
import React, { Component } from 'react';
import { Card, Row, Col, Button, Menu, Dropdown, Icon } from 'antd';
import DynamicRenderingForm from 'pages/common/DynamicRenderingForm';
import VoucherPreparationDetails from './component/VoucherPreparationDetails';
import iconInquire from 'assets/images/icon_Inquire.png';
import './style/index.less';

class TransferVoucherPreparation extends Component {
  constructor(props) {
    super(props);
    let userData = React.$getSessionData();
    this.state = {
      userData,
      selectData: {},
      queryRowData: {},
      queryFormData: [],
      headerClientHeight: 242
    };

    this.inputFormData = [{
      required: 'Y',
      title: '产品名称',
      typeCode: 'Input',
      dataIndex: 'stockDesc',
    }, {
      required: 'Y',
      title: '出库数量',
      typeCode: 'InputNumber',
      dataIndex: 'num',
    }, {
      required: 'Y',
      title: '单位',
      typeCode: 'Select',
      dataIndex: 'unit',
    }, {
      disabled: 'Y',
      title: '产品代码',
      typeCode: 'Input',
      dataIndex: 'stockCode',
    }, {
      disabled: 'Y',
      title: '品牌',
      typeCode: 'Select',
      dataIndex: 'brandID',
    }, {
      disabled: 'Y',
      title: '品种',
      typeCode: 'Select',
      dataIndex: 'varietiesID',
    }, {
      disabled: 'Y',
      title: '规格型号',
      typeCode: 'Input',
      dataIndex: 'stockSpec',
    }, {
      disabled: 'Y',
      title: '生产厂家',
      typeCode: 'Select',
      dataIndex: 'manufID',
    }, {
      disabled: 'Y',
      title: '进口国产',
      typeCode: 'Select',
      dataIndex: 'operTypeID',
    }, {
      disabled: 'Y',
      title: '产地',
      typeCode: 'Select',
      dataIndex: 'placeOrigin',
    }, {
      disabled: 'Y',
      title: '医院进价',
      typeCode: 'Input',
      dataIndex: 'hospRp',
    }, {
      disabled: 'Y',
      title: '医院售价',
      typeCode: 'Input',
      dataIndex: 'sp',
    }, {
      disabled: 'Y',
      title: '可用数量',
      typeCode: 'Input',
      dataIndex: 'rpAmt',
    }, {
      disabled: 'Y',
      title: '请求数量',
      typeCode: 'InputNumber',
      dataIndex: 'spAmt',
    }, {
      disabled: 'Y',
      title: '占用数量',
      typeCode: 'InputNumber',
      dataIndex: 'batchNumber',
    }, {
      disabled: 'Y',
      title: '批次库存',
      typeCode: 'Input',
      dataIndex: 'ProductCode',
      placeholder: '自动显示',
    }, {
      title: '备注',
      typeCode: 'TextArea',
      dataIndex: 'remarks',
    }];

    this.headerCardRef = React.createRef();
  }

  componentDidMount() {
    this.getQueryFormData();
  }

  // 获取下拉框数据
  getSelectData = async () => {
    try {
      let { userData } = this.state;
      let data = {
        params: [{
          hospID: userData?.hospID || ''
        }]
      }
      let res = await React.$asyncPost(this, '17060001', data);
      this.setState({ selectData: res, statusID: res?.defaultStatusID || '' }, () => {
        this.getQueryFormData();
      });
    } catch (error) {
      this.setState({ selectData: {} });
    }
  }

  // 获取查询表单数据
  getQueryFormData = () => {
    let { selectData } = this.state;
    let queryFormData = [{
      required: 'Y',
      title: '供给科室',
      typeCode: 'Select',
      dataIndex: 'inOperLocID',
      detailItem: selectData && 'loc' in selectData ? selectData.loc : [],
    }, {
      required: 'Y',
      title: '出库类型',
      typeCode: 'Select',
      dataIndex: 'operTypeID',
      detailItem: selectData && 'loc' in selectData ? selectData.loc : [],
    }, {
      required: 'Y',
      title: '出库人员',
      typeCode: 'Select',
      dataIndex: 'purUserID',
      detailItem: selectData && 'loc' in selectData ? selectData.loc : [],
    }, {
      required: 'Y',
      title: '请求科室',
      typeCode: 'Select',
      dataIndex: 'vendorID',
      detailItem: selectData && 'loc' in selectData ? selectData.loc : [],
    }, {
      title: '制单日期',
      typeCode: 'Date',
      dataIndex: 'createDate',
    }, {
      title: '出库备注',
      typeCode: 'Input',
      dataIndex: 'remark',
    }, {
      title: '库存子类',
      typeCode: 'Select',
      dataIndex: 'stkCatID',
      detailItem: selectData && 'loc' in selectData ? selectData.loc : [],
    }, {
      title: '入库单号',
      typeCode: 'Input',
      dataIndex: 'No',
      placeholder: '保存后自动生成单号',
    }, {
      col: 4,
      title: '赠送标志',
      typeCode: 'Switch',
      dataIndex: 'giftFlag',
      formItemCol: { labelCol: 16, wrapperCol: 8 },
    }, {
      col: 3,
      title: '调价换票',
      typeCode: 'Switch',
      dataIndex: 'adjCheque',
      formItemCol: { labelCol: 12, wrapperCol: 12 }
    }, {
      title: '单据状态',
      typeCode: 'Select',
      dataIndex: 'statusID',
      detailItem: selectData && 'loc' in selectData ? selectData.loc : [],
    }];
    this.setState({ queryFormData }, () => {
      let clientHeight = this.headerCardRef.current?.clientHeight || 242;
      this.setState({ headerClientHeight: clientHeight })
    })
  }

  // 入库辅助制单操作
  handleMoreBtnClick = e => {
    console.log('e', e)
  }

  // 保存
  handleSave = async () => {
    try {
      let values = await this.queryFormRef.handleSave();
      console.log("values", values)
    } catch (error) {
      console.log(error)
    }
  }

  // 重置表单数据
  handleReset = () => {
    this.queryFormRef && this.queryFormRef.resetFields();
  }

  render() {
    const { selectData, queryRowData, queryFormData, headerClientHeight } = this.state;
    const moreBtnMenu = (
      <Menu onClick={this.handleMoreBtnClick}>
        <Menu.Item key="1">依据订单</Menu.Item>
        <Menu.Item key="2">已审核入库单</Menu.Item>
      </Menu>
    );

    return (
      <div className="voucher-preparation receipt-voucher-preparation">
        <Card
          size="small"
          bordered={false}
          title={(
            <div className="card-title-left-img">
              <img src={iconInquire} alt="" />
              出库制单
            </div>
          )}
        >
          <Row>
            <Col span={16}>
              <DynamicRenderingForm
                formItemCol={{ labelCol: 8, wrapperCol: 16, col: 8 }}
                rowData={queryRowData}
                formData={queryFormData}
                onRef={ref => this.queryFormRef = ref}
              />
            </Col>
            <Col span={8} className="voucher-preparation-operation">
              <Row>
                <Button style={{ width: '88px' }}>历史单据</Button>
                <Button style={{ width: '88px', marginLeft: 20 }} onClick={this.handleReset}>重置</Button>
              </Row>
              <Row>
                <Button style={{ width: '88px', marginRight: 20 }} type="primary" onClick={this.handleSave}>保存</Button>
                <Button style={{ width: '88px' }} type="danger">删除</Button>
              </Row>
              <Row>
                <Button style={{ width: '88px', marginRight: 20 }} ghost type="primary">完成</Button>
                <Button style={{ width: '88px' }} ghost type="danger">取消完成</Button>
              </Row>
              <Row>
                <Button style={{ width: '88px', marginRight: 20 }}>打印</Button>
                <Dropdown overlay={moreBtnMenu}>
                  <Button>
                    辅助出库
                    <Icon type="down" />
                  </Button>
                </Dropdown>
              </Row>
            </Col>
          </Row>
        </Card>
        <VoucherPreparationDetails headerHeight={headerClientHeight} selectData={selectData} formData={this.inputFormData} rpTotal="12345.12" spTotal="4623.09" />
      </div>
    )
  }
};

export default TransferVoucherPreparation;