/**
 * zzx
 * 2020.09.16
 * 车辆事故查询
    */
    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 master_grid;
var userinfo = {
  p_id: '',
  p_username: '',
  p_workernumber: '',
  p_nickname: '',
  p_phone: null,
  p_email: null,
  p_companyid: '',
  p_enterpriseid: '',
  p_organizationid: '',
  p_companyname: '',
  p_orgname: '',
  p_enterprisename: '',
  p_usertype: '',
  p_lastlogindate: '',
  p_lastmodipassdate: null,
  p_validdate: '',
  p_import_batchno: null,
  p_data_source: null,
  forceModifyPasswdFlag: false,
  vehicle: null,
}

  // 获取默认时间
  var startTime = Prolog.formatDate(new Date(), "%YY-%MM") + "-01 00:00:00";
  var endTime = Prolog.formatDate(new Date()) + " 23:59:59";

  // 获取下拉框数据
  var dataSelect;
  getSelectGJ([
    { objectcode: "ACCID_TYPE" },
    { objectcode: "AUDIT_STATUS" }], function (data) {
      dataSelect = data.data;
    }
  );

  // 配送中心table
  var branchTable = {
    // terrace显示全部，card分页显示
    skin: "card",
    // renderer:"grid",
    columns: [
      { id: "companyid", name: "id", type: "ro", width: "130", hidden: true },
      { id: "companycode", name: "配送中心编号", type: "ro" },
      { id: "companyname", name: "配送中心名称", type: "ro" }
    ],
    multiselect: false,
    toolbar: [
      { type: "settings", position: "label-left", width: 200, labelWidth: 100 },
      {
        type: "block", id: "bk", blockOffset: 0, list: [
          { type: "input", name: "companycode", label: "配送中心编号:", width: 120 },
          { type: "newcolumn" },
          { type: "button", name: "querycarr", value: "查询" },
          { type: "newcolumn" },
          { type: "button", name: "car_Reset", value: "重置" }
        ]
      }
    ],

    url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/pubCompany/queryCompanyBranch",
    pagebar: { type: "simple" },
    type: "post", // 数据提交方式，默认为get
    params: JSON.stringify({ companytype: "S" }), // 查询提交参数，分页参数默认为pageNum,pageSize
    contentType: "application/json",
    page: true, // 是否启用分页
    totalCount: "totalCount" // 总记录数字段，默认totalCount
  };
  // 车牌号table
  var vehicleTable = {
    skin: "card",
    columns: [
      { id: "vehicleId", name: "id", type: "ro", width: "130", hidden: true },
      { id: "vehicleNo", name: "车牌号", type: "ro" },
      { id: "vehicleName", name: "车辆名称", type: "ro" }
    ],
    multiselect: false,
    url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/tBaseVehicle/queryVehicleInfo",
    type: "post",
    pagebar: { type: "simple" },
    contentType: "application/json",
    params: JSON.stringify({ companyId: userinfo.p_companyid }),
    page: true,
    totalCount: "totalCount"
  };

  // 主页grid
  var master_grid_opts = {
    skin: "card",
    columns: [
      { id: "accidentNum", name: "id", type: "ro", width: "130", hidden: true },
      { id: "branchid", name: "机构id", type: "ro", width: 120 },
      { id: "branchname", name: "机构牌号", type: "ro", width: 120 },
      { id: "accidentNum", name: "事故编号", type: "ro", width: 120 },
      { id: "acciddate", name: "事故日期", type: "ro", width: 120 },
      {
        id: "accidtype", name: "事故类型", type: "ro", width: 120, render: function (v) {
          return getSelectValue(dataSelect.ACCID_TYPE, v);
        }
      },
      { id: "accidaddress", name: "事故地点", type: "ro", width: 120 },
      // { id: "roadcon", name: "路况", type: "ro", width: 120 },
      { id: "reporter", name: "报案人姓名", type: "ro", width: 120 },
      { id: "reportdate", name: "报案时间", type: "ro", width: 120 },
      // { id: "theaccid", name: "出现经过", type: "ro", width: 120 },
      // { id: "respdes", name: "责任描述", type: "ro", width: 120 },
      { id: "carlost", name: "本车损失", type: "ro", width: 120 },
      { id: "thirdpl", name: "第三方损失", type: "ro", width: 120 },
      // { id: "injuries", name: "轻伤人数", type: "ro", width: 120 },
      // { id: "injured", name: "重伤人数", type: "ro", width: 120 },
      // { id: "death", name: "死亡人数", type: "ro", width: 120 },
      { id: "vehiclecode", name: "本方车牌号", type: "ro", width: 120 },
      { id: "usCode", name: "本方驾驶证号", type: "ro", width: 120 },
      { id: "otherVehicle", name: "对方车牌号", type: "ro", width: 120 },
      { id: "otherCode", name: "对方驾驶证号", type: "ro", width: 120 },
      // { id: "otherVehiclespec", name: "对方车辆型号", type: "ro", width: 120 },
      { id: "otherMaindriver", name: "对方驾驶员姓名", type: "ro", width: 120 },
      // { id: "otherDriverage", name: "对方驾驶员年龄", type: "ro", width: 120 },
      // { id: "otherDriversex", name: "对方驾驶员性别", type: "ro", width: 120 },
      // { id: "otherDriverdriving", name: "对方驾驶员驾龄", type: "ro", width: 120 },
      // { id: "otherDriveradd", name: "对方驾驶员地址", type: "ro", width: 120 },
      { id: "trafficpd", name: "交警部门", type: "ro", width: 120 },
      // { id: "policecontact", name: "交警联系人", type: "ro", width: 120 },
      // { id: "policecall", name: "交警电话", type: "ro", width: 120 },
      // { id: "salesman", name: "业务员", type: "ro", width: 120 },
      // { id: "pho", name: "照片地址路径", type: "ro", width: 120 },
      // { id: "dutyAlloc", name: "责任划分", type: "ro", width: 120 },
      // { id: "estimatedloss", name: "估损金额", type: "ro", width: 120 },
      // { id: "actualLoss", name: "实际损失", type: "ro", width: 120 },
      // { id: "insurancepm", name: "保险赔付情况", type: "ro", width: 120 },
      // { id: "liabilityAttribute", name: "责任属性", type: "ro", width: 120 },
      // { id: "theaccidDescribe", name: "出现经过描述", type: "ro", width: 120 },
      // { id: "usMaindriver", name: "本方驾驶员姓名", type: "ro", width: 120 },
      // { id: "usDriverage", name: "本方驾驶员年龄", type: "ro", width: 120 },
      // { id: "usDriverdriving", name: "本方驾驶员驾龄", type: "ro", width: 120 },
      // { id: "underwrite", name: "承保方", type: "ro", width: 120 },
      // { id: "uVehicle", name: "本方车牌号", type: "ro", width: 120 },
      // { id: "ifInsure", name: "对方是否保险", type: "ro", width: 120 },
      // { id: "ifPicture", name: "是否有照片", type: "ro", width: 120 },
      // { id: "giveMsg", name: "消息推送给", type: "ro", width: 120 },
      // { id: "audittime", name: "审核时间", type: "ro", width: 120 },
      // { id: "auditperson", name: "审核人", type: "ro", width: 120 },
      {
        id: "status", name: "状态", type: "ro", width: 120, render: function (v) {
          return getSelectValue(dataSelect.AUDIT_STATUS, v);
        }
      },
      { id: "memo", name: "备注", type: "ro", width: 120 }
    ],
    toolbar: [
      { type: "settings", labelWidth: 90, labelAlign: "right" },
      {
        type: "row",
        list: [
          { type: "calendar", className: "layui-col-md3", name: "startdate", label: "开始时间:", value: startTime },
          { type: "calendar", className: "layui-col-md3", name: "enddate", label: "结束时间:", value: endTime },
          {
            type: "selectTable",
            className: "layui-col-md3",
            placeholder: "请选择配送中心",
            readonly: false,
            table: branchTable,
            tableWidth: 600,
            tableHeight: 500,
            fieldText: "companyname",
            fieldValue: "companyid",
            name: "branchidList",
            label: "配送中心:",
            listener: function (Grid) {
              setMethod(Grid, branchTable, function () { });
            }
          },
          { type: "input", className: "layui-col-md3", name: "accidentNum", label: "事故编号:" },
          {
            type: "selectTable",
            className: "layui-col-md3",
            placeholder: "请选择车牌号",
            readonly: false,
            table: vehicleTable,
            tableWidth: 600,
            tableHeight: 500,
            fieldText: "vehicleNo",
            fieldValue: "vehicleNo",
            name: "vehiclecodeList",
            label: "车牌号:",
            listener: function (Grid) {
              setMethod(Grid, vehicleTable, function () { });
            }
          },
          { type: "input", className: "layui-col-md3", name: "reporter", label: "报案人:" },
          { type: "input", className: "layui-col-md3", name: "accidaddress", label: "事故地点:" },
          {
            type: "block", className: "layui-col-md3 form_btn_left",
            list: [
              { type: "button", className: "btn-normal", name: "master_search", value: "查 询" },
              { type: "newcolumn" },
              { type: "button", name: "master_reset", value: "重 置" }
            ]
          }
        ]
      }
    ],
    fixedLast: false, // 开启固定列，固定最后一行，倒数第二列不能隐藏
    multiselect: false, // 是否支持多选

    url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/vehicleManage/queryTVmAccidentreg", // 数据接口
    type: "post", // 数据提交方式，默认为get
    params: JSON.stringify({ startdate: startTime, enddate: endTime, status: 20 }), // 查询提交参数，分页参数默认为pageNum,pageSize
    page: true, // 是否启用分页
    contentType: "application/json",
    totalCount: "totalCount" // 总记录数字段，默认totalCount
  };
  master_grid = new PlgGrid(master_grid_opts);
  master_grid.renderTo("vehicleAccidentInquiry");
  master_grid.loadData();
  master_grid.attachToolBarEvent("onButtonClick", function (name) {
    switch (name) {
      case "master_search":
        var request = master_grid.getToolBarForm().getFormData();
        request.startdate = request.startdate ? Prolog.formatDate(request.startdate) + " 00:00:00" : "";
        request.enddate = request.enddate ? Prolog.formatDate(request.enddate) + " 23:59:59" : "";
        if (request.startdate > request.enddate) {
          layer.msg("开始时间不能大于结束时间");
          return false;
        }
        request.branchid = request.branchidList ? JSON.parse(request.branchidList)[0] : "";
        request.vehiclecode = request.vehiclecodeList ? JSON.parse(request.vehiclecodeList)[0] : "";
        request.status = 20;
        dealNullQueryCondition(request);
        delete request.branchidList;
        delete request.vehiclecodeList;
        master_grid.setParams(JSON.stringify(request));
        master_grid.reload();
        break;
      case "master_reset":
        master_grid.getToolBarForm().clear();
        master_grid.getToolBarForm().setText("branchidList", "");
        master_grid.getToolBarForm().setText("vehiclecodeList", "");
        master_grid.getToolBarForm().setFormData({ startdate: startTime, enddate: endTime });
        break;
    }
  });
};