<template>
    <div>
        <search-layout :needBox="true" v-if="!isAdmin">
            <template slot="searchItem1">
                <span class="label">算法名称</span>
                <el-input v-model="searchParams.algorithmName" size="small" clearable placeholder="请输入" maxlength="60">
                </el-input>
            </template>
            <template slot="searchItem2">
                <span class="label">算法描述</span>
                <el-input v-model="searchParams.description" size="small" clearable placeholder="请输入" maxlength="60">
                </el-input>
            </template>
            <template slot="searchBtn1">
                <el-button type="primary" @click="doSearch">查询</el-button>
            </template>
            <template slot="searchBtn2">
                <el-button type="primary" @click="doReset">重置</el-button>
            </template>
        </search-layout>

        <search-layout :needBox="true" v-else>
            <!--<template slot="searchItem1">
                <span class="label">ID</span>
                <el-input
                    v-model="searchParams.algorithmCode"
                    size="small"
                    clearable
                    placeholder="请输入"
                    maxlength="60"
                >
                </el-input>
            </template>-->
            <template slot="searchItem1">
                <span class="label">比赛-赛题</span>
                <el-input v-model="searchParams.topic" size="small" clearable placeholder="请输入" maxlength="60">
                </el-input>
            </template>
            <template slot="searchItem2">
                <span class="label">参赛队伍</span>
                <el-input v-model="searchParams.team" size="small" clearable placeholder="请输入" maxlength="60">
                </el-input>
            </template>
            <template slot="searchItem3">
                <span class="label">算法名称</span>
                <el-input v-model="searchParams.algorithmName" size="small" clearable placeholder="请输入" maxlength="60">
                </el-input>
            </template>
            <template slot="searchItem4">
                <span class="label">版本号</span>
                <el-input v-model="searchParams.algorithmVersion" size="small" clearable placeholder="请输入" maxlength="60">
                </el-input>
            </template>
            <template slot="searchItem5">
                <span class="label">进度</span>
                <el-select v-model="searchParams.status">
                    <el-option v-for="item in algorithmStatusList" :label="item.caption" :value="item.code"
                        :key="item.code"></el-option>
                </el-select>
            </template>
            <template slot="searchItem6">
                <span class="label">算法描述</span>
                <el-input v-model="searchParams.description" size="small" clearable placeholder="请输入" maxlength="60">
                </el-input>
            </template>
            <!--<template slot="searchItem4">
                <span class="label">校验状态</span>
                <el-select v-model="searchParams.validationStatus">
                    <el-option
                        v-for="item in validationStatusList"
                        :label="item.caption"
                        :value="item.code"
                        :key="item.code"
                    ></el-option>
                </el-select>
            </template>-->
            <template slot="searchBtn1">
                <el-button type="primary" @click="doSearch">查询</el-button>
            </template>
            <template slot="searchBtn2">
                <el-button type="primary" @click="doReset">重置</el-button>
            </template>
        </search-layout>

        <div class="myTabsBox myTabsBoxThreeTabs">
            <!--<el-button
                v-bind:class="{ addBtn: true}"
                icon="el-icon-circle-plus-outline"
                @click="addOne"
                type="primary"
                >新增</el-button
            >-->
        </div>

        <tableList ref="table" style="margin: 0 30px" :columns="isAdmin ? columns1 : columns" :getDataWay="getDataWay"
            :pagination="pagination" tooltip-effect="light" index>

        </tableList>
    </div>
</template>

<script>
import searchLayout from "@/components/grid/searchLayout";
import tableList from "@/components/grid/TableList";

export default {
    name: "algorithmsPlatformList", // 算法平台
    components: { searchLayout, tableList },
    data() {
        return {
            searchParams: {
                //搜索参数
                //algorithmCode: "", // ID
                topic: "", // 比赛-赛题
                team: "", // 参赛队伍
                algorithmName: "", // 算法名称
                algorithmVersion: "", // 版本号
                status: "", // 进度
                description: "", // 算法描述
                //uploadMode: "", // 私有类型
            },
            algorithmStatusList: [],
            getDataWay: {
                //加载表格数据
                dataType: "url",
                //dataType: "data",
                type: "post",
                // firstRequest: false,
                data: this.$api.algorithmsLibrary.selectAlgoPlatformList,
                /*data:[
                    {
                        algorithmCode:'111',
                        algorithmName:'111',
                        description:
                        '打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲哈维打款哈对我来讲'
                    }
                ],*/
                param: {},
            },
            columns: [
                //表格列
                {
                    label: "ID",
                    prop: "algorithmCode",
                },
                {
                    label: "算法名称",
                    prop: "algorithmName",
                },
                {
                    label: "算法描述",
                    prop: "description",
                    showOverflowTooltip: true
                },
            ],
            columns1: [
                //表格列
                {
                    label: "ID",
                    prop: "algorithmCode",
                },
                {
                    label: "比赛-赛题",
                    prop: "topic",
                },
                {
                    label: "参赛队伍",
                    prop: "team",
                },
                {
                    label: "算法名称",
                    prop: "algorithmName",
                },
                {
                    label: "版本号",
                    prop: "algorithmVersion",
                },
                {
                    label: "进度",
                    prop: "status",
                    formatter(row) {
                        switch (row.status) {
                            case "1":
                                return "未测试";
                            case "2":
                                return "测试中";
                            case "3":
                                return "已测试";
                            default:
                                return "";
                        }
                    },
                },
                {
                    label: "算法描述",
                    prop: "description",
                    showOverflowTooltip: true
                },
            ],
            pagination: {
                //分页使用
                currentPage: 1,
                pageSize: 10,
                position: "right",
                pageSizes: [10, 30, 50, 100, 200],
                layout: "sizes, total, prev, pager, next, jumper",
            },
            isAdmin: false, // 判断是不是管理员
        };
    },

    computed: {

    },

    methods: {
        doSearch() {
            this.$nextTick(() => {
                this.refreshList(this.searchParams);
            });
        },
        //刷新table
        refreshList(param) {
            param
                ? this.$refs["table"].loadData(param)
                : this.$refs["table"].loadData();
        },
        doReset() {
            this.searchParams = {
                //algorithmCode: "",
                topic: "",
                team: "",
                algorithmName: "",
                algorithmVersion: "",
                status: "",
                description: "",
                //uploadMode: "",
            };
            this.doSearch();
        },
        addOne() { },
    },
    async mounted() {
        /*await this.$dicsListsInit({
            validationStatusList: "validationStatus",
        });*/

        await this.$axios({
            method: "post",
            url: this.$api.common.isAdmin,
            data: {},
        }).then(async (res) => {
            if (res.code == 200) {
                this.isAdmin = res.info

                if (res.info) {
                    await this.$dicsListsInit({
                        algorithmStatusList: "algorithmStatus",
                    });
                }
            } else {
                this.$message.error(res.message || "获取是否为管理员信息失败");
            }
        });


    },
};
</script>

<style scoped lang="less">
.tabsBox {
    position: relative;
    overflow: hidden;

    .el-button {
        position: absolute;
        right: 40px;
        top: 45px;
    }
}

.myTabsBox {
    min-height: 29px;
}
</style>