package yem.wm.cm.csrm.form;

import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.datamodel.events.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.entity.earlywarn.kit.StringUtil;

/**
 * 客商类型名称
 *
 * @Author yunshuaiwei
 * @Date 2024/5/31 15:22
 **/
public class CustomersTypeNameFormPlugIn extends AbstractBillPlugIn {
    @Override
    public void propertyChanged(PropertyChangedArgs e) {
        // TODO Auto-generated method stub
        super.propertyChanged(e);
        ChangeData[] changeSet = e.getChangeSet();
        int rowIndex = changeSet[0].getRowIndex();
        String name = e.getProperty().getName();
        if (name.equals("yem_clienttype")) {
            setMerchNameType(rowIndex);
        }
    }

    private void setMerchNameType(int row) {
        IDataModel model = this.getModel();
        String clientType = (String) model.getValue("yem_clienttype", row);
        if (!StringUtil.isEmpty(clientType)) {
            if (clientType.equals("A")) {
                model.setValue("yem_merchnametype", "bd_customer", row);
            }
            if (clientType.equals("B") || clientType.equals("C")) {
                model.setValue("yem_merchnametype", "bd_supplier", row);
            }
        } else {
            model.setValue("yem_merchnametype", null, row);
        }
    }
}
