<template>
  <div class="task-submit-panel">
    <el-form ref="form" :model="form" :rules="rules" label-position="top" v-loading="loading">
      <el-row>
        <form-col :span="span" prop="submitRemark">
          <el-input v-model="form.submitRemark" type="textarea" placeholder="请输入提交说明" show-word-limit maxlength="200" />
        </form-col>
        <form-col :span="span" prop="submitAttaches">
          <image-upload v-model="form.submitAttaches" width="100px" height="100px" :limit="99" :is-show-tip="false" :file-type="fileType" />
        </form-col>
      </el-row>
    </el-form>
    <el-row type="flex" style="justify-content: flex-end" >
      <el-button type="primary" plain @click="submitForm" :loading="submitLoading" size="small" icon="el-icon-check">确 认 提 交</el-button>
    </el-row>
  </div>
</template>

<script>
import FormCol from "@/components/FormCol/index.vue";
import { submitTask } from "@/api/bst/task";
import { DatePickerOptions, FileType } from '@/utils/constants';
export default {
  name: "TaskSubmitPanel",
  components: { FormCol},
  props: {
    id: {
      type: String,
      default: null
    },
  },
  data() {
    return {
      span: 24,
      loading: false,
      submitLoading: false,
      DatePickerOptions,
      fileType: FileType.all(),
      // 表单参数
      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.reset();
            this.$emit('success');
          }).finally(() => {
            this.submitLoading = false;
          });
        }
      });
    },
  }
};
</script>

<style lang="scss" scoped>
.task-submit-panel {
  border: 1px solid #DCDFE6;
  padding: 10px;
  border-radius: 4px;
}
</style>


