package yem.wm.cm.csrm.form;


import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.form.control.Control;
import kd.bos.form.events.ClosedCallBackEvent;
import kd.bos.form.field.TextEdit;
import yem.base.common.module.meta.propselect.helper.MetaPropertyHelper;
import yem.base.common.utils.YEM;
import yem.wm.cm.csrm.enums.PageIdEnum;

import java.util.EventObject;


/**
 * 评分指标 选择关联企查查字段
 *
 * @Author yunshuaiwei
 * @Date 2024/5/24 15:34
 **/
public class ScoringRubricsssFormPlugIn extends AbstractBillPlugIn {
    @Override
    public void registerListener(EventObject e) {
        // TODO Auto-generated method stub
        super.registerListener(e);
        TextEdit fieldName = this.getControl("yem_filed");
        fieldName.addClickListener(this);
    }

    public void click(EventObject evt) {
        super.click(evt);
        Control c = (Control) evt.getSource();
        String key = c.getKey().toLowerCase();
        switch (key) {
            case "yem_filed":
                Long id = (Long) this.getModel().getValue("id");
                MetaPropertyHelper.showPropertySelect(this, String.valueOf(id), PageIdEnum.MERCHANT_APPLY.getPageId(), false);
                break;
        }
    }


    @Override
    public void closedCallBack(ClosedCallBackEvent e) {
        // TODO Auto-generated method stub
        super.closedCallBack(e);
        IDataModel model = this.getModel();
        String actionId = e.getActionId();
        if (actionId.equals(this.getModel().getValue("id") + "")) {
            DynamicObjectCollection data = (DynamicObjectCollection) e.getReturnData();
            if (YEM.isNotEmpty(data)) {
                DynamicObject info = data.get(0);
                String fullnumber = info.getString("yem_fullnumber");
                String fullname = info.getString("yem_fullname");
                model.setValue("yem_filed", fullname);
                model.setValue("yem_filedtag", fullnumber);
            }
        }
    }
}
