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

<script lang="ts" setup>
import ScanCodeInput from "@/components/ScanCodeInput/index.vue";
import { useRepairStore } from "@/store";
import { getWorkOrderCode } from "@/api/repair";
import { getScan } from "@/api/process";
const store = useRepairStore();
const router = useRouter();
const inputValue = ref("");
const toProSteps = async () => {
  store.odersData.qrCode = inputValue.value;
  const res = await getIds();
  if (res) {
    getScanData();
  }
};
const setInputValue = (value: any) => {
  inputValue.value = value;
};
//扫码开工前获取必要的ids
const getIds = async () => {
  const { data, code } = await getWorkOrderCode(inputValue.value);
  if (code != "200") {
    return false;
  }
  store.odersData.operationId = data.operationId;
  store.odersData.workOrderCode = data.workOrderCode;
  return true;
};
const getScanData = async () => {
  const { code, data, msg } = await getScan({
    operationId: store.odersData.operationId,
    qrCode: store.odersData.qrCode,
    workOrderCode: store.odersData.workOrderCode,
    //stationId暂时随便传一个
    stationId: 0,
    source: "repair",
  });
  if (code == "200") {
    store.scanInfo = data;
    router.push({ path: "/repair/operation" });
  }
};
</script>

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

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