<template>
  <my-dialog
    :visible="visible"
    header="异常处理审核"
    :width="800"
    attach="body"
    :closeOnOverlayClick="false"
    @close="emit('update:visible', false)"
  >
    <t-form colon>
      <t-row :gutter="[0, 0]">
        <t-col :span="12">
          <t-form-item label="审核" required-mark>
            <t-radio-group
              v-model="dingExceptionApprove"
              allow-uncheck
              :options="optionList"
            ></t-radio-group>
          </t-form-item>
        </t-col>
      </t-row>
    </t-form>
    <template #foot>
      <t-button theme="default" @click="emit('update:visible', false)"
        >取消</t-button
      >
      <t-button theme="primary" @click="handleAudit">保存</t-button>
    </template>
  </my-dialog>
</template>

<script setup name="AbnormalAudit">
import { ref } from 'vue';
import { workHoursWaitCheckAuditApi } from '@/api/work-hours';
// import { customerTypeFilter, timestampFilter } from '@/utils/filter';
import { DialogPlugin, MessagePlugin } from 'tdesign-vue-next';

const emit = defineEmits(['update:visible', 'confirm']);
const props = defineProps({
  visible: Boolean,
  curRow: Object,
});

const dingExceptionApprove = ref('PASS');
const optionList = ref([
  {
    label: '通过',
    value: 'PASS',
  },
  {
    label: '拒绝',
    value: 'NO_PASS',
  },
]);
const handleAudit = async () => {
  const actionName = dingExceptionApprove.value === 'PASS' ? '通过' : '拒绝';
  const warningBody = `确定要${actionName}当前记录吗`;

  const confirmDia = DialogPlugin({
    header: '操作提示',
    body: warningBody,
    confirmBtn: '确定',
    cancelBtn: '取消',
    onConfirm: async () => {
      confirmDia.hide();
      let data = {
        dingExceptionApprove: dingExceptionApprove.value,
        taskId: props.curRow.taskId,
      };
      const res = await workHoursWaitCheckAuditApi(data, false).catch(() => {});
      if (!res) return;
      MessagePlugin.success('操作成功');
      emit('update:visible', false);
      emit('confirm');
    },
  });
};
</script>
