/*
 * Author: 黎永顺
 * name: 在线申报-缴款弹框
 * Description:
 * Date: 2023/8/22
 */
import React, { Component } from "react";
import { inject, observer } from "mobx-react";
import { WeaDialog } from "ecCom";
import { getSearchs } from "../../../util";

@inject("declareStore")
@observer
class PaymentDialog extends Component {
  componentWillReceiveProps(nextProps, nextContext) {
    const { declareStore: { paymentForm, changePaymentForm }, conditions } = nextProps;
    if (nextProps.visible !== this.props.visible && nextProps.visible && nextProps.conditions) {
      paymentForm.initFormFields(conditions);
    }
    if (nextProps.visible !== this.props.visible && !nextProps.visible) {
      paymentForm.resetForm();
      changePaymentForm();
    }
  }

  handleChange = (val) => {
    const key = Object.keys(val)[0];
    if (key === "protocolNumber") {
      const { declareStore: { paymentForm } } = this.props;
      paymentForm.updateFields({
        count: val[key].value,
        paymentNumber: val[key].value,
      });
    }
  };

  render() {
    const { conditions, declareStore: { paymentForm } } = this.props;
    return (
      <WeaDialog
        {...this.props} className="paymentDialog" initLoadCss
        style={{ width: 550 }}
      >
        <div className="paymentDialogContent">
          {!_.isEmpty(conditions) && getSearchs(paymentForm, conditions, 1, false, this.handleChange)}
        </div>
      </WeaDialog>
    );
  }
}

export default PaymentDialog;
