package com.yem.em.form;

//import json.JSONArray;
//import json.JSONObject;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.form.plugin.AbstractFormPlugin;

import java.util.EventObject;

/**
 * @author zhouc
 * @date 2023/9/5 11:37
 * @className VehiclEdit
 * @description 整车领料差异表单插件
 *
 */
public class VehiclEdit  extends AbstractFormPlugin {

    @Override
    public void afterCreateNewData(EventObject e) {
        super.afterCreateNewData(e);
        IDataModel model = this.getModel();
        String Value="[{\"yem_contrastdate\":\"2032-08-25\",\"yem_discrepancy\":\"装载机\",\"yem_framenumber\":\"567006LFCNV288032\",\"yem_producttype\":\"2\"},{\"yem_contrastdate\":\"2032-08-27\",\"yem_discrepancy\":\"挖掘机\",\"yem_framenumber\":\"567006LFCPB293503\",\"yem_producttype\":\"1\"},{\"yem_contrastdate\":\"2032-08-30\",\"yem_discrepancy\":\"装载机\",\"yem_framenumber\":\"567006LFLNX292422\",\"yem_producttype\":\"1\"},{\"yem_contrastdate\":\"2032-08-30\",\"yem_discrepancy\":\"装载机\",\"yem_framenumber\":\"567006LFTNX292412\",\"yem_producttype\":\"3\"}]";
        JSONArray jsonArray = JSONObject.parseArray(Value);
        model.deleteEntryData("yem_entryentity");
        for(int i = 0;i<jsonArray.size();i++){
            JSONObject obj =(JSONObject)jsonArray.get(i);
            int row = model.createNewEntryRow("yem_entryentity");
            model.setValue("yem_framenumber", obj.getString("yem_framenumber"), row);
            model.setValue("yem_discrepancy", obj.getString("yem_discrepancy"), row);
            model.setValue("yem_producttype", obj.getString("yem_producttype"), row);
            model.setValue("yem_contrastdate", obj.getString("yem_contrastdate"), row);
        }
        this.getView().updateView("yem_entryentity");
    }
}
