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

import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
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 张立攀
 * @ClassName OverallToollibFormPlugin
 * @description: 整机资料工具库
 * @date 2023年07月20日
 * @version: 1.0
 */
public class OverallToollibFormPlugin extends AbstractBillPlugIn implements BeforeF7SelectListener {
    @Override
    public void registerListener(EventObject e) {
        BasedataEdit productmodel = this.getView().getControl("yem_productmodel");
        if(productmodel != null){
            productmodel.addBeforeF7SelectListener(this);
        }
    }
    @Override
    public void beforeF7Select(BeforeF7SelectEvent e) {
        DynamicObject datas = this.getModel().getDataEntity(true);
        String key = e.getProperty().getName();
        switch (key){
            case "yem_productmodel":
                //产品型号根据产品类型过滤
                DynamicObject types = datas.getDynamicObject("yem_producttypes");
                if(types == null){
                    this.getView().showMessage("请先选择产品类型");
                    e.setCancel(true);
                } else{
                    String number = types.getString("number");
                    e.addCustomQFilter(new QFilter("group.longnumber", QCP.like,"%" + number + "%"));
                }
                break;
            default:
                break;
        }

    }

    @Override
    public void propertyChanged(PropertyChangedArgs e) {
        String property = e.getProperty().getName();
        switch (property){
            case "yem_producttypes":
                //产品类型改变、清空产品型号
                this.getModel().setValue("yem_productmodel",null);
                break;
            default:
                break;
        }
    }
}
