<template>
    <div>
        <el-dialog title="预约调解员" :visible="mediatorVisable" v-if="mediatorVisable" @close="cancel" center :distroy-on-close="true">
            <div>
                <div>
                    <div style="margin-bottom: 20px;">预约调解员</div>
                </div>
                <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
                    @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55">
                    </el-table-column>
                    <el-table-column prop="mediatorName" label="调解员">
                    </el-table-column>
                    <el-table-column prop="specialty" label="专业">
                    </el-table-column>
                    <el-table-column prop="todoAmount" label="待办数量">
                    </el-table-column>
                    <el-table-column prop="completeAmount" label="已办数量">
                    </el-table-column>
                </el-table>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancel" class="endbutton1" round><span>取 消</span></el-button>
                <el-button @click="submitMediator" class="endbutton1" type="primary" round><span>确 认</span></el-button>
            </div>
        </el-dialog>
    </div>
</template>
  
<script>
import { Message } from 'element-ui'
import { listMediator,updateBooking } from '@/api/caseManagement/caseManagement.js'
import { createRoomId } from '@/api/metting/metting.js'
import moment from "moment";
export default {
    props: ["mediatorVisable", "mediatorData","queryParams"],
    data() {
        return {
            tableData: [],
            multipleSelection: [],
            formLabelAlign: {
                time:[]
            },
            mediatorArr:[]
        };
    },
    watch: {
        mediatorVisable(val) {
            if (val) {
                listMediator().then(res=>{
                    this.tableData = res.data;
                })
            }
        }
    },
    methods: {
        cancel() {
            this.$emit("cancelMediator");
        },
        /**提交选择结果*/
        async submitMediator() {
            if (this.multipleSelection.length > 3) {
                Message.error('最多选择三名调解员');
                return
            }else if(this.multipleSelection.length < 1){
                Message.error('请选择调解员');
                return
            }
            this.mediatorArr = [];
            this.multipleSelection.forEach(item=>{
                this.mediatorArr.push({
                    mediatorId:item.mediatorId,
                    mediatorName:item.mediatorName
                })
            })
            await this.updateBookingFn({
                id:this.mediatorData.id,
                caseFlowId:this.mediatorData.caseFlowId,
                mediatorList:this.mediatorArr,
            })
        },
        async updateBookingFn(data){
            await updateBooking(data).then(res=>{
                this.$modal.msgSuccess("成功");
                this.$emit("cancelMediator");
                this.$emit('getList', this.queryParams);
            })
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
            // console.log(this.multipleSelection,"LLLLLLLLLLLLLLLLL");
        }
    },
};
</script>
  
<style lang="scss" scoped>
.steps {
    display: flex;
    flex-wrap: wrap;
}

::v-deep .el-step {
    // width: 150px;
    flex-basis: 25% !important;
    margin-right: 20px;
    margin-bottom: 20px;
}

::v-deep .el-dialog__body {
    height: 500px !important;
    overflow: auto !important;
}

::v-deep .el-dialog {
    width: 800px;
    background: #ffffff;
    border-radius: 20px;
}

.timeTitle {
    width: 1000%;
    text-align: center;
}
</style>