var Checker_Export_Plan = "";
var Checker_Pwwd_Dialog_ID = 0;
var Product_Class = 1;
var Checker_Error_Info;
var CheckerTask_Info;
var CheckerPlanInfoList = [];
var CheckerChipID = 0;
var Checker_Product_Name = JQ_Product_Names;
var epe_qthandle = null;
var Checker_Test_CMD_ID_BEG = 200; //测试命令的起始ID应该大于200
var ProductFun_Class = [
  "0:通用",
  "1:68uF坦电容22um桥丝",
  "2:68uF坦电容8Ω电阻",
  "3:68uF坦电容6Ω电阻",
  "4:33uF钽电容22um桥丝",
  "5:33uF钽电容2Ω电阻",
  "6:100uF固液混合6Ω电阻",
  "7:82uF电解8Ω电阻",
  "8:100uF固液混合8Ω电阻",
  "9:100uF大电解30um桥丝",
];

var Checker_YE_Cfg = {
  PlanID: 1, //检测方案ID
  PlanBrief: "默认名称",
  CheckSoftVersion: [0x0001, 0x0002], //适配检测小板，检测小板主版本
  CheckHardVersion: [0x000], //适配的硬件
  TimeOutS: 30, //方案执行最长时间 单位S
  TimeOutM: 36, //主控超时
  TimeOutUI: 38, //电脑超时
  TaskIDMax: 26, //任务ID最大值
  FacInfoSize: 0,
  FacInfoAddr: -1, //小于0表示未选择
  FacFunClass: 0,
};

var CheckerChipType = ["EJ/EQ系列", "EX系列", "EW系列"];

function JQChecker_GetErrorInfo(errcode) {
  for (var i = 0; i < Checker_Error_Info.SubErrInfo.length; i++) {
    if (Checker_Error_Info.SubErrInfo[i].ErrCode == errcode) {
      return Checker_Error_Info.SubErrInfo[i].Info;
    }
  }
  return "未知错误";
}

function Checker_ChipTypeInit(chipid) {
  var select_obj = $(".product_chip_select");
  select_obj.children().remove();
  CheckerChipID = chipid;
  for (var i = 0; i < CheckerChipType.length; i++) {
    var content_str = "";
    if (i != CheckerChipID) {
      content_str =
        "<option value=" + i + ">" + CheckerChipType[i] + "</option>";
    } else {
      content_str =
        "<option value=" +
        i +
        ' selected = "selected">' +
        CheckerChipType[i] +
        "</option>";
    }

    select_obj.append(content_str);
    CheckerPlanInfoList[i] = null;
  }
  var select_obj = $(".product_class_select");
  select_obj.children().remove();
  for (var i = 0; i < Checker_Product_Name.length; i++) {
    var content_str = "";
    if (i != 0) {
      content_str =
        "<option value=" + i + ">" + Checker_Product_Name[i] + "</option>";
    } else {
      content_str =
        "<option value=" +
        i +
        ' selected = "selected">' +
        Checker_Product_Name[i] +
        "</option>";
    }
    select_obj.append(content_str);
  }

  var select_obj = $(".func_class_select");
  select_obj.children().remove();
  for (var i = 0; i < ProductFun_Class.length; i++) {
    var content_str = "";
    if (i != 0) {
      content_str =
        "<option value=" + i + ">" + ProductFun_Class[i] + "</option>";
    } else {
      content_str =
        "<option value=" +
        i +
        ' selected = "selected">' +
        ProductFun_Class[i] +
        "</option>";
    }
    select_obj.append(content_str);
  }
}

function CheckerPlan_Init() {
  console.log("JQCheckerPlan_Init   ---");
  ViewPage_ID = 7;
  if (typeof qt != "undefined" && qt != null) {
    var qwebchannel = new QWebChannel(qt.webChannelTransport, function (
      channel
    ) {
      qchannel = channel;

      if (typeof qchannel != "undefined" && qchannel != null) {
        if (epe_qthandle != null && typeof epe_qthandle != "undefined") {
          console.log("JQCheckerPlan_Init  OK ---");
        } else {
          epe_qthandle = qchannel.objects.epe_qthandle;
          if (typeof epe_qthandle != "undefined" && epe_qthandle != null) {
            console.log("JQCheckerPlan_Init  OK ---");
            epe_qthandle.Epe_PageReady();
            epe_qthandle.Epe_JQLoadPlan.connect(function (jsonstr) {
              var checker_plan = JSON.parse(jsonstr);
              Checker_LoadPlan(checker_plan);
            });
            epe_qthandle.Epe_ExportResult.connect(function (result) {
              if (result == 0) {
                layer.close(Checker_Pwwd_Dialog_ID);
              } else {
                var obj = $(".checker_pwd_report");
                if (typeof obj != "undefined" && obj != null) {
                  obj[0].innerText = "密码错误";
                }
              }
            });
            epe_qthandle.ShowCommMes.connect(function (mesg, type) {
              CheckerShowMes_autoClose("信息 ", mesg, 3000);
            });
            epe_qthandle.ShowCommport.connect(function (jsoninfo) {
              Main_ShowCommport(jsoninfo);
              console.log("Main_ShowCommport  OK ---");
            });
            epe_qthandle.Epe_ShowReadStr.connect(function (str) {
              Checker_ShowReadStr(str);
            });
          }
        }
      }
    });
  }
  Checker_ChipTypeInit(0);
  Checker_UpdateChipInfo(0);
  CheckerChangeChip(0, 0);
  $(".product_chip_select").change(function () {
    var index = parseInt($(this).val());
    Checker_UpdateChipInfo(index);
    CheckerChangeChip(CheckerChipID, index);
    CheckerChipID = index;
    Checker_AddTaskList();
  });

  if (Checker_En_CmdTest) {
    $("#checker_planTest_btn").css("display", "block");
  }
  //全部折叠
  $(".checker_taskitem_allflod")
    .unbind("click")
    .bind("click", function (event) {
      event.stopImmediatePropagation();
      CheckerTaskFoldExpand(0);
    });
  //全部展开
  $(".checker_taskitem_expand")
    .unbind("click")
    .bind("click", function (event) {
      event.stopImmediatePropagation();
      CheckerTaskFoldExpand(1);
    });
  //查找
  $(".checker_search_task")
    .unbind("click")
    .bind("click", function (event) {
      event.stopImmediatePropagation();
      CheckerTaskSearch();
    });
  //查找输入框
  $(".checker_serach_input")
    .unbind("click")
    .bind("click", function (event) {
      event.stopImmediatePropagation();
    });
  //刷新方案ID
  $(".checker_plan_title")
    .unbind("click")
    .bind("click", function (event) {
      $(".checker_plan_title")[0].innerText =
        "任务信息配置: " + Checker_GetPlanIDInput();
      event.stopImmediatePropagation();
    });
}
function CheckerTaskFoldExpand(flag) {
  var task_info_list = $(".layui-colla-content");
  for (var index = 1; index < task_info_list.length; index++) {
    if (flag == 1) {
      $(task_info_list[index]).addClass("layui-show");
    } else {
      $(task_info_list[index]).removeClass("layui-show");
    }
  }
}

function CheckerTaskSearch() {
  var inputv = $(".checker_serach_input").val();
  var taskID = parseInt(inputv);
  var checker_plan = Checker_GetCfgInfo();
  var info_list = checker_plan.TaskArray;
  var task_info_list = $(".layui-colla-content");
  var show_count = 0;
  if (isNaN(taskID)) {
    //不能转数值，则按方案名称搜索
    for (var index = 0; index < info_list.length; index++) {
      show_count = info_list[index].TaskIndex + 1;
      if (task_info_list.length < show_count) {
        continue;
      }
      if (info_list[index].TaskBrief.indexOf(inputv) >= 0) {
        $(task_info_list[show_count]).addClass("layui-show");
      } else {
        $(task_info_list[show_count]).removeClass("layui-show");
      }
    }
  } else {
    for (var index = 0; index < info_list.length; index++) {
      show_count = info_list[index].TaskIndex + 1;
      if (task_info_list.length < show_count) {
        continue;
      }
      if (info_list[index].TaskID == taskID) {
        $(task_info_list[show_count]).addClass("layui-show");
      } else {
        $(task_info_list[show_count]).removeClass("layui-show");
      }
    }
  }
}

function Checker_UpdateChipInfo(chipid) {
  switch (chipid) {
    case 0:
      Checker_Error_Info = JQ_ErrorInfo;
      CheckerTask_Info = JQCheckerTaskInfo;
      Checker_Product_Name = JQ_Product_Names;
      break;
    case 1:
      Checker_Error_Info = XT_ErrorInfo;
      CheckerTask_Info = XTCheckerTaskInfo;
      Checker_Product_Name = XT_Product_Names;
      break;
    case 2:
      Checker_Error_Info = EW_ErrorInfo;
      CheckerTask_Info = EWCheckerTaskInfo;
      Checker_Product_Name = EW_Product_Names;
      break;
  }
}
//芯片种类更换
function CheckerChangeChip(lastchip, nowchip) {
  var cfg_obj = $(".checker_cfig_div");
  var first_select = false;
  var taskInfo_list = CheckerPlanInfoList[nowchip];
  if (lastchip != nowchip) {
    CheckerPlanInfoList[lastchip] = Checker_GetCfgInfo();
  }
  if (taskInfo_list == null) {
    var date = new Date();
    date_str =
      date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
    var planid = Checker_GetPlanID(date_str, 0, 1);
    var def_cfg = {
      PlanID: planid, //检测方案ID
      PlanBrief: "",
      CheckSoftVersion: [], //适配检测小板，检测小板主版本
      CheckHardVersion: [], //适配的硬件
      TimeOutS: 30, //方案执行最长时间 单位S
      TimeOutM: 36, //主控超时
      TimeOutUI: 38, //电脑超时
      TaskIDMax: 26, //任务ID最大值
      TaskArray: [],
    };
    Checker_ImportShow(def_cfg);
  } else {
    Checker_ImportShow(taskInfo_list);
  }
}
//降数据项转为数字
function Checker_GetPlanID(date_str, product, num) {
  date_str = date_str.split("-");
  var year = date_str[0] - 2022;
  var moth = date_str[1] - 0;
  var day = date_str[2] - 0;
  year = ((year & 0x7f) << 9) | ((moth & 0x0f) << 5) | (day & 0x1f);

  var temp = (CheckerChipID & 0x0f) << 12;

  temp |= (product & 0x1f) << 7;
  temp |= num & 0x7f;

  return parseInt((year << 16) | temp);
}
//将数字转为输入项
function Checker_GetShowPlanID(planid) {
  var temp = planid >> 16;
  var show_info = {};
  var moth = (temp >> 5) & 0x0f;
  var day = temp & 0x1f;
  show_info.date_str = ((temp >> 9) & 0x7f) + 2022;
  if (moth < 10) {
    moth = "0" + moth;
  }
  if (day < 10) {
    day = "0" + day;
  }
  show_info.date_str += "-" + moth + "-" + day;
  show_info.chipid = (planid >> 12) & 0x0f;
  show_info.product = (planid >> 7) & 0x1f;
  show_info.num = planid & 0x7f;
  return show_info;
}
function Checker_GetPlanIDInput() {
  var product = $(".product_class_select").val();
  var task_info_list = $(".checker_cfig_div").children();
  var temp_obj = $(task_info_list[0]);
  var data_str = "";
  var planNum;
  var temp_input_list = temp_obj.find("input");
  for (var index = 1; index < temp_input_list.length && index < 3; index++) {
    var obj_input = $(temp_input_list[index]);
    var input_v = obj_input.val();
    if (typeof input_v == "undefined" || input_v.length < 1) {
      continue;
    }
    switch (index) {
      case 1:
        data_str = input_v;
        break;
      case 2:
        planNum = parseInt(input_v);
        break;
      default:
        break;
    }
  }
  return Checker_GetPlanID(data_str, product, planNum);
}
//获取页面配置
function Checker_GetCfgInfo() {
  var checker_plan = Checker_YE_Cfg;
  var checker_table_name = [];
  var product = $(".product_class_select").val();
  var productFun = $(".func_class_select").val() * 1;
  var task_info_list = $(".checker_cfig_div").children();
  var temp_obj = $(task_info_list[0]);
  var data_str = "";
  var planNum;
  var temp_input_list = temp_obj.find("input");
  checker_plan.TaskArray = [];
  for (var index = 1; index < temp_input_list.length; index++) {
    var obj_input = $(temp_input_list[index]);
    var input_v = obj_input.val();
    if (typeof input_v == "undefined" || input_v.length < 1) {
      continue;
    }
    switch (index) {
      case 1:
        data_str = input_v;
        break;
      case 2:
        planNum = parseInt(input_v);
        break;
      case 3:
        checker_plan.TimeOutS = parseInt(input_v);
        checker_plan.TimeOutM = checker_plan.TimeOutS + 6;
        checker_plan.TimeOutUI = checker_plan.TimeOutS + 8;
        break;
      case 4:
        checker_plan.PlanBrief = input_v;
        break;
      case 5:
        input_v.trim();
        input_v = input_v.split(" ");
        var temp_a = [];
        for (var i = 0; i < input_v.length; i++) {
          temp_a[i] = parseInt(input_v[i], 16);
        }
        checker_plan.CheckSoftVersion = temp_a;
        break;
      case 6:
        input_v.trim();
        input_v = input_v.split(" ");
        var temp_a = [];
        for (var i = 0; i < input_v.length; i++) {
          temp_a[i] = parseInt(input_v[i], 16);
        }
        checker_plan.CheckHardVersion = temp_a;
        break;
      case 7:
        checker_plan.FacInfoSize = parseInt(input_v);
        break;
      case 8:
        checker_plan.FacInfoAddr = parseInt(input_v);
        break;
    }
  }
  checker_plan.PlanID = Checker_GetPlanID(data_str, product, planNum);
  if (checker_plan.FacInfoSize > 0) {
    checker_plan.FacFunClass = productFun;
  }

  var count = 1;
  var task_index = 0;
  while (count < task_info_list.length) {
    var temp_obj = $(task_info_list[count]);
    count++;
    var task_id = $(temp_obj.find(".task_alias_input")).attr("task_id");
    task_id = parseInt(task_id);

    var task_alias = $(temp_obj.find(".task_alias_input")).val();

    temp_input_list = temp_obj.find(".param_alias_input");
    var param_info_array = [];
    for (var index = 0; index < temp_input_list.length; index++) {
      var obj_input = $(temp_input_list[index]);
      var input_v = obj_input.val();
      if (typeof input_v == "undefined" || input_v.length < 1) {
        break;
      }
      param_info_array[index] = input_v;
    }
    temp_input_list = temp_obj.find(".param_input");
    var param_array = [];
    for (var index = 0; index < temp_input_list.length; index++) {
      var obj_input = $(temp_input_list[index]);
      var input_v = obj_input.val();
      if (typeof input_v == "undefined" || input_v.length < 1) {
        break;
      }
      /*
			if(task_id == 10 || task_id == 23 || task_id == 9)
			{
				input_v = parseInt(input_v,16);
			}else{
				input_v = parseInt(input_v,10);
			}*/
      if (task_id < Checker_Test_CMD_ID_BEG) {
        input_v = parseInt(input_v, 10);
      }

      param_array[index] = input_v;
    }

    temp_input_list = temp_obj.find(".max_target_input");
    var target_max = [];
    for (var index = 0; index < temp_input_list.length; index++) {
      var obj_input = $(temp_input_list[index]);
      var input_v = obj_input.val();
      if (typeof input_v == "undefined" || input_v.length < 1) {
        break;
      }
      input_v = parseInt(input_v, 10);
      target_max[index] = input_v;
    }
    temp_input_list = temp_obj.find(".min_target_input");
    var target_min = [];
    for (var index = 0; index < temp_input_list.length; index++) {
      var obj_input = $(temp_input_list[index]);
      var input_v = obj_input.val();
      if (typeof input_v == "undefined" || input_v.length < 1) {
        break;
      }
      input_v = parseInt(input_v, 10);
      target_min[index] = input_v;
    }

    if (target_min.length != target_max.length) {
      //error;
      return;
    }
    var temp_btn_list = temp_obj.find(".target_error_btn");
    var target_error = [];
    for (
      var index = 0;
      index < temp_btn_list.length || index < target_min.length;
      index++
    ) {
      var obj_btn = $(temp_btn_list[index])[0];
      var code = obj_btn.innerText;
      code = parseInt(code, 10);
      target_error[index] = code;
    }
    var temp_btn = temp_obj.find(".exe_error_btn");
    temp_btn = $(temp_btn);
    var exe_error_code = temp_btn[0].innerText;
    exe_error_code = parseInt(exe_error_code, 10);

    var error_jump = $(temp_obj.find(".error_jump_input")).val();
    error_jump = parseInt(error_jump, 10);
    var retry_count = $(temp_obj.find(".retry_count_input")).val();
    retry_count = parseInt(retry_count, 10);

    var param_info = [];

    /*2023-11-20 修改遍历查找对应ID的配置信息*/
    var CheckerItem_Info;
    for (var i = 0; i < CheckerTask_Info.length; i++) {
      if (CheckerTask_Info[i].TaskID == task_id) {
        CheckerItem_Info = CheckerTask_Info[i];
        break;
      }
    }

    if (param_array.length != 0 && task_id < Checker_Test_CMD_ID_BEG) {
      //TaskID = 255 是独立测试命令
      param_info = CheckerItem_Info.ParamInfo.slice(0, param_array.length);
    }
    var rtv_info = [];
    // if(target_min.length != 0)
    // {
    // 	rtv_info = CheckerItem_Info.ReturnInfo.slice(0,target_min.length);
    // }

    temp_input_list = temp_obj.find(".rtv_alias_input");
    for (
      var index = 0;
      index < temp_input_list.length && index < target_min.length;
      index++
    ) {
      var obj_input = $(temp_input_list[index]);
      var input_v = obj_input.val();
      if (typeof input_v == "undefined" || input_v.length < 1) {
        break;
      }
      rtv_info[index] = input_v.trim();
      checker_table_name[checker_table_name.length] = rtv_info[index];
    }

    var teststandard = [];
    for (var i = 0; i < target_min.length; i++) {
      var obj_ = {
        Max: target_max[i],
        Min: target_min[i],
      };
      teststandard[i] = obj_;
      if (target_min[i] > target_max[i]) {
        checker_plan.PlanID = ~0;
        var msg = "任务序号 " + task_index + " 标准值范围异常";
        layer.msg(msg);
        return checker_plan;
        //跳转设置错误
      }
    }

    //task_info_list.length == task_index+1
    if (task_info_list.length <= error_jump && error_jump != 255) {
      checker_plan.PlanID = ~0;
      var msg = "任务序号 " + task_index + " 方案配置错误跳转异常";
      layer.msg(msg);
      return checker_plan;
      //跳转设置错误
    }

    var TaskInfo = {
      TaskID: task_id,
      TaskBrief: task_alias,
      TaskIndex: task_index,
      ParamCount: param_array.length,
      ParamInfo: param_info,
      ParamVal: param_array,
      TestStandard: teststandard,
      ReturnCount: target_min.length,
      ReturnInfo: rtv_info,
      ErrJumpTo: error_jump,
      ExecuteErrCode: exe_error_code,
      ResultErrCode: target_error,
      RetryCount: retry_count,
    };
    checker_plan.TaskArray[task_index] = TaskInfo;
    task_index++;
  }

  checker_plan.CheckerRtvName = checker_table_name;
  return checker_plan;
}

function Cheker_Export() {
  slect_onchange();
  Checker_Export_Plan = Checker_GetCfgInfo();

  // if(!(epe_qthandle != null && typeof(epe_qthandle) != "undefined"))
  // {
  // 	var json_str = JSON.stringify(Checker_Export_Plan);
  // 	Checker_ExportMesInfo();
  // 	console.log(json_str);
  // 	return ;
  // }

  if (Checker_Export_Plan.PlanID == ~0) {
    return;
  }
  // Checker_ExportInputPWD();
  pywebview.api.save_plan(Checker_Export_Plan);
}
function Checker_Import() {
  // var checker_plan = testPaln;
  // Checker_LoadPlan(checker_plan);
  pywebview.api.load_plan().then((result) => {
    if (result != null) {
      Checker_LoadPlan(result);
    } else {
      // Checker_LoadPlan(testPaln);
    }
  });
}
function Checker_LoadPlan(checker_plan) {
  if ((checker_plan.PlanID & 0xffffff00) == 0) {
    var date = new Date();
    date_str =
      date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
    checker_plan.PlanID = Checker_GetPlanID(date_str, 0, checker_plan.PlanID);
  }
  var plan_info = Checker_GetShowPlanID(checker_plan.PlanID);
  Checker_ChipTypeInit(plan_info.chipid);
  Checker_UpdateChipInfo(plan_info.chipid);
  CheckerChipID = plan_info.chipid;
  Checker_AddTaskList();
  Checker_ImportShow(checker_plan);
}
function Checker_ImportShow(checker_plan) {
  //var checker_plan = Checker_YE_Cfg;
  console.log(checker_plan);
  var obj_list = $(".checker_cfig_div").children();
  //删除所有元素
  while (obj_list.length > 1) {
    $(".checker_cfig_div").children().eq(-1).remove();
    obj_list = $(".checker_cfig_div").children();
  }
  var task_info_list = $(".checker_cfig_div").children();
  var temp_obj = $(task_info_list[0]);
  var temp_input_list = temp_obj.find("input");
  var planid_info = Checker_GetShowPlanID(checker_plan.PlanID);
  for (var index = 1; index < temp_input_list.length; index++) {
    var input_v = "";
    switch (index) {
      case 1:
        input_v = planid_info.date_str;
        break;
      case 2:
        input_v = planid_info.num;
        break;
      case 3:
        input_v = checker_plan.TimeOutS;
        break;
      case 4:
        input_v = checker_plan.PlanBrief;
        break;
      case 5:
        for (var i = 0; i < checker_plan.CheckSoftVersion.length; i++) {
          if (i != 0) {
            input_v += " ";
          }
          input_v += Int2HexStr(checker_plan.CheckSoftVersion[i], "", 4);
        }
        break;

      case 6:
        for (var i = 0; i < checker_plan.CheckHardVersion.length; i++) {
          if (i != 0) {
            input_v += " ";
          }
          input_v += Int2HexStr(checker_plan.CheckHardVersion[i], "", 4);
        }
        break;
      case 7:
        if (checker_plan.FacInfoSize == 0) {
          input_v = "";
        } else {
          input_v = checker_plan.FacInfoSize;
        }
        break;
      case 8:
        if (checker_plan.FacInfoAddr < 0) {
          input_v = "";
        } else {
          input_v = checker_plan.FacInfoAddr;
        }
        break;
    }
    $(temp_input_list[index]).val(input_v);
  }

  var select_obj = $(".product_class_select");
  select_obj.children().remove();
  for (var i = 0; i < Checker_Product_Name.length; i++) {
    var content_str = "";
    if (i != planid_info.product) {
      content_str =
        "<option value=" + i + ">" + Checker_Product_Name[i] + "</option>";
    } else {
      content_str =
        "<option value=" +
        i +
        ' selected = "selected">' +
        Checker_Product_Name[i] +
        "</option>";
    }
    select_obj.append(content_str);
  }

  var select_obj = $(".func_class_select");
  select_obj.children().remove();
  for (var i = 0; i < ProductFun_Class.length; i++) {
    var content_str = "";
    if (i != checker_plan.FacFunClass) {
      content_str =
        "<option value=" + i + ">" + ProductFun_Class[i] + "</option>";
    } else {
      content_str =
        "<option value=" +
        i +
        ' selected = "selected">' +
        ProductFun_Class[i] +
        "</option>";
    }
    select_obj.append(content_str);
  }

  var count = 0;
  while (count < checker_plan.TaskArray.length) {
    var TaskInfo = checker_plan.TaskArray[count];
    count++;
    Checker_Add_Task(TaskInfo.TaskID, TaskInfo.TaskBrief, TaskInfo.ReturnInfo);
    var task_id = TaskInfo.TaskID;
    temp_obj = $(".checker_cfig_div").children().eq(-1);
    temp_obj = $(temp_obj);

    var temp_input_list = temp_obj.find(".param_input");
    var param_array = TaskInfo.ParamVal;
    for (
      var index = 0;
      index < temp_input_list.length && index < param_array.length;
      index++
    ) {
      var input_v = param_array[index];
      /*
			if(task_id == 10 || task_id == 23 || task_id == 9)
			{
				input_v = Int2HexStr(input_v,"",4)
			}*/
      $(temp_input_list[index]).val(input_v);
    }
    var target_max = [];
    var target_min = [];
    for (var i = 0; i < TaskInfo.TestStandard.length; i++) {
      var obj_ = TaskInfo.TestStandard[i];
      target_max[i] = obj_.Max;
      target_min[i] = obj_.Min;
    }

    temp_input_list = temp_obj.find(".max_target_input");
    for (
      var index = 0;
      index < temp_input_list.length && index < target_max.length;
      index++
    ) {
      $(temp_input_list[index]).val(target_max[index]);
    }

    temp_input_list = temp_obj.find(".min_target_input");
    for (
      var index = 0;
      index < temp_input_list.length && index < target_min.length;
      index++
    ) {
      $(temp_input_list[index]).val(target_min[index]);
    }

    var temp_btn_list = temp_obj.find(".target_error_btn");
    var target_error = TaskInfo.ResultErrCode;
    for (
      var index = 0;
      index < temp_btn_list.length && index < target_error.length;
      index++
    ) {
      var obj_btn = $(temp_btn_list[index])[0];
      obj_btn.innerText = target_error[index];
    }
    var temp_btn = temp_obj.find(".exe_error_btn");
    temp_btn = $(temp_btn);
    temp_btn[0].innerText = TaskInfo.ExecuteErrCode;
    $(temp_obj.find(".error_jump_input")).val(TaskInfo.ErrJumpTo);
    $(temp_obj.find(".retry_count_input")).val(TaskInfo.RetryCount);
  }
}

function Checker_Flash_Item() {
  var task_info_list = $(".checker_cfig_div").children();
  var task_id = 0;
  var task_info;
  for (var i = 1; i < task_info_list.length; i++) {
    var obj_temp = $(task_info_list[i]);
    var obj_temp1 = obj_temp.find(".task_delete_btn");
    obj_temp1.attr("name", i);
    obj_temp1 = obj_temp.find(".task_up_btn");
    obj_temp1.attr("name", i);
    obj_temp1 = obj_temp.find(".task_down_btn");
    obj_temp1.attr("name", i);
    obj_temp1 = obj_temp.find(".task_jump_btn");
    obj_temp1.attr("name", i);
    /*
		obj_temp1 = obj_temp.find(".task_alias_input");
		task_id = parseInt(obj_temp1.attr("task_id"));
		task_info = CheckerTask_Info[task_id];
		obj_temp1.val(task_info.TaskName);
		*/
    if (Checker_En_CmdTest) {
      //checker_test_cmd_item
      obj_temp1 = obj_temp.find(".checker_test_cmd_item");
      obj_temp1.attr("task_index", i - 1);
    }

    obj_temp1 = obj_temp.find(".task_index_span");
    obj_temp1[0].innerText = i - 1;
  }
}

function Checker_Add_Task(task_list_index, task_alias, rtv_alias) {
  var plan_show_obj = $(".checker_cfig_div")[0];
  var task_info_size = plan_show_obj.children.length;
  var task_info = CheckerTask_Info[task_list_index];
  var taskid = task_info.TaskID;
  var html_str = " ";
  var task_show_alias = "";
  var task_rtv_alias = [];
  if (typeof task_alias != "undefined" && task_alias != null) {
    task_show_alias = task_alias;
  } else {
    task_show_alias = task_info.TaskName;
  }

  if (typeof rtv_alias != "undefined" && rtv_alias != null) {
    task_rtv_alias = rtv_alias;
    for (var i = task_rtv_alias.length; i < task_info.ReturnInfo.length; i++) {
      task_rtv_alias[i] = task_info.ReturnInfo[i];
    }
  } else {
    task_rtv_alias = task_info.ReturnInfo;
  }

  html_str += '<div class="layui-colla-item">';
  html_str +=
    '<div class="layui-colla-title" style="height: 1.8rem; line-height: 1.8rem; display: flex;flex-wrap: nowrap;">';
  html_str +=
    '<span style="height:100%; min-width:2rem" class="task_index_span"> ' +
    (task_info_size - 1) +
    "</span>";
  html_str +=
    '<input type="text" class="layui-input task_alias_input" style="height: 1.8rem; line-height: 1.8rem; padding-left:0px; border:none;background-color:rgb(0,0,0,0)" ';
  html_str += "task_id =" + taskid + " value=" + task_show_alias + ">";
  html_str += "</div> ";
  html_str += ' <div class="layui-colla-content layui-show">';
  html_str += "<p>";
  html_str += "[ " + task_info.TaskID + " : " + task_info.TaskName + " ]";
  html_str += task_info.TaskBrief;
  html_str += "</p>";

  if (task_info.ParamInfo.length > 0) {
    var info_str_max_len = 0;
    var item_size = 11;
    //最长描述字符串
    for (var index = 0; task_info.ParamInfo.length > index; index++) {
      var info_str = task_info.ParamInfo[index];
      var str_len = info_str.byteLength();
      if (str_len > info_str_max_len) {
        info_str_max_len = str_len;
      }
    }

    if (info_str_max_len > 10 && info_str_max_len < 20) {
      item_size = 5;
    } else if (info_str_max_len >= 20) {
      item_size = 2;
    }
    var count = 0;
    while (count < task_info.ParamInfo.length) {
      html_str +=
        '<div class="layui-row" style="height: 1.8rem; line-height: 1.8rem; padding: 2px; font-size: 0.8rem;">';
      html_str += '<div class="layui-col-xs1 ">';
      if (count == 0) {
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin-left: 3px;text-align: center;border-radius: 2px; background-color: #efd9a8;" >参数配置</div></div>';
      } else {
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin-left: 3px;text-align: center;border-radius: 2px; " >&nbsp;</div></div>';
      }
      for (
        var index = 0;
        index < item_size && count < task_info.ParamInfo.length;
        index++
      ) {
        if (item_size > 6) {
          html_str += '<div class="layui-col-xs1 ">';
        } else if (item_size == 2) {
          html_str += '<div class="layui-col-xs5">';
        } else {
          html_str += '<div class="layui-col-xs2 ">';
        }
        //html_str += '<input type="text"  class="layui-input param_alias_input" value="'+task_info.ParamInfo[count]+' " style="border:none; height: 1.8rem; line-height: 1.8rem; padding-left:0px; text-align:center;"></div>'
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin-left: 2px;text-align: center;border-radius: 2px;" >' +
          task_info.ParamInfo[count] +
          "</div></div>";
        count++;
      }
      html_str += "</div>";
    }
    count = 0;
    while (count < task_info.ParamInfo.length) {
      html_str +=
        '<div class="layui-row" style="height: 1.8rem; line-height: 1.8rem; padding: 2px; font-size: 0.8rem;">';
      html_str += '<div class="layui-col-xs1 ">';
      html_str +=
        ' <div class="grid-demo grid-demo-bg1" style="margin-left: 3px;text-align: center;border-radius: 2px; " >&nbsp;</div></div>';
      for (
        var index = 0;
        index < item_size && count < task_info.ParamInfo.length;
        index++
      ) {
        count++;
        if (item_size > 6) {
          html_str += '<div class="layui-col-xs1 ">';
        } else if (item_size == 2) {
          html_str += '<div class="layui-col-xs5">';
        } else {
          html_str += '<div class="layui-col-xs2 ">';
        }
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin:0 4px ;text-align: center;border-radius: 2px;" >';
        html_str +=
          '<input type="text" value="" class="layui-input param_input" style="height: 1.8rem; line-height: 1.8rem; padding-left:0px; text-align:center;">';
        html_str += "</div></div>";
      }
      html_str += "</div>";
    }
  }

  if (Checker_En_CmdTest && task_rtv_alias.length == 0) {
    //测试接口命令
    html_str +=
      '<div class="layui-row checker_test_cmd_item" style="height: 1.8rem; line-height: 1.8rem; padding: 2px; font-size: 0.8rem;">';
    html_str += '<div class="layui-col-xs1 ">';
    html_str +=
      ' <div class="grid-demo grid-demo-bg1 checker_commcmdTest_btn"  task_index =' +
      (task_info_size - 1) +
      '  style="margin-left: 3px;text-align: center;border-radius: 2px; background-color: #efd9a8;" >测试命令</div>';
    html_str += "</div></div>";
  }

  if (task_rtv_alias.length > 0) {
    var info_str_max_len = 0;
    var item_size = 11;
    for (var index = 0; task_rtv_alias.length > index; index++) {
      var info_str = task_rtv_alias[index];
      var str_len = info_str.byteLength();
      if (str_len > info_str_max_len) {
        info_str_max_len = str_len;
      }
    }
    if (info_str_max_len > 10 && info_str_max_len < 20) {
      item_size = 5;
    }
    if (info_str_max_len >= 20) {
      item_size = 2;
    }
    var count = 0;
    while (count < task_rtv_alias.length) {
      html_str +=
        '<div class="layui-row" class="checker_test_cmd_item" style="height: 1.8rem; line-height: 1.8rem; padding: 2px; font-size: 0.8rem;">';
      html_str += '<div class="layui-col-xs1 ">';
      if (count == 0) {
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin-left: 3px;text-align: center;border-radius: 2px; background-color: #efd9a8;" >返回指标</div></div>';
      } else {
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin-left: 3px;text-align: center;border-radius: 2px; " >&nbsp;</div></div>';
      }
      for (
        var index = 0;
        index < item_size && count < task_rtv_alias.length;
        index++
      ) {
        if (item_size > 6) {
          html_str += '<div class="layui-col-xs1 ">';
        } else if (item_size == 2) {
          html_str += '<div class="layui-col-xs5">';
        } else {
          html_str += '<div class="layui-col-xs2 ">';
        }
        html_str +=
          '<input type="text"  class="layui-input rtv_alias_input" value="' +
          task_rtv_alias[count] +
          ' " style="border:none; height: 1.8rem; line-height: 1.8rem; padding-left:0px; text-align:center;"></div>';
        //html_str += ' <div class="grid-demo grid-demo-bg1" style="margin-left: 2px;text-align: center;border-radius: 2px;" >'+task_info.ReturnInfo[count]+'</div></div>'
        count++;
      }
      html_str += "</div>";
    }

    count = 0;
    while (count < task_info.ReturnInfo.length) {
      html_str +=
        '<div class="layui-row" style="height: 1.8rem; line-height: 1.8rem; padding: 2px; font-size: 0.8rem;">';
      html_str += '<div class="layui-col-xs1 ">';
      if (count == 0) {
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin-left: 3px;text-align: center;border-radius: 2px; background-color: #efd9a8;" >指标上限</div></div>';
      } else {
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin-left: 3px;text-align: center;border-radius: 2px; " >&nbsp;</div></div>';
      }
      for (
        var index = 0;
        index < item_size && count < task_info.ReturnInfo.length;
        index++
      ) {
        count++;
        if (item_size > 6) {
          html_str += '<div class="layui-col-xs1 ">';
        } else if (item_size == 2) {
          html_str += '<div class="layui-col-xs5">';
        } else {
          html_str += '<div class="layui-col-xs2 ">';
        }
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin:0 4px ;text-align: center;border-radius: 2px;" >';
        html_str +=
          '<input type="text" value="" class="layui-input max_target_input" style="height: 1.8rem; line-height: 1.8rem; padding-left:0px; text-align:center;">';
        html_str += "</div></div>";
      }
      html_str += "</div>";
    }
    /*返回值上下限写入说明*/
    count = 0;
    while (count < task_info.ReturnInfo.length) {
      html_str +=
        '<div class="layui-row" style="height: 1.8rem; line-height: 1.8rem; padding: 2px; font-size: 0.8rem;">';
      html_str += '<div class="layui-col-xs1 ">';
      if (count == 0) {
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin-left: 3px;text-align: center;border-radius: 2px; background-color: #efd9a8;" >指标下限</div></div>';
      } else {
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin-left: 3px;text-align: center;border-radius: 2px; " >&nbsp;</div></div>';
      }
      for (
        var index = 0;
        index < item_size && count < task_info.ReturnInfo.length;
        index++
      ) {
        count++;
        if (item_size > 6) {
          html_str += '<div class="layui-col-xs1 ">';
        } else if (item_size == 2) {
          html_str += '<div class="layui-col-xs5">';
        } else {
          html_str += '<div class="layui-col-xs2 ">';
        }
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin:0 4px ;text-align: center;border-radius: 2px;" >';
        html_str +=
          '<input type="text" value="" class="layui-input  min_target_input" style="height: 1.8rem; line-height: 1.8rem; padding-left:0px; text-align:center;">';
        html_str += "</div></div>";
      }
      html_str += "</div>";
    }

    if (Checker_En_CmdTest) {
      //测试接口命令
      count = 0;
      while (count < task_info.ReturnInfo.length) {
        html_str +=
          '<div class="layui-row checker_test_cmd_item"   style="height: 1.8rem; line-height: 1.8rem; padding: 2px; font-size: 0.8rem;">';
        html_str += '<div class="layui-col-xs1 ">';
        if (count == 0) {
          html_str +=
            ' <div class="grid-demo grid-demo-bg1 checker_commcmdTest_btn" task_index =' +
            (task_info_size - 1) +
            '  style="margin-left: 3px;text-align: center;border-radius: 2px; background-color: #efd9a8;" >测试命令</div></div>';
        } else {
          html_str +=
            ' <div class="grid-demo grid-demo-bg1" style="margin-left: 3px;text-align: center;border-radius: 2px; " >&nbsp;</div></div>';
        }
        for (
          var index = 0;
          index < item_size && count < task_info.ReturnInfo.length;
          index++
        ) {
          count++;
          if (item_size > 6) {
            html_str += '<div class="layui-col-xs1 ">';
          } else if (item_size == 2) {
            html_str += '<div class="layui-col-xs5">';
          } else {
            html_str += '<div class="layui-col-xs2 ">';
          }
          html_str +=
            ' <div class="grid-demo grid-demo-bg1" style="margin:0 4px ;text-align: center;border-radius: 2px;" >';
          html_str +=
            '<input type="text" value="" class="layui-input " style="height: 1.8rem; line-height: 1.8rem; padding-left:0px; text-align:center;">';
          html_str += "</div></div>";
        }
        html_str += "</div>";
      }
    }

    /*返回值错误代码*/
    count = 0;
    while (count < task_info.ReturnInfo.length) {
      html_str +=
        '<div class="layui-row" style="height: 1.8rem; line-height: 1.8rem; padding: 2px; font-size: 0.8rem;">';
      html_str += '<div class="layui-col-xs1 ">';
      if (count == 0) {
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin-left: 3px;text-align: center;border-radius: 2px; background-color: #efd9a8;" >指标错误</div></div>';
      } else {
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin-left: 3px;text-align: center;border-radius: 2px; " >&nbsp;</div></div>';
      }
      for (
        var index = 0;
        index < item_size && count < task_info.ReturnInfo.length;
        index++
      ) {
        count++;
        if (item_size > 6) {
          html_str += '<div class="layui-col-xs1 ">';
        } else if (item_size == 2) {
          html_str += '<div class="layui-col-xs5">';
        } else {
          html_str += '<div class="layui-col-xs2 ">';
        }
        html_str +=
          ' <div class="grid-demo grid-demo-bg1" style="margin:0 4px ;text-align: center;border-radius: 2px;" >';
        html_str +=
          '<button type="button" class="layui-btn layui-btn-normal errorcode_button target_error_btn"';
        html_str +=
          ' style=" max-width:4rem; height: 1.8rem; line-height: 1.8rem; padding: 0 0.8rem;width: 90%;margin:0 auto;" >'+
          task_info.ReturnErr[count-1]+/* 指标错误 */
          '</button>';
        html_str += "</div></div>";
      }
      html_str += "</div>";
    }
  }

  html_str +=
    '<div class="layui-row" style="height: 1.8rem; line-height: 1.8rem; padding: 2px; font-size: 0.8rem;">';
  html_str += '<div class="layui-col-xs1 ">';
  html_str +=
    '<div class="grid-demo grid-demo-bg1" style="margin-left: 3px;text-align: center;border-radius: 2px; background-color: #efd9a8;" >流程错误</div></div>';
  html_str += '<div class="layui-col-xs1 ">';
  html_str +=
    ' <div class="grid-demo grid-demo-bg1" style="margin:0 4px ;text-align: center;border-radius: 2px;" >';
  html_str +=
    '<button type="button" class="layui-btn layui-btn-normal errorcode_button exe_error_btn"';
  html_str +=
    ' style=" max-width:4rem; height: 1.8rem; line-height: 1.8rem; padding: 0 0.8rem;width: 90%;margin:0 auto;" >'+
    task_info.TaskErr+/* 流程错误代码 */
    '</button>';
  html_str += "</div></div>";
  html_str += "</div>";

  html_str +=
    '<div class="layui-row" style="height: 1.8rem; line-height: 1.8rem; padding: 2px; font-size: 0.8rem;">';
  html_str += '<div class="layui-col-xs1 ">';
  html_str +=
    '<div class="grid-demo grid-demo-bg1 error_jump_div" style="margin-left: 3px;text-align: center;border-radius: 2px; background-color: #efd9a8;" >重试次数</div></div>';
  html_str += '<div class="layui-col-xs1 ">';
  html_str +=
    ' <div class="grid-demo grid-demo-bg1" style="margin:0 4px ;text-align: center;border-radius: 2px;" >';
  html_str +=
    '<input type="text" value="0" class="layui-input  retry_count_input" style="height: 1.8rem; line-height: 1.8rem; padding-left:0px; text-align:center;">';
  html_str += "</div></div>";
  html_str += "</div>";

  html_str +=
    '<div class="layui-row" style="height: 1.8rem; line-height: 1.8rem; padding: 2px; font-size: 0.8rem;">';
  html_str += '<div class="layui-col-xs1 ">';
  html_str +=
    '<div class="grid-demo grid-demo-bg1 error_jump_div" style="margin-left: 3px;text-align: center;border-radius: 2px; background-color: #efd9a8;" >错误跳转</div></div>';
  html_str += '<div class="layui-col-xs1 ">';
  html_str +=
    ' <div class="grid-demo grid-demo-bg1" style="margin:0 4px ;text-align: center;border-radius: 2px;" >';
  html_str +=
    '<input type="text" value="255" class="layui-input  error_jump_input" style="height: 1.8rem; line-height: 1.8rem; padding-left:0px; text-align:center;">';
  html_str += "</div></div>";
  html_str += "</div>";

  // 添加导入模板按钮
  html_str +=
  '<div class="layui-row" style="height: 1.8rem; line-height: 1.8rem; padding: 2px; font-size: 0.8rem;">\
    <div class="layui-col-xs1" style=" width:6rem; height: 1.8rem;">\
      <div class="grid-demo grid-demo-bg1" style="margin:0 2px ;text-align: center;border-radius: 2px;">\
        <button onClick="task_import_model('+task_info.TaskID+')" type="button" class="layui-btn layui-btn-normal" \
          style=" max-width:6rem; height: 1.8rem; line-height: 1.8rem; padding: 0 0.8rem;width: 90%;margin:0 auto;">导入模板</button>\
      </div>\
    </div>\
    <div class="layui-col-xs1" style=" width:6rem; height: 1.8rem;">\
      <div class="grid-demo grid-demo-bg1" style="margin:0 2px ;text-align: center;border-radius: 2px;">\
        <button onClick="task_export_model('+task_info.TaskID+')" type="button" class="layui-btn layui-btn-normal"\
          style=" max-width:6rem; height: 1.8rem; line-height: 1.8rem; padding: 0 0.8rem;width: 90%;margin:0 auto;">设为模板</button>\
      </div>\
    </div>\
  </div>'

  html_str +=
    '<div style="display: flex;flex-wrap: nowrap;" ><i class="layui-icon layui-icon-delete task_delete_btn" style="font-size: 30px; color: #ff0000;" name = "' +
    task_info_size +
    '"></i>';
  html_str +=
    ' <i class="layui-icon layui-icon-up  task_up_btn " style="font-size: 30px; color: #00aaff;" name = "' +
    task_info_size +
    '"></i>  ';
  html_str +=
    ' <i class="layui-icon layui-icon-down task_down_btn " style="font-size: 30px; color: #ffaa7f;" name = "' +
    task_info_size +
    '"></i>  ';
  html_str +=
    ' <i class="layui-icon layui-icon-right task_jump_btn " style="font-size: 30px; color: #00557f;" name = "' +
    task_info_size +
    '"></i>  ';
  html_str +=
    '<input type="text" value="" class="layui-input  task_jump_input"';
  html_str +=
    'style="height: 1.6rem; line-height: 1.6rem; width:2rem; padding-left:0px; text-align:center; float:right;margin-right:40rem;margin-top:8px">';
  html_str += "</div>";
  html_str += "</div> </div>";



  //plan_show_obj.innerHTML += html_str;
  $(".checker_cfig_div").append(html_str);
  element.render("collapse");
  var layer_info_tips = 0;
  $(".errorcode_button")
    .unbind("click")
    .bind("click", function () {
      console.log("errorcode_button");
      var obj = $(this)[0];
      layer.close(layer_info_tips);
      Checker_ErrorChoice(obj);
    });

  $(".task_alias_input")
    .unbind("click")
    .bind("click", function (event) {
      event.stopImmediatePropagation();
    });

  $(".errorcode_button")
    .unbind("mouseover")
    .bind("mouseover", function () {
      var code_num = parseInt($(this)[0].innerHTML);
      layer_info_tips = layer.tips(JQChecker_GetErrorInfo(code_num), this, {
        tips: [1, "#008c67"],
        time: 2000,
      });
    });
  // $(".error_jump_div").unbind('mouseover').bind('mouseover', function(){
  // 	var code_num =parseInt($(this)[0].innerHTML);
  // 	layer_info_tips = layer.tips("填写任务ID，参考左侧 0或者255表示不跳转，顺序执行", this,{tips:[1, '#008c67'], time:2000})
  // });
  $(".task_down_btn")
    .unbind("click")
    .bind("click", function () {
      var obj = $(this);
      var name = parseInt(obj.attr("name"));
      var task_info_list = $(".checker_cfig_div").children();
      if (task_info_list.length < 3 || name > task_info_list.length - 2) {
        return;
      }
      var cur_obj = $(task_info_list[name]);
      var next_obj = cur_obj.next();
      next_obj.after(cur_obj);

      Checker_Flash_Item();
    });

  $(".task_jump_btn")
    .unbind("click")
    .bind("click", function () {
      var obj = $(this);
      var name = parseInt(obj.attr("name"));
      var task_info_list = $(".checker_cfig_div").children();
      var cur_obj = $(task_info_list[name]);
      var jump_to = cur_obj.find(".task_jump_input").val();
      if (name < 1) {
        return;
      }
      name--;
      jump_to = parseInt(jump_to);
      if (
        typeof jump_to == undefined ||
        isNaN(jump_to) ||
        name == jump_to ||
        jump_to > task_info_list.length - 2 ||
        jump_to < 0
      ) {
        return;
      }
      console.log(".task_jump_btn " + name);
      jump_to++;
      var jump_obj = $(task_info_list[jump_to]);

      if (name < jump_to) {
        jump_obj.after(cur_obj);
      } else {
        jump_obj.before(cur_obj);
      }

      Checker_Flash_Item();
    });

  $(".task_up_btn")
    .unbind("click")
    .bind("click", function () {
      var obj = $(this);
      var name = parseInt(obj.attr("name"));
      var task_info_list = $(".checker_cfig_div").children();
      if (name == 1 || task_info_list.length < 3) {
        return;
      }
      var cur_obj = $(task_info_list[name]);
      var prev_obj = cur_obj.prev();
      prev_obj.before(cur_obj);

      Checker_Flash_Item();
    });
  $(".task_delete_btn")
    .unbind("click")
    .bind("click", function () {
      var obj = $(this);
      var name = parseInt(obj.attr("name"));
      $(".checker_cfig_div").children().eq(name).remove();
      Checker_Flash_Item();

      element.render("collapse");
      console.log("name " + name);
    });

  $(".checker_commcmdTest_btn")
    .unbind("click")
    .bind("click", function () {
      var obj = $(this);
      var task_index = parseInt(obj.attr("task_index"));

      element.render("collapse");
      console.log("checker_commcmdTest_btn " + task_index);
      Checker_CmdTest(task_index);
    });
}

function Checker_ErrorChoice(btnobj) {
  var content_str =
    '<div style="padding: 5px; min-width:55rem; line-height: 1.8rem; background-color: #393D49; color:#cdd4d3; ">';
  var error_list = Checker_Error_Info.SubErrInfo;
  var count = 0;
  var tip_id;
  var err_btn_id = 256;
  content_str +=
    '<div class="layui-row" style="min-height:20rem; line-height: 2rem; padding: 2px; "> <div class="layui-col-xs10">';
  while (count < error_list.length) {
    content_str +=
      '<div class="layui-row" style="height: 2rem; line-height: 2rem; padding: 2px; font-size: 0.8rem;">';
    for (
      var index = 0;
      index < 4 && count < error_list.length;
      index++, count++
    ) {
      content_str += '<div class="layui-col-xs3">';
      content_str +=
        '<button type="button" class="layui-btn layui-btn-normal jqchecker_choice_error " style="height: 2rem; line-height: 2rem;width: 90%; padding:0;font-size:0.8rem" ';
      content_str +=
        "errcode = " +
        error_list[count].ErrCode +
        ">" +
        error_list[count].ErrCode +
        ":" +
        error_list[count].Info +
        "</button>";
      content_str += "</div>";
    }

    content_str += "</div>";
  }
  content_str += "</div>";
  content_str += '<div class="layui-col-xs2">';
  content_str += '<div style = "min-height:8rem" class="show_err_fac"> </div>';

  content_str += "</div>";

  content_str += "</div>";
  content_str += "</div>";

  tip_id = layer.open({
    type: 1,
    offset: "auto",
    anim: 1,
    content: content_str,
    title: "选择错误代码",
  });

  $(".jqchecker_choice_error").click(function () {
    btnobj.innerText = $(this).attr("errcode");
    layer.close(tip_id);
  });
  $(".jqchecker_choice_error")
    .unbind("mouseover")
    .bind("mouseover", function () {
      var errcode = $(this).attr("errcode");
      errcode = parseInt(errcode);
      if (err_btn_id == errcode) {
        return;
      }
      err_btn_id = errcode;
      var content_str = "";
      var index = 0;
      while (1) {
        var obj_i = Checker_Error_Info.SubErrInfo[index];
        index++;
        if (errcode != obj_i.ErrCode) {
          if (obj_i.ErrCode == 255) {
            break;
          }
          continue;
        }
        var ErrFac = obj_i.ErrFac;
        for (var j = 0; j < ErrFac.length; j++) {
          content_str += "<p> " + ErrFac[j] + "</p>";
        }
        break;
      }

      $(".show_err_fac")[0].innerHTML = content_str;
    });
}

function Checker_ExportMesInfo() {
  Checker_Export_Plan.MajorErrInfo = Checker_Error_Info.MajorErrInfo;
  Checker_Export_Plan.SubErrInfo = Checker_Error_Info.SubErrInfo;

  var AllError;
  var Cheker_Info = {
    AllTaskInfoArray: CheckerTask_Info,
    PlanTaskInfoArray: [],
    AllErrorInfoArray: [],
    PlanErroInfoArray: [],
    PlanStandardInfo: [],
  };
  //taskInfoArray = Checker_Export_Plan.TaskArray;
  var allErrorInfoArray = [];
  var planErroInfoArray = [];
  var count = 0;
  var major_count = 0;
  for (var i = 0; i < Checker_Error_Info.MajorErrInfo.length; i++) {
    var info_ = {};
    info_.ErrCode = Checker_Error_Info.MajorErrInfo[i].MajorErrCode;
    info_.Info = Checker_Error_Info.MajorErrInfo[i].Info;
    info_.ErrFac = Checker_Error_Info.MajorErrInfo[i].ErrFac;
    allErrorInfoArray[count++] = info_;
  }
  planErroInfoArray = allErrorInfoArray; //将主错误放在每次方案错误里面
  major_count = count;
  for (var i = 0; i < Checker_Error_Info.SubErrInfo.length; i++) {
    allErrorInfoArray[count++] = Checker_Error_Info.SubErrInfo[i];
  }
  Cheker_Info.AllErrorInfoArray = allErrorInfoArray;

  var taskInfoArray = [];
  count = 0;
  for (var i = 0; i < Checker_Export_Plan.TaskArray.length; i++) {
    var taskid = Checker_Export_Plan.TaskArray[i].TaskID;
    var index_ = 0;
    var flag_ = 0;
    var taskMes = "";
    for (
      var index_ = 0;
      index_ < Cheker_Info.AllTaskInfoArray.length;
      index_++
    ) {
      if (Cheker_Info.AllTaskInfoArray[index_].TaskID == taskid) {
        flag_ = 1;
        taskMes = Cheker_Info.AllTaskInfoArray[index_].TaskBrief;
        break;
      }
    }
    if (flag_ == 0) {
      continue;
    }
    var obj_ = Checker_Export_Plan.TaskArray[i];
    obj_.TaskMes = taskMes;
    taskInfoArray[count++] = obj_;
  }

  count = 0;
  for (var i = 0; i < Checker_Export_Plan.TaskArray.length; i++) {
    var tempStandard = Checker_Export_Plan.TaskArray[i].TestStandard;
    var tempRetInfo = Checker_Export_Plan.TaskArray[i].ReturnInfo;
    var taskid = Checker_Export_Plan.TaskArray[i].TaskID;
    var index_ = 0;
    for (var index_ = 0; index_ < tempStandard.length; index_++) {
      var obj_ = {
        RetName: tempRetInfo[index_],
        Max: tempStandard[index_].Max,
        Min: tempStandard[index_].Min,
      };
      Cheker_Info.PlanStandardInfo[count++] = obj_;
    }
  }

  for (var i = 0; i < Checker_Error_Info.SubErrInfo.length; i++) {
    var err_code = Checker_Error_Info.SubErrInfo[i].ErrCode;
    for (
      var index_ = 0;
      index_ < Checker_Export_Plan.TaskArray.length;
      index_++
    ) {
      if (err_code == Checker_Export_Plan.TaskArray[index_].ExecuteErrCode) {
        break;
      }
      var ResultErrCodeArray =
        Checker_Export_Plan.TaskArray[index_].ResultErrCode;
      for (var index2 = 0; index2 < ResultErrCodeArray.length; index2++) {
        if (ResultErrCodeArray[index2] == err_code) {
          break;
        }
      }
    }
    planErroInfoArray[planErroInfoArray.length] =
      Cheker_Info.AllErrorInfoArray[i];
  }

  Cheker_Info.PlanTaskInfoArray = taskInfoArray;
  Cheker_Info.PlanErroInfoArray = planErroInfoArray;
  var checker_info_str = JSON.stringify(Cheker_Info, null, 2);
  var json_str = JSON.stringify(Checker_Export_Plan, null, 2);
  var pwd_str = $(".checker_export_pwd_input").val();
  if (epe_qthandle != null && typeof epe_qthandle != "undefined") {
    console.log("epe_qthandle.Epe_JQSavePlan");
    epe_qthandle.Epe_JQSavePlan2(
      pwd_str,
      CheckPlan_Export_PWD,
      Checker_Export_Plan.PlanBrief,
      json_str,
      checker_info_str
    );
  }
}
function Checker_ExportInputPWD() {
  var content_str =
    '<div style="padding: 5px; min-width:30rem; line-height: 1.8rem; background-color: #393D49; color:#cdd4d3; ">';
  var count = 0;
  var tip_id;
  var err_btn_id = 256;
  content_str +=
    '<div class="layui-row" style="min-height:2rem; line-height: 2rem; padding: 2px; "> ';
  content_str +=
    '<div class="layui-col-xs2 layui-col-xs-offset2" style = "text-align:right;" >密码：</div>';
  content_str +=
    '<div class="layui-col-xs4 "> <input type="password" value="" class="layui-input checker_export_pwd_input" style="height: 1.8rem; line-height: 1.8rem; padding-left:0px; text-align:left;"></div>';
  content_str += "</div>";

  content_str +=
    '<div class="layui-row" style="min-height:2rem; line-height: 2rem; padding: 2px; "> ';
  content_str +=
    '<div class="layui-col-xs2 layui-col-xs-offset5"> <button type="button" class="layui-btn layui-btn-normal jqchecker_export_pwd_btn " style="height: 2rem; line-height: 2rem;width: 90%; padding:0;font-size:0.8rem">确定</btn></div>';
  content_str += "</div>";

  content_str +=
    '<div class="layui-row" style="min-height:2rem; line-height: 2rem; padding: 2px; "> ';
  content_str +=
    '<div class="layui-col-xs2 layui-col-xs-offset5"> <div class="checker_pwd_report" style=" line-height: 2rem ; font-size:0.8rem; color:red"></div></div>';
  content_str += "</div>";

  content_str += "</div>";

  tip_id = layer.open({
    type: 1,
    offset: "auto",
    anim: 1,
    content: content_str,
    title: "输入导出保存密码",
  });
  Checker_Pwwd_Dialog_ID = tip_id;
  $(".jqchecker_export_pwd_btn").click(function () {
    Checker_ExportMesInfo();
  });
}

function Checker_AddTaskList() {
  var obj = $(".checker_task_list")[0];
  var list_html = "";
  //console.log(obj.innerHTML );
  for (var i = 0; i < CheckerTask_Info.length; i++) {
    if (i == 0) {
      list_html +=
        '<dd calss="layui-this"><a  onclick=Checker_Add_Task(' + i + ")>";
      list_html +=
        CheckerTask_Info[i].TaskName +
        " " +
        CheckerTask_Info[i].TaskID +
        "</a></dd> \r\n";
    } else {
      list_html += "<dd ><a onclick=Checker_Add_Task(" + i + ")>";
      list_html +=
        CheckerTask_Info[i].TaskName +
        " " +
        CheckerTask_Info[i].TaskID +
        "</a></dd> \r\n";
    }
  }
  obj.innerHTML = list_html;
  //console.log(obj.innerHTML );
  layui.element.render("nav", "ul_checker_menu");
  //console.log(layui);
}

function Checker_UpLoadServer() {
  Checker_Export_Plan = Checker_GetCfgInfo();
  if (Checker_Export_Plan.PlanID == ~0) {
    return;
  }
  var json_str = JSON.stringify(Checker_Export_Plan, null, 2);
  $.ajax({
    url: "http://47.108.119.117:9080/pjySource/upCheckplan",
    method: "POST",
    data: json_str,
    success: function (response) {
      response = eval("(" + response + ")");
      if (response.isOK == true) {
        console.log("请求成功：", response);
      }
    },
    error: function (xhr, status, error) {
      console.log("请求失败：", error);
    },
  });
}

// 选项改变之后
function slect_onchange() {
  // 选择工厂
  var chip = document.getElementById("product_class_sel_id");
  var fatc = document.getElementById("plan_fatc_sel_id");
  var step = document.getElementById("plan_step_sel_id");
  var bref = document.getElementById("plan_bref_input");
  var featur = document.getElementById("plan_featur_sel_id");
  var date_input = document.getElementById("plan_date_id");
  var planid_input = document.getElementById("plan_id_input_id");
  var fatc_text = fatc.options[fatc.selectedIndex].text;
  var step_text = step.options[step.selectedIndex].text;
  var featur_text = featur.options[featur.selectedIndex].text;
  var chip_text = chip.options[chip.selectedIndex].text;
  var date_text = date_input.value.split("-");
  bref.value =
    chip_text +
    fatc_text +
    step_text +
    featur_text.split(":")[1] +
    date_text[1] +
    date_text[2] +
    "_" +
    planid_input.value;
}

function date_click() {
  console.log("date_click");
  var date = new Date();
  var date_str =
    date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
  var date_input = document.getElementById("plan_date_id");
  date_input.value = date_str;
  // 更新日期显示
  var plan_id = Checker_GetPlanIDInput();
  var planid_info = Checker_GetShowPlanID(plan_id);
  date_input.value = planid_info.date_str;

  console.log(date_str);
  slect_onchange();
}



function task_export_model(e){
  console.log("task_export_model",e)
}


