<template>
  <div class="midPopUp" @click="handleClose" v-if="modelValue">
    <div class="container" @click.stop>
      <div class="headerTittle">{{ title }}</div>
      <div class="describeText">请扫料箱编码</div>
      <ScanCodeInput v-model="scanCode" @keyup.enter="handleSubmit" />
      <div class="bottomBtn">
        <el-button class="leftBtn" @click="handleClose">关闭</el-button>
        <el-button class="rightBtn" @click="handleSubmit" type="primary">确定</el-button>
      </div>
      <BindingScan v-model="showBinding" :operationId="operationId" :workOrderCode="workOrderCode" @close="handleClose" />
    </div>
  </div>
</template>

<script lang="ts" setup>
import ScanCodeInput from "@/components/ScanCodeInput/index.vue";
import BindingScan from "./bindingScan.vue";
import { getBoxDetail } from "@/api/prepare";
const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false,
  },
  title: {
    type: String,
  },
  workOrderCode: {
    type: String,
  },
  operationId: {
    type: String,
  },
});
const boxInfoData = ref({});
provide("boxInfoData", boxInfoData);
const scanCode = ref("");
const showBinding = ref(false);
const emits = defineEmits(["update:modelValue", "scancodefnc", "gettable"]);
const handleClose = () => {
  scanCode.value = "";
  emits("update:modelValue", false);
  emits("gettable");
};
const handleSubmit = () => {
  getBoxInfo();
};
const getBoxInfo = async () => {
  const { data } = await getBoxDetail({
    workOrderCode: props.workOrderCode,
    operationId: props.operationId,
    vehicleCode: scanCode.value,
  });
  if (data.isEnable == 1) {
    boxInfoData.value = data;
    showBinding.value = true;
  } else {
    ElMessage.warning("该物料箱包含其他物料！");
    return;
  }
};
</script>

<style lang="scss" scoped>
.midPopUp {
  z-index: 4;
}

.container {
  background-color: #f1f3f5;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 300px;
  padding: 20px 40px;
}

.infoBox {
  width: 100%;
  height: 80px;
  background-color: white;
  border-radius: 16px;
  margin-bottom: $p10;
}

.bottomBtn {
  width: 100%;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: $p10 10% 0 10%;

  .leftBtn {
    height: 55px;
    width: 45%;
    border-radius: 16px;
    font-size: $f20;
    color: black;
    background-color: #00000015;
    border: 0px;
  }

  .rightBtn {
    height: 55px;
    width: 45%;
    border-radius: 16px;
    font-size: $f20;
    color: white;
  }
}
</style>
