<template>
    <div class="app-container">
        <el-row>
            <el-col :span="22">
                <!-- 搜索表单 -->
                <el-form ref="queryFormRef" :model="queryParams" :inline="true">
                    <el-form-item prop="memberId">
                        <el-tooltip
                            content="请输入用户ID搜索"
                            placement="bottom"
                            effect="light"
                        >
                            <el-input
                                v-model="queryParams.memberId"
                                placeholder="请输入用户ID搜索"
                                style="width: 260px"
                                clearable
                                @keyup.enter="handleQuery"
                            />
                        </el-tooltip>
                    </el-form-item>
                    <el-form-item prop="id">
                        <el-tooltip
                            content="请输入钱包ID搜索"
                            placement="bottom"
                            effect="light"
                        >
                            <el-input
                                v-model="queryParams.id"
                                placeholder="请输入钱包ID搜索"
                                style="width: 260px"
                                clearable
                                @keyup.enter="handleQuery"
                            />
                        </el-tooltip>
                    </el-form-item>
                    <el-form-item prop="coinId">
                        <el-tooltip
                            content="请输入币种标识搜索"
                            placement="bottom"
                            effect="light"
                        >
                            <el-input
                                v-model="queryParams.coinId"
                                placeholder="请输入币种标识搜索"
                                style="width: 260px"
                                clearable
                                @keyup.enter="handleQuery"
                            />
                        </el-tooltip>
                    </el-form-item>
                    <el-form-item prop="isLock" v-show="searchBox.expand">
                        <span>钱包状态：</span>
                        <el-select
                            v-model="queryParams.isLock"
                            class="filter-item"
                            placeholder="请选择"
                            style="width: 110px"
                        >
                            <el-option
                                v-for="(key, value) in state.isLockMap"
                                :key="key"
                                :label="key"
                                :value="value"
                            />
                        </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-form>
            </el-col>
        </el-row>
        <el-table
            :data="listdata"
            v-loading="state.loading"
            highlight-current-row
            border
        >
            <el-table-column align="center" prop="memberId" label="用户ID" />
            <el-table-column align="center" prop="id" label="钱包ID" />
            <el-table-column align="center" prop="coinId" label="币种标识" />
            <el-table-column align="center" prop="balance" label="可用余额">
                <template #default="scope">
                    {{ truncation(scope.row.balance) }}
                </template>
            </el-table-column>

            <el-table-column
                align="center"
                prop="frozenBalance"
                label="冻结金额"
            >
                <template #default="scope">
                    {{ truncation(scope.row.frozenBalance) }}
                </template>
            </el-table-column>

            <el-table-column align="center" prop="isLock" label="钱包状态">
                <template #default="scope">
                    {{ state.isLockMap[scope.row.isLock] }}
                </template>
            </el-table-column>
            <el-table-column align="center" prop="version" label="版本" />
            <el-table-column align="center" prop="toReleased" label="发布">
                <template #default="scope">
                    {{ truncation(scope.row.toReleased) }}
                </template>
            </el-table-column>
            <el-table-column align="center" prop="address" label="地址" />
        </el-table>
        <pagination
            v-if="state.total > 0"
            :total="state.total"
            v-model:page="state.queryParams.currentPage"
            v-model:limit="state.queryParams.pageSize"
            @pagination="handleQuery"
        />
    </div>
</template>
<script lang="ts">
name: "documentaryRecord";
</script>
<script lang="ts" setup>
import {
    ExchangeOrderQueryForm,
    walletQueryForm,
} from "../../../types/api/coinspot";
import { exchangeOrder, find_by_conditions_page } from "../../../api/coinSpot";
import { timestampToTime, truncation } from "@/utils/filter";
import { reactive, onMounted, toRefs, ref } from "vue";
import { Search, Refresh, ArrowUp, ArrowDown } from "@element-plus/icons-vue";
import { ElForm } from "element-plus";

const queryFormRef = ref(ElForm);

const state = reactive({
    loading: true,
    total: 0,
    queryParams: {
        // address: "string",
        // balance: 0,
        // coinId: "",
        currentPage: 1,
        // frozenBalance: 0,
        id: "",
        isLock: "",
        memberId: "",
        pageSize: 15,
        // toReleased: 0,
        // version: 0,
    } as walletQueryForm,
    listdata: [],
    searchBox: {
        title: "展开搜索",
        expand: false,
    },
    statusMap: {
        "1": "已挂单未成交",
        "2": "已触发",
        "3": "已成交",
        "4": "已撤单",
    },
    typeMap: {
        "1": "市场价",
        "2": "限价",
        "3": "计划",
    },
    isLockMap: {
        "1": "锁定",
        "0": "正常",
    },
});
const { listdata, queryParams, searchBox } = toRefs(state);
const handleQuery = () => {
    find_by_conditions_page(state.queryParams).then((res: any) => {
        state.listdata = res.data.records;
        state.total = res.data.total;
        state.loading = false;
    });
};

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

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

onMounted(() => handleQuery());
</script>

<style lang="less" scoped></style>
