<template>
  <admin-modal
    title="作废"
    width="600px"
    :visible.sync="visible"
    :loading="loading"
    @on-cancel="handleCancel"
    @on-confirm="handleSubmit"
  >
    <a-form-model ref="ruleForm" :model="form" :rules="rules" class="form-descriptions-word">
      <a-descriptions bordered size="small" class="descriptions-width">
        <a-descriptions-item label="作废意见" :span="3">
          <AdminRequiredSign required />
          <a-form-model-item prop="approvalComment">
            <a-textarea
              v-model="form.approvalComment"
              placeholder="请输入作废意见"
              :auto-size="{ minRows: 3, maxRows: 5 }"
            />
          </a-form-model-item>
        </a-descriptions-item>
      </a-descriptions>
    </a-form-model>
  </admin-modal>
</template>

<script>
import { mapGetters } from 'vuex'
import { throttle } from 'lodash'

export default {
  name: 'ApprovalRefuse',
  props: {
    loading: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      visible: false,
      form: {
        approvalComment: ''
      },
      rules: {
        approvalComment: [{ required: true, message: '请输入审批意见！', trigger: 'blur' }]
      }
    }
  },
  computed: {
    ...mapGetters(['useApprovalProcessInfo'])
  },
  methods: {
    openModal() {
      this.visible = true
    },

    /**
     * 取消
     * @author Matrix
     * @since 2022/090/13
     */
    handleCancel() {
      this.$refs.ruleForm.resetFields()
      this.visible = false
    },

    /**
     * 退回环节确认
     * @author Matrix
     * @since 2022/090/13
     */
    handleSubmit: throttle(
      function () {
        const form = {
          ...this.useApprovalProcessInfo.actPojo,
          ...this.form
        }
        this.$refs.ruleForm.validate(valid => {
          if (valid) {
            this.$emit('on-ok', form)
          }
        })
      },
      3000,
      { trailing: false }
    )
  }
}
</script>

<style lang="scss" scoped>
@import '~@/assets/css/descriptios-reset.css';

::v-deep .descriptions-width {
  .ant-descriptions-item-label.ant-descriptions-item-colon {
    width: 100px;
  }
}
</style>
