<template>
  <div class="ele-body">
    <el-row :gutter="15">
      <el-col :span="16" style="height: 57%">
        <div style="height: 20%" class="item">
          <div v-for="item in arr" :key="item" :style="{ color: item.color }">
            <img :src="item.imgUrl" />
            <div>
              <span>
                {{ item.name }}
              </span>
              <span>
                {{ item.num }}
                <span>{{ item.unit }}</span>
              </span>
            </div>
          </div>
        </div>
        <el-card class="box-card" style="height: calc(80% - 15px)">
          <div slot="header" class="clearfix">
            <span>工单完成统计</span>
            <el-radio-group
              style="margin-left: 0.7vw"
              v-model="form.timeType"
              @change="timeTypeChange"
            >
              <el-radio-button label="1">工厂</el-radio-button>
              <el-radio-button label="2">班组</el-radio-button>
              <el-radio-button label="3">工序</el-radio-button>
            </el-radio-group>
          </div>
          <v-chart ref="barRef" style="height: 100%" :option="barOption" />
        </el-card>
      </el-col>
      <el-col :span="8" style="height: 57%">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>不良品分布图</span>
          </div>
          <v-chart ref="pieRef" style="height: 100%" :option="pieOption" />
        </el-card>
      </el-col>
      <el-col :span="24" style="height: 43%; margin-top: 15px">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>工单进度执行跟踪</span>
          </div>
          <ele-pro-table
            ref="table"
            :columns="columns"
            :datasource="datasource"
            :needPage="false"
            :toolbar="false"
          >
          </ele-pro-table>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import {
  queryHomePage,
  queryFactory,
  queryTeam,
  queryProductionLine
} from '@/api/qms';
import dictMixins from '@/mixins/dictMixins';
import { pieOption, barOption, columns } from './data';
import { use } from 'echarts/core';
import { CanvasRenderer } from 'echarts/renderers';
import { BarChart, PieChart, LineChart } from 'echarts/charts';
import {
  GridComponent,
  TooltipComponent,
  LegendComponent
} from 'echarts/components';
import EleChart from 'ele-admin/packages/ele-chart';

import VChart from 'vue-echarts';
import { echartsMixin } from '@/utils/echarts-mixin';
// 按需加载 echarts
use([
  CanvasRenderer,
  BarChart,
  PieChart,
  GridComponent,
  TooltipComponent,
  LegendComponent,
  LineChart
]);
export default {
  mixins: [dictMixins, echartsMixin(['pieRef', 'barRef'])],
  components: { VChart },
  data() {
    return {
      columns,
      arr: [
        {
          name: '在制工单数',
          num: '188',
          imgUrl: require('../../assets/Group1.png'),
          unit: '个'
        },
        {
          name: '在制工单计划生产数',
          num: '188',
          imgUrl: require('../../assets/Group2.png'),
          unit: '件'
        },
        {
          name: '在制工单已入库数',
          num: '188',
          imgUrl: require('../../assets/Group3.png'),
          unit: '件'
        },
        {
          name: '在制工单延期生产数',
          num: '188',
          imgUrl: require('../../assets/Group4.png'),
          unit: '件',
          color: '#f97876'
        }
      ],

      pieOption: {},
      barOption: {},
      form: {
        finishTime: '',
        timeType: '1'
      }
    };
  },

  created() {
    this.pieOption = pieOption([
      { value: 40, name: '  外观检测' },
      { value: 30, name: '  尺寸检测' },
      { value: 15, name: '  性能检测' },
      { value: 10, name: '  密度检测' },
      { value: 5, name: '  重量检测' }
    ]);
    this.barOption = barOption([
      50, 78, 88, 76, 75, 91, 78, 87, 81, 67, 95, 73
    ]);
  },
  methods: {
    datasource({ page, where, limit }) {
      return [];
      return getList({
        ...where,
        pageNum: page,
        size: limit
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.clearfix {
  font-size: 0.7vw;

  > span {
    font-weight: bold;
  }
  :deep(.el-radio-button__inner) {
    font-size: 0.7vw;
  }
}
.ele-body {
  height: calc(100vh - 111px);
  > .el-row {
    height: 100%;
  }
  .el-card {
    height: 100%;
    :deep(.el-card__body) {
      padding: 0.3vw;
    }
    :deep(.el-card__header) {
      padding: 0.8vw;
    }
    :deep(.el-card__body) {
      height: calc(100% - 1.6vw - 39px);
    }
    :deep(.ele-pro-table) {
      height: 99%;
    }
    :deep(.el-table) {
      font-size: 0.65vw;
    }
  }
}
.item {
  width: 100%;
  display: flex;
  margin-bottom: 15px;
  > div {
    border-radius: 4px;
    flex: 1;
    margin-left: 15px;
    background: url(../../assets/item_frame.png) no-repeat;
    background-size: 100% 100%;
    display: flex;
    align-items: center;
    padding: 12px;
    img {
      width: 2.3vw;
      // height:1.7vw;
    }
    > div {
      display: flex;
      flex-direction: column;
      // margin-left: 0.8vw;
      justify-content: center;
      align-items: center;
      width: 80%;
      span:nth-of-type(1) {
        font-size: 0.75vw;
      }
      span:nth-of-type(2) {
        font-weight: bold;
        font-size: 1.2vw;
        margin-top: 0.8vw;
        span {
          font-size: 0.7vw;
        }
      }
    }
  }
}
</style>

  