<template>
    <div class="agent_page">
        <div class="top">
            <img src="@/assets/images/agent/arrow_left.png" @click="handleBack">
            <div class="spans">
                <span>知识库</span>
                <span class="last">&nbsp;/&nbsp;创建知识库</span>
            </div>
        </div>
        <div class="steps adfacjc">
            <div class="s_text adfac" :class="{'active':step<3}">
                <div class="st_num">1</div>
                <span>知识库信息</span>
            </div>
            <div class="s_line"></div>
            <div class="s_text adfac" :class="{'active':step===2}">
                <div class="st_num">2</div>
                <span>数据添加</span>
            </div>
        </div>
        <template v-if="step===1">
            <div class="content">
                <div class="c_title">创建知识库</div>
                <el-form ref="knowledgeFormRef" :model="knowledgeDto" :rules="knowledgeRule" label-width="100px" style="margin-top: 38px;">
                    <el-form-item label="知识库名称" prop="aaa">
                        <el-input v-model="knowledgeDto.aaa" clearable placeholder="请输入知识库名称" maxlength="20" show-word-limit></el-input>
                    </el-form-item>
                    <el-form-item label="知识库描述" prop="bbb">
                        <el-input type="textarea" v-model="knowledgeDto.bbb" clearable placeholder="请输入知识库描述" maxlength="200" show-word-limit></el-input>
                    </el-form-item>
                </el-form>
            </div>
        </template>
        <template v-else-if="step===2">
            <div class="content">
                <div class="c_title">选择数据</div>
                <div class="c_tip">导入数据，构建知识库索引</div>
                <div class="c_type adfac">
                    <span>添加知识</span>
                    <el-radio-group v-model="addType">
                        <el-radio :label="1">选择文件</el-radio>
                        <el-radio :label="2">上传文件</el-radio>
                    </el-radio-group>
                </div>
                <template v-if="addType===1">
                    <div class="c_xzwj">
                        <span>请选择类目</span>
                        <div class="cx_box adf">
                            <div class="cxb_left">
                                <span>类目</span>
                                <div class="cl_list">
                                    <div class="cl_item" :class="{'active':cidx===index}" v-for="(item,index) in categoryList" :key="index" @click="handleSelectCategory(item,index)">{{ item.name }}</div>
                                </div>
                            </div>
                            <div class="cxb_rigth">
                                <el-table :data="fileList" border cell-class-name="vertical-top-cell" v-loading="loading" empty-text="暂无文件" max-height="600px">
                                    <el-table-column label="序号" width="50">
                                        <template #default="scope">
                                            {{ scope.$index + 1 }}
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="文件名称" prop="aaa"></el-table-column>
                                    <el-table-column label="状态" prop="bbb">
                                        <template #default="{ row }"></template>
                                    </el-table-column>
                                    <el-table-column label="数据来源" prop="aaa"></el-table-column>
                                    <el-table-column label="文件格式" prop="aaa"></el-table-column>
                                </el-table>
                                <el-row style="display: flex;justify-content: center;">
                                    <el-pagination
                                        @size-change="handleSizeChange"
                                        @current-change="handleCurrentChange"
                                        :current-page="queryParams.page"
                                        :page-sizes="[5, 10, 20, 50]"
                                        :page-size="10"
                                        layout="total, sizes, prev, pager, next, jumper"
                                        :total="total"
                                        v-show="total > 0">
                                    </el-pagination>
                                </el-row>
                            </div>
                        </div>
                    </div>
                </template>
                <template v-else-if="addType===2">
                    <div class="c_scwj">
                        <div class="cs_item adfac">
                            <span>选择类目</span>
                            <el-select v-model="knowledgeDto.category" placeholder="请选择" style="width: 480px;"></el-select>
                        </div>
                        <div class="cs_item adfac" style="margin-top: 37px;">
                            <span>添加方式</span>
                            <el-radio-group v-model="tjfsType">
                                <el-radio :label="1">本地上传</el-radio>
                                <el-radio :label="2">网址提交</el-radio>
                                <el-radio :label="3">百度网盘</el-radio>
                                <el-radio :label="4">自媒体平台</el-radio>
                            </el-radio-group>
                        </div>
                        <div class="cs_upload">
                            <el-upload
                                class="upload-demo"
                                drag
                                action=""
                                multiple>
                                <i class="el-icon-upload"></i>
                                <div class="el-upload__text">点击或拖拽文件上传</div>
                                <div class="el-upload__text" style="font-size: 12px;color: #C1C7D2;line-height: 20px;margin-top: 8px;">
                                    支持 .pdf,.doc,.docx,.txt,.md,.pptx,.ppt,.png,.jpg,.jpeg,.bmp,.gif,.xls,.xlsx,.html 等格式<br>
                                    单文档最大限制100MB或1000页，单图片最大限制20MB
                                </div>
                            </el-upload>
                        </div>
                    </div>
                </template>
            </div>
        </template>
        <div class="btns adfac">
            <el-button type="primary" @click="handleNext" v-if="step===1">下一步</el-button>
            <el-button type="primary" @click="handlePrevious" v-if="step===2">上一步</el-button>
            <el-button type="default" @click="handleCancel">取消</el-button>
        </div>
    </div>
</template>

<script setup name="">
    import { ref, getCurrentInstance } from 'vue'
    const { proxy } = getCurrentInstance();

    const step = ref(1)
    const addType = ref(1)
    const tjfsType = ref(1)
    const categoryList = ref([
        {id:1,name:'高企的发展路径'},
        {id:2,name:'团队管理'},
        {id:3,name:'默认类目'}
    ])
    const knowledgeFormRef = ref(null)
    const knowledgeDto = ref({
        aaa: '',
        bbb: '',
        category:''
    })
    const knowledgeRule = ref({
        aaa: [
            { required: true, message: '请输入知识库名称', trigger: 'blur' }
        ],
        bbb: [
            { required: true, message: '请输入知识库描述', trigger: 'blur' }
        ]
    })
    const fileList = ref([])
    const cidx = ref('')
    const loading = ref(false)
    const queryParams = ref({
        page: 1,
        limit: 10
    })
    const total = ref(0)
    const handleSizeChange = (val) => {
        queryParams.value.limit = val;
        getList()
    }
    const handleCurrentChange = (val) => {
        queryParams.value.page = val;
        getList()
    }
    const getList = () => {
        let query = {...queryParams.value};
        loading.value = true;
        // const res = await listOrder(query);
        // userList.value = res.data.list;
        // total.value = res.data.total;
        loading.value = false;
    }

    const handleSelectCategory = (item,index) => {
        cidx.value = index;
        getList();
    }

    const handleBack = () => {
        proxy.$router.go(-1)
    }

    const handleNext = () => {
        proxy.$refs.knowledgeFormRef.validate((valid) => {
            if (valid) {
                step.value = 2
            } else {
                return false;
            }
        })
    }
    const handlePrevious = () => {
        step.value = 1
    }
    const handleCancel = () => {
        proxy.$router.go(-1)
    }
</script>

<style scoped lang="scss">
    .agent_page{
        position: relative;
        .top{
            width: 100%;
            height: 64px;
            background: #FFFFFF;
            border-bottom: 1px solid #F3F4F6;
            display: flex;
            align-items: center;
            img{
                width: 36px;
                height: 36px;
                margin-left: 16px;
                cursor: pointer;
            }
            .spans{
                display: flex;
                align-items: center;
                margin-left: 23px;
                span{
                    font-family: PingFangSC, PingFang SC;
                    font-weight: 400;
                    font-size: 14px;
                    color: #6B7280;
                    line-height: 14px;
                    &.last{
                        color: #111111;
                    }
                }
            }
        }

        .steps{
            margin-top: 24px;
            .s_text{
                .st_num{
                    width: 24px;
                    height: 24px;
                    border-radius: 50%;
                    background: #DDE0E6;
                    font-family: PingFang-SC, PingFang-SC;
                    font-weight: bold;
                    font-size: 14px;
                    color: #FFFFFF;
                    line-height: 24px;
                    text-align: center;
                }
                span{
                    margin-left: 10px;
                    font-family: PingFangSC, PingFang SC;
                    font-weight: 400;
                    font-size: 14px;
                    color: #6B7280;
                    line-height: 14px;
                }
                &.active{
                    .st_num{
                        background: #761E6A;
                    }
                    span{
                        color: #761E6A;
                    }
                }
            }
            .s_line{
                width: 496px;
                height: 1px;
                border: 1px solid #E5E7EB;
                margin: 0 21px;
            }
        }

        .content{
            width: 100%;
            height: calc(100% - 190px);
            padding: 20px 30px 0;
            box-sizing: border-box;
            overflow-y: auto;

            .c_title{
                font-family: PingFang-SC, PingFang-SC;
                font-weight: bold;
                font-size: 16px;
                color: #111111;
                line-height: 16px;
            }
            .c_tip{
                font-family: PingFangSC, PingFang SC;
                font-weight: 400;
                font-size: 14px;
                color: #9CA3AF;
                line-height: 14px;
                margin-top: 16px;
            }
            .c_type{
                margin-top: 32px;
                span{
                    font-family: PingFang-SC, PingFang-SC;
                    font-weight: bold;
                    font-size: 14px;
                    color: #111111;
                    line-height: 14px;
                    margin-right: 40px;
                }
            }
            .c_xzwj{
                width: 100%;
                height: calc(100% - 122px);
                padding: 16px 19px;
                box-sizing: border-box;
                margin-top: 28px;
                border-radius: 6px;
                border: 1px solid #ECEEF5;
                overflow-y: auto;
                &>span{
                    font-family: PingFangSC, PingFang SC;
                    font-weight: 400;
                    font-size: 14px;
                    color: #111111;
                    line-height: 14px;
                }
                .cx_box{
                    width: 100%;
                    height: calc(100% - 30px);
                    margin-top: 14px;
                    .cxb_left{
                        width: 257px;
                        height: 100%;
                        border-radius: 6px;
                        border: 1px solid #ECEEF5;
                        padding: 25px 22px;
                        box-sizing: border-box;
                        overflow-y: auto;
                        &>span{
                            font-family: PingFangSC, PingFang SC;
                            font-weight: 400;
                            font-size: 14px;
                            color: #111111;
                            line-height: 14px;
                        }
                        .cl_list{
                            margin-top: 13px;
                            .cl_item{
                                width: 100%;
                                height: 36px;
                                border-radius: 8px;
                                font-family: PingFangSC, PingFang SC;
                                font-weight: 400;
                                font-size: 14px;
                                color: #111111;
                                line-height: 36px;
                                padding-left: 40px;
                                box-sizing: border-box;
                                cursor: pointer;
                                &.active,&:hover{
                                    background: #ECEEF5;
                                    color: #761E6A;
                                }
                            }
                        }
                    }
                    .cxb_rigth{
                        width: calc(100% - 257px);
                        height: 100%;
                        overflow-y: auto;
                        padding-left: 10px;
                        box-sizing: border-box;
                    }
                }
            }
            .c_scwj{
                margin-top: 22px;
                .cs_item{
                    span{
                        font-family: PingFang-SC, PingFang-SC;
                        font-weight: bold;
                        font-size: 14px;
                        color: #252525;
                        line-height: 14px;
                        margin-right: 43px;
                    }
                }
                .cs_upload{
                    width: 640px;
                    padding: 24px 0 0 98px;
                    box-sizing: border-box;
                }
            }
        }

        .btns{
            width: 100%;
            padding: 24px 29px;
            box-sizing: border-box;
            position: absolute;
            left: 0;
            bottom: 0;
        }
    }

    ::v-deep .el-upload,::v-deep .el-upload-dragger{
        width: 100% !important;
        background: #FAFAFB !important;
    }
</style>