<template>
    <div class="billWay_container">
      <div class="title">
        <el-row>
          <el-col :span="24">
            <div class="top">
                <div class="demo-input-suffix">
               <el-input  placeholder="客户名称" class="input-demo" v-model="noCarWayBill.companyName"></el-input>
                <el-input  placeholder="运单编号" class="input-demo" v-model="noCarWayBill.billNum"></el-input>
                <el-input  placeholder="税号" class="input-demo" v-model="noCarWayBill.taxplayerCode"></el-input>
              </div>
              <div class="demo-input-suffix" style="margin-top: 5px;margin-left: 10px;">
                 <el-date-picker v-model="noCarWayBill.endBegin" type="daterange" value-format="yyyy-MM-dd HH:mm:SS" range-separator="至" start-placeholder="指令结束始" end-placeholder="指令结束止"></el-date-picker>
                <!-- <el-date-picker v-model="noCarWayBill.startEnd" type="date" placeholder="开始指令上传时间止"></el-date-picker>
                 <el-date-picker v-model="noCarWayBill.startBegin"  type="date" placeholder="开始指令上传时间始"></el-date-picker> -->
                <!-- <el-date-picker v-model="noCarWayBill.endBegin" type="date" placeholder="结束指令上传时间始"></el-date-picker>
                <el-date-picker v-model="noCarWayBill.endEnd" type="date" placeholder="结束指令上传时间止"></el-date-picker> -->
               <el-button type="success" style="margin-left: 1%;" @click="loadData">查询</el-button>
               <el-button type="success" style="margin-left: 1%;" @click="updateStatus">更新状态</el-button>
               <el-button type="primary" style="margin-left: 1%;" @click="exportExcel">导出报表</el-button>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
      <!-- 表格部分 -->
        <template>
        <el-table
         class="table"
          v-loading="loading"
          ref="multipleTable"
          :data="billWayTable"
          :height="heightt"
          border
          tooltip-effect="dark">
          <el-table-column
            label="企业编号"
            prop="companyNum"
            show-overflow-tooltip>
          </el-table-column>
           <el-table-column
            prop="companyName"
            label="客戶名称"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="billNum"
            label="运单编号"
            show-overflow-tooltip>
          </el-table-column>
           <el-table-column
            prop="taxplayerCode"
            label="税号"
            show-overflow-tooltip>
            
          </el-table-column>
          <el-table-column
            prop="interfaceEndTime"
            label="结束指令时间"
            width="120"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="billwayStatus"
            label="运单状态"
            show-overflow-tooltip>
             <template slot-scope="scope">
              <span v-if="scope.row.billwayStatus == 1" style="color: green">未结束</span>
              <span v-else-if="scope.row.billwayStatus == 2" style="color: green">开票中</span>
              <span v-else-if="scope.row.billwayStatus == 3" style="color: green">开票完成</span>
              <span v-else-if="scope.row.billwayStatus == 4" style="color: red">超时运单</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="updateTime"
            label="最后更新时间"
            width="120"
            show-overflow-tooltip>
          </el-table-column>
           <el-table-column
            prop="updateTime"
            label="超长时间(天)"
            width="120"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="hisFlag"
            label="运单类型"
            show-overflow-tooltip>
             <template slot-scope="scope">
              <span v-if="scope.row.hisFlag == 0" >实时运单</span>
              <span v-else-if="scope.row.hisFlag == 1">历史运单</span>
            </template>
          </el-table-column>
        </el-table>
      </template> 
      <!-- 分页 -->
      <div class="block">
        <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="current"
        :page-sizes="[6, 8, 10, 20, 50, 100]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
        </el-pagination>
      </div>
    </div>
</template>
<script type="text/javascript">
import FileSaver from "file-saver";
import XLSX from "xlsx";
      export default {
        data(){
          return{
            noCarWayBill:{
              
            },
             optionone: [{
              value: 0,
              label: '实时运单'
            }, {
              value: 1,
              label: '历史运单'
            }],
            billWayTable:[],
             hightt:'0px',
            current: 1,
            pagesize: 8,
            total:''
          }
        },
        created() {
          this.heightt = tableHeight;
          this.loadData();
        },
        filters: {
            rounding (value) {
              return value.toFixed(2)
            }
        },
        methods:{
          // 列表展示
          async loadData() {
            const formData = new FormData();
            formData.append('current', this.current);
            formData.append('size', this.pagesize);
            for(var i in this.noCarWayBill){
                formData.append(i,this.noCarWayBill[i]);
            }
            const response = await this.$http.post(`noCar/findBillWayException`, formData);
            if (response.data.code === 0) {
              this.billWayTable = response.data.data.records;
              this.total = response.data.data.total;
            }
          },
           async updateStatus(){
            const response = await this.$http.post(`noCar/updateStatus`);
                  if(response.data.code === 0) {
                    this.loadData();
                    this.$message({
                      type: 'success',
                      message: '更新成功'
                    });
                  }else {
                    this.$message({
                      type: 'error',
                      message: '更新失败'
                    });
                  }
           },
          // 分页方法
          handleSizeChange(val) {
            this.pagesize = val;
            this.loadData();
            console.log(`每页 ${val} 条`);
          },
          handleCurrentChange(val) {
            this.current = val;
              this.loadData();
            // console.log(`当前页: ${val}`);
          },
       async     exportExcel() {
         let curr = this.current;
      let pagesize1 = this.pagesize;
      this.current = 1; 
      this.pagesize = this.total;
      await this.loadData();
      // 设置当前日期
      let time = new Date();
      //console.log(time);
      let year = time.getFullYear();
      let month = time.getMonth() + 1;
      let day = time.getDate();
      let name = "无车异常运单查询列表_"+year + "" + month + "" + day;
      // console.log(name)
      /* generate workbook object from table */
      //  .table要导出的是哪一个表格
      var wb = XLSX.utils.table_to_book(document.querySelector(".table"));
      /* get binary string as output */
      var wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array"
      });
      try {
        //  name+'.xlsx'表示导出的excel表格名字
        FileSaver.saveAs(
          new Blob([wbout], { type: "application/octet-stream" }),
          name + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
       this.current = curr; 
      this.pagesize = pagesize1;
      this.loadData();
      return wbout;
    },
        }
      };
</script>
<style>
.billWay_container {
  border: 1px solid #d9d9d9;
  border-radius: 10px;
}
.billWay_container .title {
  font-size: 5px;
  margin-bottom: 20px;
}
.billWay_container .top {
  padding-top: 20px;
  padding-left: 20px;
}
.billWay_container .text {
  display: inline-block;
  color: #000;
  font-size: 16px ;
  margin-left: 1%;
}
.billWay_container .input-demo {
  display: inline-block;
  width: 20%;
  margin-left: 1%;
}
.billWay_container .block {
  font-size: 5px;
  text-align: center;
  margin-top: 25px;
  margin-bottom: 25px;
}
.billWay_container .el-dialog {
  width: 60%;
}
.billWay_container .el-dialog__header, .el-dialog__body {
  padding: 0 20px;
}
.billWay_container .tou {
  font-size: 20px;
  height: 30px;
  line-height: 30px;
  padding-top: 15px;
}
.billWay_container .line {
  margin-top: 15px;
  margin-bottom: 15px;
  width: 100%;
  height: 2px;
  background-color: #d9d9d9;
}
.billWay_container .xinxi {
  text-align: center;
  margin: 15px auto;
  font-size: 18px;
}
</style>