<template>
    <div class="list-view">
        <page-title>
            <el-button
                @click="download('/transferMoneyInfo/excel')"
                icon="el-icon-upload2"
                :loading="downloading"
                :disabled="fetchingData"
                class="filter-item"
            >
                导出
            </el-button>
        </page-title>
        <div class="filters-container">
            <el-form :model="formData" :inline="true" @keyup.enter.native="initData">
                <el-form-item label="创建时间">
                    <created-at-picker v-model="formData.createdAt" @input="initData" name="创建"></created-at-picker>
                </el-form-item>
                <el-form-item label="目标用户ID">
                    <el-input v-model="formData.toUserId" placeholder="目标用户ID" clearable=""></el-input>
                </el-form-item>

                <el-form-item label="转账订单号">
                    <el-input v-model="formData.tradeNo" placeholder="转账订单号" clearable=""></el-input>
                </el-form-item>

                <el-form-item label="账号">
                    <el-input v-model="formData.accountNo" placeholder="账号" clearable=""></el-input>
                </el-form-item>

                <el-form-item label="账号名称">
                    <el-input v-model="formData.accountName" placeholder="账号名称" clearable=""></el-input>
                </el-form-item>

                <el-form-item label="批次号">
                    <el-input v-model="formData.batchNo" placeholder="批次号" clearable=""></el-input>
                </el-form-item>

                <el-form-item label="转账状态">
                    <el-select v-model="formData.status" :clearable="true">
                        <el-option
                            v-for="(value, key) in transferStatusMap"
                            :label="value"
                            :value="key"
                            :key="key"
                        ></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="支付平台">
                    <el-select v-model="formData.payPlatform" :clearable="true">
                        <el-option
                            v-for="(value, key) in payPlatformMap"
                            :label="value"
                            :value="key"
                            :key="key"
                        ></el-option>
                    </el-select>
                </el-form-item>
            </el-form>

            <div class="tool-wrapper">
                <div class="tool-right"></div>
                <el-input
                    placeholder="搜索..."
                    v-model="search"
                    clearable
                    class="filter-item search"
                    @keyup.enter.native="initData"
                >
                    <el-button @click="initData" slot="append" icon="el-icon-search"> </el-button>
                </el-input>
            </div>
        </div>
        <el-table
            :data="tableData"
            row-key="id"
            ref="table"
            header-row-class-name="table-header-row"
            header-cell-class-name="table-header-cell"
            row-class-name="table-row"
            cell-class-name="table-cell"
            :height="tableHeight"
            v-loading="fetchingData"
            @selection-change="handleSelectionChange"
        >
            <el-table-column v-if="multipleMode" align="center" type="selection" width="50"> </el-table-column>
            <el-table-column prop="id" label="ID" width="80"> </el-table-column>
            <el-table-column prop="tradeNo" label="转账订单号" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="toUserId" label="目标用户"> </el-table-column>
            <el-table-column prop="transferMethod" label="转账方式" min-width="100">
                <template v-slot="scope">
                    <el-tag
                        :type="transferMethodMap[scope.row.transferMethod].type"
                        v-if="transferMethodMap[scope.row.transferMethod]"
                    >
                        {{ transferMethodMap[scope.row.transferMethod] }}
                    </el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="accountType" label="账户类型" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="accountNo" label="账号" min-width="140" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="accountName" label="账号名称" show-overflow-tooltip> </el-table-column>
            <!-- <el-table-column prop="transferOrderId" label="第三方订单ID" show-overflow-tooltip > </el-table-column> -->
            <el-table-column prop="amount" label="交易金额"> </el-table-column>

            <el-table-column prop="transactionId" label="交易流水" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="transferDate" label="交易时间" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="status" label="状态">
                <template v-slot="scope">
                    <el-tag
                        :type="transferStatusMap[scope.row.status].type"
                        v-if="transferStatusMap[scope.row.status]"
                        >{{ transferStatusMap[scope.row.status] }}</el-tag
                    >
                </template>
            </el-table-column>
            <el-table-column prop="result" label="转账结果" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="divMoneyId" label="分账ID"> </el-table-column>
            <el-table-column prop="batchNo" label="批次"> </el-table-column>
            <el-table-column prop="payPlatform" label="支付平台" min-width="100">
                <template v-slot="scope">
                    <el-tag
                        :type="payPlatformMap[scope.row.payPlatform].type"
                        v-if="payPlatformMap[scope.row.payPlatform]"
                        >{{ payPlatformMap[scope.row.payPlatform] }}</el-tag
                    >
                </template>
            </el-table-column>
            <el-table-column prop="createdAt" label="创建时间" width="150">
                <template v-slot:header="{ column }">
                    <sortable-header :column="column" :current-sort="sort" @changeSort="changeSort"> </sortable-header>
                </template>
            </el-table-column>
        </el-table>
        <div class="pagination-wrapper">
            <el-pagination
                background
                @size-change="onSizeChange"
                @current-change="onCurrentChange"
                :current-page="page"
                :page-sizes="[10, 20, 30, 40, 50]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="totalElements"
            >
            </el-pagination>
        </div>
    </div>
</template>
<script>
import pageableTable from '@/mixins/pageableTable';
import SortableHeader from '../components/SortableHeader.vue';
import { transferMethodMap, transferStatusMap, payPlatformMap } from '@/utils/constant.js';

export default {
    components: { SortableHeader },
    name: 'transferMoneyInfoList',
    mixins: [pageableTable],
    data() {
        return {
            multipleMode: true,
            search: '',
            url: '/transferMoneyInfo/all',
            downloading: false,
            formData: {
                createdAt: '',
                toUserId: '',
                tradeNo: '',
                status: null,
                payPlatform: ''
            },
            transferStatusMap,
            transferMethodMap,
            payPlatformMap,
            multipleSelection: []
        };
    },
    computed: {
        selection() {
            return this.$refs.table.selection.map(i => i.id);
        }
    },
    methods: {
        beforeGetData() {
            return {
                search: this.search,
                query: { del: false, ...this.formData }
            };
        },
        afterGetData() {
            //nothing
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        }
    }
};
</script>
<style lang="less" scoped>
.tool-wrapper {
    display: block;
    overflow: hidden;

    .tool-right {
        float: left;
    }
}

.desc-wrapper {
    padding: 0px;
    overflow: hidden;
    .desc-line {
        margin-bottom: 10px;
        float: left;
        width: 50%;
        display: flex;
        .desc-label {
            font-weight: 800;
            width: 140px;
        }

        .desc-label:after {
            content: ':';
        }

        .desc-content {
            padding-left: 10px;
        }
    }
}
</style>
