<template>
  <a-modal
    v-model:visible="showDialog"
    @ok="saveActivityComment"
    @cancel="closeActivityCommentDialog"
    :confirmLoading="loading"
    title="操作意见"
    width="60%"
    class="outerDialog custom_dialog">
    <a-form :model="activityComment" :rules="rules" :label-col="{span: 8}" :wrapper-col="{span: 15}" ref="activityCommentForm">
      <a-form-item label="意见" prop="Comment">
        <a-textarea v-model:value="activityComment.Comment" :rows="8" type="textarea" />
      </a-form-item>
    </a-form>
    <span slot="okText">提交</span>
  </a-modal>
</template>

<script>
export default {
  name: 'ActivityCommentDialog',
  props: {
    isAg: {
      type: Number,
      default: 1,
    },
    activityName: {
      type: String,
      default: '默认操作',
    },
    tag: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      activityComment: {
        Comment: '',
        isAg: this.isAg,
      },
      showDialog: true,
      rules: {
        Comment: [
          { required: false, message: '操作意见不能为空', trigger: 'blur' },
        ],
      },
      loading: false,
    };
  },
  created() {},
  methods: {
    closeActivityCommentDialog() {
      this.$emit('closeActivityCommentDialog');
    },
    saveActivityComment() {
      this.loading = true;
      if (this.activityComment.isAg == '0') {
        if (!this.activityComment.Comment) {
          this.$message.warning('请输入不同意原因');
          this.loading = false;
          return false;
        }
      }
      this.$refs.activityCommentForm.validate((valid) => {
        if (valid) {
          if (this.activityComment.Comment === '') {
            if (this.activityComment.isAg === 1) {
              this.activityComment.Comment = '同意';
            } else {
              this.activityComment.Comment = '不同意';
            }
          }
          this.activityComment.Comment =
            this.activityName + ' - ' + this.activityComment.Comment;
          this.$emit('saveActivityComment', this.activityComment);
          this.$refs.activityCommentForm.resetFields();
        } else {
          console.log('activityCommentForm valid failed!!');
          return false;
        }
      });
    },
  },
};
</script>

<style lang='less' scoped>

</style>
