<template>
  <div class="containerBox">
    <div
      v-for="(item, index) in stepComponents"
      :key="index"
      :class="selectIndex == index ? 'operator active' : 'operator'"
      @click="setIndex(index)"
    >
      <div class="operatorText">{{ item.compentName }}</div>
      <div class="operatorIcon">
        <svg-icon :icon-class="item.compentType" size="45" />
      </div>
    </div>

    <ReportBreak ref="reportBreakRef" />
    <ReportWork ref="reportWorkRef" />
    <ReportProblem ref="reportProblemRef" />
  </div>
</template>

<script lang="ts" setup>
import ReportBreak from "@/views/pro-operation/report-break/index.vue"; // ================ 报故
import ReportWork from "@/views/pro-operation/report-work/index.vue";
import ReportProblem from "@/views/pro-operation/report-problem/index.vue";
// ================ 报故
const reportBreakRef = ref<InstanceType<typeof ReportBreak>>();

// ================ 报工
const reportWorkRef = ref<InstanceType<typeof ReportWork>>();


const reportProblemRef = ref<InstanceType<typeof ReportProblem>>();
const router = useRouter();

const selectIndex = ref(-1);

onActivated(() => {
  selectIndex.value = -1
})

const setIndex = (index: number) => {
  selectIndex.value = index;
  switch (stepComponents.value[index].compentType) {
    case "baogu":
      reportBreakRef.value?.openReportBreakDrawer();
      break;
    case "jiaoliao":
      reportProblemRef.value?.openReportProblemDrawer();
      break;
    case "gongweishangliao":
      router.push({ name: "station-up-material" });
      break;
    case "liuzhuan":
      router.push({ name: "material-flow" });
      break;
    case "tuzhi":
      router.push({ name: "drawing-list" });
      break;
    case "weiwai":
      router.push({ name: "appoint-out" });
      break;
    case "baogong":
      reportWorkRef.value?.openReportWorkDrawer();
      break;
    case "check":
      router.push({ name: "inspectCommon" });
      break;
    case "jianyan":
      router.push({ name: "inspect" });
      break;
    case "bianhao":
      router.push({ name: "write-number" });
      break;
    default:
      break;
  }
};

const stepComponents = ref([
  // {
  //   compentName: "叫料",
  //   compentType: "jiaoliao",
  // },
  // {
  //   compentName: "物料流转",
  //   compentType: "liuzhuan",
  // },
  {
    compentName: "检验",
    compentType: "jianyan",
  },
  {
    compentName: "自检/互检",
    compentType: "check",
  },
  {
    compentName: "报工",
    compentType: "baogong",
  },
  {
    compentName: "图纸",
    compentType: "tuzhi",
  },
  // {
  //   compentName: "委外",
  //   compentType: "weiwai",
  // },
  {
    compentName: "报故",
    compentType: "baogu",
  },
  {
    compentName: "问题反馈",
    compentType: "jiaoliao",
  },
]);
</script>

<style lang="scss" scoped>
.containerBox {
  width: 100%;
  font-weight: $Medium;

  .operator {
    width: 100%;
    height: 88px;
    border-radius: 16px;
    background-color: white;
    margin-bottom: 20px;
    display: flex;
    padding: 20px;
    justify-content: space-between;
    align-items: center;

    .operatorText {
      font-size: $f24;
    }

    .operatorIcon {
      font-weight: 800;
    }
  }
}

.active {
  background-color: #64bb5c !important;
  color: white;
}
</style>
