<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" />
    <Jianyanpihao ref="jianyanpihaoRef" />
  </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 Jianyanpihao from "@/views/pro-operation/jianyanpihao/index.vue";
import { useProcessStore } from "@/store";

const store = useProcessStore();
// ================ 报故
const reportBreakRef = ref<InstanceType<typeof ReportBreak>>();

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

const router = useRouter();
const jianyanpihaoRef = ref(null);
const selectIndex = ref(null);
const setIndex = (index: number) => {
  // selectIndex.value = index;
  switch (stepComponents.value[index].compentType) {
    case "baogu":
      reportBreakRef.value?.openReportBreakDrawer();
      break;
    case "jiaoliao":
      router.push({ name: "call-materiel" });
      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 "fangong":
      router.push({ name: "rework" });
      break;
    case "tichu":
      router.push({ name: "remove" });
      break;
    case "baogong":
      reportWorkRef.value?.openReportWorkDrawer();
      break;
    case "xunjian":
      router.push({ name: "checkOut" });
      break;
    case "printboard":
      router.push({ name: "printing-plate" });
      break;
    case "pdmfile":
      router.push({ name: "pdmfile" });
      break;
    case "jianyanpihao":
      //@ts-ignore
      jianyanpihaoRef.value.open();
      break;
    default:
      break;
  }
};

const stepComponents = ref([
  // {
  //   compentName: "叫料",
  //   compentType: "jiaoliao",
  // },
  // {
  //   compentName: "物料流转",
  //   compentType: "liuzhuan",
  // },
  {
    compentName: "图纸资料",
    compentType: "tuzhi",
  },
  {
    compentName: "报工",
    compentType: "baogong",
  },
  {
    compentName: "返工",
    compentType: "fangong",
  },
  {
    compentName: "剔除",
    compentType: "tichu",
  },
  {
    compentName: "印刷板",
    compentType: "printboard",
  },
  {
    compentName: "检验批号",
    compentType: "jianyanpihao",
  },
  {
    compentName: "工序通用",
    compentType: "xunjian",
  },
]);
const setComponents = () => {
  // if (store.scanInfo.inspection == 1 || store.scanInfo.firstCheck == 1) {
  //   stepComponents.value = stepComponents.value.filter(
  //     (item) => item.compentName !== "工序通用"
  //   );
  //   stepComponents.value.push({
  //     compentName: "工序通用",
  //     compentType: "xunjian",
  //   });
  // }
  if (store.processInfo.documentShow == 1) {
    stepComponents.value = stepComponents.value.filter(
      (item) => item.compentName !== "产品文档"
    );
    stepComponents.value.push({
      compentName: "产品文档",
      compentType: "pdmfile",
    });
  }
  if (
    store.odersData.operationType == "SX" ||
    store.odersData.operationType == "RX"
  ) {
    stepComponents.value = stepComponents.value.filter(
      (item) => item.compentName !== "返工"
    );
  }
};
onMounted(async () => {
  await setComponents();
  stepComponents.value.push({ compentName: "委外", compentType: "weiwai" });
  stepComponents.value.push({ compentName: "报故", compentType: "baogu" });
});
onActivated(() => {
  setComponents();
});
</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>
