<template>
  <div id="quabottom2">
    <div class="bg-color-black">
      <div class="d-flex pt-1 pl-2 jc-center">
        <span class="fs-xxxl text mx-2 fw-b">近15天来料不良批次</span>
      </div>
      <div class="d-flex jc-center body-box">
        <dv-scroll-board :config="config" ref="scroll-board" />
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  computed: {
    //数组写法
    ...mapState(['user', 'factoryoptions', 'factory']),
  },
  data() {
    return {
      config: {
        header: [],//['供方编号','物料编号', '物料名称','批次数量','处理结果'],
        data: [],
        rowNum: 5, //表格行数
        headerHeight: 40,
        headerBGC: 'rgba(15,19,37,0.1)', //表头
        oddRowBGC: 'rgba(15,19,37,0.1)', //奇数行
        evenRowBGC: 'rgba(23,28,51,0.1)', //偶数行
        columnWidth: [],// [130,200, 100,100,100],
        align: [],//['left','center','center','center','center'],
        carousel:'page',
        waitTime:2500
      },
      timing: null,
    }
  },
  mounted() {
    this.refreshdata();
  },
  beforeDestroy() {
    clearInterval(this.timing)
  },
  methods: {
    refreshdata() {
      this.getdata(); //获取-数据
      this.timing = setInterval(() => {
        this.getdata(); //获取--数据
      }, 30000);
    },
    async getdata() {
      var caller = 'KB!IQC!NGDATA';
      await this.$http.get("kanban/datalist.action?caller=" + caller + "&_noc=1&page=1&pageSize=100", {
        params: {
          condition: "1=1",
        }
      }).then((result) => {
        let columns = result.data.columns;
        let headers = new Array();
        let columnWidths = new Array();
        let fieldnames = new Array();
        let aligns = new Array();
        for (let index = 0; index < columns.length; index++) {
          const element = columns[index];
          if (element.width > 0) {
            headers.push(element.text);
            columnWidths.push(element.width);
            fieldnames.push(element.dataIndex);
            aligns.push('center');
          }
        }
        this.config.header = headers;
        this.config.columnWidth = columnWidths;
        this.config.align = aligns;
        let dataList = JSON.parse(result.data.data);
        let resultList = new Array();
        for (let index = 0; index < dataList.length; index++) {
          const element = dataList[index];
          let cellClass = 'colorGrass';
          if (element.qc_result == '不合格') {
            cellClass = 'colorRed';
          } else if (element.qc_result == '特采') {
            cellClass = 'colorRemind';
          }
          let item = new Array();
          fieldnames.forEach(function (ele) {
            // 遍历数组，对每个元素进行操作
            item.push(`<span class="fs-xl ${cellClass}">` + element[ele] + `</span>`);
          });
          resultList.push(item);
        }
        this.config.data = resultList;
        this.config = { ...this.config };
      }, (result) => {
        console.error(result)
      }
      );
    }
  }
}
</script>

<style lang="scss" scoped>
$box-height: 325px;
$box-width: 100%;

#quabottom2 {
  padding: 13px;
  height: $box-height;
  // font-size: 32px;
  width: $box-width;
  border-radius: 5px;

  .bg-color-black {
    height: $box-height - 25px;
    border-radius: 10px;
    padding: 5px;
    width: $box-width;

    .body-box {
      padding-top: 15px;
    }
  }

  .text {
    color: #c3cbde;
    //font-size: 15px;
  }

  .body-box {
    width: $box-width;

    ::v-deep .dv-scroll-board {
      height: 260px;
      padding-top: 0px; // 添加这行减少顶部间距

      .header {
        font-size: 20px !important;
        color: #c3cbde !important;
      }

      .rows {
        .row-item {
          font-size: 20px !important;
          color: #c3cbde !important;
        }
      }
    }
  }


}
</style>
