<template>
  <div class="waybill">
    <!-- 头部细节部分 -->
      <div class="title">
        <el-row>
          <el-col :span="24">
            <div class="top">
               <span style="margin-top: 10px;">导入文件：</span>
              <el-upload
                class="upload-demo"
                ref="upload"
                action="http://invoice.back.jkcredit.com/dishonestuser/upload"
                :on-preview="handlePreview"
                :on-remove="handleRemove"
                :on-change="handleSuccess"
                :auto-upload="false">
                <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                <el-button style="margin-left: 10px;" size="small" type="success" @click="batchUpload" v-loading.fullscreen.lock="fullscreenLoading">提交</el-button>
              </el-upload>

            </div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <div class="top">
              <el-input  placeholder="用户名" class="input-demo" style="margin: 0;" v-model="customerName"></el-input>
              <el-input  placeholder="用户所在公司" class="input-demo" v-model="companyName"></el-input>
              <el-input  placeholder="批次号" class="input-demo" v-model="batchNum"></el-input>
              <el-button style="margin-left: 1%;" @click="DownloadTemplate">下载模板</el-button>
              <el-button type="success" style="margin-left: 1%;" @click="loadData">查询</el-button>
              <!-- <el-button type="info" style="margin-left: 1%;">重置</el-button> -->
            </div>
          </el-col>
        </el-row>

      </div>
    <!-- 头部细节部分结束 -->
    <!-- 表格部分 -->
      <template>
        <el-table
          v-loading="loading"
          ref="multipleTable"
          :data="usertable"
          height="370px"
          border
          tooltip-effect="dark">
          <el-table-column
            label="用户名"
            prop="customerName"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            label="用户手机号"
            prop="customerPhone"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="company"
            label="用户所在公司"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="batchNumber"
            label="批次号"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            label="创建时间"
            show-overflow-tooltip>
            <template slot-scope="scope" show-overflow-tooltip>
              <span>{{scope.row.createTime | fmtDate}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            width="80">
            <template slot-scope="scope" show-overflow-tooltip>
              <span style="cursor:pointer;color: blue;" @click="checkLook(scope.row.batchNumber)">查看</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]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
        </el-pagination>
      </div>

    <!-- 查看 -->
      <el-dialog
        @close="handleEditDialogClose"
        :visible.sync="addList"
        style="font-size: 0px;">
        <template>
          <div class="tou">运单列表</div>
          <div class="line"></div>
          <div class="styleType">
            <el-input  placeholder="运单编号" class="theinput" v-model="billNum"></el-input>
            <el-input  placeholder="车牌号" class="theinput" v-model="plateNum"></el-input>
            <el-input  placeholder="税号" class="theinput" v-model="taxPlayerCode"></el-input>
            <el-button type="success" style="margin-left: 1%;" @click="loadDataCar">查询</el-button>
            <!-- <el-button type="info" style="margin-left: 1%;">重置</el-button> -->
          </div>
          <el-table
            v-loading="loading"
            ref="multipleTable"
            :data="usertabletwo"
            border
            tooltip-effect="dark">
          <el-table-column
            label="运单编号"
            prop="billNum"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="taxPlayerCode"
            label="税号"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            label="车牌号码"
            prop="plateNumber"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="startTime"
            label="运单开始时间"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="sourceAddr"
            label="运单开始地址"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="destAddr"
            label="运单目的地址"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="predictEndTime"
            label="运单预计完成时间"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="fee"
            label="运单费用(元)"
            show-overflow-tooltip>
            <template slot-scope="scope" show-overflow-tooltip>
                <span>{{scope.row.fee / 100}}</span>
            </template>
          </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>
        </template>

        <div class="blocks">
          <el-pagination
          @size-change="handleSize"
          @current-change="handleCurrent"
          :current-page="currenttwo"
          :page-sizes="[6, 8, 10]"
          :page-size="pagesizetwo"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totaltwo">
          </el-pagination>
        </div>
      </el-dialog>

  </div>
</template>

<script>
export default{
  data() {
    return {
      loading: false,
      fullscreenLoading: false,
      customerName: '',
      companyName: '',
      billNum: '',
      plateNumber: '',
      taxPlayerCode: '',
      status: '',
      addList: false,
      current: 1,
      pagesize: 8,
      total: 0,
      currenttwo: 1,
      pagesizetwo: 8,
      totaltwo: 0,
      batchNum: '',
      batchNumberQ:'',
      usertable: [],
      usertabletwo: [],
      formUserList: {
       "customerName": "",
       "file": "",
       "roleId": ""
      },
      optionone: [{
        value: '1',
        label: '成功'
      }, {
        value: '2',
        label: '失败'
      }],
      isSuccess: '',
    }
  },
  created() {
    this.formUserList.customerName = sessionStorage.getItem('userName');
    this.loadData();
  },
  methods: {
    // 列表展示
    async loadData() {
    
       const formData = new FormData();
        formData.append('current', this.current);
        formData.append('size', this.pagesize);
        formData.append('customerName',this.formUserList.customerName);
         formData.append('company', this.companyName);
        formData.append('batchNumer', this.batchNum);
        formData.append('operType', 1);
        const response = await this.$http.post(`noCar/findBatchList`, formData);
        if (response.data.code === 0) {
          this.loading = false;
          this.usertable = response.data.data.records;
          this.total = response.data.data.total;
        }
    },
    // 下载模板
    DownloadTemplate() {
      var url = hostUrl+"noCar/templateDownload?fileName=1"
      window.location.href= url;

    },
    // 批量上传模板信息
    async batchUpload() {
      this.fullscreenLoading = true;
      const formData = new FormData();
      formData.append('customerName', this.formUserList.customerName);
      formData.append('file', this.formUserList.file);
      const response = await this.$http.post(`noCar/batchImprotBillWay`,formData);
      var {data: { code, msg, data }} = response;
      if(code === 0 && msg === 'success') {
        this.loadData();
        this.fullscreenLoading = false;
        this.$message.success('上传成功');
      }else if(code === 1 && msg == null && data == null) {
        this.fullscreenLoading = false;
        this.$message.error('数据存在错误，请检查文件中数据');
      }else {
        this.fullscreenLoading = false;
        this.$message.error(msg);
      }
    },
    // 查看批次数据
    async checkLook(id) {
      this.addList = true;
      this.batchNumberQ = id;
      this.loadDataCar();
    },
    handleEditDialogClose(){
       this.addList = false;
    },
    // 查看实时数据
    async loadDataCar() {
    
        const formData = new FormData();
        formData.append('current', this.currenttwo);
        formData.append('size', this.pagesizetwo);
        formData.append('customerName', this.formUserList.customerName);
        formData.append('batchNum', this.batchNumberQ);
         formData.append('plateNumber', this.plateNumber);
        formData.append('taxPlayerCode', this.taxPlayerCode);
        formData.append('hisFlag', 0);
        const response = await this.$http.post(`noCar/findBillWay`, formData);
        if (response.data.code === 0) {
          this.loading = false;
          this.usertabletwo = response.data.data.records;
          this.totaltwo = response.data.data.total;
        }
    },
  
     handleRemove(file, fileList) {
      console.log(file, fileList);
    },

    handlePreview(file) {
      console.log(file);
    },
    handleSuccess (a) {
      this.formUserList.file = a.raw;
    },
    // 分页方法
    handleSizeChange(val) {
      this.pagesize = val;
       this.loadData();
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.current = val;
      this.loadData();
      console.log(`当前页: ${val}`);
    },
    handleSize(val) {
      this.pagesizetwo = val;
      this.loadDataCar();
      console.log(`每页 ${val} 条`);
    },
    handleCurrent(val) {
      this.currenttwo = val;
     this.loadDataCar();
      console.log(`当前页: ${val}`);
    }
  }
};
</script>

<style>
.waybill {
  border: 1px solid #d9d9d9;
  border-radius: 10px;
}
.waybill .upload-demo {
  display: inline-block;
}
.waybill .title {
  font-size: 5px;
  margin-bottom: 20px;
}
.waybill .top {
  padding-top: 20px;
  padding-left: 20px;
}
.waybill .text {
  display: inline-block;
  color: #000;
  font-size: 16px ;
  margin-left: 1%;
}
.waybill .tou {
  font-size: 20px;
  height: 30px;
  line-height: 30px;
  padding-top: 15px;
}
.waybill .line {
  margin-top: 15px;
  margin-bottom: 15px;
  width: 100%;
  height: 2px;
  background-color: #d9d9d9;
}
.waybill .theinput {
  display: inline-block;
  width: 20%;
}
.waybill .styleType {
  margin-top: 20px;
  margin-bottom: 20px;
}
.waybill .input-demo {
  display: inline-block;
  width: 20%;
  margin-left: 1%;
}
.waybill .block {
  font-size: 5px;
  text-align: center;
  margin-top: 15px;
  margin-bottom: 20px;
}
.waybill .blocks {
  font-size: 5px;
  text-align: center;
  margin-top: 20px;
  padding-bottom: 20px;
}
.waybill .el-dialog {
  width: 90%;
}
.waybill .el-dialog__header, .el-dialog__body {
  padding: 0 20px;
}
</style>
