package yem.wmc.imc.formplugin.dynamic;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONArray;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.form.control.AttachmentPanel;
import kd.bos.form.control.Control;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.openapi.common.result.CustomApiResult;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.DeleteServiceHelper;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;

/**
 * @author
 * @date 2024/1/4 17:06
 * @relevantfile *绑定手工录入界面（yem_imc_collect_enter）*
 * @description 弹出手工录入登录界面
 * @versions 1.0
 */
public class InvoiceHandInputDynamic extends AbstractFormPlugin {

    @Override
    public void registerListener(EventObject e){
        super.registerListener(e);
        this.addClickListeners("yem_cancelbutton", "yem_submitbutton");
    }

    @Override
    public void click(EventObject e){

        super.click(e);
        Control source = (Control) e.getSource();
        String key = source.getKey();
        if ("yem_cancelbutton".equals(key)) {
            this.getView().returnDataToParent(null);
            this.getView().close();
        }
        if ("yem_submitbutton".equals(key)) {
            btnOk();
        }
    }

    public  void btnOk() {
        //发票代码
        String invoicecode = (String) this.getModel().getValue("yem_invoicecode");
        //发票号码
        String invoiceno = (String) this.getModel().getValue("yem_invoiceno");
//        //开票日期
        Date invoicedate = (Date) this.getModel().getValue("yem_invoicedate");
        String invoicedateString = String.valueOf(invoicedate);

        BigDecimal invoiceamount = (BigDecimal) this.getModel().getValue("yem_invoiceamount");

//        QFilter qFilter1 = new QFilter("yem_invoice_no", QCP.equals,"23922000000032305987" );
//        DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("yem_imc_electric", new QFilter[]{qFilter1});
        Map<String, Object> map = new HashMap<>();
        map.put("yem_invoicecode", invoicecode);
        map.put("yem_invoiceno",invoiceno );

        map.put("yem_invoicedate",invoicedateString );
        map.put("yem_invoiceamount",invoiceamount );
        this.getView().returnDataToParent(map);
        this.getView().close();

//      if (invoicecode.equals(dynamicObject.get("yem_invoice_code")) &&
//              invoiceno.equals(dynamicObject.get("yem_invoice_no")) ){
//
//
//      }else{
//          CustomApiResult<DynamicObject> dynamicObjectCustomApiResult = InvoiceRecognitionController.nvoiceInformationDynamicHand();
//          DynamicObject data = dynamicObjectCustomApiResult.getData();
//      }


    }

}
