<template>
    <!-- 新增交易用户 -->
    <a-modal class="commonModal add-traders" title="新增交易用户" v-model:visible="visible" @cancel="cancel" centered :maskClosable="false" width="890px">
        <template #footer>
            <a-button key="submit" type="primary" :loading="loading" @click="submit">完成</a-button>
        </template>
        <a-form class="inlineForm" ref="formRef" :model="formState" :rules="rules">
            <a-row :gutter="24">
                <a-col :span="12">
                    <a-form-item label="用户名称" name="rolename">
                        <a-input class="dialogInput" style="width: 200px" v-model:value="formState.rolename" placeholder="请输入账户名称" />
                    </a-form-item>
                </a-col>
            </a-row>
        </a-form>
    </a-modal>
</template>

<script lang="ts">
import { _closeModal } from '@/common/setup/modal/modal';
import { defineComponent, ref, PropType } from 'vue';
import { ErmcpLoginUserEx } from '@/services/go/ermcp/account/interface';
import { LoginaccountOperateReq } from '@/services/proto/accountinfo/interface';
import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
import { loginAccountOperate } from '@/services/proto/accountinfo';
import { validateAction } from '@/common/setup/form';
import { handleTradeForm } from '../setup';
import { TraderFormState } from '../interface';
import { getUserId } from '@/services/bus/user';

export default defineComponent({
    name: 'account_info_trade_btn_add',
    emits: ['cancel', 'update'],
    props: {
        selectedData: {
            type: Object as PropType<ErmcpLoginUserEx>,
            default: {},
        },
    },
    setup(props, context) {
        // 控制关闭弹窗
        const { visible, cancel } = _closeModal(context);
        const loading = ref<boolean>(false);

        const { rules, formState, formRef } = handleTradeForm();
        function submit() {
            validateAction<TraderFormState>(formRef, formState).then((res) => {
                const reqParam: LoginaccountOperateReq = {
                    operatetype: 1, // uint32 操作类型-1:新增 2:修改 3:新增管理员 4:修改管理员 5:锁定 6:解锁 7:注销 8:恢复 9:重置密码 10:新增登录帐号 11:停用用户 12：恢复用户 13:修改用户信息
                    roleids: [24],
                    logintaaccounts: [],
                    accountname: res.rolename,
                };
                requestResultLoadingAndInfo(loginAccountOperate, reqParam, loading, ['新增成功', '新增失败:']).then(() => {
                    cancel(true);
                });
            });
        }

        // 修改  operatetype = 13
        // 注销  operatetype = 11
        return {
            formState,
            rules,
            formRef,
            visible,
            cancel,
            submit,
            loading,
        };
    },
});
</script>