<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 { getScan } from "@/api/process";
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 == "") {
    ElMessage.error("流转卡号不能为空值！");
    inputValue.value == "";
    return;
  }

  if (selectOrderIndex.value == null) {
    inputValue.value == "";
    ElMessage.error("请选择所操作工单！");
    return;
  }
  // 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;
  // }

  getScanData();
};
const getScanData = async () => {
  const value = inputValue.value;
  inputValue.value = "";
  const { code, data, msg } = await getScan({
    operationId: Number(store.odersData.operationId),
    qrCode: value,
    workOrderCode: store.odersData.workOrderCode,
    //stationId暂时随便传一个
    stationId: 1,
  });
  if (code == "200") {
    store.scanInfo = data;
    store.useSeqNo = data.seqNo;
    router.push({ path: "/pro-steps" });
  }
  inputValue.value = "";
};
//扫码成功重置工序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>
