<template>
    <!-- 审核客户资料-->
    <a-modal class="commonModal custom_info_btn_check" title="审核客户资料" v-model:visible="visible" @cancel="cancel" centered width="890px">
        <template #footer>
            <a-button key="submit" class="cancelBtn" @click="cancel">取消 </a-button>
            <a-button key="submit" type="primary" :loading="loading" :disabled="loading" @click="submit">审核通过 </a-button>
            <a-button key="submit" type="primary" :loading="loading" :disabled="loading" @click="refuseSubmit">审核拒绝 </a-button>
        </template>
        <Detail :selectedRow="selectedRow" />
    </a-modal>
</template>

<script lang="ts">
import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
import { _closeModal } from '@/common/setup/modal/modal';
import { getUserId } from '@/services/bus/user';
import { QueryCustomInfoType } from '@/services/go/ermcp/customInfo/interface';
import { auditWskhUserInfo } from '@/services/proto/accountinfo';
import { AuditWskhUserInfoReq } from '@/services/proto/accountinfo/interface';
import { Modal } from 'ant-design-vue';
import { defineComponent, PropType, ref } from 'vue';
import Detail from '../common-detail/index.vue';

export default defineComponent({
    name: 'custom_check',
    emits: ['cancel', 'update'],
    components: { Detail },
    props: {
        selectedRow: {
            type: Object as PropType<QueryCustomInfoType>,
            default: {},
        },
    },
    setup(props, context) {
        const loading = ref<boolean>(false);
        const { visible, cancel } = _closeModal(context);

        // 审核通过
        function submit() {
            Modal.confirm({
                title: '是否确认审核通过',
                okText: '确认通过',
                cancelText: '取消',
                onOk() {
                    let reqParam: AuditWskhUserInfoReq = {
                        UserID: props.selectedRow.userid, // uint64 用户ID(自增ID)SEQ_WSKH_USERINFO
                        UserState: 4, // uint32 审核状态：4-审核通过，5-审核拒绝
                        AuditedBy: getUserId(), // uint64 审核人
                        AuditRemark: '',
                    };
                    requestResultLoadingAndInfo(auditWskhUserInfo, reqParam, loading, ['审核成功', '审核失败:']).then(() => {
                        cancel(true);
                    });
                },
                onCancel() {},
            });
        }

        // 审核拒绝
        function refuseSubmit() {
            Modal.confirm({
                title: '是否确认审核拒绝',
                okText: '审核拒绝',
                cancelText: '取消',
                onOk() {
                    let reqParam: AuditWskhUserInfoReq = {
                        UserID: props.selectedRow.userid, // uint64 用户ID(自增ID)SEQ_WSKH_USERINFO
                        UserState: 5, // uint32 审核状态：4-审核通过，5-审核拒绝
                        AuditedBy: getUserId(), // uint64 审核人
                        AuditRemark: '',
                    };
                    requestResultLoadingAndInfo(auditWskhUserInfo, reqParam, loading, ['审核拒绝成功', '审核拒绝失败:']).then(() => {
                        cancel(true);
                    });
                },
                onCancel() {},
            });
        }

        return {
            visible,
            cancel,
            submit,
            loading,
            refuseSubmit,
        };
    },
});
</script>

<style lang="less">
.custom_info_btn_check {
    .upload {
        .look {
            margin-left: 0;
        }
    }
}
</style
>;
