<template>
  <div id="up1">
    <div class="bg-color-black">
      <!--
      <div class="d-flex pt-2 pl-2">
        <span>
          <icon name="align-left" class="text-icon"></icon>
        </span>
        <span class="fs-xl text mx-2">车间生产完成统计</span>
      </div>
      <div class="d-flex ai-center flex-column body-box">
        <dv-capsule-chart class="dv-cap-chart" :config="config" />
        <span class="fs-xl text mx-2">车间投产良率分析</span>
        <up1Chart />
      </div>
      -->
      <div class="ranking">
        <span>
          <icon name="chart-pie" class="text-icon"></icon>
        </span>
        <span class="fs-xl text mx-2 mb-1 pl-3">当日产品良率分析</span>
        <dv-scroll-ranking-board class="dv-scr-rank-board mt-1" :config="ranking" ref="scroll-ranking-board"/>
      </div>
    </div>
  </div>
</template>

<script>
//import up1Chart from '@/components/officechart/up1Chart'

export default {
  data() {
    return {
      config: {
        data: [],
       // unit: 'W'
      },
      timing :null,
      ranking: {
        data: [],
        carousel: 'single',
        rowNum: 6,
      },
    }
  },
  //components: { up1Chart },
  mounted() {
    this.refreshdata();
  },
  beforeDestroy () {
    clearInterval(this.timing)
  },
  methods: {
    refreshdata() {
      this.setData(); //获取数据
      this.timing = setInterval(() => {
        this.setData(); //获取--数据
      }, 30000);
    },
    async setData(){
      //工序生产完成统计 MAKEQTY
      await this.$http.get("kanban/datalist.action?caller=KB!Office!StepFinish&_noc=1&page=1&pageSize=100",{
          params: {
            condition: "1=1",
          }
      }).then((result)=>{
                let dataList = JSON.parse(result.data.data);
                let stepFinishData = new Array();
                for (let index = 0; index < dataList.length; index++) {
                  const element = dataList[index];
                  let item = new Object();
                  item.name = element.name;
                  item.value = element.value ;
                  stepFinishData.push(item);
                }
                this.config.data = stepFinishData;
                this.config = { ...this.config };
              },(result)=>{
                console.error(result)
              }
          );

      //当日产品良率
      await this.$http.get("kanban/datalist.action?caller=KB!Office!KeyStepRate&_noc=1&page=1&pageSize=100",{
        params: {
          condition: "1=1",
        }
      }).then((result)=>{
            let dataList = JSON.parse(result.data.data);
            let datas = new Array();
            for (let index = 0; index < dataList.length; index++) {
              const element = dataList[index];
              datas.push({
                name:element.name ,
                value:element.value,
              });
            }
            this.ranking.data = datas;
            this.ranking = { ...this.ranking };
            /*两种刷新方式
             const scrollBoard = this.$refs['scroll-ranking-board'];
             scrollBoard.updateRows(datas);
             this.ranking = { data: datas }
             */
          },(result)=>{
            console.error(result)
          }
      );
    }
  }
}
</script>

<style lang="scss" scoped>
#up1 {
  $box-width: 300px;
  $box-height: 410px;
  padding: 5px;
  height: $box-height;
  width: $box-width;
  border-radius: 5px;
  .bg-color-black {
    height: $box-height - 20px;
    width: $box-width - 10px;
    border-radius: 10px;
    padding: 5px 5px 5px 5px;
  }
  .ranking {
    padding: 5px;
    .dv-scr-rank-board {
      padding-top: 5px;
      height: 350px;
      width:270px
    }
  }
  .text {
    color: #c3cbde;
  }
  .body-box {
    border-radius: 10px;
    overflow: hidden;
    .dv-cap-chart {
      width: 100%;
      height: 160px;
      text-align:left;
    }
  }
}
</style>
