<template>
    <div class="list-view">
        <page-title>
            <el-button
                @click="download('/userIntegral/excel')"
                icon="el-icon-upload2"
                :loading="downloading"
                :disabled="fetchingData"
                class="filter-item"
            >
                导出
            </el-button>
            <el-button @click="presentIntegral()"  type="warning">
                批量赠送积分
            </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="用户">
                    <user-search v-model="formData.userId"></user-search>
                </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="phone" label="手机号" min-width="80" show-overflow-tooltip></el-table-column>
            <el-table-column prop="username" label="用户名" min-width="80" show-overflow-tooltip></el-table-column>
            <el-table-column prop="availableIntegral" label="可用积分" min-width="80" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="freezeIntegral" label="冻结积分" min-width="100" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="consumeIntegral" label="消耗积分" min-width="100" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="monthConsumeIntegral" label="月消耗积分" min-width="100" show-overflow-tooltip>
            </el-table-column>

            <el-table-column prop="monthStartTime" label="月消耗开始时间"  min-width="120"> </el-table-column>
            <el-table-column prop="lastChangeTime" label="积分变动时间"  min-width="120"> </el-table-column>
            
            <el-table-column prop="createdAt" label="创建时间" width="140">
                <template v-slot:header="{ column }">
                    <sortable-header :column="column" :current-sort="sort" @changeSort="changeSort"> </sortable-header>
                </template>
            </el-table-column>
            <el-table-column label="操作" min-width="180" fixed="right">
                <template v-slot="scope">
                    <el-button type="primary" size="mini" @click="viewDetail(scope.row.userId)">详情</el-button>
                    <el-button type="danger" size="mini" @click="presentIntegral(scope.row.userId)">赠送积分</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>

        <user-integral-detail ref="detailRef"></user-integral-detail>

        <user-integral-present ref="presentRef" @refresh="initData"></user-integral-present>

    </div>
</template>
<script>
import pageableTable from '@/mixins/pageableTable';
import SortableHeader from '../components/SortableHeader.vue';

import UserIntegralDetail from "./UserIntegralDetail.vue";

import UserIntegralPresent from "./UserIntegralPresent.vue";


export default {
    components: { SortableHeader },
    name: 'UserIntegralList',
    mixins: [pageableTable],
    components:{
        UserIntegralDetail,
        UserIntegralPresent
    },
    data() {
        return {
            multipleMode: false,
            search: '',
            url: '/userIntegral/all',
            downloading: false,
            formData: {
                createdAt: '',
                userId: '',
            },
        };
    },
    computed: {
        selection() {
            return this.$refs.table.selection.map(i => i.id);
        }
    },
    methods: {
        beforeGetData() {
            return {
                search: this.search,
                query: { del: false, ...this.formData }
            };
        },
        afterGetData(res) {
            
        },
        viewDetail(userId){
            this.$refs["detailRef"].init(userId);
        },
        presentIntegral(userId){
            this.$refs["presentRef"].init(userId);
        }
    }
};
</script>
<style lang="less" scoped>
.tool-wrapper {
    display: block;
    overflow: hidden;

    .tool-right {
        float: left;
    }
}

</style>
