/**
* guoj
* 2020.05.26
* 车辆管理
*/
export default () => {
  //供应商table
  var company_Table = {
    columns: [
      { id: "carrierId", name: "id", type: "ro", width: "130", hidden: true },
      { id: "carrierCode", name: "承运商编号", type: "ro" },
      { id: "carrierName", name: "承运商名称", type: "ro" }
    ],
    multiselect: false,

    url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/tmsBaseCarrier/queryTmsBaseCarrier", //数据接口
    type: "post", //数据提交方式，默认为get
    pagebar: { type: "simple" },
    contentType: "application/json",
    params: "{}", //查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  //车辆规格table
  var userTable = {
    columns: [
      { id: "id", name: "id", type: "ro", width: "130", hidden: true },
      { id: "vehicleSpecsNo", name: "规格编号", type: "ro" },
      { id: "vehicleSpecsName", name: "规格名称", type: "ro" }
    ],
    multiselect: false,

    url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/tBaseVehicleSpecs/queryTBaseVehicleSpecs", //数据接口
    type: "post", //数据提交方式，默认为get
    pagebar: { type: "simple" },
    contentType: "application/json",
    params: "{}", //查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  //GPS设备table
  var userTable3 = {
    columns: [
      { id: "smartDeviceId", name: "id", type: "ro", width: "130", hidden: true },
      { id: "smartDeviceCode", name: "GPS设备编号", type: "ro" },
      { id: "smartDeviceName", name: "GPS设备名称", type: "ro" }
    ],
    multiselect: false,

    url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/tBaseSmartDevice/queryTBaseSmartDevice", //数据接口
    type: "post", //数据提交方式，默认为get
    pagebar: { type: "simple" },
    contentType: "application/json",
    params: JSON.stringify({ "smartDeviceType": "01" }), //查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  //冷藏设备table
  var userTable2 = {
    columns: [
      { id: "smartDeviceId", name: "id", type: "ro", width: "130", hidden: true },
      { id: "smartDeviceCode", name: "冷藏设备编号", type: "ro" },
      { id: "smartDeviceName", name: "冷藏设备名称", type: "ro" }
    ],
    multiselect: false,

    url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/tBaseSmartDevice/queryTBaseSmartDevice", //数据接口
    type: "post", //数据提交方式，默认为get
    pagebar: { type: "simple" },
    contentType: "application/json",
    params: JSON.stringify({ "smartDeviceType": "02" }), //查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  var ddfrom = null;
  var ddfromH = null;
  var configA = null;
  var fromData = null;
  var grid = null;
  var gridA = null;
  var gridTemplate1B = null;
  var dataSelete = {};
  let dataType = 0;
  //获取下拉框
  getSelectGJ([{ "objectcode": "TMS_VEHICLE_BELONG" }, { "objectcode": "TMS_VEHICLE_TYPE" },
  { "objectcode": "TMS_VEHICLE_STATUS" }], function (data) {
    data.data.TMS_VEHICLE_TYPE.unshift({ "text": "", "value": "" });
    dataSelete = data.data;
  });
  var opts = {
    //terrace显示全部，card分页显示
    skin: "card",
    //renderer:"grid",
    columns: [
      { id: "vehicleId", name: "id", type: "ro", width: "100", hidden: true },
      { id: "vehicleNo", name: "车牌号", type: "ro", width: 150 },
      { id: "vehicleName", name: "车辆名称", type: "ro", width: 150 },
      { id: "color", name: "车辆颜色", type: "ro", width: 100 },
      {
        id: "vehicleType", name: "车辆类型", type: "ro", width: 100, render: (v) => {
          return getSelectValue(dataSelete.TMS_VEHICLE_TYPE, v);
        }
      },
      { id: "vehicleSpecsName", name: "车辆规格", type: "ro", width: 100 },
      { id: "model", name: "品牌型号", type: "ro", width: 100 },
      {
        id: "belong", name: "归属类型", type: "ro", width: 100, render: (v) => {
          return getSelectValue(dataSelete.TMS_VEHICLE_BELONG, v);
        }
      },
      { id: "carrierName", name: "承运商", type: "ro", width: 100 },
      {
        id: "status", name: "车辆状态", type: "ro", width: 130, render: (v) => {
          return getSelectValue(dataSelete.TMS_VEHICLE_STATUS, v);
        }
      },
      { id: "gpsNo", name: "GPS设备号", type: "ro", width: 100 },
      { id: "coldToolNo", name: "冷藏设备号", type: "ro", width: 100 },
      { id: "mileage", name: "当前里程", type: "ro", width: 130 },
      { id: "maxVol", name: "最大装载体积", type: "ro", width: 130 },
      { id: "maxWeight", name: "最大装载重量", type: "ro", width: 130 },
      { id: "maxPkg", name: "最大装载件数", type: "ro", width: 130 },
      { id: "memo", name: "备注", type: "ro", width: 130 },
      {
        id: "op",
        name: "操作",
        type: "button",
        align: "center",
        fixed: "right",
        width: 200,
        render: function () {
          return "删除^vehicleManagement_deleteClick,修改^vehicleManagement_updataClick,复制^vehicleManagement_copy,详情^vehicleManagement_details";
        }
      }
    ],
    multiselect: true,
    fixedLast: true, //开启固定列，固定最后一行，倒数第二列不能隐藏
    toolbar: [
      { type: "settings", labelWidth: 90, labelAlign: "right" },
      {
        type: "row",
        list: [
          {
            className: "layui-col-md3",
            type: "selectTable",
            placeholder: "请选择承运商",
            readonly: false,
            table: company_Table,
            tableWidth: 500,
            tableHeight: 400,
            fieldText: "carrierName",
            fieldValue: "carrierCode",
            name: "vendorcode2",
            label: "承运商编码:",
            listener: function (consignorGrid) {
              setMethod(consignorGrid, company_Table, function (data) {
                var fromdata = grid.getToolBarForm().getFormData();
                data = fromdata.vendorcode2.length == 2 ? "" : data;
                var datad = {};
                datad.carrierId = data.carrierId || "";
                grid.getToolBarForm().setFormData(datad);
              });
            }
          },
          { type: "hidden", name: "carrierId", label: "承运商:" },
          { type: "input", name: "vehicleNo", label: "车牌号:", className: "layui-col-md3" },
          { type: "combo", name: "vehicleType", label: "车辆类型:", className: "layui-col-md3", options: dataSelete.TMS_VEHICLE_TYPE },
          { type: "hidden", name: "vehicleSpecs", label: "车辆规格:" },
          {
            className: "layui-col-md3",
            type: "selectTable",
            placeholder: "请选择车辆规格",
            readonly: false,
            table: userTable,
            tableWidth: 500,
            tableHeight: 400,
            fieldText: "vehicleSpecsName",
            fieldValue: "vehicleSpecsNo",
            name: "buyername5",
            label: "车辆规格:",
            listener: function (consignorGrid) {
              setMethod(consignorGrid, userTable, function (data) {
                var fromdata = grid.getToolBarForm().getFormData();
                data = fromdata.buyername5.length == 2 ? "" : data;
                var datad = {};
                datad.vehicleSpecs = data.vehicleSpecsNo || "";
                grid.getToolBarForm().setFormData(datad);
              });
            }
          },
          {
            type: "block", className: "layui-col-md6 form_btn_left",
            list: [
              { type: "button", className: "btn-normal", name: "querywork", value: "查 询" },
              { type: "newcolumn" },
              { type: "button", name: "work_Reset", className: "normal", value: "重 置" }
            ]
          },
          {
            type: "block", className: "layui-col-md6 right",
            list: [
              { type: "button", className: "btn-addBtn btn-normal", name: "addBtn", value: "<i class='layui-icon layui-icon-add-1'></i>新 增" }
            ]
          }
        ]
      }
    ],

    url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/tBaseVehicle/queryGetTBaseVehicle", //数据接口
    type: "post", //数据提交方式，默认为get
    pagebar: {
      buttons: [
        { text: "删除", className: "layui-btn-danger", name: "delete" }
      ]
    },
    contentType: "application/json",
    params: "{}", //查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  //分页参数 pageSize pageNum
  grid = new PlgGrid(opts);
  grid.renderTo("vehicleManagement_guojzhuans2");
  grid.attachEvent("onDataReady", function () {
    setTimeout(function () {
      layui.form.render();
    }, 200);
  });
  //分组拆分条件查询
  grid.loadData();

  //按钮添加方法
  grid.attachToolBarEvent("onButtonClick", function (name) {
    //查询
    if (name == "querywork") {
      var fdata = grid.getToolBarForm().getFormData();
      fdata.type = 1;
      delete fdata.buyername5;
      grid.setParams(JSON.stringify(fdata));
      grid.reload();
    }
    //新增
    if (name == "addBtn") {
      $("#vehicleManagement_div4").html("");
      $("#vehicleManagement_div4B").html("");
      ddfromH = new PlgForm(fromData);
      ddfromH.setFormData({ status: "01" });
      cuttingScreen("#vehicleManagement_div1");
      $("#vehicleManagement_title").html("新增");
    }
    //重置
    if (name == "work_Reset") {
      grid.getToolBarForm().clear();
      grid.getToolBarForm().getDForm().setText("buyername5", "");
      grid.getToolBarForm().getDForm().setText("vendorcode2", "");
      grid.getToolBarForm().setFormData({ consignor: "" });
    }
  });
  //按钮添加方法
  grid.attachPageBarEvent(function (name) {
    //删除
    if (name == "delete") {
      let data = [];
      let datas = getDeleteAll(grid);
      datas.forEach(v => {
        data.push({ vehicleId: v });
      });
      data = JSON.stringify(data);
      utilDelete(UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/tBaseVehicle/deleteTBaseVehicle", "post", data, function (data) {
        grid.reload();
      }, "application/json");
    }
  });
  //删除
  window.vehicleManagement_deleteClick = function (rid) {
    grid.selectRowById(rid);
    let data = [];
    let datas = getDeleteAll(grid);
    datas.forEach(v => {
      data.push({ vehicleId: v });
    });
    data = JSON.stringify(data);
    utilDelete(UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/tBaseVehicle/deleteTBaseVehicle", "post", data, function (data) {

      grid.reload();
    }, "application/json");
  };
  //修改
  window.vehicleManagement_updataClick = function (rid, data) {
    $("#vehicleManagement_div4").html("");
    ddfromH = new PlgForm(fromData);
    grid.selectRowById(rid);
    data.buyername1 = data.vehicleSpecs ? JSON.stringify([data.vehicleSpecs]) : "[]";
    data.buyername2 = data.coldToolNo ? JSON.stringify([data.coldToolNo]) : "[]";
    data.buyername3 = data.gpsNo ? JSON.stringify([data.gpsNo]) : "[]";
    data.vendorcode1 = data.carrierId ? JSON.stringify([data.carrierId]) : "[]";
    ddfromH.setFormData(data);
    ddfromH.getDForm().setText("buyername1", data.vehicleSpecsName == null ? "" : data.vehicleSpecsName);
    ddfromH.getDForm().setText("buyername2", data.coldToolNo == null ? "" : data.coldToolNo);
    ddfromH.getDForm().setText("buyername3", data.gpsNo == null ? "" : data.gpsNo);
    ddfromH.getDForm().setText("vendorcode1", data.carrierName == null ? "" : data.carrierName);
    cuttingScreen("#vehicleManagement_div1");
    $("#vehicleManagement_title").html("编辑");
    //下面的是绑定证件的代码，这个版本不用，暂时屏蔽
    // $("#vehicleManagement_div4B").html("");
    // gridA.renderTo("vehicleManagement_div4B");
    // gridA.setParams(this.JSON.stringify({"objectId": data.companyid}));
    // gridA.reload();
    // setMouth();
  };
  //复制
  window.vehicleManagement_copy = function (rid, data) {
    $("#vehicleManagement_div4").html("");
    ddfromH = new PlgForm(fromData);
    $("#vehicleManagement_div4B").html("");
    grid.selectRowById(rid);
    data.vehicleId = "";
    data.buyername1 = data.vehicleSpecs ? JSON.stringify([data.vehicleSpecs]) : "[]";
    data.buyername2 = data.coldToolNo ? JSON.stringify([data.coldToolNo]) : "[]";
    data.buyername3 = data.gpsNo ? JSON.stringify([data.gpsNo]) : "[]";
    data.vendorcode1 = data.carrierId ? JSON.stringify([data.carrierId]) : "[]";
    ddfromH.setFormData(data);
    ddfromH.getDForm().setText("buyername1", data.vehicleSpecsName == null ? "" : data.vehicleSpecsName);
    ddfromH.getDForm().setText("buyername2", data.coldToolNo == null ? "" : data.coldToolNo);
    ddfromH.getDForm().setText("buyername3", data.gpsNo == null ? "" : data.gpsNo);
    ddfromH.getDForm().setText("vendorcode1", data.carrierName == null ? "" : data.carrierName);
    cuttingScreen("#vehicleManagement_div1");
    $("#vehicleManagement_title").html("新增");
  };
  //详情
  window.vehicleManagement_details = function (rid, rdata) {
    dataType = 0;
    grid.selectRowById(rid);
    cuttingScreen("#vehicleManagement_div9");
    new PlgPanel({
      renderer: "vehicleManagement_div422",
      skin: 2,
      header: {
        isShow: true,
        title: "基本信息"
      },
      defaultBody: {
        layoutCol: 3,
        valueBj: true,
        cols: [
          [{
            label: "车牌号",
            value: rdata.vehicleNo
          },
          {
            label: "车辆名称",
            value: rdata.vehicleName
          },
          {
            label: "车辆颜色",
            value: rdata.color
          },
          {
            label: "车辆类型",
            value: getSelectValue(dataSelete.TMS_VEHICLE_TYPE, rdata.vehicleType)
          }
          ],
          [{
            label: "车辆规格",
            value: rdata.vehicleSpecsName
          },
          {
            label: "品牌型号",
            value: rdata.model
          }, {
            label: "归属类型",
            value: getSelectValue(dataSelete.TMS_VEHICLE_BELONG, rdata.belong)
          },
          {
            label: "承运商",
            value: rdata.carrierName
          }
          ],
          [
            {
              label: "车辆状态",
              value: getSelectValue(dataSelete.TMS_VEHICLE_STATUS, rdata.status)
            }, {
              label: "GPS设备号",
              value: rdata.gpsNo
            },
            {
              label: "冷藏设备号",
              value: rdata.coldToolNo
            },
            {
              label: "当前里程",
              value: rdata.mileage + ""
            }
          ],
          [
            {
              label: "最大装载体积",
              value: rdata.maxVol + ""
            }, {
              label: "最大装载重量",
              value: rdata.maxWeight + ""
            },
            {
              label: "最大装载件数",
              value: rdata.maxPkg + ""
            },
            {
              label: "备注",
              value: rdata.memo
            }
          ]
        ]
      }
    });
  };
  //跳转页面
  var carousel = layui.carousel;
  carousel.render({
    elem: "#vehicleManagement_div2",
    autoplay: false,
    index: 0,
    arrow: "none",
    indicator: "none",
    anim: "fade",
    width: "100%", //设置容器宽度
    height: "100%"
  });
  fromData = {
    renderer: "vehicleManagement_div4",
    items: [
      { type: "settings", position: "label-left", width: 300, labelWidth: 115 },
      { type: "hidden", name: "vehicleId", label: "id:", width: 145 },
      { type: "input", name: "vehicleNo", label: "车牌号:", width: 145, editable: false, validate: "NotEmpty", required: true },
      { type: "hidden", name: "vehicleSpecs", label: "车辆规格:", width: 145 },
      { type: "hidden", name: "vehicleSpecsName", label: "车辆规格:", width: 145 },
      {
        width: 145,
        type: "selectTable",
        placeholder: "请选择车辆规格(必填)",
        readonly: false,
        table: userTable,
        tableWidth: 500,
        tableHeight: 400,
        fieldText: "vehicleSpecsName",
        fieldValue: "vehicleSpecsNo",
        name: "buyername1",
        label: "车辆规格:<span class='dhxform_item_required'>*</span>",
        listener: function (consignorGrid) {
          setMethod(consignorGrid, userTable, function (data) {
            var fromdata = ddfromH.getFormData();
            data = fromdata.buyername1.length == 2 ? "" : data;
            var datad = {};
            datad.vehicleSpecs = data.vehicleSpecsNo || "";
            datad.vehicleSpecsName = data.vehicleSpecsName || "";
            ddfromH.setFormData(datad);
          });
        }
      },
      { type: "combo", name: "status", label: "车辆状态:", width: 145, options: dataSelete.TMS_VEHICLE_STATUS, editable: false, validate: "NotEmpty", required: true },
      { type: "input", name: "maxVol", label: "最大装载体积(m³):", width: 145, editable: false, validate: "NotEmpty", required: true },
      { type: "input", name: "memo", label: "备注:", width: 145, editable: false },
      { type: "newcolumn", offset: 10 },
      { type: "input", name: "vehicleName", label: "车辆名称:", width: 145, editable: false, validate: "NotEmpty", required: true },
      { type: "input", name: "model", label: "品牌型号:", width: 145, editable: false, validate: "NotEmpty", required: true },
      {
        width: 145,
        type: "selectTable",
        placeholder: "请选择GPS设备号",
        readonly: false,
        table: userTable3,
        tableWidth: 500,
        tableHeight: 400,
        fieldText: "smartDeviceCode",
        fieldValue: "smartDeviceCode",
        name: "buyername3",
        label: "GPS设备号:",
        listener: function (consignorGrid) {
          setMethod(consignorGrid, userTable3, function (data) {
            var fromdata = ddfromH.getFormData();
            data = fromdata.buyername3.length == 2 ? "" : data;
            var datad = {};
            datad.gpsNo = data.smartDeviceCode || "";
            ddfromH.setFormData(datad);
          });
        }
      },
      { type: "hidden", name: "gpsNo", label: "GPS设备号:", width: 145 },
      { type: "input", name: "maxWeight", label: "最大装载重量(kg):", width: 145, editable: false, validate: "NotEmpty", required: true },
      { type: "newcolumn", offset: 10 },
      { type: "input", name: "color", label: "车辆颜色:", width: 145, editable: false, validate: "NotEmpty", required: true },
      { type: "combo", name: "belong", label: "归属类型:", width: 145, options: dataSelete.TMS_VEHICLE_BELONG, editable: false, validate: "NotEmpty", required: true },
      { type: "hidden", name: "coldToolNo", label: "冷藏设备号:", width: 145 },
      {
        width: 145,
        type: "selectTable",
        placeholder: "请选择冷藏设备号",
        readonly: false,
        table: userTable2,
        tableWidth: 500,
        tableHeight: 400,
        fieldText: "smartDeviceCode",
        fieldValue: "smartDeviceCode",
        name: "buyername2",
        label: "冷藏设备号:",
        listener: function (consignorGrid) {
          setMethod(consignorGrid, userTable2, function (data) {
            var fromdata = ddfromH.getFormData();
            data = fromdata.buyername2.length == 2 ? "" : data;
            var datad = {};
            datad.coldToolNo = data.smartDeviceCode || "";
            ddfromH.setFormData(datad);
          });
        }
      },
      { type: "input", name: "maxPkg", label: "最大装载件数:", width: 145, editable: false, validate: "NotEmpty", required: true },
      { type: "newcolumn", offset: 10 },
      { type: "combo", name: "vehicleType", label: "车辆类型:", width: 145, options: dataSelete.TMS_VEHICLE_TYPE, editable: false, validate: "NotEmpty", required: true },
      {
        width: 145,
        type: "selectTable",
        placeholder: "请选择承运商",
        readonly: false,
        table: company_Table,
        tableWidth: 500,
        tableHeight: 400,
        fieldText: "carrierName",
        fieldValue: "carrierId",
        name: "vendorcode1",
        label: "承运商:<span class='dhxform_item_required'>*</span>",
        listener: function (consignorGrid) {
          setMethod(consignorGrid, company_Table, function (data) {
            var fromdata = ddfromH.getFormData();
            data = fromdata.vendorcode1.length == 2 ? "" : data;
            var datad = {};
            datad.carrierName = data.carrierName || "";
            datad.carrierId = data.carrierId || "";
            ddfromH.setFormData(datad);
          });
        }
      },
      { type: "hidden", name: "carrierName", label: "承运商:", width: 145 },
      { type: "hidden", name: "carrierId", label: "承运商:", width: 145 },
      { type: "input", name: "mileage", label: "当前里程:", width: 145, editable: false, validate: "NotEmpty", required: true },
      { type: "input", name: "displacement", label: "排量(L):", width: 145, editable: false, validate: "NotEmpty", required: true }
    ]
  };
  configA = {
    renderer: "vehicleManagement_Template1B", //挂载点
    indexActive: 0, //初始化默认选中项
    content: [{
      title: "图片",
      template: "<div id =\"vehicleManagement_Template1B_divA\" style=\"height:100%;padding: 0px;\">" +
        "<div class=\"layui-upload\">  <button type=\"button\" class=\"layui-btn\" style='float:left' id=\"vehicleManagement_Template1B_divA1\">多图片上传</button> " +
        "<div class=\"layui-upload\">  <button type=\"button\" class=\"layui-btn\" style='margin-left:10px' id=\"vehicleManagement_Template1B_divA3\">保存</button> " +
        "  <blockquote class=\"layui-elem-quote layui-quote-nm\" style=\"margin-top: 10px;\">" +
        "  预览图： <div class=\"layui-upload-list\" id=\"vehicleManagement_Template1B_divA2\"></div> </blockquote> </div></div>"
    }, {
      title: "文件",
      template: "<div id =\"vehicleManagement_Template1B_divB\" style=\"height:100%;padding: 0px;\">" +
        "<div class=\"layui-upload\">  <button type=\"button\" class=\"layui-btn\" style='float:left' id=\"vehicleManagement_Template1B_divB1\">文件上传</button> " +
        "<div class=\"layui-upload\">  <button type=\"button\" class=\"layui-btn\" style='margin-left:10px' id=\"vehicleManagement_Template1B_divB3\">保存</button> " +
        "<div id='vehicleManagement_Template1B_divB2'></div></div>"
    }]
  };

  //返回
  $(document).on("click", "#vehicleManagement_return", function () {
    if (dataType == 0) {
      cuttingScreen("#vehicleManagement_div3");
    }
    else {
      dataType = 0;
      cuttingScreen("#vehicleManagement_div1");
    }
  });
  //返回
  $(document).on("click", "#vehicleManagement_returnA", function () {
    cuttingScreen("#vehicleManagement_div1");
  });
  function cuttingScreen(name) {
    var dataList = ["#vehicleManagement_div1", "#vehicleManagement_div3",
      "#vehicleManagement_div9", "#vehicleManagement_Template"];
    for (var i = 0; i < dataList.length; i++) {
      if (dataList[i] == name) {
        $(dataList[i]).css("display", "block");
      }
      else {
        $(dataList[i]).css("display", "none");
      }
    }
  }
  //保存
  document.querySelector("#vehicleManagement_save").onclick = function () {
    var feik = ddfromH.validate();
    if (!feik) {
      return;
    }
    //数据data
    var data = ddfromH.getFormData();
    data.branchid = userGJ.p_companyid;
    if (!data.vehicleSpecs) {
      layer.msg("车辆规格不能为空");
      return;
    }
    if (!data.carrierId) {
      layer.msg("承运商不能为空");
      return;
    }

    if (!Prolog.isCarID(data.vehicleNo)) {
      layer.msg("请输入正确的车牌");
      return;
    }

    delete data.buyername1;
    delete data.buyername2;
    delete data.buyername3;
    delete data.vendorcode1;

    //请求地址和类型
    var url = UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/tBaseVehicle/updateTBaseVehicle";
    var type = "post";
    var contentType = "application/json";
    //message新增为0，修改为1
    if (data.vehicleId == null || data.vehicleId == "") {
      url = UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/tBaseVehicle/addTBaseVehicle";
    }
    //调用ajax方法
    utilAjaxGJ(url, type, JSON.stringify(data), function (data) {

      cuttingScreen("#vehicleManagement_div3");
      grid.reload();
    }, contentType);
  };
  //证件保存
  document.querySelector("#vehicleManagement_Template_save").onclick = function () {
    //数据data
    var data = ddfrom.getFormData();
    data.branchid = userGJ.p_companyid;
    var data1 = grid.getSelectedRowData();
    var feik = ddfrom.validate();
    if (!feik) {
      return;
    }
    var url;
    var type = "post";
    var contentType = "application/json";
    if (dataType == 2) {
      data.objectCode = data1.companycode;
      data.objectId = data1.companyid;
      data.objectName = data1.locname;
      data.papertypename = ddfrom.getCombo("papertype").getComboText();
      //请求地址和类型
      url = UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/pubLicenseInformation/pubLicenseInformationUpdate/v1.0";
      //message新增为0，修改为1
      if (data.id == null || data.id == "") {
        url = UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/pubLicenseInformation/pubLicenseInformationAdd/v1.0";
      }
    }
    //调用ajax方法
    utilAjaxGJ(url, type, JSON.stringify(data), function (data) {

      cuttingScreen("#vehicleManagement_div1");
      gridA.reload();
    }, contentType);
  };
  var optsA = {
    //terrace显示全部，card分页显示
    skin: "card",
    //renderer:"grid",
    columns: [
      { id: "id", name: "id", type: "ro", width: "100", hidden: true },
      { id: "papertypename", name: "证件类型", type: "ro", width: 150 },
      { id: "paperno", name: "证件编号", type: "ro", width: 150 },
      { id: "notifiedbody", name: "发证机构", type: "ro", width: 100 },
      { id: "paperdatefrom", name: "证件有效期始", type: "ro", width: 100 },
      { id: "paperdateto", name: "证件有效期止", type: "ro", width: 100 },
      { id: "createat", name: "剩余过期天", type: "ro", width: 130 },
      { id: "remark", name: "备注", type: "ro", width: 100 },
      {
        id: "op",
        name: "操作",
        type: "button",
        align: "center",
        fixed: "right",
        width: 200,
        render: function () {
          return "删除^vehicleManagementA_deleteClick,修改^vehicleManagementA_updataClick,复制^vehicleManagementA_copy,详情^vehicleManagementA_details";
        }
      }
    ],
    multiselect: true,
    fixedLast: true, //开启固定列，固定最后一行，倒数第二列不能隐藏
    toolbar: [
      { type: "button", name: "addBtn", offsetLeft: 10, className: "plg-toolbar-right", value: "<i class='layui-icon layui-icon-add-1'></i>新增" }
    ],

    url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/pubLicenseInformation/pubLicenseInformationSearchByPage/v1.0", //数据接口
    type: "post", //数据提交方式，默认为get
    pagebar: {
      buttons: [
        { text: "删除", className: "layui-btn-danger", name: "delete" }
      ]
      // type: 'simple' //full simple
    },
    contentType: "application/json",
    params: "{}", //查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  //分页参数 pageSize pageNum
  gridA = new PlgGrid(optsA);

  //按钮添加方法
  function setMouth() {
    gridA.attachToolBarEvent("onButtonClick", function (name) {
      //新增
      if (name == "addBtn") {
        dataType = 2;
        cuttingScreen("#vehicleManagement_Template");
        $("#vehicleManagement_Template_title").text("新增");
        initFrom();
      }
    });
    //按钮添加方法
    gridA.attachPageBarEvent(function (name) {
      //删除
      if (name == "delete") {
        let data = [];
        let datas = getDeleteAll(gridA);
        datas.forEach(v => {
          data.push({ id: v });
        });
        data = JSON.stringify(data);
        utilDelete(UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/pubLicenseInformation/pubLicenseInformationDelete/v1.0", "post", data, function (data) {
            gridA.reload();
        }, "application/json");
      }
    });
  }
  //删除
  window.vehicleManagementA_deleteClick = function (rid) {
    gridA.selectRowById(rid);
    let data = [];
    let datas = getDeleteAll(gridA);
    datas.forEach(v => {
      data.push({ id: v });
    });
    data = JSON.stringify(data);
    utilDelete(UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/pubLicenseInformation/pubLicenseInformationDelete/v1.0", "post", data, function (data) {

      gridA.reload();
    }, "application/json");
  };
  //修改
  window.vehicleManagementA_updataClick = function (rid, rdata) {
    dataType = 2;
    $("#vehicleManagement_Template_title").text("修改");
    gridA.selectRowById(rid);
    cuttingScreen("#vehicleManagement_Template");
    initFrom();
    ddfrom.setFormData(rdata);
  };
  //复制
  window.vehicleManagementA_copy = function (rid, rdata) {
    dataType = 2;
    $("#vehicleManagement_Template_title").text("新增");
    gridA.selectRowById(rid);
    cuttingScreen("#vehicleManagement_Template");
    initFrom();
    rdata.id = "";
    ddfrom.setFormData(rdata);
  };
  //详情
  window.vehicleManagementA_details = function (rid, rdata) {
    dataType = 1;
    gridA.selectRowById(rid);
    cuttingScreen("#vehicleManagement_div9");
    new PlgPanel({
      renderer: "vehicleManagement_div422",
      skin: 2,
      header: {
        isShow: true,
        title: "基本信息"
      },
      defaultBody: {
        layoutCol: 3,
        valueBj: true,
        cols: [
          [
            {
              label: "证件类型",
              value: rdata.papertypename
            },
            {
              label: "证件编号",
              value: rdata.paperno
            },
            {
              label: "发证机构",
              value: rdata.notifiedbody
            },
            {
              label: "证件有效期始",
              value: rdata.paperdatefrom
            }
          ],
          [{
            label: "证件有效期止",
            value: rdata.paperdateto
          },
          {
            label: "剩余过期天",
            value: rdata.createat
          },
          {
            label: "备注",
            value: rdata.remark
          }
          ]
        ]
      }
    });
  };
  function initFrom() {
    $("#vehicleManagement_Template1A").html("");
    $("#vehicleManagement_Template1B").html("");
    ddfrom = new PlgForm(fromDataA);
    new PlgTabs(configA).on(function (ele) {
      //设置table是哪页
      tables = ele.index;
    });
    gridTemplate1B.renderTo("vehicleManagement_Template1B_divB2");
    var upload = layui.upload;
    //多图片上传
    upload.render({
      elem: "#vehicleManagement_Template1B_divA1",
      url: "https://httpbin.org/post", //改成您自己的上传接口
      multiple: true,
      accept: "images",
      acceptMime: "image/*",
      auto: false,
      bindAction: "#vehicleManagement_Template1B_divA3",
      size: 10 * 1024,
      choose: function (obj) {
        //预读本地文件示例，不支持ie8
        obj.preview(function (index, file, result) {
          $("#vehicleManagement_Template1B_divA2").append("<img src=\"" + result + "\" alt=\"" +
            file.name + "\" class=\"layui-upload-img\"><img src='/img/delete.png' alt=\"" +
            file.name + "\" style='width:40px;height:40px;margin-top:20px;margin-left:0px;" +
            "cursor:pointer' onclick=deleteImg(this)>");
        });
      },
      before: function (obj) {
        //预读本地文件示例，不支持ie8
        obj.preview(function () {
          $("#vehicleManagement_Template1B_divA2").html("");
        });
      },
      done: function () {

        //上传完毕
      }
    });
    var i = 1;
    //多文件上传
    upload.render({
      elem: "#vehicleManagement_Template1B_divB1",
      url: "https://httpbin.org/post", //改成您自己的上传接口
      multiple: true,
      exts: "xls|xlsx",
      auto: false,
      bindAction: "#vehicleManagement_Template1B_divB3",
      size: 10 * 1024,
      choose: function (obj) {
        //预读本地文件示例，不支持ie8
        obj.preview(function (index, file) {
          var id = Math.random();
          var str = "";
          var Mkb = file.size / 1024 > 1024 ? (file.size / 1048578).toFixed(2) + "M" : (file.size / 1024).toFixed(2) + "KB";
          str += id + "," + file.name + "," + Mkb + ",未上传,删除^vehicleManagement_Template1B__delete;";
          gridTemplate1B.getGrid().addRow(id, i + " ," + str, i - 1);
          i++;
          //   $("#vehicleManagement_Template1B_divA2").append("<img src=\"" + result + "\" alt=\"" + file.name + "\" class=\"layui-upload-img\">");
        });
      },
      before: function () {
        //预读本地文件示例，不支持ie8
        // obj.preview(function(index, file, result){
        // //   $("#vehicleManagement_Template1B_divA2").html("");
        // });
      },
      done: function () {

        //上传完毕
      }
    });
  }
  fromDataA = {
    renderer: "vehicleManagement_Template1A",
    items: [
      { type: "settings", position: "label-left", width: 300, labelWidth: 90 },
      { type: "hidden", name: "id", label: "id:", width: 230 },
      { type: "input", name: "paperno", label: "证件编号:", width: 230, editable: false, validate: "NotEmpty", required: true },
      { type: "newcolumn" },
      { type: "input", name: "notifiedbody", label: "发证机构:", width: 230, validate: "NotEmpty", required: true },
      { type: "newcolumn" },
      { type: "input", name: "notifiedbody1", label: "证件对象:", width: 230 },
      { type: "newcolumn" },
      { type: "combo", name: "notifiedbody2", label: "证件对象类型:", width: 230 },
      { type: "newcolumn" },
      { type: "calendar", name: "paperdatefrom", label: "有效期起:", width: 230, validate: "NotEmpty", required: true },
      { type: "newcolumn" },
      { type: "calendar", name: "paperdateto", label: "有效期止:", width: 230, validate: "NotEmpty", required: true },
      { type: "newcolumn" },
      { type: "combo", name: "papertype", label: "证件类型:", width: 230, validate: "NotEmpty", required: true },
      { type: "newcolumn" },
      { type: "input", name: "remark", label: "备注:", width: 560 }
    ]
  };
  var optsTemplate1B = {
    //terrace显示全部，card分页显示
    skin: "card",
    //renderer:"grid",
    columns: [
      { id: "stationid", name: "id", type: "ro", width: "100", hidden: true },
      { id: "stationcode", name: "文件名", type: "ro", width: 150 },
      { id: "stationname", name: "大小", type: "ro", width: 150 },
      { id: "stationname", name: "状态", type: "ro", width: 150 },
      {
        id: "op",
        name: "操作",
        type: "button",
        align: "center",
        fixed: "right",
        width: 50,
        render: function () {
          return "删除^vehicleManagement_Template1B__delete";
        }
      }
    ],
    // multiselect: true,

    url: "/basic/workbench/list", //数据接口
    type: "post", //数据提交方式，默认为get
    contentType: "application/json",
    params: "{}", //查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  //分页参数 pageSize pageNum
  gridTemplate1B = new PlgGrid(optsTemplate1B);

  //删除
  window.vehicleManagement_Template1B__delete = function () {
    gridTemplate1B.getGrid().deleteSelectedRows();
  };
  //删除
  window.deleteImg = function (data) {
    var name = data.alt;
    var div = this.document.getElementById("vehicleManagement_Template1B_divA2");
    var Imgs = div.getElementsByTagName("img");
    for (var i = 0; i < Imgs.length; i++) {
      if (Imgs[i].alt == name) {
        div.removeChild(Imgs[i]);
      }
    }
    div.removeChild(data);
  };
};