<template>
  <el-card class="card-box" header="开始任务">
    <el-form ref="form" :model="form" :rules="rules" label-position="top" v-loading="loading">
      <el-row>
        <form-col :span="span" label="预计完成时间" prop="expectFinishTime">
          <el-date-picker clearable
            style="width: 100%;"
            v-model="form.expectFinishTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            default-time="18:00:00"
            :picker-options="DatePickerOptions.DISABLE_PAST"
            placeholder="请选择预计完成时间">
          </el-date-picker>
        </form-col>
      </el-row>
    </el-form>
    <el-button type="primary" plain style="width: 100%;" @click="submitForm" :loading="submitLoading" icon="el-icon-check">确 认 开 始</el-button>
  </el-card>
</template>

<script>
import FormCol from "@/components/FormCol/index.vue";
import { startTask } from "@/api/bst/task";
import { DatePickerOptions } from '@/utils/constants';
export default {
  name: "TaskStartPanel",
  components: { FormCol},
  props: {
    id: {
      type: String,
      default: null
    },
  },
  data() {
    return {
      span: 24,
      loading: false,
      submitLoading: false,
      DatePickerOptions,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.reset();
  },
  methods: {
    // 表单重置
    reset() {
      this.form = {
        id: this.id,
        expectFinishTime: null,
      };
      this.resetForm("form");
    },
    // 提交按钮
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.submitLoading = true;
          startTask(this.form).then(response => {
            this.$modal.msgSuccess("操作成功");
            this.$emit('success');
          }).finally(() => {
            this.submitLoading = false;
          });
        }
      });
    },
  }
};
</script>