/**
   * guoj
   * 2020.07.27
   * 运输记录查询
   */
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 dataSelete = {};
  //获取下拉框
  getSelectGJ([{ "objectcode": "TMS_URGENTIDENTIFY" },{ "objectcode": "TMS_SHIP_BILLTYPE" },
  { "objectcode": "APPOINT_DETAIL_STATUS" }], function (data) {
    dataSelete = data.data;
  });
  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: "shipbillno", name: "id", type: "ro", width: "80", hidden: true },
      { id: "branchname", name: "配送中心", type: "ro", width: "100" },
      { id: "status", name: "单据状态", type: "ro", width: "100",render: (v)=>{
        return getSelectValue(dataSelete.APPOINT_DETAIL_STATUS,v);
      }},
      { id: "shipbillno", name: "运单号", type: "ro", width: "80" },
      { id: "billtype", name: "运单类型", type: "ro", width: "80",render: (v)=>{
        return getSelectValue(dataSelete.TMS_SHIP_BILLTYPE,v);
      } },
      { id: "blldate", name: "单据日期", type: "ro", width: "100" },
      { id: "urgentIdentify", name: "是否急单", type: "ro", width: "80",render: (v)=>{
        return getSelectValue(dataSelete.TMS_URGENTIDENTIFY,v);
      } },
      { id: "refbillno", name: "业务单号", type: "ro", width: "70" },
      { id: "refbilltype", name: "业务类型", type: "ro", width: "80" ,render: (v)=>{
        return getSelectValue(dataSelete.TMS_SHIP_BILLTYPE,v);
      }},
      { id: "arriverName", name: "客户名称", type: "ro", width: "80" },
      { id: "arriveAddress", name: "客户地址", type: "ro",width: "80" },
      { id: "rsumcases", name: "件数", type: "ro", width: "80" },
      { id: "rsumgoodsweight", name: "重量", type: "ro", width: "80" },
      { id: "rsumgoodsvol", name: "体积", type: "ro", width: "80" },
      { id: "appointDate", name: "承运商", type: "ro", width: "120" },
      { id: "driver1stname", name: "司机", type: "ro", width: "120" },
      { id: "voucherno", name: "车辆", type: "ro", width: "110" },
      { id: "appointTime", name: "预约时间", type: "ro", width: "80" },
      { id: "startLoadingTime", name: "装车时间", type: "ro", width: "80" },
      { id: "rshipmentdate", name: "发货时间", type: "ro", width: "80" },
      { id: "transferTime", name: "中转时间", type: "ro", width: "80" },
      { id: "signdate", name: "签收时间", type: "ro", width: "80" },
      { id: "signqty", name: "签收件数", type: "ro", width: "80" },
      { id: "receiptdate", name: "确认时间", type: "ro", width: "80" },
      { id: "receiptqty", name: "确认件数", type: "ro", width: "80" },
      { id: "memo", name: "备注", type: "ro", width: "80" }
    ],
    multiselect: false,
    toolbar: [
      { type: "settings", labelWidth: 90, labelAlign: "right" },
      {
        type: "row",
        list: [
          { type: "calendar", name: "startTime", className: "layui-col-md3",label: "开始时间:" },
          { type: "calendar", name: "endTime",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: "shipbillno", className: "layui-col-md3",label: "运单号:" },
          { type: "input", name: "refbillno", className: "layui-col-md3",label: "业务单号:" },
          { type: "input", name: "carrierno",className: "layui-col-md3", label: "承运商:" },
          { type: "input", name: "voucherno", className: "layui-col-md3",label: "车辆:" },
          { type: "input", name: "driver1stname",className: "layui-col-md3", label: "司机:" },
          {
            type: "block", className: "layui-col-md6 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-md6 right",
            list: [
              { type: "button", name: "car_export", className: "btn-normal", value: "导 出" }
            ]
          }
        ]
      }],
    url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/shippingRecordsQuery/shippingRecordsQuery",//数据接口
    type: "post",//数据提交方式，默认为get
    contentType: "application/json",
    params: JSON.stringify({startTime: FormatDate(new Date()) + " 00:00:00" ,endTime: FormatDate(new Date()) + " 23:59:59" }),//查询提交参数，分页参数默认为pageNum,pageSize
    page: true, //是否启用分页
    totalCount: "totalCount" //总记录数字段，默认totalCount
  };
  //分页参数 pageSize pageNum
   grid = new PlgGrid(opts);
  grid.renderTo("transportationRecords_zhu");
  grid.getToolBarForm().setFormData({ "systemId": "prolog-healthy-wms" });
  grid.loadData();
  //按钮添加方法
  grid.attachToolBarEvent("onButtonClick", function (name) {
    //查询
    if (name == "querycarr") {
      var jsonData = grid.getToolBarForm().getFormData();
      if (jsonData.startTime == null) {
        jsonData.startTime = FormatDate(new Date()) + " 00:00:00";
      }
      else {
        jsonData.startTime = Prolog.formatDate(jsonData.startTime) + " 00:00:00";
      }
      if (jsonData.endTime == null) {
        jsonData.endTime = FormatDate(new Date()) + " 23:59:59";
      }
      else {
        jsonData.endTime = Prolog.formatDate(jsonData.endTime) + " 23:59:59";
      }
      grid.setParams(JSON.stringify(jsonData));
      grid.reload();
    }
    //重置
    if (name == "car_Reset") {
      grid.getToolBarForm().getDForm().setText("buyername1", "");
      grid.getToolBarForm().clear();
    }
    //导出
    if(name == "car_export"){
      unfilledWorktime_export();
    }
  });
  //主界面导出事件
  function unfilledWorktime_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+"/shippingRecordsQuery/shippingRecordsExport";
    let name = "运输记录查询" + Prolog.formatDate(new Date(), "%YY%MM%DD") + ".xls";
    var jsonData = grid.getToolBarForm().getFormData();
    if (jsonData.startTime == null) {
      jsonData.startTime = FormatDate(new Date()) + " 00:00:00";
    }
    else {
      jsonData.startTime = Prolog.formatDate(jsonData.startTime) + " 00:00:00";
    }
    if (jsonData.endTime == null) {
      jsonData.endTime = FormatDate(new Date()) + " 23:59:59";
    }
    else {
      jsonData.endTime = Prolog.formatDate(jsonData.endTime) + " 23:59:59";
    }
    Prolog.exportFile(url, name, "application/json", "post", jsonData);
    PlgDialog.close(pload);

}
};