<template>
    <div>
        <el-dialog title="修改开庭时间" :visible="timeVisable" @close="cancel" center :distroy-on-close="true">
            <el-descriptions title="案件内容" :column="2" border>
                <el-descriptions-item label="案件编号">{{ timeData.caseNum }}</el-descriptions-item>
                <el-descriptions-item label="申请人(机构)">{{ timeData.applicantName }}</el-descriptions-item>
                <el-descriptions-item label="案件标的">{{ timeData.caseSubjectAmount }}</el-descriptions-item>
                <el-descriptions-item label="案件状态">
                    <el-tag size="small">{{ timeData.caseStatusName }}</el-tag>
                </el-descriptions-item>
                <el-descriptions-item label="仲裁方式">{{ timeData.arbitratMethodName }}</el-descriptions-item>
                <el-descriptions-item label="开庭时间">
                    <el-date-picker v-model="loanStartDate" :picker-options="pickerOptions" type="datetime"
                        placeholder="开庭时间">
                    </el-date-picker>
                </el-descriptions-item>

            </el-descriptions>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancel" class="endbutton1"><span>取 消</span></el-button>
                <el-button @click="submitTime" class="endbutton1"><span>提 交</span></el-button>
            </div>
        </el-dialog>
    </div>
</template>
<!-- hearDate -->
<script>
import { updateHeardate } from '@/api/caseManagement/caseManagement'
import { getToken } from "@/utils/auth";
import { createRoomId, reservedConference, sendRoomNoMessage } from '@/api/meeting/index'
import moment from "moment";
export default {
    props: ["timeVisable", "timeData", "queryParams"],
    data() {
        return {
            loanStartDate: "",
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() <= Date.now() -1 * 24 * 3600 * 1000; // 禁用超过当前时间的日期
                },
                selectableRange: `${new Date()}- 23:59:59`,//这
            },
            roomId: null
        };
    },
    watch: {
        timeVisable(val) {
            if (val) {
                // this.getEvidenceList({ caseAppliId: this.timeData.id, annexTypeList: "2" })
                this.loanStartDate = this.timeData.hearDate
            }
        },
    },
    created() {

    },
    methods: {
        cancel() {
            this.$emit("cancelTime");
        },
        // 获取房间号
        async createRoomIdFn(data) {
            await createRoomId(data).then(res => {
                this.roomId = res.data;
            })
        },
        // 预约会议
        async reservedConferenceFn(data) {
            await reservedConference(data).then(res => {
                console.log(res, "PPPPPPPPPPPPPPPPPPPPPPPPP");
            })
        },
        // 提交时间
        async updateHeardateFn(data) {
            await updateHeardate(data).then(res => {
                this.$modal.msgSuccess("修改成功");
                this.cancel();
                this.$emit("getcaseApply", this.queryParams);
            })
        },
        // 发送房间号短信
        async sendRoomNoMessageFn(data) {
            sendRoomNoMessage(data).then(res => {
                console.log(res, "PPPPPPPPPPPPPPPPPPPPPPPPP");
            })
        },
        async submitTime() {
            this.loanStartDate = moment(
                this.loanStartDate
            ).format("YYYY-MM-DD HH:mm:ss");
            await this.createRoomIdFn({ caseId: this.timeData.id });
            await this.reservedConferenceFn({
                caseId: this.timeData.id,
                roomId: this.roomId,
                scheduleStartTime: this.loanStartDate,
            })
            await this.updateHeardateFn({
                id: this.timeData.id,
                hearDate: this.loanStartDate
            })
            await this.sendRoomNoMessageFn({
                id: this.timeData.id,
                roomNo: this.roomId,
                scheduleStartTime: this.loanStartDate
            })
        }
    },
};
</script>
  
<style lang="scss" scoped>
.steps {
    display: flex;
    flex-wrap: wrap;
}
</style>