<template>
  <a-modal
    v-model="showDialog"
    @ok="saveMonthlyReportComment"
    @cancel="closeMonthlyReportCommentDialog"
    title="整改进度月报"
    width="60%"
    class="outerDialog custom_dialog">
    <a-form :model="MonthlyReportComment" :label-col="{span: 4}" :wrapper-col="{span: 20}" ref="MonthlyReportCommentForm">
      <a-upload-dragger
        action="/modular-source/6ace62b8e2bb467d98286d260aebcef2/pdcApi/file/insert?bizId=&bizType=3"
        @change="uploadSuccess"
        :headers="header"
        accept=".xls"
        ref="upload"
        class="upload-demo"
        style="width: 100%; text-align: center">
        <p class="ant-upload-drag-icon">
          <a-icon type="inbox" />
        </p>
        <p class="ant-upload-text">
          将文件拖到此处，或<em>点击上传</em>
        </p>
        <p class="ant-upload-hint">
          只能上传xls文件
        </p>
      </a-upload-dragger>
      <a-form-item label="备注" prop="Comment">
        <a-textarea v-model:value="MonthlyReportComment.Comment" :rows="8" />
      </a-form-item>
    </a-form>
    <span slot="okText">提交</span>
  </a-modal>
</template>

<script>
import upload from '../../../widgets/uploadFileWithType';
export default {
  name: 'MonthlyReportCommentDialog',
  props: {
    isAg: {
      type: Number,
      default: 1,
    },
    activityName: {
      type: String,
      default: '进度上报',
    },
  },
  components: {
    upload,
  },
  data() {
    return {
      header: {
        persId: localStorage.getItem('persId'),
        accessToken: localStorage.getItem('accessToken'),
        orgId: localStorage.getItem('currentOrgId'),
      },
      MonthlyReportComment: {
        Comment: '',
        isAg: this.isAg,
        fileExt: '',
        filePath: '',
      },
      fileExt: '',
      filePath: '',
      showDialog: true,
    };
  },
  created() {},
  methods: {
    uploadSuccess(response) {
      if (response.file.status === 'done') {
        this.fileExt = response.file.response.data.fileExt;
        this.filePath = response.file.response.data.filePath;
      } else if (response.file.status === 'error') {
        this.$message.error('上传失败！');
      }
    },
    closeMonthlyReportCommentDialog() {
      this.$emit('closeMonthlyReportCommentDialog');
    },
    saveMonthlyReportComment() {
      // this.$refs.upload.submit()
      this.$refs.MonthlyReportCommentForm.validate((valid) => {
        if (valid) {
          if (this.MonthlyReportComment.Comment === '') {
            if (this.MonthlyReportComment.isAg === 1) {
              this.MonthlyReportComment.Comment = '同意';
            } else {
              this.MonthlyReportComment.Comment = '不同意';
            }
          }
          this.MonthlyReportComment.Comment =
            this.activityName + ' - ' + this.MonthlyReportComment.Comment;
          this.MonthlyReportComment.fileExt = this.fileExt;
          this.MonthlyReportComment.filePath = this.filePath;
          this.$emit('saveMonthlyReportComment', this.MonthlyReportComment);
          this.$refs.MonthlyReportCommentForm.resetFields();
        } else {
          console.log('MonthlyReportCommentForm valid failed!!');
          return false;
        }
      });
    },
  },
  removeNewSupervision(arg) {
    if (arg) {
      console.log(arg);
      // let args = this.gwComFiles.concat(arg);
      // this.updatefilelist(args);
    }
    this.$emit('saveMonthlyReportComment', this.MonthlyReportComment);
    this.$refs.MonthlyReportCommentForm.resetFields();
    // this.$message.success('保存成功');
    this.$refs.uploadFile.init();
  },
};
</script>

<style lang='less' scoped>

</style>
