<template>
  <div class="over">
    <!-- 头部细节部分 -->
      <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" v-model="companyName"></el-input>
              <el-input  placeholder="批次号" class="input-demo" v-model="batchNumer"></el-input>
              <el-button style="margin-left: 1%;" @click="DownloadTemplate">下载模板</el-button>
              <el-button type="success" style="margin-left: 1%;" @click="firstLoadData">查询</el-button>
              <!-- <el-button type="info" style="margin-left: 1%;">重置</el-button> -->
            </div>
          </el-col>
        </el-row>

      </div>
    <!-- 头部细节部分结束 -->
    <!-- 表格部分 -->
      <template>
        <el-table
         class="table"
          v-loading="loading"
          ref="multipleTable"
          :data="usertable"
         :height="heightt"
          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="状态"
            show-overflow-tooltip>
            <template slot-scope="scope">

               <span v-if="scope.row.batchStatus == 1" style="color: red">上传中</span>
                <span v-else-if="scope.row.batchStatus == 0" style="color: green">上传成功</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-button type="success" style="margin-left: 1%;" @click="twoLoadData">查询</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="destAddr"
            label="目的地址"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="predictEndTime"
            label="结束时间"
            show-overflow-tooltip>
          </el-table-column>
           <el-table-column
            label="是否成功"
            show-overflow-tooltip>
            <template slot-scope="scope">

               <span v-if="scope.row.billwayStatus == -2 || scope.row.billwayStatus == -3" style="color: red">失败</span>
                <span v-else-if="scope.row.billwayStatus != -2 && scope.row.billwayStatus != -3" style="color: green">成功</span>

              </template>
          </el-table-column>
           <el-table-column
            prop="failReason"
            label="失败原因"
            show-overflow-tooltip>
          </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: ``,
      batchNumer: ``,
      batchNumberQ: ``,
      billNum: ``,
      num: ``,
      hightt: `0px`,
      addList: false,
      current: 1,
      pagesize: 8,
      total: 0,
      currenttwo: 1,
      pagesizetwo: 8,
      totaltwo: 0,
      batchId: ``,
      usertable: [],
      usertabletwo: [],
      formUserList: {
        'customerName': ``,
        'file': ``,
        'roleId': ``
      }
    }
  },
  created() {
    this.heightt = tableHeight // eslint-disable-line
    this.formUserList.customerName = sessionStorage.getItem(`userName`)
    this.loadData()
  },
  methods: {
    firstLoadData() {
      this.current = 1
      this.pagesize = 8
      this.loadData()
    },
    // 列表展示
    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(`batchNumber`, this.batchNumer)
      formData.append(`operType`, 2)
      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=2`// eslint-disable-line
      window.location.href = url
    },
    // 批量上传模板信息
    async batchUpload() {
      const isLt50M = this.formUserList.file.size / 1024 / 1024 < 50
      let extName = this.formUserList.file.name.substring(this.formUserList.file.name.lastIndexOf(`.`)).toLowerCase()
      let AllUpExt = `.xlsx`
      if (extName != AllUpExt) {
        this.$message.error(`格式错误！请重新选择`)
        return false
      }

      if (!isLt50M) {
        this.$message.error(`上传文件大小不能超过50MB!`)
        return false
      }
      const loading = this.$loading({
        lock: true,
        text: `系统正在努力接收中，过程大概需要几分钟的时间，请您耐心等待...`,
        spinner: `el-icon-loading`,
        background: `rgba(0, 0, 0, 0.7)`
      })
      const formData = new FormData()
      formData.append(`customerName`, this.formUserList.customerName)
      formData.append(`file`, this.formUserList.file)
      const response = await this.$http.post(`noCar/batchImprotEndBillWay`, formData)
      var {data: { code, msg, data }} = response
      if (code == 0 && msg == `success`) {
        this.loadData()
        loading.close()
        this.$message.success(`上传成功`)
      } else if (code == 1 && msg == null && data == null) {
        loading.close()
        this.$message.error(`数据存在错误，请检查文件中数据，金额是否有空的，时间是否全是时间格式`)
      } else {
        loading.close()
        this.$message.error(msg)
      }
    },
    // 查看批次数据
    async checkLook(id) {
      this.addList = true
      this.batchNumberQ = id
      this.loadDataCar()
    },
    twoLoadData() {
      this.currenttwo = 1
      this.pagesizetwo = 8
      this.loadDataCar()
    },
    // 查看实时数据
    async loadDataCar() {
      const formData = new FormData()
      formData.append(`current`, this.currenttwo)
      formData.append(`size`, this.pagesizetwo)
      formData.append(`customerName`, this.formUserList.customerName)
      formData.append(`batchNumEnd`, this.batchNumberQ)
      formData.append(`billNum`, this.billNum)
      formData.append(`hisFlag`, 0)
      const response = await this.$http.post(`noCar/findImportBillWay`, formData)
      if (response.data.code == 0) {
        this.loading = false
        this.usertabletwo = response.data.data.records
        this.totaltwo = response.data.data.total
      }
    },
    // 清空表单数据
    handleEditDialogClose() {
      this.addList = false
    },
    handleRemove(file, fileList) {
    },

    handlePreview(file) {
    },
    handleSuccess(a) {
      this.formUserList.file = a.raw
    },
    // 分页方法
    handleSizeChange(val) {
      this.pagesize = val
      this.loadData()
    },
    handleCurrentChange(val) {
      this.current = val
      this.loadData()
    },
    handleSize(val) {
      this.pagesizetwo = val
      this.loadDataCar()
    },
    handleCurrent(val) {
      this.currenttwo = val
      this.loadDataCar()
    }

  }
}
</script>

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