<template>
  <div style="height: 160px;">
      <BasicForm @register="registerForm" :minHeight="160">
        <template #descinfo>
          <div class="basic-info-title">审核信息</div>
        </template>
      </BasicForm>
    </div>
</template>
<script lang="ts">
import { defineComponent, ref, computed, unref, onMounted } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form/index';
import { accountFormSchema } from './map.data.ts';
import { filterRoleList } from '/@/api/system/system';
import { useMessage } from '/@/hooks/web/useMessage';
import { TOption } from '/@/views/rule/linkedge/config/config.data';
import { PlusOutlined } from '@ant-design/icons-vue';
import { subminExamineResult } from '/@/api/resource/examine';
import { session } from '/@/utils/Memory.js';
import { object } from 'vue-types';
import eventBus from '/@/utils/eventBus';

export default defineComponent({
  name: 'AccountModal',
  components: {
    BasicModal,
    BasicForm,
    PlusOutlined,
  },
  emits: ['success', 'register'],
  setup(_, { emit }) {
    const tenantLogo = ref('');
    const loading = ref(false);
    const roleOptions = ref<TOption[]>([]);
    const isUpdate = ref(true);
    const bussid = ref('');
    const userinfo = session.getItem('userInfo');
    const getRoleList = async () => {
      const res = await filterRoleList();
      console.log(res);
      roleOptions.value = res.map((m) => {
        return {
          label: m.name,
          value: m.id,
        };
      });
    };
    onMounted(async () => {
      //await getRoleList();   //这个会导致查询失败
    });

    const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
      labelWidth: 100,
      schemas: accountFormSchema,
      showActionButtonGroup: false,
      actionColOptions: {
        span: 18,
      },
    });

    const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
      await resetFields();
      setModalProps({ confirmLoading: false });
      isUpdate.value = !!data?.isUpdate;
      if (unref(isUpdate)) {
        bussid.value = data.record.bussid;
        setFieldsValue(data.record);
      }
    });
    const getTitle = '审核';
    async function handleSubmit(bussid) {
      //setModalProps({ confirmLoading: true });
      try {
        const { createMessage } = useMessage();
        const values = await validate(); //validate(['parentId']);
        console.log('userinfo', userinfo)
        const params = {
          bussInfoId: bussid,    //业务id
          ispass: values.ispass,       //是否通过
          opinion: values.opinion,      //意见
        }
        const res = await subminExamineResult(params) as any
        if (res && res.resp_code === 0) {
          var type = res.resp_code == 0 ? 'success' : 'error';
          createMessage[type](res.resp_msg);
          eventBus.emit('shsqUpdate')
          return true
        } else {
          eventBus.emit('shsqUpdate')
          return false
        }
      } finally {
        // setTimeout(() => {
        //   setModalProps({ confirmLoading: false });
        // }, 300);
      }
    }

    return {
      registerModal,
      registerForm,
      handleSubmit,
      getTitle,
      roleOptions,
      tenantLogo,
      loading,
    };
  },
});
</script>
<style scoped lang="less">
:deep(.vben-basic-tree) {
  width: 100% !important;
}

:deep(.is-unflod) {
  display: none !important;
}

:deep(.is-flod) {
  display: none !important;
}

.basic-info-title {
  height: 19px;
  line-height: 18px;
  padding-left: 6px;
  margin-left: 20px;
  border-left: 3px solid #0671dd;
  font-family: Source Han Sans CN;
  font-size: 16px;
  font-weight: 350;
  letter-spacing: 0px;
}

:deep(.ant-calendar-picker) {
  width: 100% !important;
}
</style>
