<template>
    <div class="app-container">
        <el-row>
            <el-col :span="22">
                <!-- 搜索表单 -->
                <el-form ref="queryFormRef" :model="queryParams" :inline="true">
                    <el-form-item prop="customerMemberId">
                        <el-tooltip
                            content="请输入用户会员ID搜索"
                            placement="bottom"
                            effect="light"
                        >
                            <el-input
                                v-model="queryParams.customerMemberId"
                                placeholder="请输入学生ID搜索"
                                style="width: 260px"
                                clearable
                                @keyup.enter="handleQuery"
                            />
                        </el-tooltip>
                    </el-form-item>
                    <el-form-item prop="traderMemberId">
                        <el-tooltip
                            content="请输入交易员会员ID搜索"
                            placement="bottom"
                            effect="light"
                        >
                            <el-input
                                v-model="queryParams.traderMemberId"
                                placeholder="请输入交易员会员ID搜索"
                                style="width: 260px"
                                clearable
                                @keyup.enter="handleQuery"
                            />
                        </el-tooltip>
                    </el-form-item>
                    <el-form-item prop="customerName" v-show="searchBox.expand">
                        <el-tooltip
                            content="请输入用户手机号搜索"
                            placement="bottom"
                            effect="light"
                        >
                            <el-input
                                v-model="queryParams.customerName"
                                placeholder="请输入学生昵称"
                                style="width: 260px"
                                clearable
                                @keyup.enter="handleQuery"
                            />
                        </el-tooltip>
                    </el-form-item>
                    <el-form-item prop="traderName" v-show="searchBox.expand">
                        <el-tooltip
                            content="请输入用户邮箱搜索"
                            placement="bottom"
                            effect="light"
                        >
                            <el-input
                                v-model="queryParams.traderName"
                                placeholder="请输入交易员昵称"
                                style="width: 260px"
                                clearable
                                @keyup.enter="handleQuery"
                            />
                        </el-tooltip>
                    </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="customerId" label="用户ID" />
            <el-table-column
                align="center"
                prop="customerMemberId"
                label="学生ID"
            />
            <el-table-column
                align="center"
                prop="customerName"
                label="学生昵称"
            />
            <el-table-column align="center" prop="traderId" label="交易员ID" />
            <el-table-column
                align="center"
                prop="traderMemberId"
                label="交易员会员ID"
            />
            <el-table-column
                align="center"
                prop="traderName"
                label="交易员昵称"
            />
            <el-table-column align="center" prop="leverage" label="杠杆" />
            <el-table-column align="center" prop="symbol" label="交易对" />
            <el-table-column align="center" prop="leverage" label="杠杆">
                <template #default="scope">
                    <span
                        :style="{
                            'background-color': `${
                                scope.row.direction
                                    ? 'red'
                                    : 'rgb(66, 185, 131)'
                            }`,
                            padding: '3px',
                            color: 'white',
                            borderRadius: '5px',
                        }"
                        >{{ scope.row.leverage + "X" }}</span
                    >
                </template>
            </el-table-column>
            <el-table-column align="center" prop="direction" label="方向">
                <template #default="scope">
                    <span
                        :style="{
                            'background-color': `${
                                scope.row.direction
                                    ? 'red'
                                    : 'rgb(66, 185, 131)'
                            }`,
                            padding: '3px',
                            color: 'white',
                            borderRadius: '5px',
                        }"
                        >{{
                            scope.row.direction ? "卖出开空" : "买入开多"
                        }}</span
                    >
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="createdTime"
                label="创建时间"
                width="150"
            >
                <template #default="scope">
                    <span>{{ timestampToTime(scope.row.createdTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="entrustTime"
                label="跟单时间"
                width="150"
            >
                <template #default="scope">
                    <span>{{ timestampToTime(scope.row.entrustTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" prop="volume" label="交易量">
                <template #default="scope">
                    {{
                        (Math.floor(scope.row.volume * 100) / 100).toFixed(2)
                    }}</template
                >
            </el-table-column>
            <!-- <el-table-column align="center" prop="nickname" label="创建时间">
                <template #default="scope">
                    <span>{{ timestampToTime(scope.row.createdTime) }}</span>
                </template>
            </el-table-column> -->
        </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 { recordform } from "@/api/documentary/index";
import { recordItme } from "@/types/api/documentary/index";
import { timestampToTime } 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: {
        currentPage: 1,
        pageSize: 15,
        customerMemberId: "" as any,
        traderMemberId: "" as any,
        customerName: "",
        traderName: "",
    },
    listdata: [] as recordItme[],
    searchBox: {
        title: "展开搜索",
        expand: false,
    },
});
const { listdata, queryParams, searchBox } = toRefs(state);
const handleQuery = () => {
    if (state.queryParams.customerMemberId == "") {
        state.queryParams.customerMemberId == "";
    } else {
        state.queryParams.customerMemberId = Number(
            state.queryParams.customerMemberId
        );
    }
    if (state.queryParams.traderMemberId == "") {
        state.queryParams.traderMemberId == "";
    } else {
        state.queryParams.traderMemberId = Number(
            state.queryParams.traderMemberId
        );
    }
    recordform(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>
