package com.yem.wm.bd.tandardcon.from;

import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
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.list.ListShowParameter;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;

import java.util.EventObject;

/**
 * @author power
 * @ClassName
 * @description: 标准提成表单插件
 * @date 2023/8/23
 */
public class TandardcomEdit extends AbstractBillPlugIn implements BeforeF7SelectListener {

    @Override
    public void registerListener(EventObject e) {
        //给物品基础资料添加beforef7Select事件监听
        BasedataEdit typeclassify = this.getControl("yem_typeclassify");
        typeclassify.addBeforeF7SelectListener(this);
    }
    /**
     * 基础资料按表头条件过滤
     */
    @Override
    public void beforeF7Select(BeforeF7SelectEvent e) {
        Control control = (Control) e.getSource();
        String key = control.getKey();
        if ("yem_typeclassify".equals(key)) {
            DynamicObject basedatafield = (DynamicObject)this.getModel().getValue("yem_products");
            if (basedatafield!=null){
                Long id = basedatafield.getLong("id");
                // 设置列表过滤条件
                ListShowParameter formShowParameter = (ListShowParameter)e.getFormShowParameter();
                formShowParameter.getListFilterParameter().setFilter(new QFilter("parent", QCP.equals,id));
            }
        }
    }
}
