<script lang="ts">
  export default {
    name: 'transferdetail'
  };
</script>

<script setup lang="ts">
import { onMounted, reactive, ref, toRefs } from 'vue';
import {
  coinTransferDetail
} from '@/api/system/coin';
import { ElForm } from 'element-plus';
import {
  CoinTransferQueryParam,
  CoinTransferItem
} from '@/types/api/system/coin';

const queryFormRef = ref(ElForm);

const state = reactive({
  loading: true,
  queryParams: {
    pageNo: 1,
    pageSize: 50,
    unit: '',
  } as CoinTransferQueryParam,
  list: [] as CoinTransferItem[],
  total: 0
});

const {
  loading,
  queryParams,
  list,
  total
} = toRefs(state);

function handleQuery() {
  state.loading = true;
  coinTransferDetail(state.queryParams).then(({ data }) => {
    state.list = data.content;
    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 = null
    state.queryParams.direction = null
  }
  handleQuery()
}

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

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

<template>
  <div class="app-container">
    <!-- 搜索表单 -->
    <el-form ref="queryFormRef" :model="queryParams" :inline="true">
    </el-form>

    <!-- 数据表格 -->
    <el-table
        ref="dataTableRef"
        v-loading="loading"
        :data="list"
        @sort-change="handleSortChange"
        highlight-current-row
        border
        >
        <el-table-column label="ID" prop="id" align="center" sortable="custom" />
        <el-table-column label="转入币种" prop="unit" min-width="160" align="center" sortable="custom" />
        <el-table-column label="转入时间" prop="transferTime" min-width="160" align="center" sortable="custom" />
        <el-table-column label="转入数量" prop="amount" min-width="110" align="center" sortable="custom" />
        <el-table-column label="钱包余额" prop="balance" min-width="110" align="center" sortable="custom">
            <template #default="scope">
                <span v-if="scope.row.balance==null"></span>
                <span v-else>
                    {{ scope.row.balance < 1 ? scope.row.balance.toFixed(8) : scope.row.balance }}
                </span>
            </template>
        </el-table-column>
        <el-table-column label="最小手续费" prop="minerFee" min-width="120" align="center" sortable="custom">
            <template #default="scope">
                <span v-if="scope.row.minerFee==null"></span>
                <span v-else>
                    {{ scope.row.minerFee < 1 ? scope.row.minerFee.toFixed(8) : scope.row.minerFee }}
                </span>
            </template>
        </el-table-column>
        <el-table-column label="操作人" prop="adminName" min-width="110" align="center" />
        <el-table-column label="冷钱包地址" prop="coldAddress" min-width="120" align="center" sortable="custom" />
        <el-table-column label="转入单号" prop="transactionNumber" min-width="120" align="center" sortable="custom" />
    </el-table>

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