package com.yem.wm.im.giftrule.form;

import com.yem.wm.utils.YEM;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.form.control.Control;
import kd.bos.form.field.BasedataEdit;
import kd.bos.form.field.events.BeforeF7SelectEvent;
import kd.bos.form.field.events.BeforeF7SelectListener;
import kd.bos.ksql.util.StringUtil;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;

import java.util.EventObject;

/**
 * @author xwudd
 * @date 11:02
 * @Description
 **/
public class GiftRuleEdit extends AbstractBillPlugIn implements BeforeF7SelectListener {

    @Override
    public void registerListener(EventObject e) {
        super.registerListener(e);
        BasedataEdit productType = (BasedataEdit)this.getControl("yem_producttype");
        productType.addBeforeF7SelectListener(this);
        BasedataEdit productTypeA = (BasedataEdit)this.getControl("yem_producttypea");
        productTypeA.addBeforeF7SelectListener(this);
    }

    @Override
    public void beforeF7Select(BeforeF7SelectEvent e) {
        String name = e.getProperty().getName();
        switch(name){
            case "yem_producttype" :
            case "yem_producttypea" :
                selectF7ProductType(e);
                break;
        }
    }

    public void selectF7ProductType(BeforeF7SelectEvent e){
        IDataModel model = this.getModel();
        DynamicObject classIfy = (DynamicObject)model.getValue("yem_classify");
        if(YEM.isNotEmpty(classIfy)){
            String longNumber = classIfy.getString("number");
            e.addCustomQFilter(new QFilter("group.longnumber", QCP.like,"%" + longNumber + "%"));
        }
    }
}
