<template>
  <el-dialog title="手动运行定时任务" v-model="show" width="400px" append-to-body draggable>
    <el-form label-width="120px">
      <el-form-item label="任务名称">
        {{ files.find(a => a.id == form.taskId)?.name }}
      </el-form-item>
      <template v-if="(files.find(a => a.id == form.taskId)?.params || []).length > 0">
        <el-divider>参数：SpEL表达式</el-divider>
        <el-alert style="margin-bottom: 1rem;">#root,#act：ApplicationContext<br />#bean: 执行任务的方法所在的bean</el-alert>
        <el-form-item v-for="(item, index) in files.find(a => a.id == form.taskId)?.params || []" :key="index"
          :label="item">
          <el-input v-model="form.paramELs[index]" />
        </el-form-item>

      </template>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitForm">手动运行</el-button>
        <el-button @click="show = false">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, getCurrentInstance } from 'vue';
import { ElLoading, ElMessage } from 'element-plus';
import * as api from '../cron';

const emit = defineEmits(["success"]);

const { proxy } = getCurrentInstance();
const form = ref({
});
const show = ref(false);

const files = ref([])

const open = async (taskList, obj = {}) => {
  form.value = { ...obj };
  show.value = true;
  files.value = taskList;
}

const submitForm = async () => {
  api.start(form.value.id, form.value.taskId, form.value.paramELs)
  ElMessage.success('手工运行任务成功')
  show.value = false
}


defineExpose({ open });
</script>

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