<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="targetMemberId">
                        <el-tooltip
                            content="请输入交易员会员ID搜索"
                            placement="bottom"
                            effect="light"
                        >
                            <el-input
                                v-model="queryParams.targetMemberId"
                                placeholder="请输入收款会员ID搜索"
                                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
                type="selection"
                width="55"
                align="center"
                :selectable="selectEnable"
            />
            <el-table-column type="index" width="50" align="center" />
            <el-table-column
                prop="coin.name"
                width="50"
                align="center"
                label="类型"
            />
            <el-table-column
                align="center"
                prop="memberId"
                label="转账会员ID"
            />
            <el-table-column
                align="center"
                prop="targetMemberId"
                label="收款会员ID"
                show-overflow-tooltip
            />
            <el-table-column align="center" prop="amount" label="转账金额">
                <template #default="scope">
                    <span>{{ truncation(scope.row.amount) }}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" prop="fee" label="交易手续费">
                <template #default="scope">
                    <span>{{ truncation(scope.row.fee) }}</span>
                </template>
            </el-table-column>

            <el-table-column align="center" prop="createTime" label="转账时间">
            </el-table-column>
            <el-table-column
                label="状态"
                prop="status"
                align="center"
                sortable="custom"
            >
                <template #default="scope">
                    <span v-if="scope.row.status == 0">待审核</span>
                    <span v-else-if="scope.row.status == 1">等待放币</span>
                    <span v-else-if="scope.row.status == 2">失败</span>
                    <span v-else-if="scope.row.status == 3">成功</span>
                    <span v-else>用户取消</span>
                </template>
            </el-table-column>
            <el-table-column label="备注/Memo" prop="remark" align="center" />
            <!-- <el-table-column
                label="操作"
                align="center"
                width="130"
                fixed="right"
            >
                <template #default="scope">
                    <el-button
                        v-if="scope.row.status == 0"
                        type="primary"
                        size="small"
                        @click.stop="viewCheck(scope.row)"
                        >审核</el-button
                    >
                    <el-button
                        v-else
                        type="success"
                        size="small"
                        @click.stop="viewCheck(scope.row)"
                        >查看</el-button
                    >
                </template>
            </el-table-column> -->
        </el-table>
        <pagination
            v-if="state.total > 0"
            :total="state.total"
            v-model:page="state.queryParams.pageNo"
            v-model:limit="state.queryParams.pageSize"
            @pagination="handleQuery"
        />
    </div>
</template>

<script lang="ts" setup>
import { timestampToTime, truncation } from "@/utils/filter";
import { reactive, onMounted, toRefs, ref, nextTick } from "vue";
import { Search, Refresh, ArrowUp, ArrowDown } from "@element-plus/icons-vue";
import { ElForm } from "element-plus";
import { transferPageQuery } from "@/api/finance/index";
import router from "@/router";

const queryFormRef = ref(ElForm);

const state = reactive({
    loading: true,
    total: 0,
    queryParams: {
        pageNo: 1,
        pageSize: 15,
        memberId: "",
        targetMemberId: "",
    },
    listdata: [],
    searchBox: {
        title: "展开搜索",
        expand: false,
    },
});
const { listdata, queryParams, searchBox } = toRefs(state);
const handleQuery = () => {
    transferPageQuery(state.queryParams).then((res: any) => {
        state.listdata = res.data.content;
        state.total = res.data.totalElements;
        state.loading = false;
    });
};

/**
 * 多选是否允许被选中
 * @param row 行数据
 * @param index 序号
 */
const selectEnable = (row: any, index: number) => {
    return row.status == 0;
};

/**
 * 审核/查看
 */
const viewCheck = (row: any) => {
    router.push({ path: "internalRecordDetail", query: { id: row.id } });
};

/**
 * 展开/收起搜索
 */
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>
