<template>
    <div class="list-view">
        <page-title>
            <el-button @click="$router.go(-1)"  type="primary"  icon="el-icon-back">返回</el-button>

            <el-button
                @click="download('/userWareHouse/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-select v-model="formData.queryType" clearable @change="initData">
                        <el-option value="1" label="优先购活动"></el-option>
                        <el-option value="2" label="白名单配置"></el-option>
                    </el-select>
                </el-form-item>
                
                <el-form-item label="优先购活动ID">
                    <el-input v-model.number="formData.activityPriorityDocumentId" placeholder="请输入优先购活动ID" clearable ></el-input>
                </el-form-item>
                <el-form-item label="白名单配置ID">
                    <el-input v-model.number="formData.whitelistConfigId"  placeholder="请输入白名单配置ID" clearable ></el-input>
                </el-form-item>
                
            </el-form>

            <el-input
                placeholder="搜索..."
                v-model="search"
                clearable
                class="filter-item search"
                @keyup.enter.native="getData"
            >
                <el-button @click="getData" slot="append" icon="el-icon-search"> </el-button>
            </el-input>
        </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" min-width="80"> </el-table-column>
            <el-table-column prop="phone" label="手机号码" show-overflow-tooltip=""> </el-table-column>
            <el-table-column prop="itemId" label="凭证类型"   min-width="150" show-overflow-tooltip="">
                <template v-slot="{ row }">
                    <span v-if="row.itemId == 0">指定铸造者优先购凭证</span>
                    <span v-if="row.itemId == 1">消耗性全局优先购凭证</span>
                    <span v-if="row.itemId == 2">消耗性指定藏品优先购凭证</span>
                </template>
            </el-table-column>
            <el-table-column prop="advancePurchaseTime" label="优先时间（h）" min-width="100"> </el-table-column>
            <el-table-column prop="advancePurchaseCount" label="优先次数"> </el-table-column>
            <el-table-column prop="targetCollectionIdList" label="生效藏品" show-overflow-tooltip="">
                <template v-slot="{ row }">
                    <span v-for="(item, index) in row.targetCollectionIdList" :key="index">{{ item }}，</span>
                </template>
            </el-table-column>
            <el-table-column prop="activityPriorityDocumentId" label="优先购活动ID" min-width="100" show-overflow-tooltip=""> </el-table-column>

            <el-table-column prop="assetId" label="关联资产ID" > </el-table-column>
            
            <el-table-column prop="targetCollectionId" label="是否有效">
                <template v-slot="{ row }">
                    <el-tag type="success" v-if="row.disabled">有效</el-tag>
                    <el-tag type="info" v-else>无效</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="text" label="说明" show-overflow-tooltip=""> </el-table-column>

            <el-table-column prop="createdAt" label="创建时间" min-width="150"></el-table-column>

            <el-table-column prop="overdueTime" label="过期时间" min-width="150"></el-table-column>
            

            <el-table-column prop="whitelistConfigId" label="白名单配置ID" min-width="100"></el-table-column>
            

            <el-table-column label="操作" align="center" fixed="right" width="150">
                <template v-slot="{ row }">
                    <el-button @click="editRow(row)" type="primary" size="mini" plain>编辑</el-button>
                    <el-button @click="deleteRow(row)" type="danger" size="mini" plain>删除</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>
    </div>
</template>
<script>
import pageableTable from '@/mixins/pageableTable';

export default {
    name: 'PreemptionWhiteList',
    mixins: [pageableTable],
    data() {
        return {
            formData: {
                queryType: null,
                activityPriorityDocumentId:this.$route.query.activityPriorityDocumentId,
                whitelistConfigId:this.$route.query.whitelistConfigId
            },
            multipleMode: false,
            search: '', // 搜索字段
            url: '/userWareHouse/all', // 列表接口
            downloading: false,
            createdAt: ''
        };
    },
    computed: {
        selection() {
            return this.$refs.table.selection.map(i => i.id);
        }
    },
    methods: {
        beforeGetData() {
            return {
                search: this.search,
                query: {
                    itemName: 'CONSUMABLE_ASSIGN_CERTIFICATE,CONSUMABLE_CERTIFICATE,PERPETUAL_CERTIFICATE',
                    del: false,
                    ...this.formData
                    // createdAt: this.createdAt
                }
            };
        },
        toggleMultipleMode(multipleMode) {
            this.multipleMode = multipleMode;
            if (!multipleMode) {
                this.$refs.table.clearSelection();
            }
        },
        // 列表 - 删除
        deleteRow(row) {
            this.$alert('删除将无法恢复，确认要删除么？', '警告', { type: 'error' })
                .then(() => {
                    return this.$http.post(`/userWareHouse/del/${row.id}`);
                })
                .then(() => {
                    this.$message.success('删除成功');
                    this.getData();
                })
                .catch(e => {
                    if (e !== 'cancel') {
                        this.$message.error(e.error);
                    }
                });
        }
    }
};
</script>
<style lang="less" scoped></style>
