package yem.wm.bd.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.metadata.IDataEntityProperty;
import kd.bos.dataentity.metadata.clr.DataEntityPropertyCollection;
import kd.bos.dataentity.serialization.SerializationUtils;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.form.CloseCallBack;
import kd.bos.form.FormShowParameter;
import kd.bos.form.IFormView;
import kd.bos.form.ShowType;
import kd.bos.form.control.Label;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.parameter.SystemParamServiceHelper;
import yem.base.common.utils.DynamicObjectUtil;
import yem.base.common.utils.YEM;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description 抬头信息帮助类
 * @Author: zhangh
 * @CreateTime: 2025-02-07  18:32
 */
public class BothCardHelper {

    private static final String ADD_CO = "yem_flex_addco";
    private static final String INFO_CO = "yem_flex_coinfo";
    private static final String ADD_GYS = "yem_flex_addgys";
    private static final String INFO_GYS = "yem_flex_gysinfo1";
    private static final String ADD_KH = "yem_flex_addbuyer";
    private static final String INFO_KH = "yem_flex_buyerinfo1";

    /**
     * @param form   基类类名
     * @param formId 跳转动态表单的标识
     * @Description: 跳转动态表单(无参数 ， 没有给子页面传递任何参数)
     * @function
     * @purposes 多处调用，防止代码的重复型
     */
    public static void showChangePage(AbstractBillPlugIn form, String formId) {
        IFormView view = form.getView();//获取单据的view视图
        FormShowParameter parameter = new FormShowParameter();
        parameter.getOpenStyle().setShowType(ShowType.Modal);//界面显示分格为弹窗，模态显示
        parameter.setFormId(formId);//添加跳转的动态表单标识
        parameter.setStatus(OperationStatus.ADDNEW);//打开表单的界面状态为新增
        parameter.setCloseCallBack(new CloseCallBack(form, formId));//回调
        view.showForm(parameter);
    }

    /**
     * @param form 基类名称(AbstractBillPlugIn)
     * @Description: 公司抬头信息标签赋值
     * @function 根据{抬头信息}隐藏字段给标签赋值
     * @purposes 套打等可以使用
     */
    public static void setCoLabel(AbstractBillPlugIn form) {
        IDataModel model = form.getView().getModel();//获取单据的model
        DynamicObject company = (DynamicObject) model.getValue("yem_org");//获取单据{抬头明细(隐藏)}中的【公司抬头】
        if (YEM.isEmpty(company)) {
            form.getView().setVisible(Boolean.TRUE, ADD_CO);//判断公司为空，显示添加公司的图标
            form.getView().setVisible(Boolean.FALSE, INFO_CO);//判断公司为空，隐藏编辑公司的图标
        } else {
            ((Label) form.getControl("yem_conamelabel")).setText((String) model.getValue("yem_companyname"));//公司名称
            ((Label) form.getControl("yem_cotin")).setText((String) model.getValue("yem_companytin"));//纳税人识别号(公司)
            ((Label) form.getControl("yem_cobank")).setText((String) model.getValue("yem_companybank"));//开户行(公司)
            ((Label) form.getControl("yem_coacct")).setText((String) model.getValue("yem_companyacct"));//账号(公司)
            ((Label) form.getControl("yem_coaddr")).setText((String) model.getValue("yem_companyaddr"));//地址(公司)

            String isdefaultinfor = (String) model.getValue("yem_isdefaultinfor");//获取默认信息(公司)
            JSONObject jsonObject = JSON.parseObject(isdefaultinfor);//将String类型转换成JSONObject

            String colinkman = (String) (YEM.isEmpty(isdefaultinfor) ? model.getValue("yem_companylinkman") : jsonObject.get("yem_companylinkman"));//联系人
            ((Label) form.getControl("yem_colinkman")).setText(colinkman);//联系人(公司)

            String cotel = (String) (YEM.isEmpty(isdefaultinfor) ? model.getValue("yem_companytel") : jsonObject.get("yem_companytel"));//电话
            ((Label) form.getControl("yem_cotel")).setText(cotel);//电话(公司)

            String coemail = (String) (YEM.isEmpty(isdefaultinfor) ? model.getValue("yem_companyemail") : jsonObject.get("yem_companyemail"));//E-Mail
            ((Label) form.getControl("yem_coemail")).setText(coemail);//E-Mail(公司)

            String covx = (String) (YEM.isEmpty(isdefaultinfor) ? model.getValue("yem_companyvx") : jsonObject.get("yem_companyvx"));//微信
            ((Label) form.getControl("yem_covx")).setText(covx);//微信(公司)

            String coqq = (String) (YEM.isEmpty(isdefaultinfor) ? model.getValue("yem_companyqq") : jsonObject.get("yem_companyqq"));//QQ
            ((Label) form.getControl("yem_coqq")).setText(coqq);//QQ(公司)

            String cofax = (String) (YEM.isEmpty(isdefaultinfor) ? model.getValue("yem_companyfax") : jsonObject.get("yem_companyfax"));//传真
            ((Label) form.getControl("yem_cofax")).setText(cofax);//传真(公司)
            form.getView().setVisible(Boolean.FALSE, ADD_CO);//判断公司不为空，隐藏添加公司的图标
            form.getView().setVisible(Boolean.TRUE, INFO_CO);//判断公司不为空，显示编辑公司的图标
        }
    }

    /**
     * @param form 基类名称
     * @Description: 供应商抬头信息标签赋值
     * @function 根据{抬头信息}隐藏字段给标签赋值
     * @purposes 套打等可以使用
     */
    public static void setSupplierLabel(AbstractBillPlugIn form) {
        IDataModel model = form.getView().getModel();//获取view中的model
        DynamicObject supplier = (DynamicObject) model.getValue("yem_supplier");//获取单据{抬头明细(隐藏)}中的【供应商】
        if (YEM.isEmpty(supplier)) {
            form.getView().setVisible(Boolean.TRUE, ADD_GYS);//判断供应商为空，显示供应商添加的图标
            form.getView().setVisible(Boolean.FALSE, INFO_GYS);//判断供应商为空，隐藏供应商编辑的图标
        } else {
            ((Label) form.getControl("yem_gysname")).setText((String) model.getValue("yem_suppliername"));//供应商名称
            ((Label) form.getControl("yem_gystin")).setText((String) model.getValue("yem_suppliertin"));//纳税人识别号(供应商)
            ((Label) form.getControl("yem_gysbank")).setText((String) model.getValue("yem_supplierbank"));//开户行(供应商)
            ((Label) form.getControl("yem_gysacct")).setText((String) model.getValue("yem_supplieracct"));//账号(供应商)
            ((Label) form.getControl("yem_gyslinkman")).setText((String) model.getValue("yem_supplierlinkman"));//联系人(供应商)
            ((Label) form.getControl("yem_gystel")).setText((String) model.getValue("yem_suppliertel"));//电话(供应商)
            ((Label) form.getControl("yem_gysaddr")).setText((String) model.getValue("yem_supplieraddr"));//地址(供应商)
            ((Label) form.getControl("yem_gysemail")).setText((String) model.getValue("yem_supplieremail"));//E-Mail(供应商)
            ((Label) form.getControl("yem_gysvx")).setText((String) model.getValue("yem_suppliervx"));//微信(供应商)
            ((Label) form.getControl("yem_gysqq")).setText((String) model.getValue("yem_supplierqq"));//QQ(供应商)
            ((Label) form.getControl("yem_gysfax")).setText((String) model.getValue("yem_supplierfax"));//传真(供应商)
            form.getView().setVisible(Boolean.FALSE, ADD_GYS);//判断供应商不为空，隐藏供应商添加的图标
            form.getView().setVisible(Boolean.TRUE, INFO_GYS);//判断供应商不为空，显示供应商编辑的图标
        }
    }

    /**
     * @param form 基类名称
     * @Description: 客户抬头信息标签赋值
     * @function 根据{抬头信息}隐藏字段给标签赋值
     * @purposes 套打等可以使用
     */
    public static void setCustomerLabel(AbstractBillPlugIn form) {
        IDataModel model = form.getView().getModel();//获取view中的model
        DynamicObject customer = (DynamicObject) model.getValue("yem_customer");//获取单据{抬头明细(隐藏)}中的【客户】
        if (YEM.isEmpty(customer)) {
            form.getView().setVisible(Boolean.TRUE, ADD_KH);//判断客户为空，显示客户添加的图标
            form.getView().setVisible(Boolean.FALSE, INFO_KH);//判断客户为空，隐藏客户编辑的图标
        } else {
            ((Label) form.getControl("yem_payername")).setText((String) model.getValue("yem_customername"));//客户名称
            ((Label) form.getControl("yem_payertin")).setText((String) model.getValue("yem_customertin"));//纳税人识别号(客户)
            ((Label) form.getControl("yem_payerbank")).setText((String) model.getValue("yem_customerbank"));//开户行(客户)
            ((Label) form.getControl("yem_payeracct")).setText((String) model.getValue("yem_customeracct"));//账号(客户)
            ((Label) form.getControl("yem_payerlinkman")).setText((String) model.getValue("yem_customerlinkman"));//联系人(客户)
            ((Label) form.getControl("yem_payertel")).setText((String) model.getValue("yem_customertel"));//电话(客户)
            ((Label) form.getControl("yem_payeraddr")).setText((String) model.getValue("yem_customeraddr"));//地址(客户)
            ((Label) form.getControl("yem_payeremail")).setText((String) model.getValue("yem_customeremail"));//E-Mail(客户)
            ((Label) form.getControl("yem_payervx")).setText((String) model.getValue("yem_customervx"));//微信(客户)
            ((Label) form.getControl("yem_payerqq")).setText((String) model.getValue("yem_customerqq"));//QQ(客户)
            ((Label) form.getControl("yem_payerfax")).setText((String) model.getValue("yem_customerfax"));//传真(客户)
            form.getView().setVisible(Boolean.FALSE, ADD_KH);//判断客户不为空，隐藏客户添加的图标
            form.getView().setVisible(Boolean.TRUE, INFO_KH);//判断客户不为空，显示客户编辑的图标
        }
    }

    /**
     * @Description: 公司抬头信息实体赋值
     * @function 新增单据时，默认给{公司抬头}赋值
     * @purposes 用途
     */
    public static void fillCoInfo(IDataModel model, DynamicObject org) {
        boolean viewBill = SystemParamServiceHelper.isViewBill("");//获取系统参数，后边进行调整
        String orgKey = viewBill ? "yem_bd_companyinfo" : "bos_org";//根据系统参数获取系统是使用《业务单元》还是《公司抬头》
        model.setValue("yem_orgtype", orgKey);   //组织类型
        model.setValue("yem_org", org.getLong("id"));//公司抬头
        model.setValue("yem_companyname", org.getString("name"));//公司名称

        DynamicObject companyinfo = queryCompany(org);//根据《业务单元》查询《公司抬头》
        if (companyinfo != null) {//判断《公司抬头》实体是否为空
            model.setValue("yem_companytin", companyinfo.get("yem_negocionum"));//纳税人识别号(公司)--纳税识别号
            model.setValue("yem_companyaddr", companyinfo.getString("yem_addresscn"));//地址(公司)--地址
            model.setValue("yem_companyfax", companyinfo.getString("yem_fax"));//传真(公司)--传真

            DynamicObjectCollection banksentry = companyinfo.getDynamicObjectCollection("yem_banksentry");//《公司抬头》中的{银行信息}
            List<DynamicObject> banksentryDefault = banksentry.stream().filter(x -> x.getBoolean("yem_isdefaultbank") == true).collect(Collectors.toList());//获取《公司抬头》中{银行信息}中的默认数据
            if (banksentryDefault.size() > 0) {
                DynamicObject row = banksentryDefault.get(0);//《公司抬头》中的{银行信息}默认数据只有唯一一个
                String bankaccount = row.getDynamicObject("yem_bankaccount") != null ? row.getDynamicObject("yem_bankaccount").getString("name") : "";//获取开户银行
                model.setValue("yem_companybank", bankaccount);//开户行(公司)--开户银行
                model.setValue("yem_companyacct", row.get("yem_accountnumber"));//账号(公司)--银行账户
            }

            DynamicObjectCollection linkmanentry = companyinfo.getDynamicObjectCollection("yem_linkmanentry");//《公司抬头》中的{联系人信息}
            List<DynamicObject> manentryDefault = linkmanentry.stream().filter(x -> x.getBoolean("yem_isdefaultlinkman") == true).collect(Collectors.toList());//获取《公司抬头》中{联系人信息}中的默认数据
            if (manentryDefault.size() > 0) {
                DynamicObject row = manentryDefault.get(0);//《公司抬头》中的{联系人信息}默认数据只有唯一一个
                model.setValue("yem_companylinkman", row.getString("yem_contactperson"));//联系人(公司)--名称
                model.setValue("yem_companytel", row.get("yem_phonenum"));//电话(公司)--联系电话
                model.setValue("yem_companyemail", row.get("yem_addemail"));//E-Mail(公司)--电子邮箱
                model.setValue("yem_companyvx", row.get("yem_suppliervx"));//微信(公司)--微信
                model.setValue("yem_companyqq", row.get("yem_supplierqq"));//QQ(公司)--QQ
            }
        }
    }

    /**
     * @param org 《业务单元》实体
     * @return DynamicObject 返回的是《公司抬头》实体
     * @Description: 查询单据
     * @function 根据业务单元查询获取《公司抬头》
     * @purposes
     */
    public static DynamicObject queryCompany(DynamicObject org) {
        String selectfields = DynamicObjectUtil.getSelectfields("yem_bd_companyinfo", false);//获取《公司抬头》表头字段标识
        selectfields = DynamicObjectUtil.getEntrySelectfields(selectfields, "yem_bd_companyinfo", "yem_banksentry", false);//获取《公司抬头》中{银行信息}分录所有字段标识
        selectfields = DynamicObjectUtil.getEntrySelectfields(selectfields, "yem_bd_companyinfo", "yem_linkmanentry", false);//获取《公司抬头》中{联系人信息}分录所有字段标识
        DynamicObject companyinfo = BusinessDataServiceHelper.loadSingle("yem_bd_companyinfo", selectfields, new QFilter[]{new QFilter("yem_org", QCP.equals, org.getLong("id"))});//根据公司条件查询《公司抬头》
        return companyinfo;
    }

    /**
     * @param form 基类类名
     * @Description: 加载动态表单的逻辑处理
     * @function 将父页面的信息携带到动态表单上
     * @purposes
     */
    public static void init(AbstractFormPlugin form) {
        IFormView view = form.getView();//获取动态表单的view视图
        IDataModel model = view.getModel();//获取动态表单的模型model

        IFormView parentView = view.getParentView();//获取父页面的view视图
        IDataModel parentModel = parentView.getModel();//获取父页面的模型model

        DataEntityPropertyCollection properties = model.getDataEntityType().getProperties();//获取动态表单上的所有字段控件
        for (IDataEntityProperty property : properties) {
            String propName = property.getName();//获取字段控件的标识
            if (parentModel.getProperty(propName) != null) {//判断该字段标识在父页面中是否存在
                Object propValue = parentModel.getValue(propName);//如果存在获取在父页面中的值
                if (propValue instanceof DynamicObject) {//类型是实体
                    DynamicObject obj = (DynamicObject) propValue;//获取实体id
                    model.setValue(propName, obj.getPkValue());
                } else {
                    model.setValue(propName, propValue);
                }
            }
        }
    }

    /**
     * @Description: 回填银行信息
     * @function ：《公司银行信息》点击确定之后，回填公司银行信息
     * @purposes 用途
     */
    public static void setCompanyBankInfor(AbstractFormPlugin form, Object returnData) {
        DynamicObject data = (DynamicObject) returnData;
        IFormView view = form.getView();
        IDataModel model = view.getModel();

        if (data != null) {
            DynamicObject bankaccount = data.getDynamicObject("yem_bankaccount");
            String bank = bankaccount != null ? bankaccount.getString("name") : "";
            model.setValue("yem_companybank", bank);//开户行
            model.setValue("yem_companyacct", data.getString("yem_accountnumber"));//账号
        }
    }

    /**
     * @Description: 回填联系人信息
     * @function ：《公司人员信息》点击确定之后，回填公司联系人信息
     * @purposes 用途
     */
    public static void setCompanyManInfor(AbstractFormPlugin form, Object returnData, DynamicObject isdefaultInfor) {
        List<DynamicObject> data = (List<DynamicObject>) returnData;
        IFormView view = form.getView();
        IDataModel model = view.getModel();

        if (data != null && data.size() > 0) {
            DataEntityPropertyCollection properties = data.get(0).getDataEntityType().getProperties();//获取{联系人信息}单据体的所有字段

            for (IDataEntityProperty property : properties) {//适用于实体字段给单据的表头字段赋值
                String name = property.getName();//获取实体字段的标识
                if (model.getProperty(name) != null) {
                    List<String> linkman = data.stream().map(x -> x.getString(name)).collect(Collectors.toList());
                    model.setValue(name, String.join(";", linkman));
                }
            }

            List<DynamicObject> defaultManInfor = data.stream().filter(x -> x.getBoolean("yem_default") == true).collect(Collectors.toList());//获取《公司联系人信息》回填的默认信息
            if (defaultManInfor.size() > 0) {
                view.getPageCache().put("data", SerializationUtils.toJsonString(defaultManInfor.get(0)));//将默认信息放在缓存李，在回传的时候可以使用
            }
        }
    }

    /**
     * @Description: 切换【客户】，客户信息值改变
     * @function 切换【客户】之后，客户信息根据赋值逻辑重新赋值
     * @purposes 用途
     */
    public static void setCustomerInfor(AbstractFormPlugin form) {
        IFormView view = form.getView();
        IDataModel model = view.getModel();

        DynamicObject customer = (DynamicObject) model.getValue("yem_customer");
        if (customer != null) {
            customer = BusinessDataServiceHelper.loadSingleFromCache(customer.getLong("id"), customer.getDataEntityType().getName());

            model.setValue("yem_customertin", customer.getString("societycreditcode"));//纳税人识别号(供应商)--纳税人识别号(供应商)

            DynamicObjectCollection entry_bank = customer.getDynamicObjectCollection("entry_bank");//银行信息
            List<DynamicObject> bankentryDefault = entry_bank.stream().filter(x -> x.getBoolean("isdefault_bank") == true).collect(Collectors.toList());
            if (bankentryDefault.size() > 0) {
                DynamicObject row = bankentryDefault.get(0);
                String bank = row.getDynamicObject("bank") != null ? row.getDynamicObject("bank").getString("name") : "";
                model.setValue("yem_customerbank", bank);//开户行(公司)--开户银行
                model.setValue("yem_customeracct", row.get("bankaccount"));//账号(公司)--银行账户
            }

            DynamicObjectCollection linkmanentry = customer.getDynamicObjectCollection("entry_linkman");//联系人信息
            List<DynamicObject> manentryDefault = linkmanentry.stream().filter(x -> x.getBoolean("isdefault_linkman") == true).collect(Collectors.toList());

            if (manentryDefault.size() > 0) {
                DynamicObject row = manentryDefault.get(0);
                model.setValue("yem_customerlinkman", row.getString("contactperson"));//联系人(公司)--名称
                model.setValue("yem_customertel", row.get("phone"));//电话(公司)--联系电话
                model.setValue("yem_customeremail", row.get("email"));//E-Mail(公司)--电子邮箱
                model.setValue("yem_customerfax", row.get("fax"));//传真(公司)--传真

                DynamicObject associatedaddress = row.getDynamicObject("associatedaddress");//关联地址
                if (associatedaddress != null) {
                    associatedaddress = BusinessDataServiceHelper.loadSingleFromCache(associatedaddress.getLong("id"), associatedaddress.getDataEntityType().getName());
                    model.setValue("yem_customervx", associatedaddress.get("yem_suppliervx"));//微信(公司)--微信
                    model.setValue("yem_customerqq", associatedaddress.get("yem_supplierqq"));//QQ(公司)--QQ
                    model.setValue("yem_customeraddr", associatedaddress.get("detailaddress"));//地址(客户)--详细地址
                }
            }
        }
    }

    /**
     * @Description: 《客户银行信息》点击确定，返回值
     * @function 《客户银行信息》点击确定之后，给《添加客户》中的信息赋值
     * @purposes 用途
     */
    public static void setCustBankInfor(AbstractBillPlugIn form, Object returnData) {
        DynamicObject data = (DynamicObject) returnData;
        IFormView view = form.getView();
        IDataModel model = view.getModel();

        if (data != null) {
            DynamicObject bankaccount = data.getDynamicObject("yem_bankaccount");//获取《客户银行信息》中的【开户行】
            String bank = bankaccount != null ? bankaccount.getString("name") : "";
            model.setValue("yem_customerbank", bank);//开户行
            model.setValue("yem_customeracct", data.getString("yem_accountnumber"));//账号
        }
    }

    /**
     * @Description: 《客户人员信息》点击确定，返回值
     * @function 《客户人员信息》点击确定之后，给《添加客户》中的信息赋值
     * @purposes 用途
     */
    public static void setCustManInfor(AbstractBillPlugIn form, Object returnData) {
        DynamicObject data = (DynamicObject) returnData;
        IFormView view = form.getView();
        IDataModel model = view.getModel();

        if (data != null) {
            DataEntityPropertyCollection properties = data.getDataEntityType().getProperties();//获取返回信息的所有字段标识(只有表头字段，没有单据体字段)
            for (IDataEntityProperty property : properties) {
                String name = property.getName();//获取字段标识
                if (model.getProperty(name) != null) {
                    model.setValue(name, data.get(name));//进行赋值
                }
            }
        }
    }

    /**
     * @Description: 切换【供应商】，重新赋值
     * @function 切换【供应商】之后，根据赋值逻辑，重新赋值
     * @purposes 用途
     */
    public static void setSupplierInfor(AbstractFormPlugin form) {
        IFormView view = form.getView();
        IDataModel model = view.getModel();

        DynamicObject supplier = (DynamicObject) model.getValue("yem_supplier");//获取【供应商】字段
        if (supplier != null) {
            supplier = BusinessDataServiceHelper.loadSingleFromCache(supplier.getLong("id"), supplier.getDataEntityType().getName());

            model.setValue("yem_suppliertin", supplier.getString("societycreditcode"));//纳税人识别号(供应商)--纳税人识别号(供应商)

            DynamicObjectCollection entry_bank = supplier.getDynamicObjectCollection("entry_bank");//《供应商》--{银行信息}
            List<DynamicObject> bankentryDefault = entry_bank.stream().filter(x -> x.getBoolean("isdefault_bank") == true).collect(Collectors.toList());//获取《供应商》中{银行信息}的默认数据
            if (bankentryDefault.size() > 0) {
                DynamicObject row = bankentryDefault.get(0);
                String bank = row.getDynamicObject("bank") != null ? row.getDynamicObject("bank").getString("name") : "";//开户行
                model.setValue("yem_supplierbank", bank);//开户行(公司)--开户银行
                model.setValue("yem_supplieracct", row.get("bankaccount"));//账号(公司)--银行账户
            }

            DynamicObjectCollection linkmanentry = supplier.getDynamicObjectCollection("entry_linkman");//《供应商》--联系人信息
            List<DynamicObject> manentryDefault = linkmanentry.stream().filter(x -> x.getBoolean("isdefault_linkman") == true).collect(Collectors.toList());//获取《供应商》中{联系人信息}的默认数据

            if (manentryDefault.size() > 0) {
                DynamicObject row = manentryDefault.get(0);
                model.setValue("yem_supplierlinkman", row.getString("contactperson"));//联系人(公司)--名称
                model.setValue("yem_suppliertel", row.get("phone"));//电话(公司)--联系电话
                model.setValue("yem_supplieremail", row.get("email"));//E-Mail(公司)--电子邮箱
                model.setValue("yem_supplierfax", row.get("fax"));//传真(公司)--传真

                DynamicObject associatedaddress = row.getDynamicObject("associatedaddress");//关联地址
                if (associatedaddress != null) {
                    associatedaddress = BusinessDataServiceHelper.loadSingleFromCache(associatedaddress.getLong("id"), associatedaddress.getDataEntityType().getName());
                    model.setValue("yem_suppliervx", associatedaddress.get("yem_suppliervx"));//微信(公司)--微信
                    model.setValue("yem_supplierqq", associatedaddress.get("yem_supplierqq"));//QQ(公司)--QQ
                    model.setValue("yem_supplieraddr", associatedaddress.get("detailaddress"));//地址(客户)--详细地址
                }
            }
        }
    }

    /**
     * @Description: 《供应商银行信息》点击确定，返回值
     * @function 《供应商银行信息》点击确定之后，给《添加客户》中的信息赋值
     * @purposes 用途
     */
    public static void setSuppBankInfor(AbstractBillPlugIn form, Object returnData) {
        DynamicObject data = (DynamicObject) returnData;
        IFormView view = form.getView();
        IDataModel model = view.getModel();

        if (data != null) {
            DynamicObject bankaccount = data.getDynamicObject("yem_bankaccount");
            String bank = bankaccount != null ? bankaccount.getString("name") : "";
            model.setValue("yem_supplierbank", bank);//开户行
            model.setValue("yem_supplieracct", data.getString("yem_accountnumber"));//账号
        }
    }

    /**
     * @param form 基类类名
     * @return void
     * @Description: 将动态表单的信息返回给父页面
     * @function
     * @purposes 用途
     */
    public static void btnOkParent(AbstractFormPlugin form) {
        IFormView view = form.getView();//获取动态表单view视图
        IDataModel model = view.getModel();//获取动态表单模型model
        IFormView parentView = view.getParentView();//获取父页面view视图
        IDataModel parentModel = parentView.getModel();//获取父页面莫得了模型
        DataEntityPropertyCollection properties = model.getDataEntityType().getProperties();//获取动态表单所有字段控件
        for (IDataEntityProperty property : properties) {
            String propName = property.getName();//获取字段标识
            if (parentModel.getProperty(propName) != null) {
                Object propValue = model.getValue(propName);//子啊动态表单上获取字段的值
                if (propValue instanceof DynamicObject) {//判断值类型是否是DynamicObject实体
                    DynamicObject obj = (DynamicObject) propValue;
                    parentModel.setValue(propName, obj.getPkValue());
                } else {
                    parentModel.setValue(propName, propValue);
                }
            }
        }
    }
}
