/*
* zzx
* 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';

let platformKanbanInquiry_timerCount = $("#platformKanbanInquiry");
export default () => {
  let userinfo = JSON.parse(window.localStorage.getItem("userinfo"));
  $("#platformKanbanInquiry_title_name").html(userinfo.p_companyname + " 进场管理看板");
  statistics();
  clearInterval(platformKanbanInquiry_timerCount.__proto__.timer);
  platformKanbanInquiry_timerCount.__proto__.timer = setInterval(() => {
    startTime();
  }, 1000);

  //返回 2009-06-12 17:18:05 格式
  function FormatDateTime(datetime) {
    if (datetime == null) {
      return "";
    }
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1; //js从0开始取
    var date = datetime.getDate();
    var hour = datetime.getHours();
    var minutes = datetime.getMinutes();
    var second = datetime.getSeconds();
    if (month < 10) {
      month = "0" + month;
    }
    if (date < 10) {
      date = "0" + date;
    }
    if (hour < 10) {
      hour = "0" + hour;
    }
    if (minutes < 10) {
      minutes = "0" + minutes;
    }
    if (second < 10) {
      second = "0" + second;
    }
    var time = year + "-" + month + "-" + date + " " + hour + ":" + minutes + ":" + second; //2009-06-12 17:18:05
    return time;
  }

  function startTime() {
    let time = FormatDateTime(new Date());
    $("#platformKanbanInquiry_title_time").html(time);
  }

  // 查询
  function statistics() {
    let token = Prolog.reloadToken();
    $.ajax({
      url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE+"/platformKanban/statistics/v1.0",
      type: "post",
      contentType: "application/json",
      data: "{}",
      beforeSend: function (xhr) {
        xhr.setRequestHeader("Authorization", token);
      },
      success: function (res) {
        setTimeout(() => {
          startTime();
        }, 60000);
        if (res.success) {
          // 处理数据
          $("#platformKanbanInquiry_vehicleAppointData").html(res.data.vehicleAppointData);
          $("#platformKanbanInquiry_vehicleArriveData").html(res.data.vehicleAppointNum);
          $("#platformKanbanInquiry_vehicleGetNumberData").html(res.data.vehicleGetNumberData);
          $("#platformKanbanInquiry_vehicleLoadingData").html(res.data.vehicleLoadingData);
          $("#platformKanbanInquiry_vehicleOutData").html(res.data.vehicleOutData);
          // $("#platformKanbanInquiry_platformData").html(res.data.platformData);
          $("#platformKanbanInquiry_platformUsedData").html(res.data.platformUsedData);
          let html = "";
          res.data.itemlist.forEach(item => {
            let statusClassName = item.status === "请进场" ? "row_success" : item.status === "进场超时" ? "row_danger" : "row_info";

            html += "    <tr>";
            html += "       <td class='main_table_row'>" + item.arriveTime + "</td>";
            html += "       <td class='main_table_row'>" + item.waitingTime + "</td>";
            html += "       <td class='main_table_row'>" + item.customerName + "</td>";
            html += "       <td class='main_table_row'>" + item.shipbillnos + "</td>";
            // html += "       <td class='main_table_row'>123456,123456,123456,123456,123456,123456</td>";
            html += "       <td class='main_table_row'>" + item.appointVehicle + "</td>";
            html += "       <td class='main_table_row status_class " + statusClassName + "'>" + item.status + "</td>";
            html += "       <td class='main_table_row'>" + item.platform + "</td>";
            html += "       <td class='main_table_row'>" + item.percentage + "</td>";
            html += "       <td class='main_table_row'>" + item.weighData + "</td>";
            html += "    </tr>";
          });
          $("#main_table_content").html(html);
          return true;
        }
        layer.msg(res.message || "接口调用失败");
        return false;

      }, error: function () {
        return false;
      }
    });
  }

  // var dataList = [];
  // for (let index = 50; index > -1; index--) {
  //   let data = dataObj = {
  //     arrivalTime: "2020-05-28 17:47",
  //     waitedTime: "20min",
  //     carrier: "中集物流",
  //     shipno: "100001",
  //     numberPlate: "浙B974110",
  //     status: "请进场",
  //     platform: "1",
  //     percentage: "80%",
  //     weight: "正常"
  //   };
  //   dataList.push(data);
  // }
  // dataList[2].status = "进场超时";
  // dataList[3].status = "等待中";
  // var html = "";
  // dataList.forEach(item => {
  //   let statusClassName = item.status === "请进场" ? "row_success" : item.status === "进场超时" ? "row_danger" : "row_info";
  //   html += "    <tr>";
  //   html += "       <td class='main_table_row'>" + item.arrivalTime + "</td>";
  //   html += "       <td class='main_table_row'>" + item.waitedTime + "</td>";
  //   html += "       <td class='main_table_row'>" + item.carrier + "</td>";
  //   html += "       <td class='main_table_row'>" + item.shipno + "</td>";
  //   html += "       <td class='main_table_row'>" + item.numberPlate + "</td>";
  //   html += "       <td class='main_table_row status_class " + statusClassName + "'>" + item.status + "</td>";
  //   html += "       <td class='main_table_row'>" + item.platform + "</td>";
  //   html += "       <td class='main_table_row'>" + item.percentage + "</td>";
  //   html += "       <td class='main_table_row'>" + item.weight + "</td>";
  //   html += "    </tr>";
  // });
  // $("#main_table_content").html(html);
};