package yem.wmc.ydn.formplugin.dynamic;

import com.alibaba.fastjson.JSONObject;
import kd.bos.dataentity.entity.LocaleString;
import kd.bos.form.FormShowParameter;
import kd.bos.form.container.Wizard;
import kd.bos.form.control.Control;
import kd.bos.form.control.Steps;
import kd.bos.form.control.StepsOption;
import kd.bos.form.plugin.AbstractFormPlugin;

import java.util.*;

/**
 * @author lipan
 * @date 2024/4/18 17:37
 * @className TrackinformEdit
 * @description
 */
public class TrackinformDynamicForm extends AbstractFormPlugin {

    private Viewshipping viewshipping=new Viewshipping();

    @Override
    public void registerListener(EventObject e) {
        super.registerListener(e);
        this.addClickListeners("yem_atlas");
        this.addClickListeners("yem_details");
    }

    @Override
    public void afterCreateNewData(EventObject e) {
        Wizard wizard = this.getControl("yem_wizardap");
        // 获取设计时的步骤条设置
        //父页面传参
        List<StepsOption> stepsOptionParent=new ArrayList<>();////父页面传参
        StepsOption stepsOption0 = new StepsOption();
        stepsOption0.setTitle(new LocaleString("提空箱"));
        stepsOption0.setDescription(new LocaleString("2023-01-01 10:00:00"));
        stepsOptionParent.add(stepsOption0);

        StepsOption stepsOption1 = new StepsOption();
        stepsOption1.setTitle(new LocaleString("进场"));
        stepsOption1.setDescription(new LocaleString("2023-01-01 10:00:00"));
        stepsOptionParent.add(stepsOption1);

        StepsOption stepsOption2 = new StepsOption();
        stepsOption2.setTitle(new LocaleString("放行"));
        stepsOption2.setDescription(new LocaleString("2023-01-01 10:00:00"));
        stepsOptionParent.add(stepsOption2);

        StepsOption stepsOption3 = new StepsOption();
        stepsOption3.setTitle(new LocaleString("装船"));
        stepsOption3.setDescription(new LocaleString("2023-01-01 10:00:00"));
        stepsOptionParent.add(stepsOption3);

        StepsOption stepsOption4 = new StepsOption();
        stepsOption4.setTitle(new LocaleString("开航"));
        stepsOption4.setDescription(new LocaleString("2023-01-01 10:00:00"));
        stepsOptionParent.add(stepsOption4);

        StepsOption stepsOption5 = new StepsOption();
        stepsOption5.setTitle(new LocaleString("中转"));
        stepsOption5.setDescription(new LocaleString("2023-01-01 10:00:00"));
        stepsOptionParent.add(stepsOption5);

        StepsOption stepsOption6 = new StepsOption();
        stepsOption6.setTitle(new LocaleString("卸船"));
        stepsOption6.setDescription(new LocaleString("2023-01-01 10:00:00"));
        stepsOptionParent.add(stepsOption6);

        StepsOption stepsOption7 = new StepsOption();
        stepsOption7.setTitle(new LocaleString("提货"));
        stepsOption7.setDescription(new LocaleString("2023-01-01 10:00:00"));
        stepsOptionParent.add(stepsOption7);

        StepsOption stepsOption8 = new StepsOption();
        stepsOption8.setTitle(new LocaleString("还空"));
        stepsOption8.setDescription(new LocaleString("2023-01-01 10:00:00"));
        stepsOptionParent.add(stepsOption8);



        Trackinform trackinform=new Trackinform();
        trackinform.setContainer("20*40Dry");
        trackinform.setOrdernumber("218389651");
        trackinform.setPickupgood("06-22 23:08");
        trackinform.setShipname("SAN FERNANDO");
        trackinform.setShippcompanies("MSK[官网]");
        trackinform.setStepsOptionParent(stepsOptionParent);





        // 设置当前节点
        Map<String, Object> currentStepMap = new HashMap<>();
        currentStepMap.put("currentStep", 6);
        currentStepMap.put("currentStatus", Steps.FINISH);
        // 更新当前节点
        wizard.setWizardCurrentStep(currentStepMap);
        List<StepsOption> stepsOptions = wizard.getStepsOptions();
        stepsOptions.clear();
        stepsOptions.addAll(trackinform.getStepsOptionParent());
        // 更新步骤条设置
        wizard.setWizardStepsOptions(stepsOptions);
        this.getModel().setValue("yem_ordernumber",trackinform.getOrdernumber());
        this.getModel().setValue("yem_shipname",trackinform.getShipname());
        this.getModel().setValue("yem_pickupgood",trackinform.getPickupgood());
        this.getModel().setValue("yem_remarks",trackinform.getRemarks());
        this.getModel().setValue("yem_shippcompanies",trackinform.getShippcompanies());
        this.getModel().setValue("yem_container",trackinform.getContainer());



        FormShowParameter showParameter = this.getView().getFormShowParameter();
        Map<String, Object> cusMap = showParameter.getCustomParams();
        JSONObject data = (JSONObject) cusMap.get("data");
        viewshipping = JSONObject.toJavaObject(data, Viewshipping.class);
        this.getModel().setValue("yem_blno",viewshipping.getblno());
        this.getModel().setValue("yem_pol",viewshipping.getpol());
        this.getModel().setValue("yem_dtp",viewshipping.getdtp());
        this.getModel().setValue("yem_dataupdatetime",viewshipping.getdataupdatetime());

    }


    @Override
    public void click(EventObject evt) {
        super.click(evt);
        Control source = (Control) evt.getSource();
        String key = source.getKey();
        switch (key) {
            case "yem_atlas"://地图
                this.getView().showMessage("地图");
                break;
            case "yem_details"://详情
                this.getView().showMessage("详情");
                break;
            default:
                break;
        }

    }
}