<script setup>
import order from "./component/order.vue";
import detail from "./component/detail.vue";
import padding from "@/components/padding.vue";
import { ref, nextTick, onMounted } from "vue";
import { ElMessage } from "element-plus";

const type = ref(1);
const code = ref("");
const inputRef = ref(null);
const orderRef = ref(null);

const handleEnterKey = () => {
  if(code.value == "") return ElMessage.error("请输入订单编号");
  type.value = 2;
  nextTick(() => {
    orderRef.value.setCode(code.value);
  });
};

const reInit = ()=>{
  handleEnterKey();
}

onMounted(() => {
  nextTick(() => {
    inputRef.value.focus();
  });
});
</script>

<template>
  <div class="my-card">
    <div class="my-code" v-show="type == 1">
      <h2>订单核销</h2>
      <div class="box">
        <input
          ref="inputRef"
          v-model="code"
          placeholder=""
          class="input"
          @keyup.enter="handleEnterKey"
        />
        <div class="btn" @click="handleEnterKey">查询</div>
      </div>
    </div>
    <order v-show="type == 2" style="flex-shrink: 0" ref="orderRef" @backOne="type=1"/>
    <padding v-show="type == 2" />
    <detail v-show="type == 2" ref="detailRef" @reInit="reInit"/>
  </div>
</template>

<style lang="scss">
.my-card {
  display: flex;
  .my-code {
    height: 70%;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .box {
      width: 38rem;
      position: relative;

      .input {
        width: 100%;
        height: 3rem;
        box-sizing: border-box;
        border-radius: 4rem;
        border: 1px solid #1890ff;
        padding: 0 1rem;
        font-size: 1.1rem;

        &:focus {
          outline: none;
          box-shadow: 0 0 0.31rem #1890ff; /* 可选：添加阴影效果以突出显示聚焦状态 */
          transition: all 0.2s ease-in-out;
        }
      }
      .btn {
        position: absolute;
        right: 0;
        top: 0;
        width: 5rem;
        height: 100%;
        border-radius: 0 4rem 4rem 0;
        background: #1890ff;
        color: #fff;
        display: flex;
        justify-content: center;
        align-items: center;
      }
    }
  }
}
/* 修改滚动条的样式 */
::-webkit-scrollbar {
  width: 0.31rem; /* 设置滚动条的宽度 */
}

/* 设置滚动条的轨道样式 */
::-webkit-scrollbar-track {
  background-color: #f1f1f1; /* 设置轨道的背景色 */
  /* margin: 1.25rem 0; */
}

/* 设置滚动条的滑块样式 */
::-webkit-scrollbar-thumb {
  background-color: #ccc; /* 设置滑块的背景色 */
  border-radius: 0.31rem; /* 设置滑块的圆角 */
}

/* 设置滚动条鼠标悬停时的滑块样式 */
::-webkit-scrollbar-thumb:hover {
  background-color: #999; /* 设置鼠标悬停时滑块的背景色 */
}
</style>
