<template>
  <div class="export-download">
    <bread-crumb :curmbFirst="curmbFirst" :curmbSecond="curmbSecond"></bread-crumb>
    <div class="component-content screenSet" id="screenSet">
      <p>导出文件列表</p>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="name" label="名称" align="center" min-width="300"></el-table-column>
        <el-table-column prop="time" label="时间" align="center" min-width="120">
          <template slot-scope="scope">{{ scope.row.time | liveDateFilter }}</template>
        </el-table-column>
        <el-table-column prop="status" label="状态" align="center" min-width="150">
          <template slot-scope="scope">{{ scope.row.status | exportStatus }}</template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" min-width="70">
          <template slot-scope="scope">
            <el-button
              type="primary"
              :disabled="scope.row.buttonStatus"
              size="small"
              @click="update(scope.row)"
            >{{ scope.row.buttonText }}</el-button>
          </template>
        </el-table-column>
        <div slot="empty">
          <div class="table-empty">
            <img src="../../assets/image/no-content1.png">
            <p>没有相关数据，请重新选择查询范围</p>
          </div>
        </div>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="param.pageNo"
          :page-sizes="[10, 30, 50]"
          :page-size="param.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalRows"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import BreadCrumb from "../../components/breadcrumb.vue";
import * as commonUtil from "../../utils/utils";
let vm = null;
export default {
  components: {
    BreadCrumb
  },
  data() {
    return {
      curmbFirst: "学情报告",
      curmbSecond: "导出下载",
      tableData: [],
      param: {
        pageSize: 10,
        pageNo: 1
      },
      totalRows: 0,
      totalTime: 3
      // buttonText: "刷新",
      // buttonStatus: false,
    };
  },
  created() {
    vm = this;
    this.search();
  },
  mounted: function() {
    commonUtil.resizeHeight();
  },
  methods: {
    setButton() {
      for (let i = 0; i < vm.tableData.length; i++) {
        vm.tableData[i].index = i;
        vm.tableData[i].buttonText = "刷新";
        vm.tableData[i].buttonStatus = false;
      }
    },
    search() {
      vm.tableData = [
        {
          id: 123,
          name:
            "浙江省心脑项目，浙江省杭州市区西湖区，第二人民医院杭州市中医院---",
          time: 1562221264000,
          status: 1
        },
        {
          id: 233,
          name:
            "江西省心脑项目，浙江省杭州市区西湖区，第二人民医院杭州市中医院---",
          time: 1562221874000,
          status: 1
        },
        {
          id: 666,
          name:
            "上海市心脑项目，浙江省杭州市区西湖区，第二人民医院杭州市中医院---",
          time: 1562225864000,
          status: 1
        }
      ];
      this.setButton();
    },
    update(row) {
      this.$nextTick(function() {
				console.log(vm.tableData[row.index]);
				let nowTime = vm.totalTime;
        vm.tableData[row.index].name = vm.tableData[row.index].name+ ' ';
        vm.tableData[row.index].buttonText = nowTime + "s后可以刷新";
				vm.tableData[row.index].buttonStatus = true;
				
        let clock = window.setInterval(() => {
					nowTime--;
					vm.tableData[row.index].name = vm.tableData[row.index].name+ ' ';
          vm.tableData[row.index].buttonText = nowTime + "s后可以刷新";
          if (nowTime < 0) {
						window.clearInterval(clock);
						vm.tableData[row.index].name = vm.tableData[row.index].name+ ' ';
            vm.tableData[row.index].buttonText = "刷新";
            vm.tableData[row.index].buttonStatus = false; //这里重新开启
          }
        }, 1000);
      });
    },
    // 更改数据显示数量
    handleSizeChange(val) {
      vm.param.pageSize = val;
      vm.search();
    },
    // 换页
    handleCurrentChange(val) {
      vm.param.pageNo = value;
      vm.search();
    }
  }
};
</script>
<style lang="scss">
.export-download {
  .component-content {
    background: #fff;
    padding: 10px;
  }
}
</style>