/**
 * hudw
 * 2022.03.10
 * 系统入口
 */
 (function () {

  // 页面初始检测登录状态

  // 页面初始配置
  Prolog.loginUrl = "/api/auth/login";
  Prolog.loginPage = "/";
  Prolog.refreshTokenUrl = "/api/token/refresh";


  //判断是否需要修改密码

  var sid = getQueryString("sid");
  var name = getQueryString("name");

  //获取通用参照数据-长策

  //获取url参数
  function getQueryString(name) {
    var url = decodeURI(window.location.search.substr(1));
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = url.match(reg);
    if (r != null) return unescape(r[2]);
    return null;
  }

  //默认空事件，主要用于表格操作列（组件升级后空按钮会造成行错位）
  //获取打印服务地址
  Prolog.ajax({
    url: "/maindata/sysParameter/query",
    type: "post",
    contentType: "application/json",
    data: JSON.stringify({ "search": "printServiceIP", "pageSize": 100, "pageNum": 1 }),
    success: function (res) {
      if (res.success) {
        let url = "http://127.0.0.1:6060/print";
        res.data.list.forEach(t => {
          if (userinfo.p_companyid == t.branchCode && t.parameterCode == "printServiceIP") {
            let arr = t.parameterValue.split(":");
            if (arr.length > 1)
              url = "http://" + t.parameterValue + "/print";
            else
              url = "http://" + t.parameterValue + ":6060/print";
          }
        });
        localStorage.setItem("printserviceip", url);
      }
    },
    error: function () { }
  });

  alertMessage_count();

  window.badgeInfoShow = function () {
    alertMessage_count();
    Sidebar.leafClick("RES1000000376", {
      PY_code: "YJTX",
      hash: "RES1000000376",
      id: "RES1000000376",
      leaf: 1,
      level: 2,
      menuId: "RES1000000376",
      name: "预警提醒",
      parentMenuId: "RES1000000048",
      path: "menu?path=auth/early_warning_alert",
      systemId: "plg-std-tms"
    });
  };

  var addressAnalysis_data = {
    key: "",
    data: {}
  };

  // 地址解析
  window.addressAnalysis_to = function ({ key, data }) {
    addressAnalysis_data.key = key;
    addressAnalysis_data.data = data;
    // navTab.deleteTabs("RES1000000353");
    Sidebar.leafClick("RES1000000353", {
      PY_code: "KHZBWH-GD",
      hash: "RES1000000353",
      id: "RES1000000353",
      leaf: 1,
      level: 2,
      menuId: "RES1000000353",
      name: "客户坐标维护-高德",
      parentMenuId: "RES1000000051",
      path: "/menu?path=tms/basic/customerCoordinatesGD",
      systemId: "plg-std-tms"
    });
  };
  // 地址解析返回
  window.addressAnalysis_return = function () {
    Sidebar.leafClick(addressAnalysis_data.key, addressAnalysis_data.data);
    addressAnalysis_data = {
      key: "",
      data: {}
    };
  };
})();