
<!--
列清单 - 通过页面配置
@Author: linqian
@Date: 2021-04-08 14:25
-->
<template>
    <div>
        <el-tabs v-model="activeTab" type="card">
            <el-tab-pane :label="item.tabLabel" :name="item.tabName" v-for="(item, index) in tabList" :key="index">
                <el-form :inline="true" class="search-form" :model="item.searchCondition">
                    <!-- 列权限-数据安全级别搜索 -->
                    <template v-if="activeTab == 'sjaqjb'">
                        <el-form-item label="数据安全等级">
                            <dg-select
                                :data="sjaqjbList"
                                v-model="item.searchCondition.codeDataTypeStr.value"
                                value-name="codeDataTypeStr"
                                label-name="label"
                            ></dg-select>
                        </el-form-item>
                        <el-form-item label="字段中文名称">
                            <el-input v-model="item.searchCondition.resourceName.value"></el-input>
                        </el-form-item>
                    </template>
                    <!-- 字段分类搜索 -->
                    <template v-if="activeTab == 'zdfl'">
                        <el-form-item label="字段分类">
                            <dg-cascader
                                :data="zdflList"
                                v-model="item.searchCondition.codeDataTypeStr.value"
                                value-name="codeDataTypeStr"
                                label-name="label"
                                children-name="child"
                                filterable
                                clearable
                                :show-all-levels="false"
                            >
                            </dg-cascader>
                        </el-form-item>
                        <el-form-item label="字段中文名称">
                            <el-input v-model="item.searchCondition.resourceName.value"></el-input>
                        </el-form-item>
                    </template>
                    <!-- 数据分级搜索 -->
                    <template v-if="activeTab == 'sjfj'">
                        <el-form-item label="数据分级">
                            <dg-select
                                :data="sjfjList"
                                v-model="item.searchCondition.codeDataTypeStr.value"
                                value-name="codeDataTypeStr"
                                label-name="label"
                            ></dg-select>
                        </el-form-item>
                        <el-form-item label="数据资源名称">
                            <el-input v-model="item.searchCondition.resourceName.value"></el-input>
                        </el-form-item>
                    </template>
                    <!-- 表权限-数据安全级别搜索 -->
                    <!-- <template v-if="activeTab == 'sjaqjb2'">
                        <el-form-item label="数据安全级别">
                            <el-input v-model="item.searchCondition.level.value"></el-input>
                        </el-form-item>
                        <el-form-item label="数据资源名称">
                            <el-input v-model="item.searchCondition.level.value"></el-input>
                        </el-form-item>
                    </template> -->
                    <!-- 数据资源分类搜索 -->
                    <template v-if="activeTab == 'sjzyfl'">
                        <el-form-item label="数据资源分类">
                            <dg-cascader
                                :data="sjzyflList"
                                v-model="item.searchCondition.codeDataTypeStr.value"
                                value-name="codeDataTypeStr"
                                label-name="label"
                                children-name="child"
                                filterable
                                clearable
                                :show-all-levels="false"
                            >
                            </dg-cascader>
                        </el-form-item>
                        <!-- <el-form-item label="一级分类">
                            <dg-select :data="[]" v-model="item.searchCondition.level.value"> </dg-select>
                        </el-form-item>
                        <el-form-item label="二级分类">
                            <dg-select :data="[]" v-model="item.searchCondition.level.value"> </dg-select>
                        </el-form-item> -->
                        <el-form-item label="标签名称">
                            <el-input v-model="item.searchCondition.resourceName.value"></el-input>
                        </el-form-item>
                    </template>
                    <el-form-item>
                        <dg-button type="primary" @click="handleSearch(item.tableRef)" icon="el-icon-search"
                            >查询</dg-button
                        >
                    </el-form-item>
                </el-form>
                <Table
                    :ref="item.tableRef"
                    :tableName="item.tabLabel"
                    :url="item.tableUrl"
                    :headerData="item.tableHeader"
                    :condition="item.searchCondition"
                    @getTotalElements="getTotalElements"
                ></Table>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>

<script>
import Table from "@/components/table";
import { getDataDetailList, getSelectList } from "@/api/data-auth.js";
import {
    sjaqjbTableHeader_column,
    zdflTableHeader,
    sjfjTableHeader,
    sjaqjbTableHeader_table,
    sjzyflTableHeader
} from "./list-table-header";
export default {
    props: {
        type: String,
        authTree: Array
    },
    components: {
        Table
    },
    data() {
        return {
            // 列权限 - tab, table配置
            columnAuthTabList: [
                {
                    tabName: "sjaqjb",
                    tabLabel: "数据安全级别",
                    total: "",
                    tableUrl: "/authsvr/v2/dataauth/dataDetailList",
                    tableRef: "sjaqjbTable",
                    tableHeader: sjaqjbTableHeader_column,
                    searchCondition: {
                        codeDataTypeStr: {
                            value: "",
                            op: "="
                        },
                        resourceName: {
                            value: "",
                            op: "="
                        }
                    }
                },
                {
                    tabName: "zdfl",
                    tabLabel: "字段分类",
                    total: "",
                    tableUrl: "/authsvr/v2/dataauth/dataDetailList",
                    tableRef: "zdflTable",
                    tableHeader: zdflTableHeader,
                    searchCondition: {
                        codeDataTypeStr: {
                            value: "",
                            op: "="
                        },
                        resourceName: {
                            value: "",
                            op: "="
                        }
                    }
                }
            ],
            // 表权限 - tab、table配置
            tableAuthTabList: [
                {
                    tabName: "sjfj",
                    tabLabel: "数据分级",
                    total: "",
                    tableUrl: "/authsvr/v2/dataauth/dataDetailList",
                    tableRef: "sjfjTable",
                    tableHeader: sjfjTableHeader,
                    searchCondition: {
                        codeDataTypeStr: {
                            value: "",
                            op: "="
                        },
                        resourceName: {
                            value: "",
                            op: "="
                        }
                    }
                },
                // {
                //     tabName: "sjaqjb2",
                //     tabLabel: "数据安全级别",
                //     total: "",
                //     tableUrl: "/appsvr/v2/manufacturers",
                //     tableRef: "sjaqjb2Table",
                //     tableHeader: sjaqjbTableHeader_table,
                //     searchCondition: {
                //         level: {
                //             value: "",
                //             op: "="
                //         }
                //     }
                // },
                {
                    tabName: "sjzyfl",
                    tabLabel: "数据资源分类",
                    total: "",
                    tableUrl: "/authsvr/v2/dataauth/dataDetailList",
                    tableRef: "sjzyflTable",
                    tableHeader: sjzyflTableHeader,
                    searchCondition: {
                        codeDataTypeStr: {
                            value: "",
                            op: "="
                        },
                        resourceName: {
                            value: "",
                            op: "="
                        }
                    }
                }
            ],

            // 实际渲染
            tabList: [],
            activeTab: [],
            sjzyflList: [], // 数据资源分类列表
            sjfjList: [], // 数据分级列表
            zdflList: [], //字段分类
            sjaqjbList: [] // 数据安全级别
        };
    },
    computed: {},
    methods: {
        /**
         * @description 表格搜索
         * @param table 搜索哪个表格
         */
        handleSearch(table) {
            this.$refs[table][0].handleSearchClick();
        },

        getTotalElements({ totalElements, tableName }) {
            const index = this.tabList.findIndex((item) => item.tabLabel == tableName);
            if (this.tabList[index].total == "") {
                this.tabList[index].total = totalElements;
                this.tabList[index].tabLabel = `${this.tabList[index].tabLabel}(${totalElements})`;
            }
        },
     
        // 获取搜索下拉值
        initTableSelectList() {
            // 获取数据资源分级下拉列表
            getSelectList("DATA_RESOURCE_CLASSIFY").then((res) => {
                this.sjzyflList = res.data.content.nodes[0].child;
            });
            // 获取数据分级下拉列表
            getSelectList("DATA_CLASSIFY").then((res) => {
                this.sjfjList = res.data.content.nodes[0].child;
            });
        },

        initColumnSelectList() {
            // 字段分类下拉列表
            getSelectList("COLUMN_CLASSIFY").then((res) => {
                this.zdflList = res.data.content.nodes[0].child;
            });
            // 获取数据安全级别下拉列表
            getSelectList("DATA_SECURITY_LEVEL").then((res) => {
                this.sjaqjbList = res.data.content.nodes[0].child;
            });
        }
    },
    created() {
        // if (this.type == "TABLE") {
            this.tabList = this.tableAuthTabList;
            this.activeTab = "sjfj";
            this.initTableSelectList();
        // } else {
        //     this.tabList = this.columnAuthTabList;
        //     this.activeTab = "sjaqjb";
        //     this.initColumnSelectList();
        // }
    },
    mounted() {}
};
</script>

<style lang='scss'>
</style>