<template>
  <a-modal
    :width="600"
    :maskClosable="false"
    :visible="visible"
    :confirm-loading="loading"
    :forceRender="true"
    title="拒绝审批"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    @ok="save"
    @close="updateVisible(false)"
  >
    <a-form ref="formRef" :model="form" :rules="rules" :label-col="{ span: 5 }">
      <a-form-item label="流程实例名称:">
        <span>{{ getFlowName() }}</span>
      </a-form-item>
      <a-form-item label="审批意见:" name="suggestContent">
        <a-textarea v-model:value="form.suggestContent" placeholder="请输入审批意见" :rows="4" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script setup name="RejectOperate">
import { ref, onMounted, reactive } from 'vue';
import { FlowTaskApi } from '../../api/FlowTaskApi';
import { message } from 'ant-design-vue';

const props = defineProps({
  visible: Boolean,
  data: Array
});

const emits = defineEmits(['update:visible', 'done']);

// 弹框加载状态
const loading = ref(false);
// 表单数据
const form = ref({
  taskId: ''
});
// 验证规则
const rules = reactive({
  suggestContent: [{ required: true, message: '请输入审批意见', type: 'string', trigger: 'blur' }]
});
// ref
const formRef = ref(null);

onMounted(() => {
  form.value.taskId = props.data[0].id;
});

// 切换弹框显示隐藏状态
const updateVisible = value => {
  emits('update:visible', value);
};

// 点击保存
const save = async () => {
  await formRef.value.validate();
  FlowTaskApi.ruTaskReject(form.value).then(res => {
    if (res.code == '00000') {
      message.success(res.message);
      emits('update:visible', false);
      emits('done');
    }
  });
};

// 获取流程名称
const getFlowName = () => {
  let name = '';
  if (props.data && props.data.length > 0) {
    name = props.data.map(item => item.definitionIdWrapper.modelName).join(',');
  }
  return name;
};
</script>

<style scoped></style>
