<template>
    <el-dialog v-el-drag-dialog :title="title" :visible.sync="dialogVisible" width="40%" :before-close="handleClose"
        @open="handleDialogOpen">
        <div class="info-personInfo">
            <div class="personInfo-content">
                <div v-for="(item, index) in personList" class="everyTeam">
                    <div class="teamInfo">
                        <el-checkbox :indeterminate="item.isIndeterminate" v-model="item.checkAll"
                            @change="handleCheckAllChange($event, index)">全选</el-checkbox><span>队伍名称：<span>{{ item.teamName
                            }}</span></span>
                    </div>
                    <div class="peopleInfo">
                        <el-checkbox-group v-model="item.checkedMembers"
                            @change="handleCheckedMembersChange($event, index)">
                            <div v-for="item1 in item.teamMemberStateBOList"
                                :class="['everyPersonList', 'cardType' + item.id % 3]">
                                <el-checkbox :label="item1.userId" :key="item1.userId" :disabled="item1.email?false:true">
                                    <span class="isOnline"
                                        :style="{ backgroundColor: item1.online ? 'green' : 'gray' }"></span>
                                    <span class="username" :style="{ color: item1.online ? 'green' : 'white' }"
                                        v-text="item1.userId"></span>
                                    <span title="组长" :style="{ color: item1.online ? 'green' : 'white' }"
                                        :class="[item1.userId == item.leader ? 'el-icon-user-solid' : '']"></span>
                                </el-checkbox>
                            </div>
                        </el-checkbox-group>

                    </div>
                </div>
            </div>
            <div class="personInfo-footer">
                <el-button type="success" size="small" @click="sendEmail">发送邮件</el-button>
            </div>
        </div>
    </el-dialog>
</template>


<script>
import elDragDialog from "@/util/directive/el-dragDialog";
import { getChatRoomMemberInfo } from "@/api/chat/chatRoom";
export default {
    data() {
        return {
            dialogVisible: false,
            personList: [],
            chatRoomInfo: {},
            checkedPersonList:[]
        }
    },
    directives: {
        elDragDialog
    },
    props: {
        currentChatRoomInfo: Object
    },
    methods: {
        handleClose() {
            this.dialogVisible = false;
        },
        showDialog() {
            this.dialogVisible = true;
        },
        handleDialogOpen() {
            this.chatRoomInfo = this.$props.currentChatRoomInfo;
            this.getCurrentTeamPeople(this.chatRoomInfo.id);
        },
        getCurrentTeamPeople(chatRoomId) {
            //查询聊天组的人员
            getChatRoomMemberInfo(chatRoomId).then(res => {
                res.forEach(item => {
                    item['checkAll'] = false;
                    item['isIndeterminate'] = false;
                    item['checkedMembers'] = [];

                })
                this.personList = res;
            }).catch(error => {
                this.$message.error(error);
            });
        },
        handleCheckAllChange(val, index) {
            let tmp = [];
            this.personList[index].teamMemberStateBOList.forEach(item=>{
                tmp.push(item.userId);
            });
            this.personList[index].checkedMembers = val ? tmp : [];
            this.personList[index].isIndeterminate = false;
        },
        handleCheckedMembersChange(value, index) {
            let checkedCount = value.length;
            this.personList[index].checkAll = checkedCount === this.personList[index].teamMemberStateBOList.length;
            this.personList[index].isIndeterminate = checkedCount > 0 && checkedCount < this.personList[index].teamMemberStateBOList.length;
        },
        //发送邮件
        sendEmail(){
            this.checkedPersonList = [];
            this.personList.forEach(item=>{
                item.checkedMembers.forEach(item1=>{
                    this.checkedPersonList.push(item.teamMemberStateBOList.filter(item2=>{return item2.userId==item1})[0].email);
                })
            });
            this.$emit('openSendEmailPage',this.checkedPersonList);
        }
    },
    computed: {
        title() {
            return this.chatRoomInfo.nickname + " 成员信息";
        }
    }
}
</script>


<style lang="scss">
.info-personInfo {
    width: 100%;
    height: 40%;
    overflow-y: auto;

    .title {
        width: 100%;
        height: 30px;
        line-height: 30px;

        img {
            width: 20px;
            height: 20px;
        }

        span {
            font-size: 16px;
            font-weight: 500;
            color: white;
            vertical-align: text-bottom;
        }
    }

    .personInfo-content {
        width: 100%;
        height: calc(100% - 50px);
        overflow-y: auto;

        .everyTeam {
            width: calc(33% - 10px);
            height: calc(100% - 30px);
            border: 1px solid #3a5f94c9;
            border-radius: 6px;
            padding: 5px;
            box-sizing: border-box;
            float: left;
            margin-top: 10px;
            margin-left: 8px;

            .teamInfo {
                width: 100%;
                height: 30px;
                // text-align: center;

                &>span {
                    margin-left: 20px;
                    color: white;

                    &>span {
                        color: #2c8aeb;
                    }
                }

            }

            .peopleInfo {
                width: 100%;
                height: calc(100% - 30px);
                overflow-y: auto;

                &::-webkit-scrollbar {
                    display: none;
                }

                .everyPersonList {
                    width: 100%;
                    height: 30px;
                    line-height: 35px;
                    padding-left: 70px;
                    margin-top: 5px;

                    .isOnline {
                        width: 10px;
                        height: 10px;
                        border-radius: 50%;
                        display: inline-block;
                        margin-right: 5px;
                    }

                    .username {
                        color: white;
                    }
                }

                // &>div:nth-child(3n) {
                //     background-image: url(@/assets/img/ddkz/12.png);
                //     background-size: 100% 100%;
                // }

                // &>div:nth-child(3n+1) {
                //     background-image: url(@/assets/img/ddkz/13.png);
                //     background-size: 100% 100%;
                // }

                // &>div:nth-child(3n+2) {
                //     background-image: url(@/assets/img/ddkz/14.png);
                //     background-size: 100% 100%;
                // }

                .cardType0 {
                    background-image: url(@/assets/img/ddkz/12.png);
                    background-size: 100% 100%;
                }

                .cardType1 {
                    background-image: url(@/assets/img/ddkz/14.png);
                    background-size: 100% 100%;
                }

                .cardType2 {
                    background-image: url(@/assets/img/ddkz/13.png);
                    background-size: 100% 100%;
                }
            }
        }
    }
    .personInfo-footer{
        width: 100%;
        height: 50px;
        text-align: right;
    }
}
</style>