<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="86px">

            <el-form-item prop="startTime">
                <el-date-picker clearable v-model="queryParams.startTime" type="date" value-format="yyyy-MM-dd HH:mm"
                    placeholder="请选择">
                </el-date-picker>
            </el-form-item>
            <el-form-item prop="endTime">
                <el-date-picker clearable v-model="queryParams.endTime" type="date" value-format="yyyy-MM-dd HH:mm"
                    placeholder="请选择">
                </el-date-picker>
            </el-form-item>

            <el-form-item class="ml20">
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <!-- 表格数据 -->
        <el-table :data="AppointmentList">
            <el-table-column label="序号" type="index" width="55" align="center" />
            <el-table-column label="录播室" align="center" prop="studioName" />
            <el-table-column label="预约日期" align="center" prop="appointmentTime" />
            <el-table-column label="预约节次" align="center" prop="appointmentJc" />
            <el-table-column label="录播内容" align="center" prop="studioContent" />
            <el-table-column label="预约人" align="center" prop="appointmentUserName" />
            <el-table-column label="申请时间" align="center" prop="applyTime" />
            <el-table-column label="状态" align="center" prop="statu">
                <template slot-scope="{ row }">
                    {{ row.statu == 1 ? "预约成功" : row.statu == 2 ? "取消" : "" }}
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button v-if="scope.row.statu == '1'" size="mini" type="text" icon="el-icon-edit"
                        @click="handleqx(scope.row)">取消预约
                    </el-button>
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">详情
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--详情对话框 -->
        <el-dialog :title="title" :visible.sync="look" width="1200px" append-to-body @close="cancel">
            <el-form ref="postForm" :model="postForm" :rules="rules" label-width="110px">

                <h2 style="text-align: center;font-size: 24px;font-family: SourceHanSansSC-regular;">录播室预约单</h2>
                <div>
                    <div class="dialog-footer btn">
                        <el-button class="btnup" type="primary" @click="cancel">关 闭</el-button>
                    </div>
                    <table style="width: 100%;" class="tabstyle">
                        <tr>
                            <td>录播室</td>
                            <td class="btntext">{{ studioName }}</td>
                            <td>预约日期</td>
                            <td class="btntext">{{ appointmentTime }}</td>

                        </tr>
                        <tr>
                            <td>节次</td>
                            <td class="btntext">{{ appointmentJc }}</td>
                            <td>预约人</td>
                            <td class="btntext">{{ appointmentUserName }}</td>
                        </tr>
                        <td rowspan="1" class="btntxt">录播内容</td>
                        <td colspan="5">{{ studioContent }}</td>


                        <tr>
                            <td>申请时间</td>
                            <td>{{ applyTime }}</td>
                            <td>状态</td>
                            <td class="btntext" colspan="5">{{ statu === '1' ? '预约成功' : '取消' }}</td>
                        </tr>
                    </table>
                </div>
                <div class="sm">说明：录播室每天开放 上午四节、下午四节、晚上三节。共计每天11节。
                    请提前一天进行预约。
                </div>
            </el-form>
        </el-dialog>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList"></pagination>


    </div>
</template>

<script>
import {
    cancleAppointment,//取消预约    
    getAppointmentList,//查看个人录播室预约情况列表
    getstudioUse// 查看录播室预约详情
} from "@/api/smartSchool/personWork/recordingroomAppointment/myAppointment"

export default {
    name: 'useRecord',
    data() {
        return {
            dialogEditNote: false,
            form: {},
            // 日期范围
            dateRange: [],
            // 模糊搜索
            queryParams: {
                startTime: "",
                endTime: "",
                pageNum: 1,
                pageSize: 10,
            },
            // 录播室名称
            studioName: "",
            // 预约日期
            appointmentTime: "",
            // 节次
            appointmentJc: "",
            // 预约人
            appointmentUserName: "",
            // 录播内容
            studioContent: "",
            // 申请时间
            applyTime: "",
            // 状态
            statu: "",
            postForm: {},
            rules: {},
            // 加载遮罩
            loading: true,
            // 记录条数
            total: 0,
            title: "",
            // 记录列表
            AppointmentList: [],
            // 详情
            look: false,
        };
    },
    created() {
        this.getList();
    },
    methods: {
        // 获取列表
        getList() {
            this.loading = true;
            getAppointmentList(this.queryParams).then(response => {
                this.AppointmentList = response.rows;
                console.log(11, response.rows);
                this.total = response.total;
                this.loading = false;
            })
        },
        //  查看录播室预约详情
        handleEdit(row) {
            const id = row.id || this.ids
            this.postForm = row;
            getstudioUse(id).then(response => {
                console.log(222, response.data);
                this.studioName = response.data.studioName;
                this.appointmentTime = response.data.appointmentTime;
                this.appointmentJc = response.data.appointmentJc;
                this.appointmentUserName = response.data.appointmentUserName;
                this.studioContent = response.data.studioContent;
                this.applyTime = response.data.applyTime;
                this.statu = response.data.statu;
                this.loading = false;
                this.look = true;
            })
        },
        /** 取消预约操作 */
        handleqx(row) {
            const id = this.queryParams.id;
            if (row.statu === "1") {
                const today = new Date().toISOString().split("T")[0];
                const appointmentDate = row.appointmentTime;
                if (appointmentDate >= today) {
                    // 未到预约当天，可以取消预约
                    this.$modal.confirm('确认要取消"' + row.studioName + '"的预约吗？')
                        .then(() => {
                            console.log(row.id, row.statu);
                            return cancleAppointment({ statu: "2", id: row.id });
                        })
                        .then(() => {
                            this.getList();
                            this.$modal.msgSuccess("取消预约成功");
                        })
                        .catch(() => {
                            // 处理取消操作的逻辑
                        });
                } else {
                    // 已过预约当天，无法取消预约
                    this.$modal.msgError("已过预约当天，无法取消预约");
                }
            } else {
                // 非待处理状态，无法取消预约
                this.$modal.msgError("当前预约状态无法取消");
            }
        },


        // 模糊搜索
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        // 重置
        resetQuery() {
            this.dateRange = [];
            this.resetForm("queryForm");
            this.handleQuery();
        },

        // 取消按钮
        cancel() {
            this.look = false;
            this.form = {}
            this.handleQuery();
        },


    },

};
</script>
<style lang="scss">
.tabstyle {
    border-collapse: collapse;
    margin-bottom: 15px;
    font-size: 16px !important;

}

.tabstyle td,
.tabstyle th {
    border: 1px solid black;
    padding: 8px;
    position: relative;
}

.tabstyle input[type="text"] {
    border: none;
    outline: none;
    font-size: inherit;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    /* opacity: 0; */
}

.btntext {
    width: 300px;
}

.btn {
    display: flex;
    flex-direction: row;
    justify-content: end;

}

.btnup {
    margin-left: 12px;
    margin-bottom: 15px;
    padding: 9px 25px;
    border-radius: 6px;
    background-color: rgba(15, 64, 245, 1);
    color: rgba(255, 255, 255, 1);
    font-size: 13px;
    text-align: center;
    font-family: PingFang SC;

}
</style>
