<template>
    <div class="app-container">
        <div class="page-container">
            <el-form :model="queryParams" :inline="true" label-width="80px">
                <el-form-item label="兑换时间">
                    <el-date-picker v-model="dateRange" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期"
                        style="width: 240px;" value-format="yyyy-MM-dd" @change="dateChange"></el-date-picker>
                </el-form-item>
                <el-form-item label="兑换人">
                    <el-input placeholder="请输入" v-model="queryParams.nickName" style="width: 220px;"></el-input>
                </el-form-item>
                <el-form-item label="兑换商品">
                    <el-input placeholder="请输入" v-model="queryParams.goodsName" style="width: 220px;"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleQuery">查询</el-button>
                    <el-button @click="handleReset">重置</el-button>
                </el-form-item>
            </el-form>
            <el-row class="mb10">
                <el-col :span="24">
                    <el-button type="primary" @click="handleAdd">积分兑换</el-button>
                    <el-button type="primary" plain @click="handleExport">导出积分明细</el-button>
                    <el-button type="primary" plain @click="handleBatchExchange">批量兑换</el-button>
                </el-col>
            </el-row>
            <el-table :data="tableList">
                <el-table-column label="序号" width="55" type="index" align="center"></el-table-column>
                <el-table-column label="兑换人" prop="nickName" align="center"></el-table-column>
                <el-table-column label="兑换商品" align="center" prop="goodsName"></el-table-column>
                <el-table-column label="兑换积分" prop="goodsExchangePoints" align="center"></el-table-column>
                <el-table-column label="兑换时间" prop="createTime" align="center"></el-table-column>
                <el-table-column label="会员等级" prop="userGradeName" align="center"></el-table-column>
                <el-table-column label="剩余积分" prop="userRemainingPoints" align="center"></el-table-column>
                <el-table-column label="操作人" prop="createBy" align="center"></el-table-column>
            </el-table>
            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList" />
        </div>
        <!-- 积分兑换 -->
        <exchange-dialog ref="exchangeDialogRef" @handleOk="handleReset"></exchange-dialog>
        <!-- 批量兑换 -->
         <batch-exchange ref="batchExchangeRef" @handleOk="handleReset"></batch-exchange>
    </div>
</template>

<script>
import { listData, pointsExchange } from '@/api/pointsExchange';
import ExchangeDialog from '../pointsManage/ExchangeDialog.vue';
import BatchExchange from './BatchExchange.vue';
export default {
    name: 'PointsExchange',
    data() {
        return {
            queryParams: {
                pageNum: 1,
                pageSize: 10
            },
            tableList: [],
            total: 0,
            dateRange: [],
            optionList: []
        }
    },
    components: {
        ExchangeDialog,
        BatchExchange
    },
    created() {

    },
    mounted() {
        this.getList()
    },
    methods: {
        // 列表数据
        getList() {
            listData(this.queryParams).then(res => {
                console.log(res)
                this.tableList = res.rows;
                this.total = res.total
            })
        },
        // 兑换商品列表
        getOptions() {
            pointsExchange().then(res => {
                console.log(res)
                this.optionList = res.data
            })
        },
        // 新增
        handleAdd() {
            this.$refs.exchangeDialogRef.openModal()
        },
        // 删除
        handleDelete(row) {
            this.$modal.confirm('确认要删除商品名称为：' + row.name + '的数据吗？').then(function () {
                return delData(row.id);
            }).then(() => {
                this.$modal.msgSuccess("删除成功");
                this.getList()
            })
        },
        // 导出积分明细
        handleExport() {
            this.download('/bbs/points/exchange/export', {
                ...this.queryParams
            }, `积分明细_${new Date().getTime()}.xlsx`)
        },
        // 时间段选择
        dateChange(val) {
            if (val.length > 0) {
                this.queryParams['params[startTime]'] = val[0]
                this.queryParams['params[endTime]'] = val[1]
            }
        },
        // 查询
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList()
        },
        // 重置
        handleReset() {
            this.queryParams = {
                pageNum: 1,
                pageSize: 10
            }
            this.dateRange = []
            this.getList()
        },
        handleBatchExchange(){
            this.$refs.batchExchangeRef.openModal()
        },
    }
}
</script>

<style lang="scss" scoped>
.app-container {
    background-color: rgba(241, 242, 247, 1);
    height: calc(100vh - 50px);

    .page-container {
        background-color: white;
        height: 100%;
        border-radius: 6px;
        padding: 20px 30px;
        box-sizing: border-box;
        overflow: auto;
    }
}
</style>
