<template>
  <div class="edit-popup">
    <popup
      ref="popupRef"
      title="创建日程安排"
      :async="true"
      width="800px"
      @confirm="handleSubmit"
      @close="handleClose"
    >
      <el-form class="formdata" :model="detailsdt" label-width="120px">
        <el-form-item label="任务日期">
          <el-date-picker
            v-model="formData.time"
            type="date"
            placeholder="选择日期"
          />
        </el-form-item>
        <el-form-item label="任务模板">
          <el-input v-model="formData.template_id" />
        </el-form-item>
        <el-form-item label="任务排期">
          <el-input v-model="formData.scheduling_id" />
        </el-form-item>
      </el-form>
    </popup>
  </div>
</template>

<script lang="ts" setup name="taskEidt">
import type { FormInstance } from "element-plus";
import Popup from "@/components/popup/index.vue";
import { apiTaskCreat, apiTaskView } from "@/api/task";
import { apiTaskTemplateLists } from "@/api/task_template";
import { timeFormat } from "@/utils/util";
import { reactive, onUpdated, type PropType } from "vue";
import DialogIndexMan from "./dialog_index_man.vue";

const emit = defineEmits(["success", "close"]);
const formRef = shallowRef<FormInstance>();
const popupRef = shallowRef<InstanceType<typeof Popup>>();
const mode = ref("add");
const detailsdt = ref({});
const datetime = ref([]);

const templateList = ref([]);
const getTemplateList = () => {
  apiTaskTemplateLists().then((res) => {
    templateList.value = res;
    console.log(templateList.value);
  });
};
getTemplateList();

// 表单数据
const formData = reactive({
  time: "",
  template_id: "",
  scheduling_id: "",
});

// 提交按钮
// const handleSubmit = async () => {
//   const data = { ...formData };
//   mode.value == "edit" ? await apiTaskCreat(data) : await apiTaskCreat(data);
//   popupRef.value?.close();
//   emit("success");
// };

//打开弹窗
const open = (type = "add") => {
  mode.value = type;
  popupRef.value?.open();
};

// 关闭回调
const handleClose = () => {
  emit("close");
};

defineExpose({
  open,
});
</script>
<style lang="scss" scoped>
.formdata {
  .el-form-item {
    .el-date-picker {
      width: 100%;
    }
  }
}
</style>
