/**
   * jiw
   * 2021.11.29
   * 消息队列日志
   */
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 grid;

  // 获取默认时间
  var startTime = Prolog.formatDate(new Date()) + " 00:00:00";
  var endTime = Prolog.formatDate(new Date()) + " 23:59:59";
  // 获取下拉框
  var rsp_PORTAL_ID = [];
  getSelectGJ([
    { "objectcode": "PORTAL_ID" }], function (data) {
      rsp_PORTAL_ID = data.data.PORTAL_ID;
      rsp_PORTAL_ID.unshift({ "value": "", "text": "" });
    });
  //分页参数
  var opts = {
    //terrace显示全部，card分页显示
    skin: "card",
    //renderer:"grid",
    columns: [
      { id: "lineid", name: "id", type: "ro", width: "80", hidden: true },
      { id: "createtime", name: "队列时间", type: "ro", width: "120" },
      { id: "portalId", name: "队列类别", type: "ro", width: "80", align: "center", render: function (v) { return Prolog.getNameByID(rsp_PORTAL_ID, v); } },
      { id: "funno", name: "队列标识", type: "ro", width: "220" },
      { id: "funname", name: "队列描述", type: "ro", width: "140" },
      { id: "objid", name: "业务数据ID", type: "ro", width: "100" },
      { id: "objcode", name: "业务数据编号", type: "ro", width: "120" },
      { id: "objname", name: "业务数据名称", type: "ro", width: "120" },
      { id: "params", name: "队列参数", type: "txt", width: "300" },
      { id: "remark", name: "错误描述", type: "txt", width: "400" },
      {
        id: "status", name: "队列状态", type: "ro", align: "center", width: "60", render: function (v) {
          return v == "E" ? "错误" : "初始";
        }
      },
      {
        id: "op", name: "操作", type: "button", align: "center", width: 100, render: function () {
          return "重发^res_msgLog_sendClick,删除^res_msgLog_delClick";

        }
      }
    ],
    multiselect: false,
    fixedLast: true, //开启固定列，固定最后一行，倒数第二列不能隐藏
    toolbar: [
      { type: "settings", labelWidth: 90, labelAlign: "right" },
      {
        type: "row",
        list: [
          { type: "calendar", className: "layui-col-md3", name: "startdate", label: "开始时间:", value: startTime, readonly: true },
          { type: "calendar", className: "layui-col-md3", name: "enddate", label: "结束时间:", value: endTime, readonly: true },
          { type: "input", name: "funno", className: "layui-col-md3", label: "队列标识:" },
          { type: "combo", name: "portalId", className: "layui-col-md3", label: "队列类别:", readonly: true, options: rsp_PORTAL_ID },
          { type: "input", name: "objid", className: "layui-col-md3", label: "业务数据ID:" },
          { type: "input", name: "objcode", className: "layui-col-md3", label: "业务数据编号:" },
          { type: "input", name: "objname", className: "layui-col-md3", label: "业务数据名称:" },
          {
            type: "block", className: "layui-col-md3 form_btn_left",
            list: [
              { type: "button", className: "btn-normal", name: "btn_search", value: "查 询" },
              { type: "newcolumn" },
              { type: "button", name: "btn_reset", className: "normal", value: "重 置" }
            ]
          }
        ]
      }],
    url: UPCLOUD_RDC_TMS_INTERFACE_SERVICE+"/mqLog/list/v1.0",//数据接口
    type: "post",//数据提交方式，默认为get
    contentType: "application/json",
    params: JSON.stringify({ startdate: startTime, enddate: endTime }),//查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  //分页参数 pageSize pageNum
  grid = new PlgGrid(opts);
  grid.renderTo("msgLog_grid");
  grid.loadData();
  //按钮添加方法
  grid.attachToolBarEvent("onButtonClick", function (name) {
    //查询
    if (name == "btn_search") {
      var jsonData = grid.getToolBarForm().getFormData();
      if (jsonData.startdate == null) {
        jsonData.startdate = FormatDate(new Date()) + " 00:00:00";
      }
      else {
        jsonData.startdate = Prolog.formatDate(jsonData.startdate) + " 00:00:00";
      }
      if (jsonData.enddate == null) {
        jsonData.enddate = FormatDate(new Date()) + " 23:59:59";
      }
      else {
        jsonData.enddate = Prolog.formatDate(jsonData.enddate) + " 23:59:59";
      }
      if (jsonData.startdate > jsonData.enddate) {
        layer.msg("开始时间不能大于结束时间");
        return false;
      }
      grid.setParams(JSON.stringify(jsonData));
      grid.reload();
    }
    //重置
    if (name == "btn_reset") {
      grid.getToolBarForm().clear();
      grid.getToolBarForm().setFormData({ startdate: startTime, enddate: endTime });
    }
  });

  window.res_msgLog_sendClick = function (rid) {
    grid.selectRowById(rid);
    let pload = PlgDialog.load(2, { shade: [0.6, "#fff"] });
    Prolog.ajax({
      url: UPCLOUD_RDC_TMS_INTERFACE_SERVICE+"/mqLog/resend/v1.0",
      type: "post",
      contentType: "application/json",
      data: JSON.stringify({ "lineids": rid }),
      success: function (data) {
        PlgDialog.close(pload);
        if (data.success) {
          grid.reload();

        }
      },
      error: function () { PlgDialog.close(pload); PlgDialog.msg("接口调用失败"); err++; }
    });
  };

  window.res_msgLog_delClick = function (rid) {
    grid.selectRowById(rid);
    Prolog.delGridRowData(grid, UPCLOUD_RDC_TMS_INTERFACE_SERVICE+"/mqLog/delete/v1.0", "post", "application/json", JSON.stringify({ "lineid": rid }), false);
  };

};