<template>
  <div class="grade-step">
    <div class="grade-step-other">
      <div
        v-for="(step, sindex) in steps.otherStep"
        :key="sindex"
        :class="[
          'step-item',
          {
            'step-act': curStep.name === step.name,
            'step-other': step.type !== 'done'
          }
        ]"
        @click="selectStep(step)"
      >
        <p>{{ step.count }}</p>
        <p class="step-name">{{ step.name }}</p>
        <p>{{ step.count }}</p>
      </div>
    </div>
    <div class="grade-step-level" :style="levelStepStyles">
      <div
        class="step-item"
        v-if="showAnalysis"
        :class="['step-analysis', { 'step-act': curStep.name === 'analysis' }]"
        @click="selectAnalysis"
      >
        <p>&nbsp;</p>
        <p class="step-name">图表</p>
        <p>&nbsp;</p>
      </div>
      <div
        v-for="(step, sindex) in steps.levelStep"
        :key="sindex"
        :class="[
          'step-item',
          {
            'step-act': curStep.name === step.name,
            'step-other': step.type !== 'done'
          }
        ]"
        @click="selectStep(step)"
      >
        <p>
          <span>{{ step.gcount }}/</span><span>{{ step.gpercent }}%</span
          ><span>({{ step.pt }}%)</span>
        </p>
        <p class="step-name">{{ step.name }}</p>
        <p>
          <span>{{ step.count }}/</span><span>{{ step.percent }}%</span
          ><span>({{ step.kdpt }}%)</span>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "grade-step",
  props: {
    showAnalysis: {
      type: Boolean,
      default: true
    },
    steps: {
      type: Object,
      default() {
        return { levelStep: [], otherStep: [] };
      }
    },
    initStep: {
      type: Object,
      default() {
        return { type: "analysis", name: "analysis" };
      }
    }
  },
  data() {
    return {
      curStep: {}
    };
  },
  computed: {
    levelStepStyles() {
      return {
        marginRight: this.steps.otherStep.length * 82 + 20 + "px"
      };
    }
  },
  mounted() {
    this.selectStep(this.initStep);
  },
  methods: {
    selectStep(step) {
      this.curStep = { ...step };
      this.$emit("on-change", this.curStep);
    },
    selectAnalysis() {
      this.selectStep({ type: "analysis", name: "analysis" });
    }
  }
};
</script>
