<template>
  <BasicModal
    v-bind="$attrs"
    width="720px"
    :showOkBtn="false"
    @register="registerModal"
  >
    <BasicForm @register="registerForm"/>
  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { formSchema } from './blacklist.data';
  import { getPushBlacklist } from '/@/api/platform/common/controller/pushBlacklist';
  import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
  import { useRoute } from 'vue-router';

  /** 通用变量统一声明区域 */
  const tag = ref<Nullable<string>>('');
  /** https://v3.cn.vuejs.org/api/options-data.html#emits */
  const emit = defineEmits(['success', 'register']);
  const router = useRoute();
  const [registerForm, { resetFields, setFieldsValue, validate, clearValidate, updateSchema }] = useForm({
    labelWidth: 100,
    schemas: formSchema,
    showActionButtonGroup: false,
    baseColProps: { span: 24 }
  });
  const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data: BoxPayload = { _tag: '' }) => {
    // 处理清除脏数据
    await resetFields();
    await clearValidate();
    // 处理设置数据
    tag.value = data._tag;
    const props: Partial<ModalProps> = { confirmLoading: false };
    props.title = '查看黑名单用户';
    await setFieldsValue(await getPushBlacklist({
      concernUserId: data.record?.concernUserId,
      fanUserId: data.record?.fanUserId
    }));
    // 尾部:设置处理后的最终配置数据
    setModalProps(props);
  });
</script>
