package com.yem.ia.intebilllogon.form;

import com.yem.ia.intebilllogon.Utils.BackfilljsonAssignUtils;
import com.yem.ia.intebilllogon.Utils.ObjectToJsonUtils;
import com.yem.ia.intebilllogon.commom.CommonUtils;
import com.yem.ia.intebilllogon.commom.DyDataUtils;
import com.yem.wm.utils.AttachmentUtil;
import com.yem.wm.utils.StringUtils;
import com.yem.wm.utils.YunzhijiaUtils;
//import json.JSONArray;
//import json.JSONObject;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.bill.OperationStatus;
import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.datamodel.ListSelectedRowCollection;
import kd.bos.exception.KDBizException;
import kd.bos.form.CloseCallBack;
import kd.bos.form.ShowType;
import kd.bos.form.StyleCss;
import kd.bos.form.control.Control;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.events.ClosedCallBackEvent;
import kd.bos.form.field.TextEdit;
import kd.bos.list.ListFilterParameter;
import kd.bos.list.ListShowParameter;
import kd.bos.servicehelper.AttachmentServiceHelper;
import kd.bos.servicehelper.BusinessDataServiceHelper;

import java.io.*;
import java.math.BigDecimal;
import java.util.*;


/**
 * @author zhouc
 * @date 2023/8/17 17:12
 * @className intebilllogonDemo
 * @description 根据智能审批单据注册表拼接json测试工具类
 */
public class intebilllogonDemo extends AbstractBillPlugIn {
    public void afterDoOperation(AfterDoOperationEventArgs e) throws KDBizException {
        super.afterDoOperation(e);
        String key = e.getOperateKey();
        IDataModel model = this.getModel();
        DynamicObject dataEntity = this.getModel().getDataEntity(true);
        if (key.equals("generatejson")) {//拼接测试json
            JSONObject Object = new JSONObject();
            Object.put("formCodeId", dataEntity.getString("yem_yzjid"));
            String[] creator = new String[]{dataEntity.getString("yem_creator")};
            Object.put("creator", dataEntity.getString("yem_creator"));
            DynamicObject yem_formid = dataEntity.getDynamicObject("yem_formid");
            String yem_formcode = dataEntity.getString("yem_formcode");
            JSONObject widgetValueObject = new JSONObject();//单据头对象
            JSONObject json = new JSONObject();//
            if (StringUtils.isNotEmpty(yem_formcode)) {
                //获取单据数据
                DynamicObject Bill = BusinessDataServiceHelper.loadSingle(yem_formcode, yem_formid.getString("number"));
                if (Bill != null) {
                    DynamicObjectCollection yem_signentryentity = dataEntity.getDynamicObjectCollection("yem_signentryentity");
                    if (yem_signentryentity.size() > 0) {
                        for (int i = 0; i < yem_signentryentity.size(); i++) {
                            DynamicObject signentryentity = yem_signentryentity.get(i);
                            Boolean yem_subisdelete = signentryentity.getBoolean("yem_subisdelete");//是否删除
                            String yem_iaentitytype = signentryentity.getString("yem_iaentitytype");//审批实体类型
                            String yem_iaformid = signentryentity.getString("yem_iaformid");//审批字段标识
                            String yem_ianame = signentryentity.getString("yem_ianame");//审批字段名称
                            String yem_iatype = signentryentity.getString("yem_iatype");//审批字段类型
                            int iaaccuracy = signentryentity.getInt("yem_iaaccuracy");//字段精度
                            String yem_erpfiledformid = signentryentity.getString("yem_erpfiledformid");//ERP字段标识
                            String yem_erpfiledformname = signentryentity.getString("yem_erpfiledformname");//ERP字段名称
                            String yem_erpfiledtype = signentryentity.getString("yem_erpfiledtype");//ERP字段类型
                            String yem_filedtypename = signentryentity.getString("yem_filedtypename");//ERP基础资料标识
                            String yem_identifierbasic = signentryentity.getString("yem_identifierbasic");//ERP基础数据唯一标识
                            String yem_defaultvalue = signentryentity.getString("yem_defaultvalue");//默认值
                            String yem_modledefaultvalue = signentryentity.getString("yem_modledefaultvalue");//动态默认
                            if (!yem_subisdelete) {
                                if (yem_iaentitytype.equals("H")) {//单据头H  单据体D
                                    if (StringUtils.isNotEmpty(yem_defaultvalue)) {//是否默认不为空
                                        if ("人员选择".equals(yem_iatype)) {
                                            widgetValueObject.put(yem_iaformid, new String[]{yem_defaultvalue});
                                        } else {
                                            widgetValueObject.put(yem_iaformid, yem_defaultvalue);
                                        }
                                    }
                                    if (StringUtils.isNotEmpty(yem_modledefaultvalue)) {//动态默认不为空
                                        widgetValueObject.put(yem_iaformid, DyDataUtils.getDyData(Bill, yem_modledefaultvalue, yem_identifierbasic));
                                    }
                                    if (StringUtils.isNotEmpty(yem_erpfiledformid)) {////ERP字段标识不为空
                                        //创建人修改人审核人已基础资料处理
                                        if ("basedata".equals(yem_erpfiledtype) || "auditor".equals(yem_erpfiledtype)
                                                || "modifier".equals(yem_erpfiledtype) || "creator".equals(yem_erpfiledtype)
                                                || "user".equals(yem_erpfiledtype)) {
                                            DynamicObject DynamicObject = Bill.getDynamicObject(yem_erpfiledformid);
                                            if (DynamicObject != null) {
                                                widgetValueObject.put(yem_iaformid, CommonUtils.GetObjDynamicObjectStats(DynamicObject, yem_identifierbasic));
                                            }
                                        } else if ("datetime".equals(yem_erpfiledtype) || "date".equals(yem_erpfiledtype)) {
                                            Date DateObject = Bill.getDate(yem_erpfiledformid);
                                            if (StringUtils.isNotEmpty(yem_identifierbasic)) {
//                                                new SimpleDateFormat(yem_identifierbasic).format(DateObject)// 2023-08-04
                                                // DateObject.getTime()
                                                widgetValueObject.put(yem_iaformid, DateObject.getTime());
                                            }
                                        } else if ("number".equals(yem_erpfiledtype)) {
                                            if (iaaccuracy > 0) {
                                                Bill.getBigDecimal(yem_erpfiledformid).setScale(iaaccuracy, BigDecimal.ROUND_HALF_UP);
                                            } else {
                                                widgetValueObject.put(yem_iaformid, Bill.getBigDecimal(yem_erpfiledformid));
                                            }
                                        } else {
                                            widgetValueObject.put(yem_iaformid, Bill.getString(yem_erpfiledformid));
                                        }
                                    }
                                    Object.put("widgetValue", widgetValueObject);
                                } else {
                                    //单据数据集合
                                    JSONObject widgetValueEntry = new JSONObject();//单据头对象
                                    JSONArray jsonArray = new JSONArray();
                                    DynamicObjectCollection entity = Bill.getDynamicObjectCollection(yem_erpfiledformid);
                                    DynamicObjectCollection yem_subentryentity = signentryentity.getDynamicObjectCollection("yem_subentryentity");
                                    for (int K = 0; K < entity.size(); K++) {
                                        DynamicObject entityDynamico = entity.get(K);
                                        JSONObject entityObject = new JSONObject();
                                        for (int j = 0; j < yem_subentryentity.size(); j++) {
                                            DynamicObject subentryentity = yem_subentryentity.get(j);
                                            String yem_iaformid1 = subentryentity.getString("yem_iaformid1");//审批字段标识
                                            int iaaccuracy1 = subentryentity.getInt("yem_iaaccuracy1");//字段精度
                                            String yem_iatype1 = subentryentity.getString("yem_iatype1");//审批字段类型
                                            String yem_erpfiledformid1 = subentryentity.getString("yem_erpfiledformid1");//ERP字段标识
                                            String yem_erpfiledformname1 = subentryentity.getString("yem_erpfiledformname1");//ERP字段名称
                                            String yem_erpfiledtype1 = subentryentity.getString("yem_erpfiledtype1");//ERP字段类型
                                            String yem_filedtypename1 = subentryentity.getString("yem_filedtypename1");//ERP基础资料标识
                                            String yem_identifierbasic1 = subentryentity.getString("yem_identifierbasic1");//ERP基础数据唯一标识
                                            String yem_defaultvalue1 = subentryentity.getString("yem_defaultvalue1");//默认值
                                            String yem_modledefaultvalue1 = subentryentity.getString("yem_modledefaultvalue1");//动态默认
                                            if (StringUtils.isNotEmpty(yem_defaultvalue1)) {//是否默认不为空

                                                if ("人员选择".equals(yem_iatype1)) {
                                                    entityObject.put(yem_iaformid, new String[]{yem_defaultvalue1});
                                                } else {
                                                    entityObject.put(yem_iaformid1, yem_defaultvalue1);
                                                }
                                            }
                                            if (StringUtils.isNotEmpty(yem_modledefaultvalue1)) {//动态默认不为空
                                                entityObject.put(yem_iaformid1, DyDataUtils.getDyData(Bill, yem_modledefaultvalue1, yem_identifierbasic1));
                                            }
                                            if (StringUtils.isNotEmpty(yem_erpfiledformid1)) {////ERP字段标识不为空
                                                //创建人修改人审核人已基础资料处理
                                                if ("basedata".equals(yem_erpfiledtype1) || "auditor".equals(yem_erpfiledtype1)
                                                        || "modifier".equals(yem_erpfiledtype1) || "creator".equals(yem_erpfiledtype1)
                                                        || "user".equals(yem_erpfiledtype1)) {
                                                    DynamicObject DynamicObject = entityDynamico.getDynamicObject(yem_erpfiledformid1);
                                                    if (DynamicObject != null) {
                                                        entityObject.put(yem_iaformid1, CommonUtils.GetObjDynamicObjectStats(DynamicObject, yem_identifierbasic1));
                                                    }
                                                } else if ("datetime".equals(yem_erpfiledtype1) || "date".equals(yem_erpfiledtype1)) {
                                                    Date DateObject = entityDynamico.getDate(yem_erpfiledformid1);
                                                    if (StringUtils.isNotEmpty(yem_identifierbasic1)) {
//                                                        entityObject.put(yem_iaformid1, new SimpleDateFormat(yem_identifierbasic1).format(DateObject));
                                                        entityObject.put(yem_iaformid1, DateObject.getTime());
                                                    }
                                                } else if ("number".equals(yem_erpfiledtype1)) {
                                                    if (iaaccuracy1 > 0) {
                                                        BigDecimal value = entityDynamico.getBigDecimal(yem_erpfiledformid1).setScale(iaaccuracy1, BigDecimal.ROUND_HALF_UP);
                                                        entityObject.put(yem_iaformid1, value);
                                                    } else {
                                                        entityObject.put(yem_iaformid1, entityDynamico.getBigDecimal(yem_erpfiledformid1));
                                                    }
                                                } else {
                                                    entityObject.put(yem_iaformid1, entityDynamico.getString(yem_erpfiledformid1));
                                                }
                                            }
                                        }
                                        jsonArray.add(entityObject);
                                    }
                                    widgetValueEntry.put("widgetValue", jsonArray);
                                    json.put(yem_iaformid, widgetValueEntry);
                                    Object.put("details", json);//分录数据
                                }
                            }
                        }
                    }
                } else {
                    this.getView().showErrorNotification("未获取到对应数据");
                }
            }
            this.getView().getModel().setValue("yem_generatejson", Object);//拼接json
        }
        if (key.equals("generatejson_zz")) {
            DynamicObject yemFormid = dataEntity.getDynamicObject("yem_formid");
            if (yemFormid != null) {
                Map map = new HashMap<>();
                map.put("entityName", yemFormid.getString("number"));
//                map.put("billtype","yem_orderproreqbill_DB");
                JSONObject json = ObjectToJsonUtils.ObjectToJson(dataEntity.getLong("yem_formcode"), map);
                this.getView().getModel().setValue("yem_generatejson", json);
                this.getView().showSuccessNotification("获取完成！");
            } else {
                this.getView().showErrorNotification("未选择ERP对象，获取失败！");
            }

        }
        if (key.equals("backfilljson")) {
            String Json = returnJson();
            BackfilljsonAssignUtils.BackfilljsonAssign(Json);
            this.getView().showSuccessNotification("回填完成！");
        }
        if ("syncosmic".equals(key)) {
            Boolean fag = false;
            long yem_formcode = dataEntity.getLong("yem_formcode");
            if (yem_formcode == 0) {
                this.getView().showErrorNotification("请选择【单据id】后重试！");
                return;
            }
            DynamicObject yemFormid = dataEntity.getDynamicObject("yem_formid");
            if (yemFormid == null) {
                this.getView().showErrorNotification("请维护【ERP业务对象】后重试！");
                return;
            }
            String clientUrl = RequestContext.get().getClientUrl();
            String Formid = yemFormid.getString("number");
            List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments(Formid, yem_formcode, "attachmentpanel");
            if (attachments.size() > 0) {
                fag = true;
            }
            if (fag) {
                //获取云之家token
                String url = YunzhijiaUtils.yzjurl+"/cmmpapi/cmmp/fileToken.do?tokenId=D4EB05B9FE9C41D0868D33EC92AAEDB4";
                String Token = "";
                try {
                    Token = YunzhijiaUtils.doPost(url, "");
                } catch (Exception ex) {
                    throw new KDBizException(ex.toString());
                }
                JSONObject json = JSONObject.parseObject(Token);
                System.err.println(json);
                Boolean success = json.getBoolean("success");
                if (success) {
                    JSONObject data = json.getJSONObject("data");
                    String accessToken = data.getString("accessToken");
                    //实际情况
//                    File file = new File("D:\\Download\\引出数据_WKISV4_1228011150.xlsx");
//                    String filename = "引出数据_WKISV4_1228011150.xlsx";
                    for (int i = 0; i < attachments.size(); i++) {
                        Map<String, Object> map = attachments.get(i);
                        try {
                            String fileurl = (String) map.get("url");
                            if (fileurl.contains("http://localhost:8080/ierp/")) {
                                fileurl = fileurl.replace("http://localhost:8080/", "http://10.64.112.152:8022/");
                            }
                            String filename = (String) map.get("name");
                            String s1 = YunzhijiaUtils.uploadfile(fileurl, accessToken, filename);
                            JSONObject s1json = JSONObject.parseObject(s1);
                            Boolean successs1 = s1json.getBoolean("success");
                            if (successs1) {
                                JSONArray datas1 = s1json.getJSONArray("data");
                                for (int j = 0; j < datas1.size(); j++) {
                                    JSONObject object = new JSONObject();
                                    JSONObject jsonObject = datas1.getJSONObject(j);
                                    if (jsonObject != null) {
                                        //创建ERP与云之家对照表
                                        CommonUtils.Addattyunzhijia(Formid, yem_formcode, map, "attachmentpanel", jsonObject);
                                    }
                                }
                            }
                            System.err.println(s1);
                        } catch (Exception ex) {
                            String message = ex.getMessage();
                            throw new KDBizException(message);
                        }
                    }
                }
            }

        }
        if ("uploadcosmic".equals(key)) {
            long yem_formcode = dataEntity.getLong("yem_formcode");
            if (yem_formcode == 0) {
                this.getView().showErrorNotification("请选择【单据id】后重试！");
                return;
            }
            DynamicObject yemFormid = dataEntity.getDynamicObject("yem_formid");
            if (yemFormid == null) {
                this.getView().showErrorNotification("请维护【ERP业务对象】后重试！");
                return;
            }
            String Formid = yemFormid.getString("number");
            String yem_fileid = dataEntity.getString("yem_fileid");
            if (yem_fileid.length() == 0) {
                this.getView().showErrorNotification("请维护【云之家附件id】后重试！");
                return;
            }
            String yem_cattachmentkey = dataEntity.getString("yem_cattachmentkey");
            if (yem_cattachmentkey.length() == 0) {
                this.getView().showErrorNotification("请维护【苍穹附件面板标识】后重试！");
                return;
            }
            //获取云之家token
            String url = YunzhijiaUtils.yzjurl+"/cmmpapi/cmmp/fileToken.do?tokenId=D4EB05B9FE9C41D0868D33EC92AAEDB4";
            String Token = "";
            try {
                Token = YunzhijiaUtils.doPost(url, "");
            } catch (Exception ex) {
                throw new KDBizException(ex.toString());
            }
            JSONObject json = JSONObject.parseObject(Token);
            System.err.println(json);
            Boolean success = json.getBoolean("success");
            if (success) {
                JSONObject data = json.getJSONObject("data");
                String accessToken = data.getString("accessToken");
                byte[] downloadfile = YunzhijiaUtils.downloadfile(yem_fileid, accessToken);
                if (downloadfile.length > 0) {
                    InputStream input = new ByteArrayInputStream(downloadfile);
                    DynamicObject dynamicObject = AttachmentUtil.uploadAttachment(
                            "yem_es", Formid, String.valueOf(yem_formcode),
                            yem_cattachmentkey, "整机资料工具库_模版12.15.xlsx", input);
                }
            }
        }
    }

    public String returnJson() {

        String Json = "{\"data\":{\"formInfo\":{\"widgetLinkRecordsMap\":{},\"widgetMap\":{\"Te_5\":{\"codeId\":\"Te_5\",\"extendFieldMap\":{},\"title\":\"预计到货天数\"," +
                "\"type\":\"textWidget\",\"value\":\"\"},\"Te_11\":{\"codeId\":\"Te_11\",\"extendFieldMap\":{},\"title\":\"查询电话\",\"type\":\"textWidget\",\"value\":\"\"}," +
                "\"Te_4\":{\"codeId\":\"Te_4\",\"extendFieldMap\":{},\"title\":\"联系方式\",\"type\":\"textWidget\",\"value\":\"13953902233\"},\"Te_10\":{\"codeId\":\"Te_10\"," +
                "\"extendFieldMap\":{},\"title\":\"付费方式\",\"type\":\"textWidget\",\"value\":\"寄付\"},\"Te_3\":{\"codeId\":\"Te_3\",\"extendFieldMap\":{},\"title\":\"收货人姓名\"," +
                "\"type\":\"textWidget\",\"value\":\"李青林\"},\"Te_2\":{\"codeId\":\"Te_2\",\"extendFieldMap\":{},\"title\":\"收货地址\",\"type\":\"textWidget\"," +
                "\"value\":\"临沂市兰山区327国道杭州叉车\"},\"Te_20\":{\"codeId\":\"Te_20\",\"extendFieldMap\":{},\"title\":\"总重量（kg）\",\"type\":\"textWidget\",\"value\":\"10\"}," +
                "\"Te_30\":{\"codeId\":\"Te_30\",\"extendFieldMap\":{\"wordLimit\":200},\"title\":\"车牌号\",\"type\":\"textWidget\",\"value\":\"\"}," +
                "\"Te_1\":{\"codeId\":\"Te_1\",\"extendFieldMap\":{},\"title\":\"预计发货日期\",\"type\":\"textWidget\",\"value\":\"2023-08-17\"}," +
                "\"Te_0\":{\"codeId\":\"Te_0\",\"extendFieldMap\":{},\"title\":\"收货公司\",\"type\":\"textWidget\",\"value\":\"山东万宇叉车销售有限公司\"}," +
                "\"Ra_0\":{\"codeId\":\"Ra_0\",\"extendFieldMap\":{},\"displaylinkageVos\":[],\"options\":[{\"checked\":false,\"value\":\"是\",\"key\":\"AaBaCcDd\"}," +
                "{\"checked\":false,\"value\":\"否\",\"key\":\"EeFfGgHh\"}],\"linkRule\":[],\"title\":\"包装是否完好无损\",\"type\":\"radioWidget\",\"value\":\"\"}," +
                "\"Ra_1\":{\"codeId\":\"Ra_1\",\"extendFieldMap\":{},\"displaylinkageVos\":[],\"options\":[{\"checked\":false,\"value\":\"是\",\"key\":\"AaBaCcDd\"}," +
                "{\"checked\":false,\"value\":\"否\",\"key\":\"EeFfGgHh\"}],\"linkRule\":[],\"title\":\"数量是否正确\",\"type\":\"radioWidget\",\"value\":\"\"}," +
                "\"_S_APPLY\":{\"eid\":\"54991\",\"codeId\":\"_S_APPLY\",\"existEcosphere\":false,\"title\":\"提交人\",\"type\":\"personSelectWidget\"," +
                "\"personInfo\":[{\"image\":\"https://static.yunzhijia.com/space/c/photo/load?id=64390942f4614b0001aa2d1f\",\"companyName\":\"英轩控股集团有限公司\"," +
                "\"jobTitle\":\"售后服务专员\",\"name\":\"刘京升\",\"deptLongName\":\"英轩控股集团有限公司/英轩控股集团/叉车事业部/叉车营销部\",\"oid\":\"61bc3c5fe4b07717771c281f\"," +
                "\"dept\":\"叉车营销部\",\"userId\":\"61bc3c5ee4b07717771c2757\"}],\"value\":[\"61bc3c5fe4b07717771c281f\"],\"option\":\"single\"}," +
                "\"Te_9\":{\"codeId\":\"Te_9\",\"extendFieldMap\":{},\"title\":\"发运方式\",\"type\":\"textWidget\",\"value\":\"\"}," +
                "\"Te_8\":{\"codeId\":\"Te_8\",\"extendFieldMap\":{},\"title\":\"发货日期\",\"type\":\"textWidget\",\"value\":\"\"}," +
                "\"Te_7\":{\"codeId\":\"Te_7\",\"extendFieldMap\":{},\"title\":\"销售出库单号\",\"type\":\"textWidget\",\"value\":\"COP20230817000001\"}," +
                "\"Te_6\":{\"codeId\":\"Te_6\",\"extendFieldMap\":{},\"title\":\"发货单号\",\"type\":\"textWidget\",\"value\":\"\"}," +
                "\"_S_SERIAL\":{\"codeId\":\"_S_SERIAL\",\"title\":\"流水号\",\"type\":\"serialNumWidget\",\"value\":\"CCPJFYD-20230817-001\"}," +
                "\"_S_DATE\":{\"fillApplyDate\":false,\"codeId\":\"_S_DATE\",\"fromNowOn\":false,\"title\":\"申请日期\",\"type\":\"dateWidget\"" +
                ",\"value\":1692261140745},\"_S_DEPT\":{\"eid\":\"54991\",\"codeId\":\"_S_DEPT\",\"title\":\"所属部门\",\"type\":\"departmentSelectWidget\"" +
                ",\"deptInfo\":[{\"name\":\"叉车营销部\",\"orgId\":\"fae2d2e4-34ce-11e9-8ef3-ecf4bbea149a\",\"realLongName\":\"英轩控股集团有限公司!英轩控股集团!叉车事业部!叉车营销部\"," +
                "\"longName\":\"叉车营销部(英轩控股集团/叉车事业部)\"}],\"selectCompanyOnly\":false,\"value\":[\"fae2d2e4-34ce-11e9-8ef3-ecf4bbea149a\"]}," +
                "\"_S_TITLE\":{\"codeId\":\"_S_TITLE\",\"extendFieldMap\":{\"titleEntity\":{\"kind\":\"TITLE_NULL\",\"list\":[{\"formItem\":\"_S_APPLY\"," +
                "\"kind\":\"ITEM_FORM_ITEM\"},{\"formItem\":\"的\",\"kind\":\"ITEM_STRING\"},{\"formItem\":\"模板名称\",\"kind\":\"ITEM_TEMPLATENAME\"}]}," +
                "\"defaultTitle\":true},\"title\":\"标题\",\"type\":\"textWidget\",\"value\":\"山东万宇叉车销售有限公司三包配件发运单\"}}," +
                "\"detailMap\":{\"Dd_0\":{\"buttonName\":\"添加明细\",\"detailDefaultValues\":[],\"codeId\":\"Dd_0\",\"openErpLink\":false,\"widgetVos\":{\"Te_29\":{\"codeId\":\"Te_29\",\"extendFieldMap\":{\"wordLimit\":200},\"title\":\"单号\",\"type\":\"textWidget\"},\"Te_16\":{\"codeId\":\"Te_16\",\"extendFieldMap\":{},\"title\":\"发件原因\",\"type\":\"textWidget\"},\"Ac_0\":{\"displayCountSet\":false,\"expression\":\"\",\"displayThousand\":true,\"detailCountName\":\"总件数\",\"expressionReality\":[{\"type\":\"widget\",\"value\":\"Nu_0\"},{\"type\":\"operator\",\"value\":\"+\"},{\"type\":\"widget\",\"value\":\"Nu_1\"},{\"type\":\"operator\",\"value\":\"+\"},{\"type\":\"widget\",\"value\":\"Nu_2\"},{\"type\":\"operator\",\"value\":\"+\"},{\"type\":\"widget\",\"value\":\"Nu_3\"}],\"displayAmountWords\":false,\"title\":\"总件数\",\"type\":\"arithmeticWidget\",\"detailCountAmountWords\":false,\"codeId\":\"Ac_0\",\"decimalDigit\":2,\"extendFieldMap\":{},\"detailCount\":true},\"Nu_1\":{\"codeId\":\"Nu_1\",\"decimalDigit\":2,\"extendFieldMap\":{},\"detailCountName\":\"\",\"title\":\"纸箱\",\"type\":\"numberWidget\",\"detailCount\":false},\"Nu_0\":{\"codeId\":\"Nu_0\",\"decimalDigit\":2,\"extendFieldMap\":{},\"detailCountName\":\"\",\"title\":\"木箱\",\"type\":\"numberWidget\",\"detailCount\":false},\"Nu_3\":{\"codeId\":\"Nu_3\",\"decimalDigit\":2,\"extendFieldMap\":{},\"detailCountName\":\"\",\"title\":\"其他\",\"type\":\"numberWidget\",\"detailCount\":false},\"Nu_2\":{\"codeId\":\"Nu_2\",\"decimalDigit\":2,\"extendFieldMap\":{},\"detailCountName\":\"\",\"title\":\"包装袋\",\"type\":\"numberWidget\",\"detailCount\":false}},\"extendFieldMap\":{\"showSerialNum\":false},\"widgetValue\":[{\"_id_\":\"1\",\"Te_29\":\"COUT202308170005\",\"Nu_1\":\"0\",\"Ac_0\":\"0.00\",\"Te_16\":\"链条断裂\",\"Nu_0\":\"0\",\"Nu_3\":\"0.0\",\"Nu_2\":\"0\"}],\"imageInfo\":{},\"title\":\"明细\",\"type\":\"detailedWidget\",\"detailMap\":{}},\"Dd_1\":{\"buttonName\":\"添加明细\",\"detailDefaultValues\":[],\"codeId\":\"Dd_1\",\"openErpLink\":false,\"widgetVos\":{\"Te_19\":{\"codeId\":\"Te_19\",\"extendFieldMap\":{},\"title\":\"备注\",\"type\":\"textWidget\"},\"Nu_4\":{\"codeId\":\"Nu_4\",\"decimalDigit\":2,\"extendFieldMap\":{},\"detailCountName\":\"总数量\",\"title\":\"数量\",\"type\":\"numberWidget\",\"detailCount\":true},\"Te_18\":{\"codeId\":\"Te_18\",\"extendFieldMap\":{},\"title\":\"批次\",\"type\":\"textWidget\"},\"Te_17\":{\"codeId\":\"Te_17\",\"extendFieldMap\":{},\"title\":\"种类\",\"type\":\"textWidget\"}},\"extendFieldMap\":{\"showSerialNum\":true},\"title\":\"油品\",\"type\":\"detailedWidget\",\"detailMap\":{}},\"Dd_2\":{\"buttonName\":\"添加明细\",\"detailDefaultValues\":[],\"codeId\":\"Dd_2\",\"openErpLink\":false,\"widgetVos\":{\"Te_22\":{\"codeId\":\"Te_22\",\"extendFieldMap\":{},\"title\":\"物料名称\",\"type\":\"textWidget\"},\"Te_21\":{\"codeId\":\"Te_21\",\"extendFieldMap\":{},\"title\":\"物料编码\",\"type\":\"textWidget\"},\"Ra_2\":{\"codeId\":\"Ra_2\",\"extendFieldMap\":{},\"displaylinkageVos\":[],\"options\":[{\"checked\":false,\"value\":\"是\",\"key\":\"AaBaCcDd\"},{\"checked\":false,\"value\":\"否\",\"key\":\"EeFfGgHh\"}],\"linkRule\":[],\"title\":\"是否需要发回\",\"type\":\"radioWidget\"},\"Nu_5\":{\"codeId\":\"Nu_5\",\"decimalDigit\":0,\"extendFieldMap\":{},\"detailCountName\":\"总数量\",\"title\":\"数量\",\"type\":\"numberWidget\",\"detailCount\":true},\"Te_27\":{\"codeId\":\"Te_27\",\"extendFieldMap\":{},\"title\":\"备注\",\"type\":\"textWidget\"},\"Te_25\":{\"codeId\":\"Te_25\",\"extendFieldMap\":{},\"title\":\"包装方式\",\"type\":\"textWidget\"}},\"extendFieldMap\":{\"showSerialNum\":true},\"widgetValue\":[{\"Te_22\":\"链条\",\"Te_21\":\"LH1634×87-DZ\",\"Ra_2\":\"AaBaCcDd\",\"Nu_5\":\"2\",\"_id_\":\"1\",\"Te_27\":\"\",\"Te_25\":\"/\"}],\"imageInfo\":{},\"title\":\"物料明细\",\"type\":\"detailedWidget\",\"detailMap\":{}}}},\"basicInfo\":{\"nodeName\":\"完成审批\",\"eid\":\"54991\",\"eventId\":\"933a0586-cc8a-46c2-857f-3ae435c0a6d4\",\"formDefId\":\"645da8f541e8d8000102a762\",\"dataType\":1,\"myNetworkInfo\":{\"eid\":\"54991\",\"name\":\"英轩控股集团有限公司\"},\"nodeType\":\"END\",\"title\":\"叉车三包配件发运单\",\"flowInstId\":\"64dddb1411ab5f00012505d0\",\"formCodeId\":\"dab105db137542ff98b60f75f59099d7\",\"actionType\":\"reach\",\"myPersonInfo\":{\"image\":\"https://static.yunzhijia.com/space/c/photo/load?id=64390942f4614b0001aa2d1f\",\"jobNo\":\"12738\",\"name\":\"刘京升\",\"oid\":\"61bc3c5fe4b07717771c281f\"},\"formInstId\":\"64dddb142c2ffc000103a84b\",\"eventTime\":1692266775615,\"myDeptInfo\":{\"name\":\"叉车营销部\",\"orgId\":\"fae2d2e4-34ce-11e9-8ef3-ecf4bbea149a\"}," +
                "\"interfaceId\":\"2bcHfLoj\",\"interfaceName\":\"EAS\",\"returned\":false,\"nodeId\":\"64ddf117e835600001b0e2a1\"}},\"success\":true,\"errorCode\":0}";
        String jsonss = "{\"data\":{\"formInfo\":{\"widgetLinkRecordsMap\":{},\"widgetMap\":{\"Te_5\":{\"codeId\":\"Te_5\",\"extendFieldMap\":{},\"title\":\"预计到货天数\",\"type\":\"textWidget\",\"value\":\"\"},\"Te_11\":{\"codeId\":\"Te_11\",\"extendFieldMap\":{},\"title\":\"查询电话\",\"type\":\"textWidget\",\"value\":\"\"},\"Te_4\":{\"codeId\":\"Te_4\",\"extendFieldMap\":{},\"title\":\"联系方式\",\"type\":\"textWidget\",\"value\":\"13953902233\"},\"Te_10\":{\"codeId\":\"Te_10\",\"extendFieldMap\":{},\"title\":\"付费方式\",\"type\":\"textWidget\",\"value\":\"寄付\"},\"Te_3\":{\"codeId\":\"Te_3\",\"extendFieldMap\":{},\"title\":\"收货人姓名\",\"type\":\"textWidget\",\"value\":\"李青林\"},\"Te_2\":{\"codeId\":\"Te_2\",\"extendFieldMap\":{},\"title\":\"收货地址\",\"type\":\"textWidget\",\"value\":\"临沂市兰山区327国道杭州叉车\"},\"Te_20\":{\"codeId\":\"Te_20\",\"extendFieldMap\":{},\"title\":\"总重量（kg）\",\"type\":\"textWidget\",\"value\":\"10\"},\"Te_30\":{\"codeId\":\"Te_30\",\"extendFieldMap\":{\"wordLimit\":200},\"title\":\"车牌号\",\"type\":\"textWidget\",\"value\":\"\"},\"Te_1\":{\"codeId\":\"Te_1\",\"extendFieldMap\":{},\"title\":\"预计发货日期\",\"type\":\"textWidget\",\"value\":\"2023-08-17\"},\"Te_0\":{\"codeId\":\"Te_0\",\"extendFieldMap\":{},\"title\":\"收货公司\",\"type\":\"textWidget\",\"value\":\"山东万宇叉车销售有限公司\"},\"Ra_0\":{\"codeId\":\"Ra_0\",\"extendFieldMap\":{},\"displaylinkageVos\":[],\"options\":[{\"checked\":false,\"value\":\"是\",\"key\":\"AaBaCcDd\"},{\"checked\":false,\"value\":\"否\",\"key\":\"EeFfGgHh\"}],\"linkRule\":[],\"title\":\"包装是否完好无损\",\"type\":\"radioWidget\",\"value\":\"\"},\"Ra_1\":{\"codeId\":\"Ra_1\",\"extendFieldMap\":{},\"displaylinkageVos\":[],\"options\":[{\"checked\":false,\"value\":\"是\",\"key\":\"AaBaCcDd\"},{\"checked\":false,\"value\":\"否\",\"key\":\"EeFfGgHh\"}],\"linkRule\":[],\"title\":\"数量是否正确\",\"type\":\"radioWidget\",\"value\":\"\"},\"_S_APPLY\":{\"eid\":\"54991\",\"codeId\":\"_S_APPLY\",\"existEcosphere\":false,\"title\":\"提交人\",\"type\":\"personSelectWidget\",\"personInfo\":[{\"image\":\"https://static.yunzhijia.com/space/c/photo/load?id=64390942f4614b0001aa2d1f\",\"companyName\":\"英轩控股集团有限公司\",\"jobTitle\":\"售后服务专员\",\"name\":\" 刘京升\",\"deptLongName\":\"英轩控股集团有限公司/英轩控股集团/叉车事业部/叉车营销部\",\"oid\":\"61bc3c5fe4b07717771c281f\",\"dept\":\"叉车营销部\",\"userId\":\"61bc3c5ee4b07717771c2757\"}],\"value\":[\"61bc3c5fe4b07717771c281f\"],\"option\":\"single\"},\"Te_9\":{\"codeId\":\"Te_9\",\"extendFieldMap\":{},\"title\":\"发运方式\",\"type\":\"textWidget\",\"value\":\"\"},\"Te_8\":{\"codeId\":\"Te_8\",\"extendFieldMap\":{},\"title\":\"发货日期\",\"type\":\"textWidget\",\"value\":\"\"},\"Te_7\":{\"codeId\":\"Te_7\",\"extendFieldMap\":{},\"title\":\"销售出库单号\",\"type\":\"textWidget\",\"value\":\"COP20230817000001\"},\"Te_6\":{\"codeId\":\"Te_6\",\"extendFieldMap\":{},\"title\":\"发货单号\",\"type\":\"textWidget\",\"value\":\"\"},\"_S_SERIAL\":{\"codeId\":\"_S_SERIAL\",\"title\":\"流水号\",\"type\":\"serialNumWidget\",\"value\":\"CCPJFYD-20230817-001\"},\"_S_DATE\":{\"fillApplyDate\":false,\"codeId\":\"_S_DATE\",\"fromNowOn\":false,\"title\":\"申请日期\",\"type\":\"dateWidget\",\"value\":1692261140745},\"_S_DEPT\":{\"eid\":\"54991\",\"codeId\":\"_S_DEPT\",\"title\":\"所属部门\",\"type\":\"departmentSelectWidget\",\"deptInfo\":[{\"name\":\"叉车营销部\",\"orgId\":\"fae2d2e4-34ce-11e9-8ef3-ecf4bbea149a\",\"realLongName\":\"英轩控股集团有限公司!英轩控股集团!叉车事业部!叉车营销部\",\"longName\":\"叉车营销部(英轩控股集团/叉车事业部)\"}],\"selectCompanyOnly\":false,\"value\":[\"fae2d2e4-34ce-11e9-8ef3-ecf4bbea149a\"]},\"_S_TITLE\":{\"codeId\":\"_S_TITLE\",\"extendFieldMap\":{\"titleEntity\":{\"kind\":\"TITLE_NULL\",\"list\":[{\"formItem\":\"_S_APPLY\",\"kind\":\"ITEM_FORM_ITEM\"},{\"formItem\":\"的\",\"kind\":\"ITEM_STRING\"},{\"formItem\":\"模板名称\",\"kind\":\"ITEM_TEMPLATENAME\"}]},\"defaultTitle\":true},\"title\":\"标题\",\"type\":\"textWidget\",\"value\":\"山东万宇叉车销售有限公司三包配件发运单\"}},\"detailMap\":{\"Dd_0\":{\"buttonName\":\"添加明细\",\"detailDefaultValues\":[],\"codeId\":\"Dd_0\",\"openErpLink\":false,\"widgetVos\":{\"Te_29\":{\"codeId\":\"Te_29\",\"extendFieldMap\":{\"wordLimit\":200},\"title\":\"单号\",\"type\":\"textWidget\"},\"Te_16\":{\"codeId\":\"Te_16\",\"extendFieldMap\":{},\"title\":\"发件原因\",\"type\":\"textWidget\"},\"Ac_0\":{\"displayCountSet\":false,\"expression\":\"\",\"displayThousand\":true,\"detailCountName\":\"总件数\",\"expressionReality\":[{\"type\":\"widget\",\"value\":\"Nu_0\"},{\"type\":\"operator\",\"value\":\"+\"},{\"type\":\"widget\",\"value\":\"Nu_1\"},{\"type\":\"operator\",\"value\":\"+\"},{\"type\":\"widget\",\"value\":\"Nu_2\"},{\"type\":\"operator\",\"value\":\"+\"},{\"type\":\"widget\",\"value\":\"Nu_3\"}],\"displayAmountWords\":false,\"title\":\"总件数\",\"type\":\"arithmeticWidget\",\"detailCountAmountWords\":false,\"codeId\":\"Ac_0\",\"decimalDigit\":2,\"extendFieldMap\":{},\"detailCount\":true},\"Nu_1\":{\"codeId\":\"Nu_1\",\"decimalDigit\":2,\"extendFieldMap\":{},\"detailCountName\":\"\",\"title\":\"纸箱\",\"type\":\"numberWidget\",\"detailCount\":false},\"Nu_0\":{\"codeId\":\"Nu_0\",\"decimalDigit\":2,\"extendFieldMap\":{},\"detailCountName\":\"\",\"title\":\"木箱\",\"type\":\"numberWidget\",\"detailCount\":false},\"Nu_3\":{\"codeId\":\"Nu_3\",\"decimalDigit\":2,\"extendFieldMap\":{},\"detailCountName\":\"\",\"title\":\"其他\",\"type\":\"numberWidget\",\"detailCount\":false},\"Nu_2\":{\"codeId\":\"Nu_2\",\"decimalDigit\":2,\"extendFieldMap\":{},\"detailCountName\":\"\",\"title\":\"包装袋\",\"type\":\"numberWidget\",\"detailCount\":false}},\"extendFieldMap\":{\"showSerialNum\":false},\"widgetValue\":[{\"_id_\":\"1\",\"Te_29\":\"COUT202308170005\",\"Nu_1\":\"0\",\"Ac_0\":\"0.00\",\"Te_16\":\"链条断裂\",\"Nu_0\":\"0\",\"Nu_3\":\"0.0\",\"Nu_2\":\"0\"}],\"imageInfo\":{},\"title\":\"明细\",\"type\":\"detailedWidget\",\"detailMap\":{}},\"Dd_1\":{\"buttonName\":\"添加明细\",\"detailDefaultValues\":[],\"codeId\":\"Dd_1\",\"openErpLink\":false,\"widgetVos\":{\"Te_19\":{\"codeId\":\"Te_19\",\"extendFieldMap\":{},\"title\":\"备注\",\"type\":\"textWidget\"},\"Nu_4\":{\"codeId\":\"Nu_4\",\"decimalDigit\":2,\"extendFieldMap\":{},\"detailCountName\":\"总数量\",\"title\":\"数量\",\"type\":\"numberWidget\",\"detailCount\":true},\"Te_18\":{\"codeId\":\"Te_18\",\"extendFieldMap\":{},\"title\":\"批次\",\"type\":\"textWidget\"},\"Te_17\":{\"codeId\":\"Te_17\",\"extendFieldMap\":{},\"title\":\"种类\",\"type\":\"textWidget\"}},\"extendFieldMap\":{\"showSerialNum\":true},\"title\":\"油品\",\"type\":\"detailedWidget\",\"detailMap\":{}},\"Dd_2\":{\"buttonName\":\"添加明细\",\"detailDefaultValues\":[],\"codeId\":\"Dd_2\",\"openErpLink\":false,\"widgetVos\":{\"Te_22\":{\"codeId\":\"Te_22\",\"extendFieldMap\":{},\"title\":\"物料名称\",\"type\":\"textWidget\"},\"Te_21\":{\"codeId\":\"Te_21\",\"extendFieldMap\":{},\"title\":\"物料编码\",\"type\":\"textWidget\"},\"Ra_2\":{\"codeId\":\"Ra_2\",\"extendFieldMap\":{},\"displaylinkageVos\":[],\"options\":[{\"checked\":false,\"value\":\"是\",\"key\":\"AaBaCcDd\"},{\"checked\":false,\"value\":\"否\",\"key\":\"EeFfGgHh\"}],\"linkRule\":[],\"title\":\"是否需要发回\",\"type\":\"radioWidget\"},\"Nu_5\":{\"codeId\":\"Nu_5\",\"decimalDigit\":0,\"extendFieldMap\":{},\"detailCountName\":\"总数量\",\"title\":\"数量\",\"type\":\"numberWidget\",\"detailCount\":true},\"Te_27\":{\"codeId\":\"Te_27\",\"extendFieldMap\":{},\"title\":\"备注\",\"type\":\"textWidget\"},\"Te_25\":{\"codeId\":\"Te_25\",\"extendFieldMap\":{},\"title\":\"包装方式\",\"type\":\"textWidget\"}},\"extendFieldMap\":{\"showSerialNum\":true},\"widgetValue\":[{\"id\":\"1757313975139203073\",\"Te_22\":\"链条\",\"Te_21\":\"LH1634×87-DZ\",\"Ra_2\":\"AaBaCcDd\",\"Nu_5\":\"2\",\"_id_\":\"1\",\"Te_27\":\"textWidget\",\"Te_25\":\"/\"}],\"imageInfo\":{},\"title\":\"物料明细\",\"type\":\"detailedWidget\",\"detailMap\":{}}}},\"basicInfo\":{\"nodeName\":\"完成审批\",\"eid\":\"54991\",\"eventId\":\"933a0586-cc8a-46c2-857f-3ae435c0a6d4\",\"formDefId\":\"645da8f541e8d8000102a762\",\"dataType\":1,\"myNetworkInfo\":{\"eid\":\"54991\",\"name\":\"英轩控股集团有限公司\"},\"nodeType\":\"END\",\"title\":\"叉车三包配件发运单\",\"flowInstId\":\"64dddb1411ab5f00012505d0\",\"formCodeId\":\"dab105db137542ff98b60f75f59099d7\",\"actionType\":\"reach\",\"myPersonInfo\":{\"image\":\"https://static.yunzhijia.com/space/c/photo/load?id=64390942f4614b0001aa2d1f\",\"jobNo\":\"12738\",\"name\":\" 刘京升\",\"oid\":\"61bc3c5fe4b07717771c281f\"},\"formInstId\":\"64dddb142c2ffc000103a84b\",\"eventTime\":1692266775615,\"myDeptInfo\":{\"name\":\"叉车营销部\",\"orgId\":\"fae2d2e4-34ce-11e9-8ef3-ecf4bbea149a\"},\"interfaceId\":\"2bcHfLoj\",\"interfaceName\":\"EAS\",\"returned\":false,\"nodeId\":\"64ddf117e835600001b0e2a1\"}},\"success\":true,\"errorCode\":0}";
        return jsonss;
    }

    @Override
    public void registerListener(EventObject e) {
        super.registerListener(e);
        TextEdit yem_arbusbill = this.getView().getControl("yem_formcode");
        yem_arbusbill.addButtonClickListener(this);
    }

    @Override
    public void click(EventObject evt) {
        super.click(evt);
        Control c = (Control) evt.getSource();
        String key = c.getKey().toLowerCase();
        switch (key) {
            case "yem_formcode":
                yem_formcode();
                break;
        }
    }

    @Override
    public void closedCallBack(ClosedCallBackEvent e) {
        super.closedCallBack(e);
        String actionId = e.getActionId();
        IDataModel model = this.getModel();
        if ("yem_formcode".equals(actionId)) {
            ListSelectedRowCollection listData = (ListSelectedRowCollection) e.getReturnData();
            if (listData != null && listData.size() > 0) {
                long fid = (long) listData.get(0).getPrimaryKeyValue();
                String FBillNo = listData.get(0).getBillNo();
                this.getView().getModel().setValue("yem_formcode", fid);
                this.getView().getModel().setValue("yem_remark", FBillNo);
            }
        }
    }

    public void yem_formcode() {
        DynamicObject dataEntity = this.getModel().getDataEntity(true);
        DynamicObject yemFormid = dataEntity.getDynamicObject("yem_formid");
        if (yemFormid == null) {
            this.getView().showErrorNotification("请先选择业务对象");
            return;
        }
        ListShowParameter listpara = new ListShowParameter();
        listpara.setBillFormId(yemFormid.getString("number"));
        listpara.setParentPageId(this.getView().getPageId());
        listpara.setMultiSelect(false);
        listpara.setStatus(OperationStatus.VIEW);
        listpara.getOpenStyle().setShowType(ShowType.Modal);
        ListFilterParameter listFilterParameter = new ListFilterParameter();
//        QFilter qFilter = new QFilter("billstatus", QCP.equals, "C");
//        listFilterParameter.setFilter(qFilter);
        listpara.setListFilterParameter(listFilterParameter);
        listpara.getOpenStyle().setCacheId(listpara.getPageId());
        listpara.setLookUp(true);
        //设置弹出子单据页面的样式
        StyleCss inlineStyleCss = new StyleCss();
        inlineStyleCss.setHeight("800");
        inlineStyleCss.setWidth("1400");
        listpara.getOpenStyle().setInlineStyleCss(inlineStyleCss);
        CloseCallBack closeCallBack = new CloseCallBack(this.getClass().getName(), "yem_formcode");
        listpara.setCloseCallBack(closeCallBack);
//        listpara.setCaption("暂估应收单");
        this.getView().showForm(listpara);
    }
}
