<template>
    <div class="box">
        <div class="inquire">
            <span>分区</span>
            <partition-select v-model:partition-id="formData.partitionId" />
        </div>
        <div class="inquire">
            <span>房间ID:</span>
            <el-input v-model="formData.roomErbanNo" placeholder="" class="input"></el-input>
        </div>
        <div class="inquire">
            <div class="block">
                <span class="demonstration">开始时间</span>
                <el-date-picker v-model="formData.startTime" type="datetime" placeholder="开始时间">
                </el-date-picker>
            </div>
        </div>
        <div class="inquire">
            <span class="demonstration">状态</span>
            <el-select v-model="formData.eventStatus" placeholder="请选择">
                <el-option label="全部" :value="-1"></el-option>
                <el-option label="待审核" :value="0"></el-option>
                <el-option label="审核通过" :value="1"></el-option>
                <el-option label="拒绝" :value="2"></el-option>
                <el-option label="删除" :value="3"></el-option>
                <el-option label="过期" :value="4"></el-option>
            </el-select>
        </div>
        <el-button style="" type="primary" @click="getData()">查询</el-button>
        <!-- 表格数据 -->
        <el-table v-loading="tableData.loading" :data="tableData.data" ref="multipleTable"
            @selection-change="handleSelectionChange" border style="width: 100%; margin-top: 25px">
            <el-table-column prop="id" align="center" label="id" />
            <el-table-column prop="roomErbanNo" align="center" label="房间ID" />
            <el-table-column prop="erbanNo" align="center" label="举办人ID" />
            <el-table-column prop="nick" align="center" label="举办人昵称" />
            <el-table-column prop="partitionDesc" align="center" label="分区" />
            <el-table-column prop="eventTopic" align="center" label="活动标题" />
            <el-table-column prop="eventDetail" align="center" label="活动内容" />
            <el-table-column prop="eventBanner" align="center" label="活动banner" >
                <template v-slot="scope">
                    <el-image style="width: 100px; height: 100px" :src="scope.row.eventBanner" :zoom-rate="1.1"
                        :preview-src-list="[scope.row.eventBanner]" fit="scale-down" preview-teleported="true"
                        hide-on-click-modal="true" />
                </template>
            </el-table-column>
            <el-table-column prop="eventStartTimeStr" align="center" label="开始时间" />
            <el-table-column prop="eventDuration" align="center" label="活动时长（分钟）" />
            <el-table-column prop="createTimeStr" align="center" label="提交时间" />
            <el-table-column align="center" label="操作" width="200">
                <template v-slot="scope">
                    <template v-if="scope.row.eventStatus === 0">
                        <el-button class="primary" type="primary" @click="
                            operatorEvent(scope.row, 1);
                        " size="default">同意</el-button>
                        <el-button class="primary" type="danger" @click="
                            operatorEvent(scope.row, 2);
                        " size="default">拒绝</el-button>
                    </template>
                    <template v-else>
                        {{ scope.row.eventStatus === 1 ? '审核通过' : scope.row.eventStatus === 2 ? '已拒绝' :
                            scope.row.eventStatus === 3 ? '已删除' + '('+scope.row.remark+')' : '已过期' }}
                    </template>
                </template>
            </el-table-column>
            <el-table-column prop="operator" align="center" label="操作人" />
        </el-table>
        <!-- 分页 -->
        <el-pagination style="margin-top: 10px" class="paginationClass" :current-page="formData.pageNo"
            :page-size="formData.pageSize" :page-sizes="[10, 20, 50, 100, 200]" layout="sizes, prev, pager, next"
            :total="tableData.total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>
</template>

<script>
import { ref, onMounted, reactive } from 'vue'
import PartitionSelect from "../common/partitionSelect.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { dateFormat } from "@/utils/system-helper";
import { getListEvent, operatorListEvent } from "@/api/boom/roomActivityApplication";
export default {
    name: "roomActivityApplication",
    components: { PartitionSelect },
    setup() {
        const formData = reactive({
            partitionId: undefined,
            roomErbanNo: '',
            startTime: '',
            eventStatus: -1,
            pageNo: 1,
            pageSize: 10,
        });
        const tableData = reactive({
            data: [],
            total: 0,
            loading: false,
        })
        const getData = () => {
            if (formData.startTime) {
                formData.startTime = dateFormat(formData.startTime, "yyyy-MM-dd hh:mm:ss")
            }
            tableData.loading = true;
            getListEvent(formData).then(res => {
                if (res.code == 200) {
                    tableData.data = res.data.rows
                    tableData.loading = false;
                    tableData.total = res.data.total

                } else {
                    tableData.loading = false;
                    ElMessage.error(res.message);
                }
            })
        };
        const operatorEvent = (row, eventStatus) => {
            const eventId = row.id;
            ElMessageBox.confirm('确认此操作吗', "提示", {
                type: "warning",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
            }).then(() => {
                operatorListEvent({ eventId, eventStatus }).then(res => {
                    if (res.code === 200) {
                        ElMessage.success('操作成功');
                        getData();
                    } else {
                        ElMessage.error(res.message);
                    }
                })
            })


        }
        const handleSizeChange = (val) => {
            formData.pageSize = val;
            getData();
        };
        const handleCurrentChange = (val) => {
            formData.pageNo = val;
            getData();
        };
        return {
            formData,
            getData,
            tableData,
            handleSizeChange,
            handleCurrentChange,
            operatorEvent
        }
    }
}
</script>

<style lang="less" scoped>
.box {
    padding-top: 20px;
    background: #ecf0f5;

    .inquire {
        display: inline-block;
        margin-right: 20px;

        span {
            margin-right: 10px;
        }

        .input {
            width: 180px;
            margin-right: 10px;
        }
    }

    .dialogTableVisibleBut {
        display: block;
        margin: 30px 0 0 830px;
    }

    .paginationClass {
        margin: 15px 0 5px 0px;
    }
}
</style>