<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.fee_status" placeholder="请选择" class="selects" clearable>
                            <el-option v-for="item in feeStatusOptions" :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.acquire_mode" placeholder="请选择" class="selects" clearable>
                            <el-option v-for="item in acquireModeOptions" :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.status" placeholder="请选择" class="selects" clearable>
                            <el-option v-for="item in statusOptions" :key="item.value" :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                   
                  
                </el-form>
            </div>
        </div>
        <div class="content-table">
          <div class="table-wrapper">
            <el-table :data="tableData" border style="width: 100%">
                <el-table-column fixed type="index" label="序号" align="center" width="80" :index="indexMethod">
                </el-table-column>
                <el-table-column prop="invention_name" label="发明名称" align="center" width="200" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="patent_no" label="专利号" align="center" width="150" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="grant_notice_no" label="授权公告号" align="center" width="150" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="grant_date" label="授权公告日" align="center" width="120">
                </el-table-column>
                <el-table-column prop="acquire_mode" label="获得方式" align="center" width="120">
                    <template slot-scope="scope">
                        {{ getAcquireModeLabel(scope.row.acquire_mode) }}
                    </template>
                </el-table-column>
                <el-table-column prop="patentee" label="专利权人" align="center" width="180" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="fee_status" label="年费状态" align="center" width="100">
                    <template slot-scope="scope">
                        {{ getFeeStatusLabel(scope.row.fee_status) }}
                    </template>
                </el-table-column>
                <el-table-column prop="status" label="是否有效" align="center" width="100">
                    <template slot-scope="scope">
                        {{ scope.row.status === 1 || scope.row.status === '1' ? '有效' : '无效' }}
                    </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作" align="center" width="120">
                    <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,Details,deletes} from '@/api/resource/achievement/knowledge'
export default {
    props: {
        type: {
            type: Number,
            default: 1 // 发明专利，默认值为1
        }
    },
    data() {
        return {
            listDate:[
                {
                    value1:"",
                    value2:"",
                    value3:"",
                },
                {
                    value1:"",
                    value2:"",
                    value3:"",
                }
            ],
            performanceShow:false,
            input:"",
            dialogVisible: false,
            currentPage: 1,
            pageSize: 10,
            total: 0,
            tableData: [{
                niandu1: '1',
                niandu2: '2024年度审计报告及财务情况说明书',
                niandu3: '1.2565',
                niandu4: '26.254',
                niandu5: '2.26885',
                niandu6: '125655',
                niandu7: '125655',
                niandu8: '125655',
                niandu9: '有效',
            }, {
                niandu1: '2024',
                niandu2: '2024年度审计报告及财务情况说明书',
                niandu3: '1.2565',
                niandu4: '26.254',
                niandu5: '2.26885',
                niandu6: '125655',
                niandu7: '125655',
                niandu8: '125655',
                niandu9: '有效',
            }, {
                niandu1: '2024',
                niandu2: '2024年度审计报告及财务情况说明书',
                niandu3: '1.2565',
                niandu4: '26.254',
                niandu5: '2.26885',
                niandu6: '125655',
                niandu7: '125655',
                niandu8: '125655',
                niandu9: '有效',
            }, {
                niandu1: '2024',
                niandu2: '2024年度审计报告及财务情况说明书',
                niandu3: '1.2565',
                niandu4: '26.254',
                niandu5: '2.26885',
                niandu6: '125655',
                niandu7: '125655',
                niandu8: '125655',
                niandu9: '有效',
            }, {
                niandu1: '2024',
                niandu2: '2024年度审计报告及财务情况说明书',
                niandu3: '1.2565',
                niandu4: '26.254',
                niandu5: '2.26885',
                niandu6: '125655',
                niandu7: '125655',
                niandu8: '125655',
                niandu9: '有效',
            }, {
                niandu1: '2024',
                niandu2: '2024年度审计报告及财务情况说明书',
                niandu3: '1.2565',
                niandu4: '26.254',
                niandu5: '2.26885',
                niandu6: '125655',
                niandu7: '125655',
                niandu8: '125655',
                niandu9: '有效',
            }, {
                niandu1: '2024',
                niandu2: '2024年度审计报告及财务情况说明书',
                niandu3: '1.2565',
                niandu4: '26.254',
                niandu5: '2.26885',
                niandu6: '125655',
                niandu7: '125655',
                niandu8: '125655',
                niandu9: '有效',
            }, {
                niandu1: '2024',
                niandu2: '2024年度审计报告及财务情况说明书',
                niandu3: '1.2565',
                niandu4: '26.254',
                niandu5: '2.26885',
                niandu6: '125655',
                niandu7: '125655',
                niandu8: '125655',
                niandu9: '有效',
            },],
            // 年费状态选项：0-未缴, 1-已缴, 2-逾期, 3-减免
            feeStatusOptions: [
                {
                    value: '',
                    label: "全部"
                },
                {
                    value: '0',
                    label: "未缴"
                },
                {
                    value: '1',
                    label: "已缴"
                },
                {
                    value: '2',
                    label: "逾期"
                },
                {
                    value: '3',
                    label: "减免"
                }
            ],
            // 获得方式选项：空字符串-全部, 1-自主研发, 2-受让, 3-受赠, 4-并购, 5-其他
            acquireModeOptions: [
                {
                    value: '',
                    label: "全部"
                },
                {
                    value: '1',
                    label: "自主研发"
                },
                {
                    value: '2',
                    label: "受让"
                },
                {
                    value: '3',
                    label: "受赠"
                },
                {
                    value: '4',
                    label: "并购"
                },
                {
                    value: '5',
                    label: "其他"
                }
            ],
            // 是否有效选项：空字符串-全部, 0-无效, 1-有效
            statusOptions: [
                {
                    value: '',
                    label: "全部"
                },
                {
                    value: '0',
                    label: "无效"
                },
                {
                    value: '1',
                    label: "有效"
                }
            ],
            options3: [
                {
                    value: 1,
                    label: "有效"
                },
                {
                    value: 2,
                    label: "无效"
                }
            ],
            options2: [
                {
                    value: 1,
                    label: "本年 (期)"
                },
                {
                    value: 2,
                    label: "2025"
                }
            ],
            options: [
                {
                    value: 1,
                    label: "全部"
                },
                {
                    value: 2,
                    label: "2025"
                }
            ],
            form: {
                fee_status: '', // 年费状态（可选，空值表示"全部"）
                acquire_mode: '', // 获得方式（可选，空值表示"全部"）
                status: '', // 是否有效（可选，空值表示"全部"）
                value3: "",
                value: "全部",
                value2: "本年 (期)"
            }
        }
    },
    mounted() {
        this.getList()
    },
    watch: {
        'form.fee_status'() {
            this.currentPage = 1
            this.getList()
        },
        'form.acquire_mode'() {
            this.currentPage = 1
            this.getList()
        },
        'form.status'() {
            this.currentPage = 1
            this.getList()
        },
        type() {
            // 当type变化时重新获取列表
            this.currentPage = 1
            this.getList()
        }
    },
    methods: {
        // 获取列表数据
        async getList() {
            try {
                const params = {
                    page: String(this.currentPage),
                    limit: String(this.pageSize),
                    orderBy: 'id',
                    orderDir: 'desc',
                    type: String(this.type) // 知识产权类型：1-发明专利, 2-植物新品种, 3-国家新药, 4-集成电路布图设计专有权, 5-实用新型专利, 6-软件著作权, 7-外观设计专利, 8-商标信息
                }
                // 添加筛选条件
                // 年费状态：如果为空字符串，表示"全部"，不传该参数；否则传递选择的值
                if (this.form.fee_status !== '') {
                    params.fee_status = String(this.form.fee_status) // 年费状态：0-未缴, 1-已缴, 2-逾期, 3-减免
                }
                // 获得方式：如果为空字符串，表示"全部"，不传该参数；否则传递选择的值
                if (this.form.acquire_mode !== '') {
                    params.acquire_mode = String(this.form.acquire_mode) // 获得方式：1-自主研发, 2-受让, 3-受赠, 4-并购, 5-其他
                }
                // 是否有效：如果为空字符串，表示"全部"，不传该参数；否则传递选择的值
                if (this.form.status !== '') {
                    params.status = String(this.form.status) // 是否有效：0-无效, 1-有效
                }
                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('获取列表失败，请稍后重试')
            }
        },
        btnAdds(){
            this.$emit('btnAdds')
        },
        //提交添加
        btnJixiao(){
            this.performanceShow=true
        },
        //添加
        btnAdd(){
            this.dialogVisible=true
        },
        // 序号计算方法
        indexMethod(index) {
            return (this.currentPage - 1) * this.pageSize + index + 1
        },
        // 获取年费状态标签
        getFeeStatusLabel(value) {
            const option = this.feeStatusOptions.find(item => item.value === String(value))
            return option ? option.label : '未知'
        },
        // 获取获得方式标签
        getAcquireModeLabel(value) {
            const option = this.acquireModeOptions.find(item => item.value === String(value))
            return option ? option.label : '未知'
        },
        // 分页
        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('getaudit', row)
            }
        },
        // 删除
        async handleDelete(row) {
            if (!row.id) {
                this.$message.warning('数据异常，无法删除')
                return
            }
            this.$confirm('确认删除这条记录吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                try {
                    const res = await deletes(row.id)
                    if (res && res.code === 1) {
                        this.$message.success('删除成功')
                        this.getList()
                    } else {
                        this.$message.error(res?.msg || '删除失败，请稍后重试')
                    }
                } catch (error) {
                    console.error('删除失败:', error)
                    this.$message.error('删除失败，请稍后重试')
                }
            }).catch(() => {})
        }
    }
}
</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>

.adds{
    width: 30px;
    height: 20px;
    background: #DCE0FD;
    color: #5065F6;
    position: relative;
    left: 54px;
    font-size: 14px;
    text-align: center;
    line-height: 18px;
    cursor: pointer;
}
.lies:hover .closes {
    opacity: 1;; /* 鼠标滑过 .lies 时才显示 */
}
.closes{
    background: #FCF1EB;
    width: 20px;
    height: 30px;
    position: relative;
    top: 5px;
    cursor: pointer;
    text-align: center;
    line-height: 30px;
    color: #F04B4B;
    font-size: 20px;
    opacity: 0;
}
.liee{
    background-color: #DCE0FD;
    color: #17192C;
    text-align:center
}
.lie{
    border: 1px solid #3333;
    width: 100px;
    height: 40px;
    line-height: 40px;
    border-right: none;
    border: none;
    border-bottom: 1px solid #EDEFFE
}
.lies{
display: flex;
/* border-bottom: 1px solid #EDEFFE */
}
.zhuyi{
   color: #5165f7;
    font-size: 14px;
    text-align: center;
    position: relative;
    top: -12px;
}
:deep(.el-input__wrapper) {
  box-shadow: none !important;
  padding-left: 7 !important;
  background: none !important;
}
/* 去掉内部输入框的padding */
:deep(.el-input__inner) {
    padding-left: 7 !important;
  border: none !important;
  background: none !important;
}
.th1{
    width: 120px;         /* 设置固定宽度（可以根据需要调整） */
  font-size: 13px;      /* 字体大小比默认小 */
  text-align: right;    /* 右对齐 */
  padding-right: 8px;
  border-right: 1px solid #DCE0FD;
  background: #EDEFFE !important;
  border-bottom: 1px solid #DCE0FD !important;
}
.container {
    width: 72%;
   margin: 0 auto;
}

h1 {
    color: #333;
    text-align: center;
    margin-bottom: 25px;
    font-weight: 600;
    font-size: 24px;
}

.department-table {
    width: 100%;
    border-collapse: collapse;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.department-table {
    width: 100%;
    border-collapse: collapse;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.department-table tr{
    border: 1px solid #DCE0FD;
    cursor: pointer;
}

.department-table th {
   
    /* 淡紫色表头 */
    color: #5a4a6a;
    font-weight: 600;
    text-align: left;
    padding: 16px 20px;

}

.department-table td {
    background-color: white;
    padding: 5px 20px;
    border-bottom: 1px solid #f0f0f0;
    color: #333;
}

.department-table tr:last-child td {
    border-bottom: none;
}

.department-table tr:hover td {
    background-color: #f9f9f9;
    transition: background-color 0.2s;
}

.empty-value {
    color: #999;
    font-style: italic;
}

.footer {
    text-align: center;
    margin-top: 25px;
    color: #888;
    font-size: 14px;
}

.contents {
    width: 90%;
    margin: 0 auto;
}

:deep .el-dialog__body {
    padding: 0 !important;
}

.dialog-footer {
    text-align: center;
    margin: 0 auto;
    margin-top: 12px;
}

.dialog-header {
    width: 100%;
    height: 54px;
    background: #F7F7FA;
    text-align: center;
    line-height: 54px;
    position: relative;
    top: -28px;
    color: #363636;
    font-weight: bold;
    font-size: 18px
}

:deep .el-tooltip__popper.is-dark {
    color: #F04B4B !important;
}

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

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

.tianjia2 {
    position: relative;
    top: -9px;
    background-color: #EDEFFE;
    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;
    position: relative;
    width: 100%;
}

.table-wrapper {
    flex: 1;
    overflow-x: auto;
}

.external-111 {
    width: 23px;
    position: absolute;
    right: 0;
    top: 41px;
    z-index: 10;
    display: flex;
    flex-direction: column;
}

.bianji {
    width: 23px;
    height: 47px;
    background: #2AB95F;
    color: white;
    text-align: center;
    font-size: 12px;
    line-height: 23px;
    cursor: pointer;
    writing-mode: vertical-lr;
    text-orientation: mixed;
    margin-bottom: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.formitem {
    position: relative;
    top: -5px;
}

::deep .el-form-item__label {
    font-size: 15px !important;
}

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

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

.tubiao {
    position: relative;
    top: 22px;
    z-index: 99;
    left: -20px;
    cursor: pointer;
}

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