<template>
    <div>
        <div class="headers">
            <div class="headers-name">企业荣誉明细 ｜{{ total }}</div>
            <div style="position: relative;top: 6px;">
              
                <el-form :inline="true" :model="form" class="demo-form-inline">
                    
                    <el-form-item label="荣誉类型" size="small" style="position: relative;top: -3px;">
                        <el-select v-model="form.honor_type" placeholder="请选择" class="selects" clearable @change="handleSearch">
                            <el-option v-for="item in honorTypeOptions" :key="item.value" :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="荣誉级别" size="small" style="position: relative;top: -3px;">
                        <el-select v-model="form.honor_level" placeholder="请选择" class="selects" clearable @change="handleSearch">
                            <el-option v-for="item in honorLevelOptions" :key="item.value" :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="" size="small" style="position: relative;top: -3px;">
                        <el-input placeholder="请输入荣誉名称" v-model="form.honor_name" class="input-with-select">
                            <el-button slot="append" icon="el-icon-search" @click="handleSearch"></el-button>
                        </el-input>
                    </el-form-item>
                   
                    <el-form-item>
                        <el-button type="primary" @click="btnAdd" size="small" class="tianjia">添加</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <div class="content-table">
           
          <div style="flex: 1;">
            <el-table :data="tableData" border style="width: 100%">
                <el-table-column fixed type="index" label="序号" align="center" width="80px" :index="indexMethod">
                </el-table-column>
                <el-table-column prop="honor_name" label="荣誉名称" align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="honor_type_text" label="荣誉类型" align="center" width="120">
                    
                </el-table-column>
                <el-table-column prop="honor_level_text" label="级别" align="center" width="100">
                  
                </el-table-column>
                <el-table-column prop="publish_date" label="发布日期" align="center" width="120">
                </el-table-column>
                <el-table-column prop="valid_until" label="有效期至" align="center" width="120">
                </el-table-column>
                <el-table-column prop="issuing_unit" label="发布单位" align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column fixed="right" label="操作" align="center" width="80">
                    <template slot-scope="scope">
                        <el-button @click="handleClick(scope.row)" type="text" size="small">详情</el-button>
                    </template>
                </el-table-column>
            </el-table>
          </div>
          <div class="external-111" v-if="tableData.length">
                <div class="bianji" v-for="(item, index) in tableData" :key="index">
                    待编辑
                </div>
            </div>
        </div>
        <div class="footer">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="currentPage" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import { list } from '@/api/resource/qualification/corporatehonors'

export default {
    data() {
        return {
            currentPage: 1,
            pageSize: 10,
            total: 0,
            tableData: [],
            // 荣誉类型选项
            honorTypeOptions: [
                { value: 1, label: '科技型企业' },
                { value: 2, label: '研发创新' },
                { value: 3, label: '行业影响力' },
                { value: 4, label: '技术创新' },
                { value: 5, label: '质量奖项' },
                { value: 6, label: '其他' }
            ],
            // 荣誉级别选项
            honorLevelOptions: [
                { value: 1, label: '国家级' },
                { value: 2, label: '省级' },
                { value: 3, label: '市级' },
                { value: 4, label: '区级' },
                { value: 5, label: '其他' }
            ],
            form: {
                honor_type: '',
                honor_level: '',
                honor_name: ''
            }
        }
    },
    mounted() {
        this.getList()
    },
    activated() {
        this.getList()
    },
    methods: {
        // 获取列表数据
        async getList() {
            try {
                const params = {
                    page: this.currentPage,
                    limit: this.pageSize,
                    orderBy: 'id',
                    orderDir: 'desc'
                }
                // 添加筛选条件
                if (this.form.honor_type) {
                    params.honor_type = this.form.honor_type
                }
                if (this.form.honor_level) {
                    params.honor_level = this.form.honor_level
                }
                if (this.form.honor_name) {
                    params.honor_name = this.form.honor_name
                }
                
                const res = await list(params)
                if (res && res.code === 1 && res.data) {
                    this.tableData = res.data.data || []
                    this.total = res.data.total || 0
                } else {
                    this.tableData = []
                    this.total = 0
                }
            } catch (error) {
                console.error('获取列表失败:', error)
                this.$message.error('获取列表失败')
            }
        },
        // 获取荣誉类型文本
        getHonorTypeText(type) {
            const item = this.honorTypeOptions.find(opt => opt.value === type)
            return item ? item.label : '-'
        },
        // 获取荣誉级别文本
        getHonorLevelText(level) {
            const item = this.honorLevelOptions.find(opt => opt.value === level)
            return item ? item.label : '-'
        },
        // 搜索
        handleSearch() {
            this.currentPage = 1
            this.getList()
        },
        // 序号计算
        indexMethod(index) {
            return (this.currentPage - 1) * this.pageSize + index + 1
        },
        // 添加
        btnAdd() {
            this.$emit('goAdd')
        },
        // 分页大小改变
        handleSizeChange(val) {
            this.pageSize = val
            this.currentPage = 1
            this.getList()
        },
        // 页码改变
        handleCurrentChange(val) {
            this.currentPage = val
            this.getList()
        },
        // 详情
        handleClick(row) {
            if (row && row.id) {
                this.$emit('getDetail', row)
            }
        }
    }
}
</script>
<style>
.el-tooltip__popper.is-dark {
    color: #F04B4B !important;
    background: #FCF1EB !important;
}

.el-tooltip__popper .popper__arrow {
    border-top-color: #FCF1EB !important;
}

.el-tooltip__popper .popper__arrow::after {
    border-top-color: #FCF1EB !important;
}

.el-tooltip__popper[x-placement^='bottom'] .popper__arrow {
    border-bottom-color: #FCF1EB !important;
}

.el-tooltip__popper[x-placement^='left'] .popper__arrow {
    border-left-color: #FCF1EB !important;
}

.el-tooltip__popper[x-placement^='right'] .popper__arrow {
    border-right-color: #FCF1EB !important;
}
</style>
<style scoped>
.bianji {
    width: 20px;
    background: #2AB95F;
    color: white;
    margin-top: 14px;
    text-align: center;
    font-size: 11px;
    line-height: 14px;
    cursor: pointer;
}

.external-111 {
    width: 90px;
    position: relative;
    top: 43px;
}

.input-with-select {
    border: 1px solid #3333;
}

.footer {
    display: flex;
    justify-content: end;
    margin-top: 20px;
}

.tianjia {
    position: relative;
    top: -9px;
    background-color: #5065F6;
}

::v-deep .el-table thead {
    background-color: #DCE0FD !important;
    color: #363636 !important;
}

::v-deep .el-table__header th {
    background-color: #DCE0FD !important;
    color: #363636 !important;
}

.content-table {
    display: flex;
}

.selects {
    width: 120px;
    border: 1px solid #3333;
}

.headers-name {
    font-size: 15px;
    position: relative;
    top: 14px;
}

.headers {
    display: flex;
    justify-content: space-between;
}
</style>
