<template>
  <div class="midPopUp" v-if="checkPop" @click="checkPop = false">
    <div class="container" @click.stop>
      <div class="title titleText" style="font-size: 38px">检验批号</div>
      <el-scrollbar class="listBody">
        <el-form ref="formRef" :model="form" label-width="aotu" :key="formKey">
          <el-form-item
            :rules="{
              required: true,
              message: '该选项为必选',
              trigger: 'change',
            }"
            label="批号："
            prop="no"
            ><el-input v-model="form.no" />
          </el-form-item>
        </el-form>
      </el-scrollbar>
      <div class="btns">
        <el-button
          type="primary"
          @click="validate"
          class="titleText"
          style="width: 260px; height: 50px; border-radius: 16px"
          >提 交
        </el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { getJYNum, sendJYData } from "@/api/process";
import { emitter, EventsNames } from "@/utils/common";
import { useDictionaryStore } from "@/store";
import { useProcessStore } from "@/store/modules/processView";
const dictS = useDictionaryStore();
const store = useProcessStore();
const route = useRoute();
//点检项数组
const form = ref({});
const resetForm = () => {
  form.value = {};
};
const formRef = ref(null);
const checkPop = ref(false);
const formKey = ref(false);
const getNumData = async () => {
  const { data } = await getJYNum(store.odersData.workOrderCode);
  form.value.no = data;
};
const open = () => {
  formKey.value = !formKey.value;
  resetForm();
  getNumData();
  checkPop.value = true;
};
const validate = () => {
  formRef.value.validate((valid) => {
    if (valid) {
      submit();
    } else {
      ElMessage.error("请检查是否有未填项");
    }
  });
};
const submit = async () => {
  const { data, code } = await sendJYData({
    workOrderCode: store.odersData.workOrderCode,
    checkCode: form.value.no,
  });
  if (code == "200") {
    ElMessage.success("提交成功！");
    resetForm();
    formKey.value = !formKey.value;
    checkPop.value = false;
  }
};

defineExpose({ open });
</script>

<style lang="scss" scoped>
.title {
  width: 100%;
  height: 50px;
  text-align: center;
  margin-bottom: 20px;
}

:deep(label) {
  display: inline-block;
}

.listBody {
  height: calc(100% - 160px);
  padding: 0 $p20;

  .item {
    width: 100%;
    background-color: white;
    border-radius: 16px;
    margin: 10px 0;
    padding: $p10 $p20;

    .showInfo {
      .remark {
        font-size: $f20;
        color: red;
        margin-right: 5px;
      }
    }
  }
}

.btns {
  width: 100%;
  height: 50px;
  @include flex;
}

//表单字体样式
:deep(.el-form-item__label) {
  font-size: $f20;
  max-width: 600px;
  display: inline-block;
  height: auto;
  padding-right: 0px;
}

:deep(.el-radio__label) {
  font-size: $f20;
}

:deep(.el-radio) {
  display: flex;
  align-items: center;
}

:deep(.el-textarea__inner) {
  font-size: $f20;
}
</style>
