<template>
    <div class="layout-tabs-content-box">
        <div class="">
            <div class="height-56 flex-row align-items-center justify-content-between">
                <div class="f22 color-text-primary">数据字典</div>
                <div class="flex-row">
                    <div class="mr-16">
                        <el-input
                            placeholder="请输入搜索内容"
                            suffix-icon="el-icon-search"
                            v-model.trim="queryParam.codeName"
                            size="small"
                            clearable
                            @change="handleSearch"
                            @keydown.enter.native="handleSearch"
                            >
                        </el-input>
                    </div>
                    <el-button size="small" type="primary" @click="handleAddForm">新增数据字典</el-button>
                </div>
                
            </div>

            <div class="" >
                <el-table :data="tableData" :height="`${contentHeight}`">
                    <el-table-column type="index" label="序号" width="55"></el-table-column>
                    <el-table-column prop="typeName" label="字典标签"></el-table-column>
                    <el-table-column prop="codeName" label="字典名称"></el-table-column>
                    <el-table-column prop="seq" label="排序"></el-table-column>
                    <el-table-column prop="remark" label="备注"></el-table-column>
                    <el-table-column  label="操作" width="150">
                        <template slot-scope="scope">
                            <div class="flex-row align-items-center">
                                <div class="f14 color-1960F4 cursor-pointer mr-8" @click="handleAddForm(scope)">编辑</div>
                                <div class="f14 color-1960F4 cursor-pointer" @click="handleDelete(scope)">删除</div>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="text-center pt-16">
                <el-pagination
                    @size-change="getDictList"
                    @current-change="getDictList"
                    :current-page="queryParam.current"
                    :page-size="queryParam.size"
                    layout="total, prev, pager, next, jumper"
                    :total="total">
                </el-pagination>
            </div>


        </div>
         <!-- 新增数据字典弹框 -->
        <addDictDialog v-if="addDictDialog" :addDictDialog.sync="addDictDialog" />

    </div>
</template>
<script>

import basicManage from "@/services/basicManage";
    export default {
        components: {
            addDictDialog: () => import('./components/addDictDialog.vue'),
        },
        data() {
            return {
                queryParam: {
                    codeName:'',
                    current:1,
                    size:10
                },
                tableData: [],
                total:0,
                addDictDialog:null
            }
        },
        created() {
            this.getDictList(1)
        },
        computed:{
            // 获取抽屉drawer的内容高度
            contentHeight(){
                let oh = document.documentElement.clientHeight;
                return oh-56-48-56-50-32          
            }  
        },
        methods: {

            getDictList(val){
                this.queryParam.current = val
                basicManage.getDictList(this.queryParam).then(res => {
                    if (!res.code) {
                    this.tableData = res.records;
                    this.total = res.total;
                    }
                })
            },
            // 搜索
            handleSearch() {
                this.queryParam.current = 1
                this.queryParam.size = 10
                this.getDictList(1)
            },
            // 新增弹窗  
            handleAddForm(scope){
                let title = scope.row?'编辑数组字典':'新增数组字典'
                let data = scope.row?scope.row:''
                this.addDictDialog={
                    title:title,
                    data: data
                }

            }, 
            // 删除
            handleDelete(scope){
                this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }).then(() => {
                    if(!this.$clickThrottle()) { return }//防止重复点击
                    basicManage.deleteDictById({ id: scope.row.id }).then((res) => {
                        
                        this.$message.success("成功");
                        this.getDictList(1)
                       
                    });
                }).catch(() => {});
            },
        }
    }
</script>