<script lang="ts">
export default {
    name: "list",
};
</script>

<script setup lang="ts">
import { onMounted, reactive, ref, toRefs } from "vue";
import { ElForm, ElMessage, ElTree } from "element-plus";
import {
    Search,
    Refresh,
    Connection,
    Download,
    ArrowUp,
    ArrowDown,
    Plus,
} from "@element-plus/icons-vue";
import { localStorage } from "@/utils/storage";
import { truncation } from "@/utils/filter";
import FileSaver from "file-saver";
import XLSX from "xlsx";
import router from "@/router";
import {
    memberManage,
    memberLock,
    memberUnlock,
    memberForceClose,
    memberEnableReward,
    memberDisableReward,
    forbiddenMember,
    forbiddenMemberTrans,
    setSuperPartner,
    setInviter,
    flushTheCache,
    setMoneyLock,
    addUser,
    forceOffline,
    updatePhone,
    unbindGoogle,
    ctTransfer,
    generateWallet,
    setInternal,
} from "@/api/member/list";
import {
    MemberItem,
    MemberQueryParam,
    MemberForceCloseParam,
    InviteRelationParam,
} from "@/types/api/member/list";

const emit = defineEmits(["memberClick"]);
const queryFormRef = ref(ElForm);
const dataFormRef = ref(ElForm);
const irDataFormRef = ref(ElForm);
const userFormRef = ref(ElForm);
const updatePhoneRef = ref(ElForm);
const transferParamsRef = ref(ElForm);
const profitStatusMap = {
    "1": "盈利",
    "-1": "亏损",
};

const deviceTypeMap = {
    "1": "苹果",
    "2": "安卓",
};
const commonStatusMap = {
    "0": "正常",
    "1": "非法",
    "": "全部",
};

const superPartnerMap = {
    "0": "否",
    "1": "是",
};
const lockOrRewardMap = {
    "0": "禁止平仓",
    "1": "禁止返佣",
};

const state = reactive({
    loading: true,
    // 选中ID数组
    ids: [],
    // 非单个禁用
    single: true,
    // 非多个禁用
    multiple: true,
    searchBox: {
        title: "展开搜索",
        expand: false,
    },
    queryParams: {
        pageNo: 1,
        pageSize: 15,
        superPartner: "",
        account: "",
        commonStatus: "",
        lockOrReward: "",
        isInternal: "",
        transactionStartTime: "",
        transactionEndTime: "",
        profitStatus: "",
        property: "registrationTime",
        direction: "1",
        deviceType: "",
    } as MemberQueryParam,
    userParams: {
        email: "",
        password: "",
        promotionCode: "",
    },
    memberList: [] as MemberItem[],
    total: 0,
    dialog: {
        title: "",
        visible: false,
    },
    inviterelationDialog: {
        title: "",
        visible: false,
    },
    userDialog: {
        title: "",
        visible: false,
    },
    formData: {} as MemberForceCloseParam,
    irFormData: {} as InviteRelationParam,
    rules: {
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
    },
    visible: false,
    updatePhoneParams: {
        memberId: "",
        phone: "",
    },
    updatePhoneState: false,
    roleId: "",
    transferCt: false,
    transferParams: {
        memberId: "",
        amount: "",
    },
});

const {
    loading,
    searchBox,
    queryParams,
    memberList,
    total,
    dialog,
    inviterelationDialog,
    formData,
    irFormData,
    rules,
    userDialog,
    userParams,
    visible,
    updatePhoneParams,
    updatePhoneState,
    transferCt,
    transferParams,
} = toRefs(state);

function handleQuery() {
    emit("memberClick", {});
    state.loading = true;
    // console.log(state.queryParams);
    memberManage(state.queryParams).then(({ data }) => {
        state.memberList = data.content;
        // console.log(state.memberList);
        state.total = data.totalElements;
        state.loading = false;
    });
}

/**
 * 排序
 */
function handleSortChange(column: any) {
    var sortingType = column.order;
    state.queryParams.property = column.prop;
    if (sortingType === "ascending") {
        state.queryParams.direction = "1";
    } else if (sortingType === "descending") {
        state.queryParams.direction = "0";
    } else {
        state.queryParams.property = "registrationTime";
        state.queryParams.direction = "1";
    }
    handleQuery();
}

/**
 * 查询重置
 */
function resetQuery() {
    queryFormRef.value.resetFields();
    handleQuery();
}

function handleSelectionChange(selection: any) {
    state.ids = selection.map((item: any) => item.id);
    state.single = selection.length !== 1;
    state.multiple = !selection.length;
}

function handleRowClick(row: any) {
    emit("memberClick", row);
}

/**
 * 差值
 */
function rwdiff(obj: any) {
    let v1 = obj.row.totalRecharge == null ? 0 : obj.row.totalRecharge;
    let v2 = obj.row.totalWithdraw == null ? 0 : obj.row.totalWithdraw;
    v1 = parseFloat(v1);
    v2 = parseFloat(v2);
    v2 = v2 < 0 ? Math.abs(v2) : v2;
    return v1 - v2;
}

/**
 * 余额比对
 */
function etdiff(obj: any) {
    let v1 = obj.row.estimatedBalance.toFixed(2);
    let v2 = obj.row.totalBalance.toFixed(2);
    v1 = parseFloat(v1);
    v2 = parseFloat(v2);
    let diff = Math.abs(v1) - Math.abs(v2);
    let finalValue = Math.abs(diff);
    return finalValue >= 200;
}

/**
 * 禁止平仓、可以平仓
 */
function optMemberLock(row: any) {
    if (row.isLock) {
        memberUnlock({ memberId: row.id }).then((res: any) => {
            if (!res.code) {
                ElMessage.success(res.message);
                handleQuery();
            } else {
                ElMessage.error(res.message);
            }
        });
    } else {
        memberLock({ memberId: row.id }).then((res: any) => {
            if (!res.code) {
                ElMessage.success(res.message);
                handleQuery();
            } else {
                ElMessage.error(res.message);
            }
        });
    }
}

/**
 * 禁止返佣、可以返佣
 */
function optMemberReward(row: any) {
    if (row.disableReward) {
        memberEnableReward({ memberId: row.id }).then((res: any) => {
            if (!res.code) {
                ElMessage.success(res.message);
                handleQuery();
            } else {
                ElMessage.error(res.message);
            }
        });
    } else {
        memberDisableReward({ memberId: row.id }).then((res: any) => {
            if (!res.code) {
                ElMessage.success(res.message);
                handleQuery();
            } else {
                ElMessage.error(res.message);
            }
        });
    }
}

const updateGoogleState = (row: any) => {
    // console.log(row);
    unbindGoogle(row).then((res: any) => {
        if (res.code == 0) {
            ElMessage.success(res.message);
            handleQuery();
        } else {
            ElMessage.error(res.message);
        }
    });
};

/**
 * 禁用、解禁会员
 */
function optForbiddenMember(row: any) {
    forbiddenMember({ memberId: row.id, status: !row.status ? 1 : 0 }).then(
        (res: any) => {
            if (!res.code) {
                ElMessage.success(res.message);
                handleQuery();
            } else {
                ElMessage.error(res.message);
            }
        }
    );
}

/**
 * 禁用、解禁会员交易
 */
function optForbiddenMemberTrans(row: any) {
    forbiddenMemberTrans({
        memberId: row.id,
        status: !row.transactionStatus ? 1 : 0,
    }).then((res: any) => {
        if (!res.code) {
            ElMessage.success(res.message);
            handleQuery();
        } else {
            ElMessage.error(res.message);
        }
    });
}

/**
 * 授权代理商
 */
function optSetSuperPartner(row: any) {
    setSuperPartner({
        memberId: row.id,
        superPartner: row.superPartner === "0" ? "1" : "0",
    }).then((res: any) => {
        if (!res.code) {
            ElMessage.success(res.message);
            handleQuery();
        } else {
            ElMessage.error(res.message);
        }
    });
}

// 刷新缓存

const cacheFlush = (row: any) => {
    flushTheCache({ id: row.id }).then((res: any) => {
        if (!res.code) {
            ElMessage.success(res.message);
        } else {
            ElMessage.error(res.message);
        }
    });
};

// 冻结资产

const assetManipulation = (row: any) => {
    setMoneyLock({
        isMoneyLock: row.isMoneyLock != "1" ? "1" : "0",
        memberId: row.id,
    }).then((res: any) => {
        if (res.code == 0) {
            ElMessage.success(res.message);
            handleQuery();
        }
    });
};

// 设置/取消内部账户
const setInternalAccount = (row: any) => {
    const newVal = row.isInternal == 1 ? 0 : 1;
    setInternal({ isInternal: newVal, memberId: row.id }).then((res: any) => {
        if (res.code == 0) {
            ElMessage.success(res.message);
            handleQuery();
        } else {
            ElMessage.error(res.message);
        }
    });
};

// 生成钱包

const addGenerateWallet = async (row: any) => {
    let data = (await generateWallet(row.id)) as any;
    if (data.code == 0) {
        ElMessage.success(data.message);
        handleQuery();
    }
};

/**
 * 会员平仓
 */
function showMemberForceClose(row: any) {
    state.dialog = {
        title: "用户平仓",
        visible: true,
    };

    formData.value.memberId = row.id;
    formData.value.username = localStorage.get("user");
    formData.value.password = "";
}

/**
 * 提交用户平仓
 */
function submitFormData() {
    dataFormRef.value.validate((valid: any) => {
        if (valid) {
            loading.value = true;
            memberForceClose(state.formData)
                .then((res: any) => {
                    if (!res.code) {
                        ElMessage.success(res.message);
                        cancel();
                        loading.value = false;
                    } else {
                        ElMessage.error(res.message);
                        cancel();
                        loading.value = false;
                    }
                })
                .catch(() => {
                    loading.value = false;
                });
        }
    });
}

/**
 * 取消
 */
function cancel() {
    dialog.value.visible = false;
    formData.value.memberId = 0;
    formData.value.username = "";
    formData.value.password = "";
    dataFormRef.value.resetFields();
    dataFormRef.value.clearValidate();
}

/**
 * 显示增加邀请关系弹窗
 */
function addInviterelationDialog(row: any) {
    if (row.inviterId != null) {
        ElMessage.error("已存在邀请人");
        return;
    }
    state.inviterelationDialog = {
        title: "增加邀请关系",
        visible: true,
    };

    irFormData.value.id = row.id;
}

// 打开设置手机号弹窗

const updatePhoneDialog = (row: any) => {
    state.updatePhoneState = true;
    state.updatePhoneParams.memberId = row.id;
    state.updatePhoneParams.phone = row.mobilePhone;
};

// 打开CT转账

const ctTransferDiaoding = (row: any) => {
    state.transferCt = true;
    state.transferParams.memberId = row.id;
};

// 提交手机修改

const submitupDate = async () => {
    let res = (await updatePhone(state.updatePhoneParams)) as any;
    if (res.code == 0) {
        ElMessage.success(res.message);
        handleQuery();
        updateCancel("updatePhoneState");
    }
};

const submitTransfer = async () => {
    let res = (await ctTransfer(state.transferParams)) as any;
    if (res.code == 0) {
        ElMessage.success(res.message);
        handleQuery();
        updateCancel("transferCt");
    }
};

/**
 * 提交增加邀请关系
 */
function submitIrFormData() {
    irDataFormRef.value.validate((valid: any) => {
        if (valid) {
            loading.value = true;
            // console.log(irFormData);
            if (irFormData.value.id == irFormData.value.inviterId) {
                ElMessage.warning("邀请关系不可以设置自己ID");
                loading.value = false;
            } else {
                setInviter(state.irFormData)
                    .then((res: any) => {
                        if (!res.code) {
                            ElMessage.success(res.message);
                            handleQuery();
                            irCancel();
                            loading.value = false;
                        } else {
                            ElMessage.error(res.message);
                            irCancel();
                            loading.value = false;
                        }
                    })
                    .catch(() => {
                        loading.value = false;
                    });
            }
        }
    });
}

// 强制下线

const forceOfflines = async (row: any) => {
    let res = (await forceOffline({ memberId: row.id })) as any;
    if (res.code == 0) {
        ElMessage.success(res.message);
    }
};

// 添加新用户

const addNewUser = () => {
    addUser(state.userParams).then((res: any) => {
        if (res.code == 0) {
            ElMessage.success(res.message);
            state.userDialog.visible = false;
            irCancel();
        } else {
            ElMessage.warning(res.message);
        }
    });
};

/**
 * 取消
 */
function irCancel() {
    inviterelationDialog.value.visible = false;
    userDialog.value.visible = false;
    irFormData.value.id = 0;
    irFormData.value.inviterId = "";
    irDataFormRef.value.resetFields();
    irDataFormRef.value.clearValidate();
    userParams.value.email = "";
    userParams.value.promotionCode = "";
    userParams.value.password = "";
}

const updateCancel = (index: string) => {
    if (index == "transferCt") {
        state.transferCt = false;
        transferParamsRef.value.resetFields();
    } else if (index == "updatePhoneState") {
        state.updatePhoneState = false;
        updatePhoneRef.value.resetFields();
    }
};

const goMemberdetail = (row: any) => {
    if (window.localStorage.getItem("user") == '"root"') {
        router.push({ path: "memberdetail", query: { id: row.id } });
    } else {
        ElMessage.warning("未有权限");
    }
};

const goAgentArcDiag = () => {
    router.push({ path: "agentarcdiag" });
};
const exportExcel = () => {
    var xlsxParam = { raw: true };
    /* 从表生成工作簿对象 */
    var wb = XLSX.utils.table_to_book(
        document.querySelector("#out-table"),
        xlsxParam
    );
    /* 获取二进制字符串作为输出 */
    var wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
    });
    try {
        FileSaver.saveAs(
            //Blob 对象表示一个不可变、原始数据的类文件对象。
            //Blob 表示的不一定是JavaScript原生格式的数据。
            //File 接口基于Blob，继承了 blob 的功能并将其扩展使其支持用户系统上的文件。
            //返回一个新创建的 Blob 对象，其内容由参数中给定的数组串联组成。
            new Blob([wbout], { type: "application/octet-stream" }),
            //设置导出文件名称
            "会员列表.xlsx"
        );
    } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
    }
    return wbout;
};

const closeSearch = () => {
    state.searchBox.expand = !state.searchBox.expand;
    state.searchBox.title = !state.searchBox.expand ? "展开搜索" : "收起搜索";
};

onMounted(() => {
    handleQuery();
    state.roleId = JSON.parse(
        window.localStorage.getItem("userInfo") as string
    ).roleId;
});
</script>

<template>
    <div class="app-container">
        <!-- 搜索表单 -->
        <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item prop="account">
                <el-input
                    v-model="queryParams.account"
                    placeholder="输入用户名、邮箱、手机号、姓名..."
                    style="width: 300px"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item prop="transactionStartTime">
                <el-date-picker
                    v-model="queryParams.transactionStartTime"
                    style="width: 210px"
                    format="YYYY-MM-DD HH:mm:ss"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    type="datetime"
                    placeholder="开始日期"
                />
            </el-form-item>
            <el-form-item prop="transactionEndTime">
                <el-date-picker
                    v-model="queryParams.transactionEndTime"
                    style="width: 210px"
                    format="YYYY-MM-DD HH:mm:ss"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    type="datetime"
                    placeholder="结束日期"
                />
            </el-form-item>
            <el-form-item prop="profitStatus" v-show="searchBox.expand">
                <span>盈亏：</span>
                <el-select
                    v-model="queryParams.profitStatus"
                    class="filter-item"
                    placeholder="请选择"
                    style="width: 100px"
                >
                    <el-option
                        v-for="(key, value) in profitStatusMap"
                        :key="key"
                        :label="key"
                        :value="value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item prop="deviceType" v-show="searchBox.expand">
                <span>设备：</span>
                <el-select
                    v-model="queryParams.deviceType"
                    class="filter-item"
                    placeholder="请选择"
                    style="width: 100px"
                >
                    <el-option
                        v-for="(key, value) in deviceTypeMap"
                        :key="key"
                        :label="key"
                        :value="value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item prop="commonStatus" v-show="searchBox.expand">
                <span>会员状态：</span>
                <el-select
                    v-model="queryParams.commonStatus"
                    class="filter-item"
                    placeholder="请选择"
                    style="width: 100px"
                >
                    <el-option
                        v-for="(key, value) in commonStatusMap"
                        :key="key"
                        :label="key"
                        :value="value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item prop="superPartner" v-show="searchBox.expand">
                <span>是否代理商：</span>
                <el-select
                    v-model="queryParams.superPartner"
                    class="filter-item"
                    placeholder="请选择"
                    style="width: 100px"
                >
                    <el-option
                        v-for="(key, value) in superPartnerMap"
                        :key="key"
                        :label="key"
                        :value="value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item prop="lockOrReward" v-show="searchBox.expand">
                <span>禁止平仓、返佣：</span>
                <el-select
                    v-model="queryParams.lockOrReward"
                    class="filter-item"
                    placeholder="请选择"
                    style="width: 110px"
                >
                    <el-option
                        v-for="(key, value) in lockOrRewardMap"
                        :key="key"
                        :label="key"
                        :value="value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item prop="isInternal" v-show="searchBox.expand">
                <span>账户类型：</span>
                <el-select
                    v-model="queryParams.isInternal"
                    class="filter-item"
                    placeholder="请选择"
                    style="width: 110px"
                    clearable
                >
                    <el-option label="普通账户" value="0" />
                    <el-option label="内部账户" value="1" />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" :icon="Search" @click="handleQuery"
                    >搜索</el-button
                >
                <el-button :icon="Refresh" @click="resetQuery">重置</el-button>
                <el-button
                    link
                    @click="closeSearch"
                    style="border: 0"
                    size="small"
                >
                    {{ searchBox.title }}
                    <template v-if="searchBox.expand"
                        ><el-icon class="el-icon--right"><ArrowUp /></el-icon
                    ></template>
                    <template v-else
                        ><el-icon class="el-icon--right"><ArrowDown /></el-icon
                    ></template>
                </el-button>
            </el-form-item>
            <el-row class="right-btns">
                <el-button
                    type="primary"
                    size="default"
                    :icon="Connection"
                    @click.stop="goAgentArcDiag"
                >
                    架构图
                </el-button>
                <el-button
                    type="success"
                    size="default"
                    :icon="Download"
                    @click.stop="exportExcel"
                >
                    导出
                </el-button>
                <!-- <el-button
                    type="info"
                    size="default"
                    :icon="Plus"
                    @click.stop="userDialog.visible = true"
                >
                    新增用户
                </el-button> -->
            </el-row>
        </el-form>

        <!-- 数据表格 -->
        <el-table
            id="out-table"
            ref="dataTableRef"
            v-loading="loading"
            :data="memberList"
            @selection-change="handleSelectionChange"
            @row-click="handleRowClick"
            @sort-change="handleSortChange"
            highlight-current-row
            border
        >
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column
                label="会员ID"
                prop="id"
                align="center"
                min-width="80"
                sortable="custom"
            />
            <el-table-column
                label="会员名称/注册IP"
                prop="username"
                min-width="140"
                align="center"
                sortable="custom"
                show-overflow-tooltip
            >
                <template #default="scope">
                    <div>{{ scope.row.username }}</div>
                    <div>{{ scope.row.registrationIp }}</div>
                </template>
            </el-table-column>
            <el-table-column
                label="代理商"
                prop="superPartner"
                align="center"
                sortable="custom"
            >
                <template #default="scope">
                    <div v-if="scope.row.superPartner == 0">否</div>
                    <div v-else-if="scope.row.superPartner == 1">是</div>
                    <div v-else-if="scope.row.superPartner == 2">
                        超级合伙人
                    </div>
                    <div v-else>普通会员</div>
                </template>
            </el-table-column>
            <el-table-column
                label="设备/登录IP"
                prop="deviceType"
                align="center"
            >
                <template #default="scope">
                    <div>{{ deviceTypeMap[scope.row.deviceType] }}</div>
                    <div>{{ scope.row.loginIp }}</div>
                </template>
            </el-table-column>

            <el-table-column label="邀请者ID" prop="inviterId" align="center" />
            <el-table-column
                label="账户余额(USDT)"
                prop="totalBalance"
                min-width="130"
                align="center"
                sortable="custom"
                show-overflow-tooltip
            >
                <template #default="scope">
                    <a
                        href="javascript:;"
                        @click.prevent="goMemberdetail(scope.row)"
                    >
                        {{ truncation(scope.row.totalBalance) }}
                    </a>
                </template>
            </el-table-column>
            <el-table-column
                label="资产账户"
                prop="cashBalance"
                min-width="90"
                align="center"
            >
                <template #default="scope">
                    <div :style="{ color: etdiff(scope) ? '#ff0000' : '' }">
                        {{ truncation(scope.row.cashBalance) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="合约账户"
                prop="contractBalance"
                min-width="90"
                align="center"
            >
                <template #default="scope">
                    <div :style="{ color: etdiff(scope) ? '#ff0000' : '' }">
                        {{ truncation(scope.row.contractBalance) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="跟单账户"
                prop="followBalance"
                min-width="90"
                align="center"
            >
                <template #default="scope">
                    <div :style="{ color: etdiff(scope) ? '#ff0000' : '' }">
                        {{ truncation(scope.row.followBalance) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="余额比对"
                prop="estimatedBalance"
                min-width="90"
                align="center"
                show-overflow-tooltip
            >
                <template #default="scope">
                    <div :style="{ color: etdiff(scope) ? '#ff0000' : '' }">
                        {{ truncation(scope.row.estimatedBalance) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="后台充值"
                prop="adminRecharge"
                min-width="90"
                align="center"
                show-overflow-tooltip
            >
                <template #default="scope">
                    <div v-if="scope.row.adminRecharge == null">0</div>
                    <div v-else
                        :style="{ color: scope.row.adminRecharge > 0 ? '#ff0000' : '' }"
                    >
                        {{ truncation(scope.row.adminRecharge) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="总充值"
                prop="totalRecharge"
                min-width="90"
                align="center"
                sortable="custom"
                show-overflow-tooltip
            >
                <template #default="scope">
                    <div v-if="scope.row.totalRecharge == null">0</div>
                    <div v-else>
                        {{ truncation(scope.row.totalRecharge) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="总提现"
                prop="totalWithdraw"
                min-width="90"
                align="center"
                sortable="custom"
            >
                <template #default="scope">
                    <div v-if="scope.row.totalRecharge == null">0</div>
                    <div v-else>
                        {{ truncation(scope.row.totalWithdraw) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="差值" min-width="100" align="center">
                <template #default="scope">
                    <div
                        :style="{ color: rwdiff(scope) >= 0 ? '' : '#ff0000' }"
                    >
                        {{ truncation(rwdiff(scope)) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="合约盈利"
                prop="totalProfit"
                min-width="90"
                align="center"
                sortable="custom"
            >
                <template #default="scope">
                    <div v-if="scope.row.totalProfit == null">0</div>
                    <div v-else>
                        {{ truncation(scope.row.totalProfit) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="合约亏损"
                prop="totalLoss"
                min-width="90"
                align="center"
                sortable="custom"
            >
                <template #default="scope">
                    <div v-if="scope.row.totalLoss == null">0</div>
                    <div v-else>
                        {{ truncation(scope.row.totalLoss) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="合约今日盈利"
                prop="todayProfit"
                min-width="120"
                align="center"
                sortable="custom"
            >
                <template #default="scope">
                    <div v-if="scope.row.todayProfit == null">0</div>
                    <div v-else>
                        {{ truncation(scope.row.todayProfit) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="合约今日亏损"
                prop="todayLoss"
                min-width="120"
                align="center"
                sortable="custom"
            >
                <template #default="scope">
                    <div v-if="scope.row.todayLoss == null">0</div>
                    <div v-else>
                        {{ truncation(scope.row.todayLoss) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="跟单返佣"
                prop="followAward"
                min-width="120"
                align="center"
            >
                <template #default="scope">
                    <div v-if="scope.row.followAward == null">0</div>
                    <div v-else>
                        {{ truncation(scope.row.followAward) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="跟单盈利"
                prop="followProfit"
                min-width="120"
                align="center"
            >
                <template #default="scope">
                    <div v-if="scope.row.followProfit == null">0</div>
                    <div v-else>
                        {{ truncation(scope.row.followProfit) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="跟单亏损"
                prop="followLoss"
                min-width="120"
                align="center"
            >
                <template #default="scope">
                    <div v-if="scope.row.followLoss == null">0</div>
                    <div v-else>
                        {{ truncation(scope.row.followLoss) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="跟单手续费"
                prop="followFee"
                min-width="120"
                align="center"
            >
                <template #default="scope">
                    <div v-if="scope.row.followFee == null">0</div>
                    <div v-else>
                        {{ truncation(scope.row.followFee) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="今日开仓数"
                prop="todayPosition"
                min-width="110"
                align="center"
                sortable="custom"
            />
            <el-table-column
                label="今日开单数"
                prop="todayOrder"
                min-width="110"
                align="center"
                sortable="custom"
            />

            <!-- <el-table-column
                label="今日仓位"
                prop="todayPosition"
                min-width="140"
                align="center"
                sortable="custom"
            />
            <el-table-column
                label="3分钟订单数"
                prop="orderViolateCount"
                min-width="140"
                align="center"
                sortable="custom"
            />
            <el-table-column
                label="3分钟仓位数"
                prop="violateCount"
                min-width="140"
                align="center"
                sortable="custom"
            /> -->
            <el-table-column
                label="总返拥手续费"
                prop="totalAward"
                min-width="120"
                align="center"
                sortable="custom"
            >
                <template #default="scope">
                    <div v-if="scope.row.totalAward == null">0</div>
                    <div v-else>
                        {{ truncation(scope.row.totalAward) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="今日返拥手续费"
                prop="todayAward"
                min-width="130"
                align="center"
                sortable="custom"
            >
                <template #default="scope">
                    <div v-if="scope.row.todayAward == null">0</div>
                    <div v-else>
                        {{ truncation(scope.row.todayAward) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="开平仓手续费总和"
                prop="totalFee"
                min-width="140"
                align="center"
                sortable="custom"
                show-overflow-tooltip
            >
                <template #default="scope">
                    <div v-if="scope.row.todayAward == null">0</div>
                    <div v-else>
                        {{ truncation(scope.row.totalFee) }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="注册时间"
                prop="registrationTime"
                min-width="140"
                align="center"
                sortable="custom"
            />
            <el-table-column
                label="交易状态"
                prop="transactionStatus"
                min-width="90"
                align="center"
                sortable="custom"
            >
                <template #default="scope">
                    {{ !scope.row.transactionStatus ? "冻结" : "正常" }}
                </template>
            </el-table-column>
            <el-table-column
                label="资产状态"
                prop="transactionStatus"
                min-width="90"
                align="center"
                sortable="custom"
            >
                <template #default="scope">
                    {{ scope.row.isMoneyLock ? "冻结" : "正常" }}
                </template>
            </el-table-column>
            <el-table-column
                label="状态"
                prop="status"
                min-width="80"
                align="center"
                sortable="custom"
            >
                <template #default="scope">
                    {{ scope.row.status === 0 ? "正常" : "非法" }}
                </template>
            </el-table-column>
            <el-table-column
                label="账户类型"
                prop="isInternal"
                min-width="90"
                align="center"
            >
                <template #default="scope">
                    <el-tag
                        :type="scope.row.isInternal == 1 ? 'warning' : 'info'"
                        size="small"
                    >{{ scope.row.isInternal == 1 ? "内部账户" : "普通账户" }}</el-tag>
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
                width="310"
                fixed="right"
                v-if="state.roleId != '70'"
            >
                <template #default="scope">
                    <el-tooltip
                        :content="
                            !scope.row.isLock
                                ? '已开启用户平仓'
                                : '已禁止用户平仓'
                        "
                        placement="bottom"
                        effect="light"
                    >
                        <el-button
                            :type="scope.row.isLock ? 'success' : 'info'"
                            size="small"
                            @click.stop="optMemberLock(scope.row)"
                        >
                            <span v-if="scope.row.isLock">可以平仓</span>
                            <span v-else>禁止平仓</span>
                        </el-button>
                    </el-tooltip>
                    <el-button
                        type="primary"
                        size="small"
                        @click.stop="showMemberForceClose(scope.row)"
                    >
                        用户平仓
                    </el-button>
                    <el-tooltip
                        :content="
                            !scope.row.disableReward
                                ? '已开启用户返佣'
                                : '已禁止用户返佣'
                        "
                        placement="bottom"
                        effect="light"
                    >
                        <el-button
                            :type="scope.row.disableReward ? 'success' : 'info'"
                            size="small"
                            @click.stop="optMemberReward(scope.row)"
                        >
                            <span v-if="scope.row.disableReward">可以返佣</span>
                            <span v-else>禁止返佣</span>
                        </el-button>
                    </el-tooltip>
                    <!-- <el-button size="small" type="warning">
                        刷新缓存
                    </el-button> -->
                    <el-dropdown v-if="state.roleId != '70'">
                        <span class="el-dropdown-link">
                            <div class="dropdown-text">更多</div>
                        </span>
                        <template #dropdown>
                            <el-dropdown-menu>
                                <el-dropdown-item
                                    @click.stop="optForbiddenMember(scope.row)"
                                >
                                    <span v-if="scope.row.status"
                                        >解冻账户</span
                                    >
                                    <span v-else>冻结账户</span>
                                </el-dropdown-item>
                                <el-dropdown-item
                                    @click.stop="assetManipulation(scope.row)"
                                >
                                    <span>{{
                                        scope.row.isMoneyLock != "1"
                                            ? "冻结资产"
                                            : "解冻资产"
                                    }}</span>
                                </el-dropdown-item>
                                <el-dropdown-item
                                    @click.stop="
                                        optForbiddenMemberTrans(scope.row)
                                    "
                                >
                                    <span v-if="scope.row.transactionStatus"
                                        >禁止交易</span
                                    >
                                    <span v-else>允许交易</span>
                                </el-dropdown-item>
                                <el-dropdown-item
                                    @click.stop="optSetSuperPartner(scope.row)"
                                >
                                    <span v-if="scope.row.superPartner === '0'"
                                        >授权代理商</span
                                    >
                                    <span v-else>取消代理商</span>
                                </el-dropdown-item>
                                <el-dropdown-item
                                    v-if="state.roleId != '70'"
                                    @click.stop="
                                        addInviterelationDialog(scope.row)
                                    "
                                    >增加邀请关系</el-dropdown-item
                                >
                                <el-dropdown-item
                                    @click.stop="cacheFlush(scope.row)"
                                    >刷新缓存</el-dropdown-item
                                >
                                <el-dropdown-item
                                    @click.stop="forceOfflines(scope.row)"
                                    >强制下线</el-dropdown-item
                                >
                                <el-dropdown-item
                                    @click.stop="updatePhoneDialog(scope.row)"
                                    >修改手机号</el-dropdown-item
                                >
                                <el-dropdown-item
                                    v-if="scope.row.googleState"
                                    @click.stop="updateGoogleState(scope.row)"
                                    >取消谷歌绑定</el-dropdown-item
                                >
                                <el-dropdown-item
                                    @click.stop="ctTransferDiaoding(scope.row)"
                                    >转账CT</el-dropdown-item
                                >
                                <el-dropdown-item
                                    @click.stop="addGenerateWallet(scope.row)"
                                    >生成钱包</el-dropdown-item
                                >
                                <el-dropdown-item
                                    @click.stop="setInternalAccount(scope.row)"
                                >
                                    <span v-if="scope.row.isInternal == 1">取消内部账户</span>
                                    <span v-else>设置内部账户</span>
                                </el-dropdown-item>
                            </el-dropdown-menu>
                        </template>
                    </el-dropdown>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页工具条 -->
        <pagination
            v-if="total > 0"
            :total="total"
            v-model:page="queryParams.pageNo"
            v-model:limit="queryParams.pageSize"
            @pagination="handleQuery"
        />

        <!-- 用户平仓弹窗 -->
        <el-dialog
            :title="dialog.title"
            v-model="dialog.visible"
            width="500px"
            destroy-on-close
        >
            <el-form
                ref="dataFormRef"
                :model="formData"
                :rules="rules"
                label-width="100px"
            >
                <el-form-item label="会员ID" prop="memberId">
                    <el-input
                        v-model="formData.memberId"
                        placeholder="请输入会员ID"
                        readonly
                    />
                </el-form-item>
                <el-form-item label="管理员" prop="username">
                    <el-input
                        v-model="formData.username"
                        placeholder="请输入管理员"
                        readonly
                    />
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input
                        type="password"
                        v-model="formData.password"
                        placeholder="请输入密码"
                    />
                </el-form-item>
            </el-form>

            <template #footer>
                <div class="dialog-footer">
                    <el-button
                        type="primary"
                        :loading="loading"
                        @click="submitFormData"
                        >确 定</el-button
                    >
                    <el-button @click="cancel">取 消</el-button>
                </div>
            </template>
        </el-dialog>

        <!-- 增加邀请关系弹窗 -->
        <el-dialog
            :title="inviterelationDialog.title"
            v-model="inviterelationDialog.visible"
            width="500px"
            destroy-on-close
        >
            <el-form
                ref="irDataFormRef"
                :model="irFormData"
                :rules="rules"
                label-width="100px"
            >
                <el-form-item label="会员ID" prop="userId">
                    <el-input
                        v-model="irFormData.id"
                        placeholder="请输入会员ID"
                        readonly
                    />
                </el-form-item>
                <el-form-item label="邀请人ID" prop="inviterId">
                    <el-input
                        v-model="irFormData.inviterId"
                        placeholder="请设置邀请人的ID"
                    />
                </el-form-item>
            </el-form>

            <template #footer>
                <div class="dialog-footer">
                    <el-button
                        type="primary"
                        :loading="loading"
                        @click="submitIrFormData"
                        >确 定</el-button
                    >
                    <el-button @click="irCancel">取 消</el-button>
                </div>
            </template>
        </el-dialog>
        <!-- 修改手机 -->
        <el-dialog
            title="修改手机号"
            v-model="updatePhoneState"
            width="500px"
            destroy-on-close
        >
            <el-form
                ref="updatePhoneRef"
                :model="updatePhoneParams"
                label-width="100px"
            >
                <el-form-item label="会员ID" prop="memberId">
                    <el-input
                        v-model="updatePhoneParams.memberId"
                        placeholder="请输入会员ID"
                        readonly
                    />
                </el-form-item>
                <el-form-item label="手机号" prop="phone">
                    <el-input
                        v-model="updatePhoneParams.phone"
                        placeholder="请设置新的手机号"
                    />
                </el-form-item>
            </el-form>

            <template #footer>
                <div class="dialog-footer">
                    <el-button
                        type="primary"
                        :loading="loading"
                        @click="submitupDate"
                        >确 定</el-button
                    >
                    <el-button @click="updateCancel('updatePhoneState')"
                        >取 消</el-button
                    >
                </div>
            </template>
        </el-dialog>
        <!-- 转账CT -->
        <el-dialog
            title="CT转账"
            v-model="transferCt"
            width="500px"
            destroy-on-close
        >
            <el-form
                ref="transferParamsRef"
                :model="transferParams"
                label-width="100px"
            >
                <el-form-item label="会员ID" prop="memberId">
                    <el-input
                        v-model="transferParams.memberId"
                        placeholder="请输入会员ID"
                        readonly
                    />
                </el-form-item>
                <el-form-item label="数量" prop="amount">
                    <el-input
                        v-model="transferParams.amount"
                        placeholder="请输入数量"
                    />
                </el-form-item>
            </el-form>

            <template #footer>
                <div class="dialog-footer">
                    <el-button
                        type="primary"
                        :loading="loading"
                        @click="submitTransfer"
                        >确 定</el-button
                    >
                    <el-button @click="updateCancel('transferCt')"
                        >取 消</el-button
                    >
                </div>
            </template>
        </el-dialog>
        <!-- 增加新用户弹窗 -->
        <el-dialog
            :title="userDialog.title"
            v-model="userDialog.visible"
            width="500px"
            destroy-on-close
        >
            <el-form
                ref="irDataFormRef"
                :model="userParams"
                :rules="rules"
                label-width="100px"
            >
                <el-form-item label="账号" prop="email">
                    <el-input
                        v-model.trim="userParams.email"
                        placeholder="请输入账号"
                    />
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input
                        v-model.trim="userParams.password"
                        placeholder="请设置密码"
                    />
                </el-form-item>
                <el-form-item label="邀请人会员ID" prop="promotionCode">
                    <el-input
                        v-model.trim="userParams.promotionCode"
                        placeholder="请输入邀请人会员ID"
                    />
                </el-form-item>
            </el-form>

            <template #footer>
                <div class="dialog-footer">
                    <el-button
                        type="primary"
                        :loading="loading"
                        @click="addNewUser"
                        >确 定</el-button
                    >
                    <el-button @click="irCancel">取 消</el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<style lang="scss" scoped>
a {
    color: #2d8cf0;
}
a:hover {
    color: #0c25f1;
}
.right-btns {
    float: right;
    margin-bottom: 20px;
}
.resource-tree-node {
    width: 100%;
    flex-wrap: wrap;
    display: flex;
    font-size: 14px;
    justify-content: flex-end;
    margin: 0 50px;
    .node-content {
        width: 400px;
        display: flex;
        flex-wrap: wrap;
    }
    .el-divider--vertical {
        height: 2em !important;
    }
}
.el-tree-node__content {
    height: auto !important;
}

.el-checkbox-group {
    display: flex;
    flex-wrap: wrap;
    &:hover {
        background-color: var(--el-tree-node-hover-bg-color);
    }
    &:active {
        background-color: var(--el-tree-node-hover-bg-color);
    }
}

.el-checkbox.el-checkbox--small {
    margin: 5px;
    z-index: 999;
    background: #fff;
}
.dropdown-text {
    margin-left: 12px;
    height: 24px;
    line-height: 24px;
    font-size: 12px;
}
</style>
