<template>
  <el-form :model="prioritySetForm" ref="prioritySetRef">
    <el-form-item
      style="position: relative"
      label="优先级代号"
      prop="taskOrder"
      :rules="[
        {
          required: true,
          message: '请输入优先级代号,不可以为空!',
          trigger: 'blur',
        },
        {
          validator: verifyWageHour,
        },
      ]"
    >
      <el-input v-model="prioritySetForm.taskOrder"></el-input>
    </el-form-item>
    <el-form-item style="position: absolute; bottom: 2px; right: 20px">
      <el-button
        style="width: 90px"
        @click="$emits('update:updateShowPrioritySet', false)"
        >取消</el-button
      >
      <el-button style="width: 90px" type="primary" @click="prioritySetSubmit"
        >提交</el-button
      >
    </el-form-item>
  </el-form>
</template>
<script setup>
import { ref, reactive, onMounted } from "vue";
import templateHooks from "@/Hooks/templateHooks";

const props = defineProps({
  currentRow: {
    type: Object,
    default: () => {},
  },
  updateShowPrioritySet: Boolean,
});
const $emits = defineEmits(["update:updateShowPrioritySet", "confirmSubmit"]);

const prioritySetRef = ref(); //优先级设置Ref
const prioritySetForm = reactive({
  taskOrder: "", // 优先级代号
});
// 任务优先级提交
const prioritySetSubmit = () => {
  prioritySetRef.value.validate((valid) => {
    if (valid) {
      $messageBox
        .confirm("您确定要进行提交吗？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
          center: true,
        })
        .then(() => {
          let postData = {
            planId: props.currentRow.id,
            taskOrder: prioritySetForm.taskOrder,
          };
          $emits("confirmSubmit", postData);
        })
        .catch((e) => {});
    }
  });
};
// 自定义优先级校验规则
const verifyWageHour = (rule, value, callback) => {
  if (value) {
    value = value.toString();
    if (isNaN(Number(value))) {
      callback(new Error("仅可输入数字!"));
    } else {
      callback();
    }
  } else {
    callback(new Error("请输入优先级代号,不可以为空!"));
  }
};
onMounted(() => {
  console.log(props.currentRow);
  prioritySetForm.taskOrder = props.currentRow.taskOrder;
});
const { $message, $messageBox } = templateHooks();
</script>

<style lang="scss" scoped></style>
