package com.yem.wm.bc.companytitle.dynamic;

import com.yem.wm.bc.companytitle.util.TitleFuncUtil;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.FormShowParameter;
import kd.bos.form.IFormView;
import kd.bos.form.ShowType;
import kd.bos.form.control.Control;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.servicehelper.BusinessDataServiceHelper;

import java.util.EventObject;

/**
 * @author xwudd
 * @date 18:48
 * @Description
 **/
public class AddCustomerTitleEdit  extends AbstractFormPlugin {
    @Override
    public void registerListener(EventObject e) {
        this.addClickListeners("yem_customerbankacc");
    }

    @Override
    public void click(EventObject e) {
        Control control = (Control)e.getSource();
        String key = control.getKey();
        switch (key){
            case "yem_customerbankacc" :
                selectBankInfo();
                break;
        }
    }

    @Override
    public void propertyChanged(PropertyChangedArgs e) {
        String name = e.getProperty().getName();
        switch(name){
            case "yem_customer" :
                setInfo();
                break;
        }
    }

    /**
     * @description 选择银行信息
     * @author xwudd
     * return
     * @time 2023/7/26 16:54
     */
    public void selectBankInfo(){
        IFormView view = this.getView();
        IDataModel model = this.getModel();
        DynamicObject customer = (DynamicObject) model.getValue("yem_customer");
        if(customer != null){
            FormShowParameter fsp = new FormShowParameter();
            fsp.setFormId("yem_customerbankinfor");
            fsp.getOpenStyle().setShowType(ShowType.Modal);
            fsp.setCustomParam("customer",customer);
            view.showForm(fsp);
        }else{
            view.showErrorNotification("请选择客户抬头！");
        }
    }

    public void setInfo(){
        IDataModel model = this.getModel();
        DynamicObject customer = (DynamicObject)model.getValue("yem_customer");
        TitleFuncUtil.setCustomerInfo(model,customer);
    }
}
