<template>
    <el-dialog :center="true" :visible.sync="dialogVisibleTemplate" width="1200px" class="addTemplateDialog">
        <!-- <div v-if="showDialog == true" class="a-dialog" v-el-drag-dialog> -->
        <div class="a-d-top">
            <div class="a-d-topTit">
                <div style="width: 136px">模板库</div>
            </div>
            <div>
                <el-input placeholder="请输入内容" prefix-icon="el-icon-search" v-model="input2" clearable>
                </el-input>
            </div>
            <div class="a-d-t-right">
                <el-button @click="open2()" type="primary" size="small" style="margin-right: 10px;">设置模板</el-button>
                <span @click.stop="close">×</span>
            </div>
        </div>
        <div style="display: flex; height: calc(100% - 10px)">
            <div class="a-d-t-left">
                <div :style="tagIndex == item.id
                    ? 'background: rgba(226, 238, 255, 1);color: rgba(54, 129, 252, 1)'
                    : ''
                    " class="a-d-t-l-item" v-for="(item) in dialogTagList" :key="item.id"
                    @click.stop="setTagIndex(item.id)">
                    {{ item.name }}
                </div>
            </div>
            <div class="a-d-box">

                <div style="
							font-family: PingFang SC;
							font-size: 16px;
							font-weight: 600;
							line-height: 22px;
							text-align: left;
							margin: 20px 0;
							margin-bottom: 10px;
						">
                    {{ tagname }}
                </div>
                <div style="display: flex; flex-wrap: wrap;height:100%" v-loading="loading">
                    <div class="a-d-b-item" v-for="(item, index) in searchDataList" :key="index">
                        <div class="a-d-b-i-top">
                            <img style="height: 22px; width: 22px" :src="require('../../../assets/icon/classroomObservation/digImg.svg')
                                " />
                            <el-tooltip :content="item.name" placement="top" effect="dark">
                                <!-- content to trigger tooltip here -->
                                <div class="a-d-b-i-t-title">{{ item.name }}</div>
                            </el-tooltip>
                        </div>
                        <!-- <div class="a-d-b-i-top" v-if="item.uname">创建人：{{ item.uname }}</div> -->
                        <div class="a-d-b-i-top" v-show="false">创建人：{{ item.uname }}</div>
                        <!-- <el-tooltip :content="item.detail" placement="top" effect="dark"> -->
                            <div class="a-d-b-i-bottom">{{ item.detail }}</div>
                        <!-- </el-tooltip> -->
                        <div class="a-d-b-i-bottomBtn">
                            <div style="
										display: flex;
										width: 100%;
										justify-content: space-around;
									">
                                <div class="a-d-b-i-t-btn" v-if="item.userid == userid" style="margin-right: 10px;"
                                    @click="deleteA(item.id)">删除</div>
                                <div class="a-d-b-i-t-btn1" v-if="item.userid == userid" style="margin-right: 10px;"
                                    @click="open2(item.id)">修改</div>
                                <div class="a-d-b-i-t-btn1" @click="open(item.id)">
                                    使用
                                </div>
                            </div>
                        </div>
                    </div>
                    <div v-if="!searchDataList.length" style="text-align: center;">暂无内容</div>
                </div>
            </div>
        </div>
        <!-- </div> -->
    </el-dialog>
</template>

<script>

export default {
    props: {
        dialogVisibleTemplate: {
            type: Boolean,
            default: false
        },
        userid: {
            type: String
        },
        org: {
            type: String
        },
        oid: {
            type: String
        }
    },
    data() {
        return {
            dialogTagList: [
                { id: '2', name: "社区模板" },
                { id: '1', name: "我的模板" },
            ],
            tagIndex: '2',
            searchDataList: [],
            input2: '',
            loading: false
        }
    },
    computed: {
        tagname() {
            return this.dialogTagList.filter((item) => {
                return item.id == this.tagIndex
            })[0].name
        }
    },
    watch: {
        dialogVisibleTemplate(newValue, oldValue) {
            if (newValue) {
                this.getList();
            }
        },
        input2(newValue) {
            this.getList();
        }
    },
    methods: {
        handleClose(done) {
            this.close()
            done();
        },
        close() {
            this.$emit('update:dialogVisibleTemplate', false)
        },
        confirm() {
            this.$emit('update:dialogVisibleTemplate', false)
        },
        setTagIndex(index) {
            this.tagIndex = index
            this.getList();
        },
        open(id) {
            this.$emit('goToCourseTemplate', id)
        },
        open2(id) {
            this.$emit('goToCourseTemplate2', id)
        },
        deleteA(id) {
            let _this = this
            _this.$confirm(
                "确定删除此模板吗？",
                "提示",
                {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }
            )
                .then(() => {
                    let params = [{
                        id: id
                    }]
                    _this.ajax
                        .post(_this.$store.state.api + "deleteTipsTemplateHK", params)
                        .then((res) => {
                            _this.$message.success("删除成功");
                            _this.getList()
                        })
                        .catch((err) => {
                            _this.$message.error("网络不佳");
                            console.error(err);
                        });
                })
                .catch(() => {
                    return;
                });


        },
        getList() {
            this.loading = true
            let params = {
                userid: this.userid,
                oid: this.oid,
                org: this.org,
                type: this.tagIndex,
                name: this.input2
            }
            this.ajax
                .get(this.$store.state.api + "selectTipsTemplateHK", params)
                .then((res) => {
                    this.loading = false
                    this.searchDataList = res.data[0]
                    if (!this.input2) {
                        // this.searchDataList.unshift(
                        //     {
                        //     name: "项目式学习 (Project-Based Learning, PBL)",
                        //     detail: "项目式学习是一种以学生为中心的教学方法，通过实际项目和问题解决，培养学生的深度学习和应用能力。",
                        //     id:''
                        // });
                    }
                })
                .catch((err) => {
                    this.$message.error("网络不佳");
                    console.error(err);
                });
        }
    },
}
</script>

<style scoped>
.addTemplateDialog>>>.el-dialog {
    /* min-width: 1200px; */
    max-width: 100%;
    margin-top: 8vh !important;
    height: 700px;
    box-shadow: 0px 0 8px 0px #555555;
    border-radius: 8px;
    background-color: #fff;
    /* top: 0px; */
    /* margin: 0 auto; */
    overflow: hidden;
}

.addTemplateDialog>>>.el-dialog__body {
    height: 100%;
    /* min-width: 1200px; */
    max-width: 100%;
    flex-shrink: 0;
    box-sizing: border-box;
    padding-bottom: 50px;
    padding-top: 10px;
}

.addTemplateDialog>>>.el-dialog__header {
    display: none;
}


.a-d-top {
    /* background: #adadad; */
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    height: 54px;
    border-radius: 8px 8px 0 0;
    user-select: none;
    border-bottom: 1px #ccc solid;
}

.a-d-top>>>.el-input__inner {
    width: 320px;
    height: 32px;
}

.a-d-top>>>.el-input__icon {
    line-height: 32px;
}

.a-d-topTit {
    width: 171px;
    height: 32px;
    display: flex;
    align-items: center;
    font-family: PingFang SC;
    box-sizing: border-box;
    padding: 5px;
    line-height: 22px;
    justify-content: center;
    /* text-align: left; */
}

.a-d-t-left {
    width: 200px;
    height: 100%;
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: flex-start;
    box-sizing: border-box;
    padding: 15px 0 0 0;
}

.a-d-t-l-item {
    /* width: auto;
	height: 90%;
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 0 10px;
	border-radius: 10px;
	background-color: #d4d9da;
	margin-right: 3px;
	cursor: pointer; */
    cursor: pointer;
    width: 136px;
    height: 32px;
    display: flex;
    align-items: center;
    border-radius: 5px;
    font-family: PingFang SC;
    box-sizing: border-box;
    padding: 5px;
    font-size: 14px;
    font-weight: 600;
    line-height: 22px;
    text-align: left;
    margin-bottom: 20px;
}

.a-d-t-l-item:hover {
    background-color: white;
}

.a-d-t-right {
    /* width: 40px; */
    height: 40px;
    margin-right: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: black !important;
}

.a-d-t-right>span {
    width: 25px;
    height: 25px;
    border-radius: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* align-items: center; */
    font-size: 22px;
    color: #fff;
    /* background-color: #adadad; */
    cursor: pointer;
    /* background-color: #e6e6e6; */
    color: #adadad;
}

.a-d-box {
    width: 100%;
    height: 100%;
    background-color: #f0f2f5;
    overflow: scroll;
    overflow-x: hidden;
    box-sizing: border-box;
    padding: 15px;
    padding-bottom: 50px;
}

.a-d-b-item {
    width: 30%;
    height: 240px;
    display: flex;
    flex-direction: column;
    background-color: #fff;
    border-radius: 10px;
    padding: 15px;
    float: left;
    box-sizing: border-box;
    margin-bottom: 10px;
    margin-right: 20px;
    /* position: relative; */
}

/* .a-d-b-item:hover .a-d-b-i-bottomBtn {
	display: block !important;
}
.a-d-b-item:hover .a-d-b-i-bottomPer {
	display: none !important;
} */
.a-d-b-i-top {
    width: 100%;
    /* height: 50%; */
    height: 20px;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    /* justify-content: space-between; */
}

.a-d-b-i-top>img {
    width: 35px;
    height: 35px;
}

/* .a-d-b-i-top>div{ */
/* width: auto;
	height: 35px;
	display: flex;
	justify-content: center;
	align-items: center;
	margin-left: 10px; */
/* } */

.a-d-b-i-t-title {
    width: 100%;
    height: 35px;
    display: block;
    align-items: center;
    box-sizing: border-box;
    padding: 0 10px;
    text-overflow: ellipsis;
    overflow: hidden;
    word-break: break-all;
    white-space: nowrap;
    line-height: 35px;
    /* display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 1;
	overflow: hidden; */
}

.a-d-b-i-bottom {
    width: 100%;
    flex: 1;
    overflow: hidden;
    /* max-height: 186px; */
    max-height: 100px;
    height: 140px;
    min-height: 140px;
    font-size: 14px;
    -webkit-line-clamp: 7;
    line-height: 20px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.a-d-b-i-t-btn {
    font-size: 14px;
    width: 98%;
    box-sizing: border-box;
    padding: 8px 0;
    border: 1px solid rgb(247, 30, 30);
    border-radius: 5px;
    color: rgb(247, 30, 30);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.a-d-b-i-t-btn1 {
    font-size: 14px;
    width: 98%;
    box-sizing: border-box;
    padding: 8px 0;
    border: 1px solid rgba(54, 129, 252, 1);
    border-radius: 5px;
    background-color: rgba(54, 129, 252, 1);
    display: flex;
    color: #fff;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.itemTit {
    width: 136px;
    height: 32px;
    padding: 5px 8px 5px 8px;
    gap: 8px;
    opacity: 0px;
    margin: 20px 0;
    margin-bottom: 10px;
    border-bottom: 1px #ccc solid;
}

.a-d-b-subject {
    margin: 20px 0 20px 0;
}

.a_d_b_s_btn {
    /* box-sizing: border-box; */
    padding: 5px 10px;
    border-radius: 4px;
    border: solid 1px #3681FC;
    color: #3681FC;
    background-color: white;
    margin-right: 10px;
    cursor: pointer;
    transition: .3s;
}

.a_d_b_s_ActiveBtn {
    background-color: #3681FC;
    color: white;
}


</style>