<template>
  <div>
    <!-- 年度开工率 -->
    <Echart
        :options="options"
        id="bottom1Chart"
        height="480px"
        width="100%"
        ref="column-board"
    ></Echart>
  </div>
</template>

<script>
import Echart from '@/common/echart'
//import { formatDate } from '../../../../utils/index.js'
export default {
  data () {
    return {
      options:{
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        legend: {},
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data:[]
          }
        ],
        yAxis: [
          {
            type: 'value',
          },
          {
            type: 'value',
            name: 'rate',
            min: 0,
            max: 100,
            interval: 20,
            axisLabel: {
              formatter: '{value}%'
            }

          }

        ],
        series: [
          {
            name: '生产计划数',
            type: 'bar',
            barWidth: 20,
            emphasis: {
              focus: 'series'
            },
            data:[],
            /*label: {
              show: true
            }*/
          },
          {
            name: '良品',
            type: 'bar',
            barWidth: 20,
            stack: 'Ad',
            emphasis: {
              focus: 'series'
            },
            data:[]
          },
          {
            name: '不良',
            type: 'bar',
            stack: 'Ad',
            barWidth: 10,
            data:[],
            emphasis: {
              focus: 'series'
            }
          },
          {
            name: '完成率%',
            type: 'line',
            data:[],
            yAxisIndex: 1,
            tooltip: {
              valueFormatter: function (value) {
                return value + '%';
              }
            },
            itemStyle: {
              normal: {
                barBorderRadius: 5,
                color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  { offset: 0, color: "rgba(156,107,211,0.8)" },
                  { offset: 0.2, color: "rgba(156,107,211,0.5)" },
                  { offset: 1, color: "rgba(156,107,211,0.2)" }
                ])
              }
            },
            emphasis: {
              focus: 'series'
            }
          }
        ]
      },
      timing :null
    };
  },
  components: {
    Echart, //子组件
  },
  props: {
    cdata: {
      type: Object,
      default: () => ({})
    },
  },

  mounted() {
    this.refreshdata();
  },
  beforeDestroy () {
    clearInterval(this.timing)
  },
  methods: {
    refreshdata() {
      this.setData(); //获取数据
      this.timing = setInterval(() => {
        this.setData(); //获取--数据
      }, 30000);
    },
    async setData() {
      //20220211 -+formatDate(new Date()
      await this.$http.get("kanban/datalist.action?caller=KB!OFFICE!WCDAYTURNOUT&_noc=1&page=1&pageSize=100",{
        params: {
          condition: "1=1",
        }
      }).then((result)=>{
                let dataList = JSON.parse(result.data.data);
                let xAxis0 = new Array();
                let series0 = new Array();
                let series1 = new Array();
                let series2 = new Array();
                let series3 = new Array();
                for (let index = 0; index < dataList.length; index++) {
                  const element = dataList[index];
                  xAxis0.push(element.v_wcname);
                  //生产计划数
                  series0.push(element.v_planqty);
                  //良数
                  series1.push(element.v_okqty);
                  //不良
                  series2.push(element.v_ngqty);
                  //完成比例 = 良数/生产计划数
                  series3.push(element.v_okrate);
                }
                this.options.xAxis[0].data = xAxis0;
                this.options.series[0].data = series0;
                this.options.series[1].data = series1;
                this.options.series[2].data = series2;
                this.options.series[3].data = series3;
              },(result)=>{
                console.error(result)
              }
          );
    }
  }
}
</script>