<template>
  <div id="menuScreen">
    <div class="title">今日食材</div>
    <div class="title2">
      <span>食材</span>
      <span>地址</span>
      <span>日期</span>
    </div>

    <div class="tables">
      <div class="gun">
        <el-table :cell-style="{ color: '#fff' }" :header-cell-style="{ color: '#fff' }" :data="tableData"
          style="width: 100%;height:100%;font-size: 2.4vh;">
          <el-table-column prop="product" align="center" label="">
          </el-table-column>
          <el-table-column prop="address" label="" align="center">
          </el-table-column>
          <el-table-column prop="billDate" label="" align="center">
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { foodList } from '@/api/canteen/basic.js'
export default {
  data() {
    return {
      tableData: [],
      nowDate: '',
      intervalId: null
    }
  },
  created() {
    this.getList()
    this.dataRefreh()
  },
  destroyed(){
    // 在页面销毁后，清除计时器
    this.clear();
  },
  methods: {
    getList() {
      this.getNow()
      // {billDate: this.nowDate}
      foodList({pageSize: 100,billDate: this.nowDate}).then(res => {
        if (res.code === 200) {
          this.tableData = res.rows
        }
      })
    },
    getNow() {
      var date = new Date();
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      if (month < 10) {
        month = "0" + month;
      }
      if (day < 10) {
        day = "0" + day;
      }
      const nowDate = year + "-" + month + "-" + day;
      this.nowDate = nowDate
    },
   // 定时刷新数据函数
   dataRefreh() {
      // 计时器正在进行中，退出函数
      if (this.intervalId != null) {
        return;
      }
      // 计时器为空，操作
      this.intervalId = setInterval(() => {
        console.log("刷新" + new Date());
        this.getList(); //加载数据函数
      }, 1000*60*10);
    },
    // 停止定时器
    clear() {
      clearInterval(this.intervalId); //清除计时器
      this.intervalId = null; //设置为null
    },
  }
}
</script>

<style lang="scss" scoped>
#menuScreen {
  width: 100%;
  height: 100%;
  // overflow: hidden;
  background-image: url('../../assets/images/background.png');
  background-repeat: no-repeat;
  background-size: cover;
}

.title {
  text-align: center;
  font-size: 8vh;
  color: #fff;
  font-weight: 600;
  // text-shadow: 0 0 5px #fff,
  //   0 0 10px #fff,
  //   0 0 15px #fff,
  //   0 0 20px #00a67c,
  //   0 0 35px #00a67c,
  //   0 0 40px #00a67c,
  //   0 0 50px #00a67c,
  //   0 0 75px #00a67c;
}

.title2 {
  text-align: center;
  font-size: 3vh;
  color: #fff;
  font-weight: 600;
  width: 80%;
  color: #FFF;
  margin: 2% auto;
  display: flex;
  justify-content: space-around;
  //   text-shadow: 0 0 5px #fff,
  //     0 0 10px #fff,
  //     0 0 15px #fff,
  //     0 0 20px #00a67c,
  //     0 0 35px #00a67c,
  //     0 0 40px #00a67c,
  //     0 0 50px #00a67c,
  //     0 0 75px #00a67c;
  // }
}

.gun {
  animation: tables 12s linear infinite;
}

.tables {
  width: 80%;
  height: 680px;
  margin: 0 auto;
  overflow: hidden;
}

@keyframes tables {
  0% {
    transform: translateY(0px)
  }

  100% {
    transform: translateY(calc(-100% + 680px));
  }
}

/*最外层透明*/
::v-deep .el-table,
::v-deep .el-table__expanded-cell {
  // font-size: 18px;
  background-color: transparent !important;
}

/* 表格内背景颜色 */
::v-deep .el-table th,
::v-deep .el-table tr,
::v-deep .el-table td {
  background-color: transparent !important;

  border-top: 1px solid #808DA6;
  border-bottom: none;
}

::v-deep .el-table .el-table__header-wrapper {
  display: none;
}
::v-deep .el-table .cell {
  line-height: normal;
}
</style>