<template>
    <div class="list-view">
        <page-title> </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.dateRange" @input="initData" name="交易"></created-at-picker>
                </el-form-item>

                <el-form-item label="*用户">
                    <user-search v-model="formData.userId"></user-search>
                </el-form-item>

                <el-form-item label="*账户类型">
                    <el-select v-model="formData.acctType">
                        <el-option label="可用账户" value="USEROWN_AVAILABLE"></el-option>
                        <el-option label="待结算账户" value="USEROWN_PSETTLE"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="出入帐标识">
                    <el-select v-model="formData.flagDc" clearable="">
                        <el-option label="出账" value="DEBIT"></el-option>
                        <el-option label="入账" value="CREDIT"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="交易时间排序">
                    <el-select v-model="formData.sortType" @input="initData" clearable="">
                        <el-option label="降序" value="DESC"></el-option>
                        <el-option label="升序" value="ASC"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div class="tool-wrapper">
                <div class="tool-right">
                    <el-tag type="success">收入总金额({{ totalInAmount || 0 }}￥)</el-tag>
                    &nbsp;
                    <el-tag type="warning">支出总金额({{ totalOutAmount || 0 }}￥)</el-tag>
                </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"
        >
            <el-table-column v-if="multipleMode" align="center" type="selection" width="50"> </el-table-column>
            <el-table-column prop="date_acct" label="账务日期" width="100"> </el-table-column>
            <el-table-column prop="oid_acctno" label="账户号" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="jno_acct" label="资金流水号" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="accp_txnno" label="交易单号" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="txn_type" label="交易类型">
                <template v-slot="scope">
                    {{ txnTypeMap[scope.row.txn_type] }}
                </template>
            </el-table-column>
            <el-table-column prop="txn_time" label="交易时间" :formatter="formatTime" width="140"> </el-table-column>
            <el-table-column prop="flag_dc" label="出入帐标识">
                <template v-slot="scope">
                    <el-tag v-if="scope.row.flag_dc == 'DEBIT'" type="danger">出账</el-tag>
                    <el-tag v-if="scope.row.flag_dc == 'CREDIT'" type="success">入账</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="amt" label="金额"> </el-table-column>
            <el-table-column prop="amt_bal" label="交易后余额"> </el-table-column>
            <el-table-column prop="memo" label="资金流水备注" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="jno_cli" label="商户订单号" show-overflow-tooltip> </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 moment from 'moment';

export default {
    components: { SortableHeader },
    name: 'LianlianTradeLog',
    mixins: [pageableTable],
    data() {
        let startDate = moment().subtract(1, 'months').format('YYYY-MM-DD HH:mm:ss');
        let endDate = moment().format('YYYY-MM-DD HH:mm:ss');
        return {
            multipleMode: false,
            search: '',
            url: '/walletLianlianpay/tradeLogList',
            downloading: false,
            formData: {
                dateRange: [startDate, endDate],
                acctType: 'USEROWN_AVAILABLE',
                userId: null,
                flagDc: ''
            },
            totalOutAmount: '',
            totalInAmount: '',
            txnTypeMap: {
                USER_TOPUP: '用户充值',
                MCH_TOPUP: '商户充值',
                GENERAL_CONSUME: '普通消费',
                SECURED_CONSUME: '担保消费',
                SERVICE_FEE: '手续费收取',
                INNER_FUND_EXCHANGE: '内部代发',
                OUTER_FUND_EXCHANGE: '外部代发',
                ACCT_CASH_OUT: '账户提现',
                SECURED_CONFIRM: '担保确认',
                CAPITAL_CANCEL: '手续费应收应付核销',
                INNER_DIRECT_EXCHANGE: '定向内部代发'
            }
        };
    },
    computed: {
        selection() {
            return this.$refs.table.selection.map(i => i.id);
        }
    },
    methods: {
        beforeGetData() {
            return {
                search: this.search,
                query: { del: false, ...this.formData }
            };
        },
        afterGetData(res) {
            this.totalOutAmount = res.totalOutAmount;
            this.totalInAmount = res.totalInAmount;
        },
        formatTime(row, column, cellValue, index) {
            if (cellValue) {
                return moment(cellValue, 'YYYYMMDDHHmmss').format('YYYY-MM-DD HH:mm:ss');
            }
        }
    }
};
</script>
<style lang="less" scoped>
.tool-wrapper {
    display: block;
    overflow: hidden;

    .tool-right {
        float: left;
    }
}
</style>
