<template>
    <div class="list-view">
        <page-title>
            <el-button
                @click="download('/userFundAccount/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="账号">
                    <el-input v-model="formData.accountNo"       placeholder="账号"  clearable=""  ></el-input>
                </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.accountStatus"  :clearable="true" @change="initData">
                        <el-option v-for="(value,key) in accountStatusMap" :label="value"  :value="key" :key="key"></el-option>
                    </el-select>
                </el-form-item>
                
            </el-form>
             <div class="tool-wrapper">       
                 <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="id" label="ID" width="100"> </el-table-column>
            <el-table-column prop="userId" label="用户ID" > </el-table-column>
             <el-table-column prop="accountType" label="资金账户类型" width="140"> 
                <template slot-scope="scope">
                        <el-tag :type="accountTypeMap[scope.row.accountType].type" v-if="accountTypeMap[scope.row.accountType]">{{accountTypeMap[scope.row.accountType]}}</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="accountNo" label="账号" min-width="160"  show-overflow-tooltip> </el-table-column>
            <el-table-column prop="accountName" label="账户名称"  min-width="100"  show-overflow-tooltip> </el-table-column>
            <el-table-column prop="userBankCardId" label="用户绑卡ID" min-width="100"  show-overflow-tooltip> </el-table-column>
            <el-table-column prop="thirdUserId" label="第三方用户ID" min-width="100"  show-overflow-tooltip> </el-table-column>
            <el-table-column prop="thirdBankId" label="第三方绑卡ID" min-width="100"  show-overflow-tooltip> </el-table-column>
            <el-table-column prop="thirdBankNo" label="银行子账户" min-width="100"  show-overflow-tooltip> </el-table-column>
            
            <el-table-column prop="accountStatus" label="状态" width="100"> 
                <template slot-scope="scope">
                        <el-tag :type="accountStatusMap[scope.row.accountStatus].type" v-if="accountStatusMap[scope.row.accountStatus]">{{accountStatusMap[scope.row.accountStatus]}}</el-tag>
                </template>
            </el-table-column>
            
            <el-table-column prop="accountError" label="账户信息"  min-width="160"  show-overflow-tooltip > </el-table-column>
            <el-table-column prop="orderNo" label="开户订单号"  min-width="160"  show-overflow-tooltip > </el-table-column>
            
            
            <el-table-column prop="applyTime" label="申请开户时间" width="140">
                <template slot="header" slot-scope="{ column }">
                    <sortable-header :column="column" :current-sort="sort" @changeSort="changeSort"> </sortable-header>
                </template>
            </el-table-column>
            <el-table-column prop="notifyTime" label="通知时间" width="140"> </el-table-column>
            
            <el-table-column prop="createdAt" label="创建时间" width="140">
                <template slot="header" slot-scope="{ column }">
                    <sortable-header :column="column" :current-sort="sort" @changeSort="changeSort"> </sortable-header>
                </template>
            </el-table-column>

             <el-table-column label="操作"  min-width="100" fixed="right">
                <template slot-scope="scope">
                    <el-button type="primary" size="mini"  @click="checkBalance(scope.row.id)" >查询余额</el-button>
                </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>



        <el-dialog title="账户余额"  :visible.sync="balanceResultDialog">
            <div class="desc-wrapper">
                <div class="desc-line">
                    <div class="desc-label">银行子账户</div>
                    <div class="desc-content">{{balanceResultData.bankAccount}}</div>
                </div>
                 <div class="desc-line">
                    <div class="desc-label">账户类型</div>
                    <div class="desc-content">{{balanceResultData.accountType}}</div>
                </div>
                 <div class="desc-line">
                    <div class="desc-label">可用余额</div>
                    <div class="desc-content">{{balanceResultData.availableBalance}}</div>
                </div>
                <div class="desc-line">
                    <div class="desc-label">冻结余额</div>
                    <div class="desc-content">{{balanceResultData.freezeBalance}}</div>
                </div>
                <div class="desc-line">
                    <div class="desc-label">待结算余额</div>
                    <div class="desc-content">{{balanceResultData.psettleBalance}}</div>
                </div>
                <div class="desc-line">
                    <div class="desc-label"><b>合计金额</b></div>
                    <div class="desc-content">{{balanceResultData.totalBalance}}</div>
                </div>
                <div class="desc-line">
                    <div class="desc-label">缓存时间</div>
                    <div class="desc-content">{{balanceResultData.freshTime}}</div>
                </div>
                
            </div>
            <div slot="footer">
            
                <el-button type="primary" @click="balanceResultDialog = false;">关闭</el-button>
                
            </div>
        </el-dialog>


    </div>
</template>
<script>
import pageableTable from '@/mixins/pageableTable';
import SortableHeader from '../components/SortableHeader.vue';
import {accountStatusMap,accountTypeMap} from "@/utils/constant.js";


export default {
    components: { SortableHeader },
    name: 'UserFundAccountList',
    mixins: [pageableTable],
    data() {
        return {
            multipleMode: false,
            search: '',
            url: '/userFundAccount/all',
            downloading: false,
            formData:{
                 createdAt: "",
                 accountNo:"",
                 userId: null,
                 accountStatus: null,
            },
            accountStatusMap,
            accountTypeMap,
            balanceResultDialog:false,
            balanceResultData:{}
        };
    },
    computed: {
        selection() {
            return this.$refs.table.selection.map(i => i.id);
        }
    },
    methods: {
        beforeGetData() {
            return {
                search: this.search,
                query: { del: false, ...this.formData}
            };
        },
        afterGetData(){

        },
        checkBalance(fundAccountId){
            this.fetchingData = true;
            this.$http
                .post("/userFundAccount/getBalance", {fundAccountId})
                .then(res => {
                    this.fetchingData = false;
                    this.balanceResultDialog = true;
                    this.balanceResultData = res;
                    //this.initData();
                })
                .catch(e => {
                    this.fetchingData = false;                    
                    this.$message.error(e.error);
                });
        },
        
    }
};
</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%;
        height:30px;
        display:flex;
        .desc-label{
            font-weight:800;
            width:140px;
        }

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

        .desc-content{
            padding-left:10px;
        }
    }
}


</style>
