/**
   * 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 grid;
  var dataSelete = {};
  //获取下拉框
  getSelectGJ([{ "objectcode": "TMS_SHIP_BILLTYPE" }], function (data) {
    data.data.TMS_SHIP_BILLTYPE.unshift({ "text": "", "value": "" });
    dataSelete = data.data;
  });
  //配送中心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
  };
  //预约方table
  var company_Table = {
    columns: [
      { id: "companyid", name: "id", type: "ro", width: "130", hidden: true },
      { id: "companycode", name: "预约方编号", type: "ro" },
      { id: "companyname", name: "预约方名称", type: "ro" }
    ],
    multiselect: false,
    url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE+"/pubCompany/queryPubCompanyPopup", //数据接口
    type: "post", //数据提交方式，默认为get
    contentType: "application/json",
    pagebar: { type: "simple" },
    params: JSON.stringify({ companytype: "5" }), //查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  //分页参数
  var opts = {
    //terrace显示全部，card分页显示
    skin: "card",
    //renderer:"grid",
    columns: [
      { id: "appointBillNo", name: "预约单号", type: "ro", width: "130" },
      { id: "branchname", name: "配送中心", type: "ro", width: "100" },
      { id: "status", name: "单据状态", type: "ro", width: "100", render: function (v, rd) { return rd.statusName ? rd.statusName : v; } },
      { id: "billdate", name: "单据时间", type: "ro", width: "120" },
      { id: "appointVehicle", name: "车辆", type: "ro", width: "70" },
      { id: "appointDriver", name: "司机", type: "ro", width: "80" },
      { id: "appointDriverTel", name: "手机号", type: "ro", width: "100" },
      { id: "shipbillno", name: "运单号", type: "ro", width: "120" },
      { id: "codeNumber", name: "打码号", type: "ro", width: "120" },
      { id: "customerName", name: "承运商/供应商", type: "ro", width: "120" },
      { id: "appointPackage", name: "预约件数", type: "ro", width: "80" },
      { id: "appointWhight", name: "预约重量", type: "ro", width: "80" },
      { id: "appointVolume", name: "预约体积", type: "ro", width: "80" },
      { id: "appointDate", name: "预约提/送货日期", type: "ro", width: "120" },
      { id: "appointTimeName", name: "预约提/送货时间", type: "ro", width: "120" },
      { id: "arriveTime", name: "实际到场时间", type: "ro", width: "120" },
      { id: "callTime", name: "叫号时间", type: "ro", width: "120" },
      { id: "intoTime", name: "入场时间", type: "ro", width: "120" },
      { id: "outTime", name: "离场时间", type: "ro", width: "120" },
      { id: "waitingTime", name: "等待时长", type: "ro", width: "80" },
      { id: "loadTime", name: "装卸时长", type: "ro", width: "80" },
      { id: "temporaryPlace", name: "临时车位", type: "ro", width: "80" },
      { id: "platform", name: "分配站台", type: "ro", width: "80" },
      { id: "callNumber", name: "叫号顺序", type: "ro", width: "80" },
      { id: "startWhight", name: "进场称重", type: "ro", width: "80" },
      { id: "endWhight", name: "离场称重", type: "ro", width: "80" },
      { id: "startLoadingTime", name: "装车开始时间", type: "ro", width: "120" },
      { id: "endLoadingTime", name: "装车完成时间", type: "ro", width: "120" },
      { id: "outPlatformTime", name: "站台释放时间", type: "ro", width: "120" },
      { id: "memo", name: "备注", type: "ro", width: "100" }
    ],
    multiselect: false,
    toolbar: [
      { type: "settings", labelWidth: 70, labelAlign: "right" },
      {
        type: "row",
        list: [
          { type: "input", name: "shipbillno", rows: 6, className: "layui-col-md3", label: "运单号:", placeholder: "多个单号用 \";\" 号隔开，示例：1234567;7654321" },
          { type: "calendar", name: "startdate", className: "layui-col-md3", label: "计划日期始:"},
          { type: "calendar", name: "enddate", 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: "配送中心:" },
          {
            className: "layui-col-md3",
            type: "selectTable",
            placeholder: "请选择预约方",
            readonly: false,
            table: company_Table,
            tableWidth: 500,
            tableHeight: 400,
            fieldText: "companycode",
            fieldValue: "companycode",
            name: "customercode1",
            label: "预约方编号:",
            listener: function (consignorGrid) {
              setMethod(consignorGrid, company_Table, function (data) {
                var fromdata = grid.getToolBarForm().getFormData();
                data = fromdata.customercode1.length == 2 ? "" : data;
                var datad = {};
                datad.customerid = data.companyid;
                grid.getToolBarForm().setFormData(datad);
              });
            }
          },
          { type: "hidden", name: "customerid", label: "预约方:" },
          { type: "input", name: "appointVehicle", className: "layui-col-md3", label: "车牌号:" },
          { type: "input", name: "appointDriver", className: "layui-col-md3", label: "司机:" },
          {
            type: "block", className: "layui-col-md4 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-md5 right",
            list: [
              { type: "button", name: "btn_export", className: "plg-toolbar-right btn-normal", value: "导 出" }
            ]
          }
        ]
      }],
    url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/tmsAppointBill/enforceQuery/v1.0",//数据接口
    type: "post",//数据提交方式，默认为get
    contentType: "application/json",
    params: JSON.stringify({ startdate: FormatDate(new Date()) + " 00:00:00", enddate: FormatDate(new Date()) + " 23:59:59" }),//查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  //分页参数 pageSize pageNum
  grid = new PlgGrid(opts);
  grid.renderTo("reservationExecutionQuery_zhu");
  grid.getToolBarForm().setFormData({ "systemId": "prolog-healthy-wms" });
  grid.loadData({"success": true,"message": "查询成功","code": "200","data": {"list": [],"totalCount": 0,"pageCount": 0,"pageNum": 1,"pageSize": 10,"startRow": 0,"endRow": 10}});
  //按钮添加方法
  grid.attachToolBarEvent("onButtonClick", function (name) {
    //查询
    if (name == "querycarr") {
      var jsonData = grid.getToolBarForm().getFormData();
      if (jsonData.startdate) {
        jsonData.startdate = Prolog.formatDate(jsonData.startdate) + " 00:00:00";
      }
      if (jsonData.enddate) {
        jsonData.enddate = Prolog.formatDate(jsonData.enddate) + " 23:59:59";
      }
      grid.setParams(JSON.stringify(jsonData));
      grid.reload();
    }
    //重置
    if (name == "car_Reset") {
      grid.getToolBarForm().getDForm().setText("buyername1", "");
      grid.getToolBarForm().getDForm().setText("customercode1", "");
      grid.getToolBarForm().clear();
    }
    //导出
    if (name == "btn_export") {
      let pload = PlgDialog.load(2, { shade: [0.6, "#fff"] });
      if (grid.getRowsNum() <= 0) {
        PlgDialog.close(pload);
        PlgDialog.msg("没有要导出的数据");
        return;
      }
      let url = UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/tmsAppointBill/export";
      let name = "预约执行情况" + Prolog.formatDate(new Date(), "%YY%MM%DD") + ".xls";
      let p = grid.getToolBarForm().getFormData();
      p.startdate = p.startdate ? Prolog.formatDate(p.startdate) + " 00:00:00" : "";
      p.enddate = p.enddate ? Prolog.formatDate(p.enddate) + " 23:59:59" : "";
      p.pageNum = 0;
      p.pageSize = 0;
      Prolog.exportFile(url, name, "application/json", "post", p);
      PlgDialog.close(pload);
    }
  });
};