<template>
  <!-- 汽运单价页面 -->
  <div class="salePlan">
    <div class="top">
      <el-input placeholder="请输入内容" v-model="input" clearable> </el-input>
      <el-button type="primary" class="btn" @click="onclick" :loading="loading">
        <i class="el-icon-search"></i>查询
      </el-button>
      <el-button type="primary" @click="btnclick(0)">
        <i class="el-icon-plus"></i>新增
      </el-button>
       <el-button type="primary" @click="exportData()"><i class="el-icon-download"></i>导出(Excel)</el-button>
<!--      <el-upload
        class="upload-excel"
        action=""
        :on-change="importExcel"
        :show-file-list="false"
        accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
        :auto-upload="false"
      >
        <el-button type="primary">
          导入单价表
        </el-button>
      </el-upload>-->
    </div>

<el-tabs v-model="activeName">
      <!-- 正在启用 -->
       <el-tab-pane label="正在启用" name="first">
          <dilTable ref="excelDom" v-bind.sync="option" :loading="loading" :isKuang="isKuang" @func="func">
        </dilTable>
      </el-tab-pane>
      <!-- 历史启用 -->
      <el-tab-pane label="历史启用" name="second">
          <dilTable ref="excelDom" v-bind.sync="option2" :loading="loading" :isKuang="isKuang" @func="func">
          </dilTable>
      </el-tab-pane>

    </el-tabs>
  </div>
</template>
<script>
export default {
  name: "TransportPrice",
  data() {
    return {
      activeName: "first",
      isKuang:false,
      loading:false,
      input: "",
      option: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/ams/getAmsContractTransportPrice1?apiId=109&deleted=0",
      },
      option2: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/ams/getAmsContractTransportPrice1?apiId=109&deleted=1",
      },
      tableTitle:'汽运单价'
    };
  },
  methods: {
    func(){
      this.loading = false;
      this.isKuang = false;
    },
    onclick() {
      this.loading = true;
      this.isKuang = true;
      if(this.input){
        this.option.requestUrl ="/api/v1/ams/getAmsContractTransportPrice1?apiId=109&con=" +this.input;
      }else{
        this.option.requestUrl ="/api/v1/ams/getAmsContractTransportPrice1?apiId=109&i="+new Date();
      }
    },
    btnclick() {
      this.$router.push("/addTransportPrice");
    },
    /*importExcel(file){
      let that = this;
      if (!file) {
        that.$message({
          message: "文件错误!",
          type: "warning"
        });
        return;
      }
      let excelData =[]
      var reader=new FileReader();
      var data=null;
      var workbook = null;
      //设置读取操作
      reader.onload = function (e){
        console.log(e);
        data = e.target.result;
        workbook=XLSX.read(data,{type:'binary'});
        console.log(workbook)
        //只取第一个表的数据
        let rows= XLSX.utils.sheet_to_json(
          workbook.Sheets[workbook.SheetNames[0]]
        );
        console.log(rows)
        let index=1;
        // for (index=1;index<rows.length;index++){
        //   if (
        //     typeof workbook.Sheets[workbook.SheetNames[0]]["A"+index] !=
        //     "undefined"
        //   ){
        //     index++;
        //     break
        //   }
        // }
        // console.log("表头行数:" + index);
        // if(index>=rows.length){
        //   that.$message({
        //     message: "文件错误!",
        //     type: "warning",
        //   });
        //   return
        // }
        if (
          typeof workbook.Sheets[workbook.SheetNames[0]]["A" + index] == 'undefined' ||
          typeof workbook.Sheets[workbook.SheetNames[0]]["B" + index] == 'undefined' ||
          typeof workbook.Sheets[workbook.SheetNames[0]]["C" + index] == 'undefined' ||
          typeof workbook.Sheets[workbook.SheetNames[0]]["D" + index] == 'undefined' ||
          typeof workbook.Sheets[workbook.SheetNames[0]]["E" + index] == 'undefined' ||
          typeof workbook.Sheets[workbook.SheetNames[0]]["F" + index] == 'undefined' ||
          typeof workbook.Sheets[workbook.SheetNames[0]]["G" + index] == 'undefined' ||
          typeof workbook.Sheets[workbook.SheetNames[0]]["H" + index] == 'undefined' ||
          workbook.Sheets[workbook.SheetNames[0]]["A" + index].v != "序号" ||
          workbook.Sheets[workbook.SheetNames[0]]["B" + index].v != "省份" ||
          workbook.Sheets[workbook.SheetNames[0]]["C" + index].v != "市/区" ||
          workbook.Sheets[workbook.SheetNames[0]]["D" + index].v != "县/镇" ||
          workbook.Sheets[workbook.SheetNames[0]]["E" + index].v != "卸货地点" ||
          workbook.Sheets[workbook.SheetNames[0]]["F" + index].v != "参考运距（公里）" ||
          workbook.Sheets[workbook.SheetNames[0]]["G" + index].v != "运价（元/吨）" ||
          workbook.Sheets[workbook.SheetNames[0]]["H" + index].v != "吨公里（元/吨.km）"
        ){
          if (
            typeof workbook.Sheets[workbook.SheetNames[0]]["A" + index] == 'undefined' ||
            workbook.Sheets[workbook.SheetNames[0]]["A" + index].v != "序号"
          ) {
            that.$message({
              message: "表格格式错误:序号错误",
              type: "warning"
            });
          }
          if (
            typeof workbook.Sheets[workbook.SheetNames[0]]["B" + index] == 'undefined' ||
            workbook.Sheets[workbook.SheetNames[0]]["B" + index].v != "省份"
          ) {
            that.$message({
              message: "表格格式错误:省份错误",
              type: "warning"
            });
          }
          if (
            typeof workbook.Sheets[workbook.SheetNames[0]]["C" + index] == 'undefined' ||
            workbook.Sheets[workbook.SheetNames[0]]["C" + index].v != "市/区"
          ) {
            that.$message({
              message: "表格格式错误:市/区错误",
              type: "warning"
            });
          }
          if (
            typeof workbook.Sheets[workbook.SheetNames[0]]["D" + index] == 'undefined' ||
            workbook.Sheets[workbook.SheetNames[0]]["D" + index].v != "县/镇"
          ) {
            that.$message({
              message: "表格格式错误:县/镇错误",
              type: "warning"
            });
          }
          if (
            typeof workbook.Sheets[workbook.SheetNames[0]]["E" + index] == 'undefined' ||
            workbook.Sheets[workbook.SheetNames[0]]["E" + index].v != "卸货地点"
          ) {
            that.$message({
              message: "表格格式错误:卸货地点错误",
              type: "warning"
            });
          }
          if (
            typeof workbook.Sheets[workbook.SheetNames[0]]["F" + index] == 'undefined' ||
            workbook.Sheets[workbook.SheetNames[0]]["F" + index].v != "参考运距（公里）"
          ) {
            that.$message({
              message: "表格格式错误:参考运距（公里）错误",
              type: "warning"
            });
          }
          if (
            typeof workbook.Sheets[workbook.SheetNames[0]]["G" + index] == 'undefined' ||
            workbook.Sheets[workbook.SheetNames[0]]["G" + index].v != "运价（元/吨）"
          ) {
            that.$message({
              message: "表格格式错误:运价（元/吨）错误",
              type: "warning"
            });
          }
          if (
            typeof workbook.Sheets[workbook.SheetNames[0]]["G" + index] == 'undefined' ||
            workbook.Sheets[workbook.SheetNames[0]]["H" + index].v != "吨公里（元/吨.km）"
          ) {
            that.$message({
              message: "表格格式错误:吨公里（元/吨.km）错误",
              type: "warning"
            });
          }
        }
        //读取表格
        for (let i = index+1; i <= rows.length+1 ; i++){
          console.log(workbook.Sheets[workbook.SheetNames[0]]["B" + i].v)
        }
      }
      reader.readAsBinaryString(file.raw);
    }*/
  },

};
</script>
<style lang='scss' scoped>
.salePlan {
  .top{
    padding: 1.25rem 0.375rem;
    .el-input {
      width: 20%;
      margin-right: 1.25rem;
    }
  }
}
</style>
