/**
   * guoj
   * 2019.1.23
   * 系统日志
   */
import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE,UPCLOUD_RDC_TMS_BUSINESS_SERVICE,UPCLOUD_RDC_TMS_INTERFACE_SERVICE} from '@/config/serviceSettings.js';
import { getSelectGJ, querySysPicture } from '@/utils/prolog.ajax.js';


export default () => {
  var sysid;
  utilSyncAjaxGJ("/users/sysconf/selected", "get", {}, function (data) {
    sysid = data.data;
    for (var i = 0; i < sysid.length; i++) {
      sysid[i].value = sysid[i].val;
    }
  });
  var opts = {
    //terrace显示全部，card分页显示
    skin: "card",
    //renderer:"grid",
    columns: [
      { id: "id", name: "id", type: "ro", width: "130", hidden: true },
      { id: "createTime", name: "记录时间", type: "ro", width: 130 },
      { id: "level", name: "日志级别", type: "ro", width: "100" },
      { id: "errorMessage", name: "日志信息", type: "ro", width: "150" },
      { id: "description", name: "日志描述", type: "ro", width: "250" },
      { id: "uri", name: "路径", type: "ro", width: "250" },
      { id: "className", name: "类名", type: "ro", width: "130" },
      { id: "method", name: "方法名", type: "ro", width: "130" },
      { id: "params", name: "参数", type: "ro", width: "150" },
      { id: "systemId", name: "系统id", type: "ro", width: "130", hidden: true },
      { id: "userName", name: "操作人", type: "ro", width: "130", hidden: true },
      { id: "ip", name: "ip地址", type: "ro", width: "130" },
      {
        id: "op", name: "操作", type: "button", align: "left", fixed: "right", width: "100", render: function () {
          return "详情^Journal_updata";
        }
      }
    ],
    multiselect: false,
    fixedLast: true, //开启固定列，固定最后一行，倒数第二列不能隐藏
    enableSideBar: true, //开启侧边工具栏
    sideBar: [
      { type: "calendar", name: "startTime", label: "记录时间" },
      { type: "calendar", name: "endTime", label: "" },
      { type: "combo", name: "systemId", label: "系统id", options: sysid },
      { type: "input", name: "level", label: "日志级别" },
      { type: "input", name: "className", label: "类名" },
      { type: "input", name: "userName", label: "操作人" },
      { type: "input", name: "errorMessage", label: "日志信息" },
      { type: "input", name: "method", label: "方法名" },
      { type: "input", name: "description", label: "日志描述" },
      { type: "input", name: "ip", label: "ip地址" },
      { type: "button", name: "querycarr", value: "查询" },
      { type: "button", name: "car_Reset", className: " normal", value: "重置" }
    ],
    url: "/sys/logs/platform",//数据接口
    type: "get",//数据提交方式，默认为get  prolog-healthy-wms
    params: { "systemId": "prolog-healthy-wms" },//查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  //分页参数 pageSize pageNum
  var grid = new PlgGrid(opts);
  grid.renderTo("Journal_zhu");
  //grid.getToolBarForm().renderHiddenToggleItem('more');
  grid.getSideBarForm().setFormData({ "systemId": "prolog-healthy-wms" });
  grid.loadData();
  //按钮添加方法
  grid.attachSideBarEvent("onButtonClick", function (name) {
    if (name == "querycarr") {
      var jsonData = grid.getSideBarForm().getFormData();
      jsonData.startTime = jsonData.startTime == null ? "" : Prolog.formatDate(jsonData.startTime);
      jsonData.endTime = jsonData.endTime == null ? "" : Prolog.formatDate(jsonData.endTime);
      grid.setParams(jsonData);
      grid.reload();
    }
    if (name == "car_Reset") {
      grid.getSideBarForm().clear();
    }
  });
  //详情
  window.Journal_updata = function (rid, rdata) {
    grid.selectRowById(rid);
    changePanel();
    new PlgPanel({
      renderer: "Journal_xi1",
      skin: 2,
      header: {
        isShow: true,
        title: "基本信息"
      },
      defaultBody: {
        layoutCol: 3,
        valueBj: true,
        cols: [
          [{
            label: "记录时间",
            value: rdata.createTime
          }, {
            label: "日志级别",
            value: rdata.level
          }, {
            label: "日志信息",
            value: rdata.errorMessage
          }], [{
            label: "日志描述",
            layoutCol: 12,
            value: rdata.description
          }], [{
            label: "路径",
            layoutCol: 12,
            value: rdata.uri
          }], [{
            label: "系统id",
            value: rdata.systemId
          }, {
            label: "操作人",
            value: rdata.userName
          }, {
            label: "ip地址",
            value: rdata.ip
          }, {
            label: "序号",
            value: rdata.sn
          }],
          [{
            label: "方法名",
            value: rdata.method
          }],
          [{
            label: "类名",
            layoutCol: 12,
            value: rdata.className
          }
          ],
          [{
            label: "参数",
            layoutCol: 12,
            value: rdata.params
          }
          ]
        ]
      }
    });
  };
  //跳转页面
  var carousel = layui.carousel;
  var car = carousel.render({
    elem: "#Journal_div",
    autoplay: false,
    index: 0,
    arrow: "none",
    indicator: "none",
    anim: "fade",
    width: "100%", //设置容器宽度
    height: "100%"
  });
  //跳转方法
  var tt = "Journal_zhu";
  function changePanel() {
    car.slide(tt);
    tt = tt == "Journal_xi" ? "Journal_zhu" : "Journal_xi";
  }

  //返回
  document.querySelector("#Journal_return").onclick = function () {
    changePanel();
  };
};