<template>
  <!-- 扫码板块 -->
  <div class="icon">
    <img class="imgIcon" src="@/assets/icons/shaoma.svg" />
  </div>
  <div class="body">
    <ScanCodeInput v-model="inputValue" @keyup.enter="toProSteps" />
  </div>
</template>

<script lang="ts" setup>
import ScanCodeInput from "@/components/ScanCodeInput/index.vue";
import { useProcessStore } from "@/store";

import { emitter, EventsNames } from "@/utils/common";
const store = useProcessStore();
const router = useRouter();
const inputValue = ref("");
//选择状态
const selectOrderIndex = inject("selectOrderIndex");
//扫码状态
const scanStatus = inject("scanStatus");
//选中的oderItem
const selectSeqArray = inject("selectSeqArray");
//工序data
const opsArray = inject("opsArray");
const toProSteps = () => {
  if (inputValue.value == "") return ElMessage.error("流转卡号不能为空值！");

  if (selectOrderIndex.value == null)
    return ElMessage.error("请选择所操作工单！");
  let status = false;
  for (let i = 0; i < selectSeqArray.value.length; i++) {
    if (selectSeqArray.value[i].seqNo == inputValue.value) {
      status = true;
      opsArray.value = selectSeqArray.value[i].ops;
      store.odersData.qrCode = inputValue.value;
    }
  }
  if (status) {
    ElMessage.success("扫码成功！");
    scanStatus.value = true;
    emitFnc();
  } else {
    ElMessage.error("流转卡号有误！");
    scanStatus.value = false;
  }
  inputValue.value = "";
  // getScanData();
};
//扫码成功重置工序index
const emitFnc = () => {
  emitter.emit(EventsNames.PROCESS_STEPINDEX, null);
};

</script>

<style lang="scss" scoped>
.icon {
  @include flex;
  height: 120px;

  .imgIcon {
    width: 100px;
    height: 100px;
  }
}
</style>
