<template>
    <div class="modelListPanel">
        <div class="addBtn" @click="addOne">
            <span>新增</span>
            <i class="el-icon-plus"></i>
        </div>
        <div class="listPanel">
            <div class="inputPanel">
                <el-input
                    placeholder="请输入内容"
                    v-model="searchName"
                    maxlength="60"
                    class="input-with-select"
                    clearable
                >
                    <el-button
                        slot="append"
                        icon="el-icon-search"
                        @click="searchOne"
                    ></el-button>
                </el-input>
            </div>
            <div class="title">公有</div>
            <ul class="list listPub">
                <li v-for="item in listPub" :key="item.id">
                    <span @click="showInfo(item.id)">
                        {{ item[showName] }}
                    </span>
                </li>
            </ul>
            <div class="title">私有</div>
            <ul class="list listPri">
                <li v-for="item in listPri" :key="item.id">
                    <span @click="showInfo(item.id)">
                        {{ item[showName] }}
                    </span>
                    <i class="el-icon-delete" @click="delOne(item.id)"></i>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
//import  from '';

export default {
    name: "modelList", // 模型列表
    components: {},
    data() {
        return {
            searchName: "",
            listPub: [], // 公有列表
            listPri: [], // 私有列表
        };
    },

    props: {
        getListApi: {
            type: String,
            default: "",
        },
        showName: {
            type: String,
            default: "",
        },
    },

    methods: {
        getList() {
            if (!this.getListApi) return;

            let data = {};
            data[this.showName] = this.searchName;

            this.$axios({
                method: "post",
                url: this.getListApi,
                data,
            }).then((res) => {
                if (res.code == 200 && res.info) {
                    this.listPub = res.info.filter((i) => i.share === "1");
                    this.listPri = res.info.filter((i) => i.share === "0");
                } else {
                    this.$message.error(res.message || "获取失败");
                }
            });
        },
        showInfo(id) {
            this.$emit("showInfo", id);
        },
        addOne() {
            this.$emit("addOne");
        },
        delOne(id) {
            this.$confirm("确认是否删除？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                this.$emit("delOne", id);
            });
        },
        searchOne() {
            this.getList();
        },
    },

    mounted() {
        this.getList();
    },
};
</script>

<style lang='less' scoped>
.modelListPanel {
    position: relative;
    width: 322px;
    margin-right: 10px;

    .addBtn {
        position: relative;
        z-index: 1;
        display: flex;
        justify-content: space-between;
        width: 320px;
        padding: 12px 24px;
        margin: 0 auto;
        border-radius: 3px;
        color: #ffffff;
        background: @themeColor;
        cursor: pointer;
    }

    .listPanel {
        padding-top: 18px;
        border: 1px solid @grayLine;
        border-radius: 4px;
        box-shadow: 3px 0 6px @grayLine, 0 3px 6px @grayLine, 0 0px transparent,
            -3px 0 6px @grayLine;
        overflow: hidden;

        .title {
            border-left: 6px solid @themeColor;
            padding-left: 20px;
            margin-bottom: 4px;
            color: @themeColor;
            font-size: 16px;
            font-weight: bold;
        }

        .list {
            margin: 0 10px 40px 26px;
            border-top: 1px solid @grayLine;

            li {
                margin-top: 10px;

                span,
                i {
                    cursor: pointer;
                }
            }
        }

        .listPub,
        .listPri {
            height: calc(50% - 91px);
            overflow-y: auto;
        }

        .listPri li {
            display: flex;
            justify-content: space-between;
            width: 100%;

            i {
                font-size: 16px;
                color: @themeColor;
            }
        }
    }

    .inputPanel {
        margin: 0 10px 20px;

        .el-input {
            width: 300px;
        }

        /deep/ .el-input-group__append {
            background-color: #fff;
            border-color: #e5e5e5;
            padding: 0;
            overflow: hidden;
        }
    }

    .input-with-select .el-input-group__prepend {
        background-color: #fff;
    }

    /deep/ .el-input-group__append button.el-button,
    /deep/ .el-input-group__append div.el-select .el-input__inner,
    /deep/ .el-input-group__append div.el-select:hover .el-input__inner,
    /deep/ .el-input-group__prepend button.el-button,
    /deep/ .el-input-group__prepend div.el-select .el-input__inner,
    /deep/ .el-input-group__prepend div.el-select:hover .el-input__inner {
        border-color: transparent;
        background-color: transparent;
        color: inherit;
        border-top: 0;
        border-bottom: 0;
    }
}
</style>