<template>
  <BasicModal width="600px" v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit"
    :useWrapper="true" :minHeight="200">
    <div style="height: 50vh">
      <BasicForm @register="registerForm">
        <template #descinfo>
          <div class="basic-info-title">描述信息</div>
        </template>
      </BasicForm>
    </div>
  </BasicModal>
</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';

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() {
      setModalProps({ confirmLoading: true });
      try {
        const { createMessage } = useMessage();
        const values = await validate(); //validate(['parentId']);
        console.log('userinfo', userinfo)
        const params = {
          bussInfoId: bussid.value,    //业务id
          ispass: values.ispass,       //是否通过
          opinion: values.opinion,      //意见
        }
        const res = await subminExamineResult(params) as any
        if (res) {
          console.log(res);
          closeModal();
          emit('success');
          var type = res.resp_code == 0 ? 'success' : 'error';
          createMessage[type](res.resp_msg);
        } else {
          closeModal();
          emit('success');
          createMessage.error('审核失败!');
        }
      } 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>
