/**
   * guoj
   * 2020.06.24
   * 进场登记
      */
    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 dataselect = [];
  //获取下拉框
  getSelectGJ([{ "objectcode": "TMS_APPOINT_TYPE" }], function (data) {
    dataselect = data.data;
    dataselect.TMS_APPOINT_TYPE.unshift({ "text": "", "value": "" });
  });
  var grid;
  //配送中心table
  var userTable = {
      columns: [
          { id: "companyid", name: "id", type: "ro", width: "130", hidden: true },
          { id: "companycode", name: "配送中心编号", type: "ro" },
          { id: "companyname", name: "配送中心名称", type: "ro" }
      ],
      multiselect: false,
      contentType: "application/json",

      url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/pubCompany/queryCompanyBranch", //数据接口
      type: "post", //数据提交方式，默认为get
      pagebar: { type: "simple" },
      params: JSON.stringify({"companytype": "S"}), //查询提交参数，分页参数默认为pageNum,pageSize
      page: true, //是否启用分页
      totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  //分页参数
  var opts = {
    //terrace显示全部，card分页显示
    skin: "card",
    //renderer:"grid",
    columns: [
      { id: "appointBillNo", name: "id", type: "ro", hidden: true },
      { id: "branchname", name: "配送中心", type: "ro" },
      { id: "getNumberTime", name: "取号时间", type: "ro" },
      { id: "callNumber", name: "取号", type: "ro" },
      { id: "appointVehicle", name: "车辆", type: "ro" },
      { id: "appointDriver", name: "司机", type: "ro"},
      { id: "appointType", name: "配送类型", type: "ro" ,render: (v)=>{
        return getSelectValue(dataselect.TMS_APPOINT_TYPE,v);
      }},
      { id: "customerName", name: "承运商", type: "ro" },
      { id: "customerName", name: "供应商", type: "ro" },
      { id: "appointPackage", name: "总件数", type: "ro" },
      { id: "appointWhight", name: "总重量", type: "ro" },
      { id: "appointVolume", name: "总体积", type: "ro" },
      { id: "memo", name: "备注", type: "ro" }
    ],
    multiselect: false,
    toolbar: [
      { type: "settings", labelWidth: 90, labelAlign: "right" },
      {
        type: "row",
        list: [
          { type: "calendar", name: "sdate", className: "layui-col-md3",label: "开始时间:" },
          { type: "calendar", name: "edate",className: "layui-col-md3", label: "结束时间:" },
          {
            className: "layui-col-md3",
              type: "selectTable",
              placeholder: "请选择配送中心",
              readonly: false,
              table: userTable,
              tableWidth: 500,
              tableHeight: 400,
              fieldText: "companyname",
              fieldValue: "companycode",
              name: "buyername1",
              label: "配送中心:",
              listener: function (consignorGrid) {
                  setMethod(consignorGrid, userTable, function (data) {
                      var datad = {};
                      datad.branchid = data.companyid;
                      grid.getToolBarForm().setFormData(datad);
                  });
              }
          },
          { type: "hidden", name: "branchid", label: "配送中心:" },
          { type: "input", name: "appointVehicle", className: "layui-col-md3", label: "车牌号:" },
          { type: "input", name: "appointDriver", label: "司机:", className: "layui-col-md3" },
          { type: "combo", name: "appointType",className: "layui-col-md3", label: "配送类型:" ,options: dataselect.TMS_APPOINT_TYPE},
          {
            type: "block", className: "layui-col-md3 form_btn_left",
            list: [
              { type: "button",className: "btn-normal", name: "querycarr", value: "查 询" },
              { type: "newcolumn" },
              { type: "button", name: "car_Reset", className: "normal", value: "重 置" }
            ]
          },
          {
            type: "block", className: "layui-col-md3 right",
            list: [
              { type: "button", className: "btn-addBtn btn-normal", name: "entryRegistration_print", value: "进场登记" }
            ]
          }
        ]
      }],

    url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bookingManage/intoRegisterQuery",//数据接口
    type: "post",//数据提交方式，默认为get
    contentType: "application/json",
    params: JSON.stringify({ sdate: ship_FormatDate(new Date()) + " 00:00:00", edate: FormatDate(new Date()) + " 23:59:59" }),//查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  //分页参数 pageSize pageNum
   grid = new PlgGrid(opts);
  grid.renderTo("entryRegistration_zhu");
  grid.getToolBarForm().setFormData({ "systemId": "prolog-healthy-wms" });
  grid.getToolBarForm().setFormData({ sdate: ship_FormatDate(new Date()),edate: FormatDate(new Date())});
  grid.loadData();
  //按钮添加方法
  grid.attachToolBarEvent("onButtonClick", function (name) {
    //查询
    if (name == "querycarr") {
      var jsonData = grid.getToolBarForm().getFormData();
      if (jsonData.sdate == null) {
        jsonData.sdate = ship_FormatDate(new Date()) + " 00:00:00";
      }
      else {
        jsonData.sdate = Prolog.formatDate(jsonData.sdate) + " 00:00:00";
      }
      if (jsonData.edate == null) {
        jsonData.edate = FormatDate(new Date()) + " 23:59:59";
      }
      else {
        jsonData.edate = Prolog.formatDate(jsonData.edate) + " 23:59:59";
      }
      grid.setParams(JSON.stringify(jsonData));
      grid.reload();
    }
    //重置
    if (name == "car_Reset") {
      grid.getToolBarForm().getDForm().setText("buyername1", "");
      grid.getToolBarForm().clear();
      grid.getToolBarForm().setFormData({ sdate: ship_FormatDate(new Date()),edate: FormatDate(new Date())});
    }
    //进场登记
    if (name == "entryRegistration_print") {
      let idh = grid.getSelectedRowId();
      if(idh == "" || idh == null){
        layer.msg("请选择一行");
        return;
      }
      let datad = grid.getRowData(idh );
      utilAjaxGJ(UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/bookingManage/intoRegister", "post",JSON.stringify(datad), ()=>{
        layer.msg("成功");
        grid.reload();
      }, "application/json");
    }
  });
};