<template>
    <div>
        <div class="communal-list">
            <div class="communal-title">
                <div>导出邀请函</div>
            </div>
            <div>
                <el-select @change="changeOption()" v-model="DiId" filterable placeholder="请输入团组名称" style="width: 20%;">
                    <el-option v-for="item in delegations" :key="item.id" :label="item.teamName" :value="item.id">
                    </el-option>
                </el-select>
                <el-button type="primary" style="margin-left: 10px;" @click="btn">导出</el-button>
            </div>
            <!-- <template>
                <el-table :data="tableDatas.slice((currentPage - 1) * pageSize, currentPage * pageSize)" border
                    style="width: 100%" v-loading="loading" element-loading-text="拼命加载中...">
                    <el-table-column prop="num" label="序 号" width="55">
                        <template slot-scope="scope">
                            {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="city" label="所在城市" width="150">
                    </el-table-column>
                    <el-table-column prop="name" label="酒店名称" width="300">
                    </el-table-column>
                    <el-table-column prop="tel" label="酒店电话" width="200">
                    </el-table-column>
                    <el-table-column prop="fax" label="酒店传真" width="180">
                    </el-table-column>
                    <el-table-column prop="contact" label="联系人" width="180">
                    </el-table-column>
                    <el-table-column prop="contactPhone" label="联系电话" width="200">
                    </el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button size="mini" @click="upDate(scope.$index, scope.row)">编辑</el-button>
                            <el-button size="mini" type="danger" @click="del(scope.$index, scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </template>
            <div class="block">
                <el-pagination align='center' @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page="currentPage" :page-sizes="[10, 12, 15, 20]" :page-size="pageSize"
                    layout="total, sizes, prev, pager, next" :total="tableDatas.length">
                </el-pagination>
            </div> -->
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            loading: false,
            tableDatas: [],
            tableData: [],
            delegations: [],
            currentPage: 1, // 当前页码
            pageSize: 12,// 每页的数据条数
            DiId: 0,
            input: '',
            token: '',
            userId: 0
        }
    },
    methods: {
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.currentPage = 1;
            this.pageSize = val;
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val;
        },
        changeOption() {
            this.QueryinvitationLetter();
        },
        QueryinvitationLetter() {
            var url = "/api/Groups/QueryinvitationLetter"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    DiId: that.DiId
                }
            }).then(function (res) {
                console.log(res)
                if (res.data.code == 200) {
                    debugger
                    that.tableData = res.data.data.deleClient;
                    that.tableDatas = that.tableData;
                    that.delegations = res.data.data.delegations
                    if(that.DiId==0){
                        that.DiId = that.delegations[0].id
                    }
                    if (that.tableDatas.slice((that.currentPage - 1) * that.pageSize, that.currentPage * that.pageSize).length == 0) {
                        if (that.currentPage > 1) {
                            that.currentPage = that.currentPage - 1;
                        }
                    }
                }
                that.loading = false
            }).catch(function (error) {
                that.loading = false
                that.$message.error("网络错误，请稍后重试");
            });
        },
        btn() {
            var url = "/api/Groups/invitationLetter"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    DiId: that.DiId
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    window.location.href = res.data.data
                } else {
                    that.$message.error(res.data.msg);
                }

            }).catch(function (error) {
                that.$message.error("网络错误，请稍后重试");
            });
        }
    },
    mounted() {
        this.token = JSON.parse(localStorage.getItem('userinif')).token;
        this.userId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
        this.QueryinvitationLetter();
    }
}
</script>
<style>
.communal-list {
    background-color: #fff;
    padding: 10px;
    box-shadow: 0 0 5px #0005;
    border-radius: 10px;
}

.communal-title {
    display: flex;
    font-size: 17px;
    font-weight: 600;
    color: #555;
    margin-top: 8px;
    margin-bottom: 10px;
    justify-content: space-between;
    align-items: center;
}

.communal-box {
    display: flex;
}

.communal-box>button {
    margin-left: 10px;
    padding: 8px 20px;
}
</style>