<template>
  <div class="purchasFuelNewMonitor">
    <div class="frameCalculation">
      <span>净重时间：</span>
      <el-date-picker
        v-model="startTime"
        type="datetime"
        placeholder="选择日期"
      >
      </el-date-picker>
      <span>至</span>
      <el-date-picker
        v-model="endTime"
        type="datetime"
        placeholder="选择日期"
      >
      </el-date-picker>
      <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="totalNumberFrist" :disabled="true" style="width: 140px;"></el-input>
      <span style="margin-left: 1rem;">合计车数：</span>
      <el-input v-model="totalCapacity" :disabled="true" style="width: 100px;"></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 {
      totalNumberSecond:null,
      totalNumberFrist:null,
      totalCapacity:null,
      option: {
        requestUrl: "",
      },
      startTime: null,
      endTime: null,
      tableTitle:'零星出厂统计报表'
    };
  }, 
  created(){
          this.option.requestUrl = '/api/v1/tms/getPurInwardReport?apiId=441&startTime=null&endTime=null&i=' +new Date()
  },
  methods: {
    func(res){
        console.log(res)
        var resultNetWeightTotalFirst = 0
        var resultNetWeightTotalSecond = 0
        var currentCapacityTotal = 0
        res.list.forEach(e => {
          currentCapacityTotal++
          resultNetWeightTotalFirst = resultNetWeightTotalFirst+e.netWeightFirst
          resultNetWeightTotalSecond = resultNetWeightTotalSecond + e.netWeightSecond
        });
        this.totalNumberFrist = resultNetWeightTotalFirst.toFixed(2) + "t" + "/" + resultNetWeightTotalSecond.toFixed(2) + "t"
        this.totalCapacity = currentCapacityTotal;
    },
    getRequestUrl(){
        this.option.requestUrl = '/api/v1/tms/getPurInwardReport?apiId=441&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(startTime && endTime){
        if(startTime < endTime){
          this.option.requestUrl = '/api/v1/tms/getPurInwardReport?apiId=441' + "&startTime=" + startTime + "&endTime=" + endTime + "&i=" +new Date(); 
        }else{
          this.startTime = null;
          this.endTime = null;
          this.$message.warning('开始时间要比结束时间早')
        }
      }else{
        console.log(startTime && endTime)
        this.getRequestUrl()
      }
    },
  },
};
</script>

<style lang="scss">
.purchasFuelNewMonitor {
  .frameCalculation {
    width: 100%;
    height: 100px;
    display: flex;
    align-items: center;
    padding-left: 50px;
    .el-date-editor{
      margin: 20px;
    }
  }
}
</style>