<template>
  <div class="purchasFuelNewMonitor">
    <div class="frameCalculation">
      <span>计毛时间：</span>
      <el-date-picker
        v-model="startTime"
        type="datetime"
        placeholder="选择日期"
        style="width:200px"
      >
      </el-date-picker>
      <span>至</span>
      <el-date-picker
        v-model="endTime"
        type="datetime"
        placeholder="选择日期"
        style="width:200px"
      >
      </el-date-picker>
      <el-input
        v-model="input"
        placeholder="请输入收货单位或物资或车牌号"
        style="width:200px"
        clearable
      ></el-input>
      <el-button type="primary" class="btn" @click="onclick">
        <i class="el-icon-search"></i>
      </el-button>
      <el-button type="primary" @click="exportData()"
        ><i class="el-icon-download"></i>Excel</el-button
      >
      <span style="margin-left: 1rem;">合计净重：</span>
      <el-input
        v-model="totalNumber"
        :disabled="true"
        style="width: 100px;"
      ></el-input>
      <span style="margin-left: 1rem;">合计车数：</span>
      <el-input
        v-model="totalCapacity"
        :disabled="true"
        style="width: 50px;"
      ></el-input>
    </div>
    <div class="table">
      <dilTable ref="excelDom" v-bind.sync="option" @func="func"></dilTable>
    </div>
  </div>
</template>

<script>
import { sjTime } from "@/utils/sharedJsFile";
import { getCookie } from "@/utils/util.js";
export default {
  data() {
    return {
      input: null,
      totalNumber: null,
      totalCapacity: null,
      option: {
        requestUrl: ""
      },
      startTime: null,
      endTime: null,
      tableTitle: "零星出厂统计报表"
    };
  },
  created() {
    if (
      getCookie("orgCode") == "dagangadmin" ||
      getCookie("orgCode") == "zidonghuabu"
    ) {
      this.option.requestUrl =
        "/api/v1/tms/getSporadicSuppliesReport2?apiId=425&startTime=null&endTime=null&i=" +
        new Date();
    } else if (getCookie("orgCode") == "wuliuchuyunzhongxin") {
      this.option.requestUrl =
        "/api/v1/tms/getSporadicSuppliesReport2?apiId=425&orderType=13&startTime=null&endTime=null&i=" +
        new Date();
    } else {
      this.option.requestUrl =
        "/api/v1/tms/getSporadicSuppliesReport2?apiId=425&userId=" +
        getCookie("orgCode") +
        "&startTime=null&endTime=null&i=" +
        new Date();
    }
  },
  methods: {
    func(res) {
      console.log(res);
      var resultNetWeightTotal = 0;
      var currentCapacityTotal = 0;
      res.list.forEach(e => {
        currentCapacityTotal++;
        resultNetWeightTotal = resultNetWeightTotal + e.resultNetWeight;
      });
      this.totalNumber = resultNetWeightTotal.toFixed(2) + "t";
      this.totalCapacity = currentCapacityTotal;
    },
    getRequestUrl() {
      if (
        getCookie("orgCode") == "dagangadmin" ||
        getCookie("orgCode") == "zidonghuabu"
      ) {
        this.option.requestUrl =
          "/api/v1/tms/getSporadicSuppliesReport2?apiId=425&startTime=null&endTime=null&i=" +
          new Date();
      } else if (getCookie("orgCode") == "wuliuchuyunzhongxin") {
        this.option.requestUrl =
          "/api/v1/tms/getSporadicSuppliesReport2?apiId=425&orderType=13&startTime=null&endTime=null&i=" +
          new Date();
      } else {
        this.option.requestUrl =
          "/api/v1/tms/getSporadicSuppliesReport2?apiId=425&userId=" +
          getCookie("orgCode") +
          "&startTime=null&endTime=null&i=" +
          new Date();
      }
    },
    onclick() {
      let startTime = null;
      let endTime = null;
      if (this.startTime) {
        startTime = sjTime(this.startTime);
      }
      if (this.endTime) {
        endTime = sjTime(this.endTime);
      }
      if (!this.input && (!startTime || !endTime)) {
        this.$message.warning("请输入查询条件");
        return;
      }
      if (
        getCookie("orgCode") == "dagangadmin" ||
        getCookie("orgCode") == "zidonghuabu"
      ) {
        this.option.requestUrl =
          "/api/v1/tms/getSporadicSuppliesReport2?apiId=425&startTime=" +
          startTime +
          "&endTime=" +
          endTime +
          "&con=" +
          this.input +
          "&i=" +
          new Date();
      } else if (getCookie("orgCode") == "wuliuchuyunzhongxin") {
        this.option.requestUrl =
          "/api/v1/tms/getSporadicSuppliesReport2?apiId=425&orderType=13&startTime=" +
          startTime +
          "&endTime=" +
          endTime +
          "&con=" +
          this.input +
          "&i=" +
          new Date();
      } else {
        this.option.requestUrl =
          "/api/v1/tms/getSporadicSuppliesReport2?apiId=425&userId=" +
          getCookie("orgCode") +
          "&startTime=" +
          startTime +
          "&endTime=" +
          endTime +
          "&con=" +
          this.input +
          "&i=" +
          new Date();
      }
    }
  }
};
</script>

<style lang="scss">
.purchasFuelNewMonitor {
  .frameCalculation {
    margin-left: 20px;
    margin-top: 20px;
  }
  .table {
    margin-left: 20px;
    margin-top: 20px;
  }
}
</style>
