`
<template>
  <div style="position: relative">
    <div class="headerInfo">
      <!-- <div
        class="titleText"
        style="
          width: 300px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        "
      >
        {{ store.processInfo.materialName }} -
        {{ store.processInfo.materialModel }}
      </div>
      <div class="info">
        <div class="item">
          当前工序:
          {{
            store.scanInfo.operationName ? store.scanInfo.operationName : "-"
          }}
        </div>
        <div class="item">
          下一工位:{{
            store.scanInfo.nextStation ? store.scanInfo.nextStation : "-"
          }}
        </div>
        <div class="item">
          卡号:{{ store.scanInfo.seqNo ? store.scanInfo.seqNo : "-" }}
        </div>
        <div class="item">
          编码:{{
            store.scanInfo.materialCode ? store.scanInfo.materialCode : "-"
          }}
        </div>
      </div> -->
    </div>
    <div class="mainContentBox">
      <el-row :gutter="20">
        <el-col :span="4" class="boxStyle">
          <div class="productInfo" @click="openPop">
            <template v-if="taskIndex != null">
              <div
                class="productitleText"
                style="font-size: 500; font-size: 24px"
              >
                {{ taskArray[taskIndex].materialName }}
              </div>
              <div
                class="productitleText"
                style="
                  color: #ffffff60;
                  white-space: nowrap;
                  overflow: hidden;
                  text-overflow: ellipsis;
                "
              >
                {{ taskArray[taskIndex].materialModel }}
              </div>
              <div style="display: flex">
                <div class="productitleText" style="color: #ffffff60">S/N</div>
                <div class="productitleText">
                  &nbsp;{{ snVal ? snVal : "-" }}
                </div>
              </div>
            </template>
            <template v-else>
              <div
                class="productitleText"
                style="
                  font-size: 500;
                  font-size: 24px;
                  display: flex;
                  justify-content: center;
                  align-items: center;
                  height: 100%;
                "
              >
                请选择产品
              </div>
            </template>
          </div>
          <!-- 侧边栏盒子 -->
          <div class="commonTitle">工序</div>
          <el-scrollbar
            style="height: calc(100vh - 220px); padding-bottom: 60px"
          >
            <Steps
              v-if="opsArray.length > 0"
              :opsArray="opsArray"
              @init="init"
            />
            <template v-else>
              <div
                class="productitleText"
                style="
                  font-size: 500;
                  font-size: 24px;
                  display: flex;
                  height: calc(100vh - 280px);
                  justify-content: center;
                  align-items: center;
                  background-color: var(--ohos-area-bg);
                  border-radius: 16px;
                  color: white;
                "
              >
                暂无工序
              </div>
            </template>
          </el-scrollbar>
        </el-col>
        <el-col :span="20">
          <div class="typeContainer">
            <el-scrollbar>
              <div style="display: flex">
                <div
                  v-for="(item, index) in stepComponents"
                  :key="index"
                  class="scrollbar-demo-item"
                >
                  <router-link :to="{ name: item.name }" replace>
                    <div
                      :class="getNameClass(index)"
                      class="typeBox"
                      @click="setSelectIndex(index)"
                    >
                      <div class="svgIcon">
                        <svg-icon :icon-class="item.iconName" size="30" />
                      </div>
                      <div class="name">{{ item.compentName }}</div>
                    </div>
                  </router-link>
                </div>
                <div
                  v-if="snVal == null && taskIndex == null"
                  style="
                    font-size: 40px;
                    font-weight: 500;
                    color: white;
                    width: 100%;
                    height: 80px;
                    text-align: center;
                    line-height: 80px;
                  "
                >
                  请先选择工序
                </div>
                <div
                  v-else-if="snVal == null"
                  style="
                    font-size: 40px;
                    font-weight: 500;
                    color: white;
                    width: 100%;
                    height: 80px;
                    text-align: center;
                    line-height: 80px;
                  "
                >
                  请选择其他工序
                </div>
              </div>
            </el-scrollbar>
          </div>

          <div :key="key" class="routerView" v-if="snVal != null">
            <el-scrollbar style="width: 100%">
              <router-view v-slot="{ Component, route }">
                <keep-alive
                  include="Dianjian,Jiluxiang,Duomeiticaiji,Esop,Jingu,Mingpaibangding,Shebeijilu,Tiaoshipipei,Wuliaocaiji,Screwdriver"
                >
                  <component :is="Component" :key="route.fullPath" />
                </keep-alive>
              </router-view>
            </el-scrollbar>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="midPopUp" v-if="popStatus" @click.stop="popStatus = false">
      <div class="popView">
        <div class="hang">
          请扫码：
          <ScanCodeInput
            style="width: 400px"
            v-model="seqVal"
            @keyup.enter="console.log(111)"
          />
        </div>
        <el-divider class="dark" content-position="center"
          ><div
            style="
              background-color: var(--ohos-area-bg);
              width: 100%;
              height: 100%;
              display: flex;
              font-size: 20px;
              padding: 0 20px;
              color: white;
              font-weight: 500;
            "
          >
            选择近期产品
          </div></el-divider
        >
        <el-scrollbar style="height: calc(100vh - 220px)">
          <div class="taskBox">
            <div
              class="productInfo"
              :key="item + index"
              style="background-color: var(--ohos-area-active-bg)"
              v-for="(item, index) in taskArray"
              @click="selectProduct(index)"
            >
              <div
                class="productitleText"
                style="font-size: 500; font-size: 24px; color: #000000"
              >
                {{ item.materialName }}
              </div>
              <div
                class="productitleText"
                style="
                  color: #00000060;
                  white-space: nowrap;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  width: 20vw;
                "
              >
                {{ item.materialModel }}
              </div>
              <div style="display: flex">
                <div class="productitleText" style="color: #00000060">Code</div>
                <div class="productitleText" style="color: #000000">
                  &nbsp;{{ item.materialCode }}
                </div>
              </div>
            </div>
          </div>
        </el-scrollbar>
      </div>
    </div>
  </div>
</template>

<script setup>
import OperationBar from "@/views/pro-steps/operationBar.vue";
import ScanCodeInput from "@/components/ScanCodeInput/index.vue";
import Steps from "@/views/process/components/steps.vue";
import { useProcessStore } from "@/store";
import { getOpCompent } from "@/api/prosteps";
import { getOrders } from "@/api/process";
import { getScan } from "@/api/process";

defineOptions({
  name: "ProSteps",
});
const popStatus = ref(null);
const openPop = async () => {
  await getTaskArray();
  popStatus.value = true;
};
const seqVal = ref("");
const snVal = ref(null);
const selectProduct = async (index) => {
  taskIndex.value = index;
  selectIndex.value = 0;
  //设置数据
  store.odersData.workOrderCode =
    taskArray.value[taskIndex.value].workOrderCode;
  store.processInfo.materialName =
    taskArray.value[taskIndex.value].materialName;
  store.processInfo.materialModel =
    taskArray.value[taskIndex.value].materialModel;
  if (taskArray.value[taskIndex.value].ops.length > 0) {
    opsArray.value = taskArray.value[taskIndex.value].ops;
    selectStepIndex.value = 0;
    snVal.value =
      taskArray.value[taskIndex.value].ops[selectStepIndex.value].seqs.length >
      0
        ? taskArray.value[taskIndex.value].ops[selectStepIndex.value].seqs[0]
            .seqNo
        : null;
  } else {
    selectStepIndex.value = null;
    ElMessage.warning("暂无操作步骤");
  }
  if (snVal.value != null) {
    await init(0);
  } else {
    ElMessage.warning("当前工序暂不可操作");
  }
  popStatus.value = false;
};
const store = useProcessStore();
store.odersData.productLineId = 10;
const taskArray = ref([]);
const taskIndex = ref(null);
const getScanData = async () => {
  const value = snVal.value;
  const res = await getScan({
    operationId: Number(
      taskArray.value[taskIndex.value].ops[selectStepIndex.value].operationId
    ),
    qrCode: value,
    workOrderCode: taskArray.value[taskIndex.value].workOrderCode,
    //stationId暂时随便传一个
    stationId: 1,
  });
  if (res) {
    const { code, data, msg } = res;
    if (code == "200") {
      store.scanInfo = data;
      store.useSeqNo = data.seqNo;
    }
    return true;
  } else {
    snVal.value = null;
    stepComponents.value = [];
    router.replace({ name: "ProSteps" });
    return false;
  }
};
const getTaskArray = async () => {
  const { data } = await getOrders({
    pageNo: 1,
    pageSize: 999999999,
    queryComplete: 0,
  });
  taskArray.value = data.records;
};
const opsArray = ref([]);
const selectStepIndex = ref(null);
provide("selectStepIndex", selectStepIndex);
const key = ref(false);
const route = useRoute();
const router = useRouter();
const instance = getCurrentInstance();
const loading = ref(false);
const recondOPId = ref(null);
const qrCode = ref(null);
//配置标签信息Data
const stepComponents = ref([]);
const defaultComponents = [
  {
    compentName: "物料采集",
    iconName: "wuliaocaiji",
    path: "wuliaocaiji",
    name: "Wuliaocaiji",
  },
  {
    compentName: "记录项",
    iconName: "jiluxiang",
    path: "jiluxiang",
    name: "Jiluxiang",
  },
  {
    compentName: "多媒体采集",
    iconName: "duomeiticaiji",
    path: "duomeiticaiji",
    name: "Duomeiticaiji",
  },
  {
    compentName: "ESOP",
    iconName: "ESOP",
    path: "esop",
    name: "Esop",
  },
  {
    compentName: "点检",
    iconName: "dianjian",
    path: "dianjian",
    name: "Dianjian",
  },
  {
    compentName: "设备记录",
    iconName: "shebeijilu",
    path: "shebeijilu",
    name: "Shebeijilu",
  },
  {
    compentName: "紧固",
    iconName: "jingu",
    path: "jingu",
    name: "Jingu",
  },
  {
    compentName: "调试配对",
    iconName: "tiaoshipipei",
    path: "tiaoshipipei",
    name: "Tiaoshipipei",
  },
  {
    compentName: "铭牌绑定",
    iconName: "mingpai",
    path: "mingpaibangding",
    name: "Mingpaibangding",
  },
  {
    compentName: "测试记录",
    iconName: "mingpai",
    path: "ceshijilu",
    name: "Ceshijilu",
  },
  {
    compentName: "工序表单",
    iconName: "mingpai",
    path: "execl",
    name: "Excel",
  },
  {
    compentName: "数据采集",
    iconName: "mingpai",
    path: "screwdriver",
    name: "Screwdriver",
  },
];
//当前路由在setpComponents中的index
const selectIndex = ref(0);

//配置data固定路由参数等
const setStepComponents = (data) => {
  let resData = [];
  data.forEach((item) => {
    defaultComponents.forEach((obj) => {
      if (item.compentName === obj.compentName) {
        resData.push({ ...item, ...obj });
      }
    });
  });
  return resData;
};
const getNameClass = (index) => {
  return index === selectIndex.value ? "typeBoxSelected" : "typeBoxNormal";
};
//获取当前tags列表
const getOpCompentArray = async () => {
  const { data } = await getOpCompent(
    "/" +
      `${Number(
        taskArray.value[taskIndex.value].ops[selectStepIndex.value].operationId
      )}` +
      "/" +
      `${store.scanInfo.id}`
  );
  stepComponents.value = setStepComponents(data);
  router.replace({ name: stepComponents.value[selectIndex.value].name });
};
//设置标签是否被选中
const setSelectIndex = (index) => {
  selectIndex.value = index;
};
const init = async (index) => {
  if (taskIndex.value == null) {
    return;
  }
  selectStepIndex.value = index != null ? index : 0;
  //数据设置
  store.odersData.operationId =
    taskArray.value[taskIndex.value].ops[selectStepIndex.value].operationId;
  store.processInfo.operationCode =
    taskArray.value[taskIndex.value].ops[selectStepIndex.value].operationCode;
  store.processInfo.operationName =
    taskArray.value[taskIndex.value].ops[selectStepIndex.value].operationName;
  snVal.value =
    taskArray.value[taskIndex.value].ops[selectStepIndex.value].seqs.length > 0
      ? taskArray.value[taskIndex.value].ops[selectStepIndex.value].seqs[0]
          .seqNo
      : null;
  if (snVal.value != null) {
    const res = await getScanData();
    if (res == true) {
      await getOpCompentArray();
    }
  } else {
    stepComponents.value = [];
    ElMessage.warning("当前工序暂不可操作");
  }
};
onActivated(async () => {
  //缓存组件数据逻辑
  init(selectStepIndex.value);
});
</script>

<style lang="scss" scoped>
:deep(.el-input__wrapper) {
  background-color: #000;
}
.boxStyle {
  height: calc(100vh - 80px);

  .commonTitle {
    color: var(--ohos-text);
    font-size: 28px;
  }
}
.productInfo {
  width: 100%;
  height: 100px;
  margin-bottom: 10px;
  border-radius: 16px;
  background-color: var(--ohos-area-bg);
  padding: 10px 20px;
  cursor: pointer;
  .productitleText {
    color: white;
  }
}
.optionBox {
  height: calc(100vh - 150px);
  background-color: var(--ohos-area-bg);
  border-radius: 16px;
}
.headerInfo {
  height: 20px;
  width: calc(100vw - 40px);
  // padding: 10px;
  // margin: 0 20px;
  // display: flex;
  // justify-content: space-between;
  // align-items: center;
  // border-radius: 16px;
  // border-right: 0px;
  // border-left: 0px;
  // box-sizing: border-box;
  // margin-bottom: 10px;
  // background-color: white;

  .info {
    display: flex;
    flex-shrink: 0;

    .item {
      margin: 0 5px;
      font-size: 14px;
      font-weight: 300;
    }
  }
}

.scrollbar-demo-item {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 80px;
  width: 135px;
  border-radius: 16px;
  text-align: center;
  background-color: var(--ohos-box-bg);
  margin-right: 10px;
}

.typeContainer {
  width: 100%;
  height: 80px;
  overflow-x: auto;

  .svgIcon {
    @include flex;
  }
}

.mainContentBox {
  height: calc(100vh - 110px);
}

.routerView {
  display: flex;
  flex: 1;
  overflow-y: auto;
  width: 100%;
  height: calc(100vh - 214px);
  margin-top: 20px;
  background-color: #ffffff20 !important;
  padding: 0 20px;
  border-radius: 16px;
}

.typeBox {
  height: 80px;
  width: 135px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  .name {
    height: 16px;
    font-weight: 500;
    font-size: $f20;
    line-height: 20px;
    text-align: center;
    font-style: normal;
    text-transform: none;
    margin-top: $p10;
  }
}

.typeBoxNormal {
  background: transparent;
  color: var(--ohos-text);
}

.typeBoxSelected {
  background-color: var(--ohos-area-active-bg);
  color: black !important;
}
:deep(.el-divider__text) {
  padding: 0px;
}
.popView {
  width: 80%;
  display: flex;
  flex-direction: column;
  height: 80%;
  background-color: var(--ohos-area-bg);
  border-radius: 16px;
  padding: 20px;
  .hang {
    display: flex;
    align-items: center;
    color: white;
    font-size: 20px;
  }
  .taskBox {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 每行 3 列 */
    gap: 20px; /* 设置间距为 20px */
  }
}
</style>
