<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="submitAttaches">
          <image-upload v-model="form.submitAttaches" />
        </form-col>
        <form-col :span="span" label="备注" prop="submitRemark">
          <el-input v-model="form.submitRemark" type="textarea" placeholder="请输入备注" show-word-limit maxlength="200" />
        </form-col>
      </el-row>
    </el-form>
    <el-button type="primary" plain @click="submitForm" :loading="submitLoading" style="width: 100%;" icon="el-icon-check">确 认 提 交</el-button>
  </el-card>
</template>

<script>
import FormCol from "@/components/FormCol/index.vue";
import { submitTask } from "@/api/bst/task";
import { DatePickerOptions } from '@/utils/constants';
export default {
  name: "TaskSubmitPanel",
  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,
        submitAttaches: null,
        submitRemark: null,
      };
      this.resetForm("form");
    },
    // 提交按钮
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.submitLoading = true;
          submitTask(this.form).then(response => {
            this.$modal.msgSuccess("提交成功");
            this.$emit('success');
          }).finally(() => {
            this.submitLoading = false;
          });
        }
      });
    },
  }
};
</script>