<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-date-picker
                            v-model="form.publish_date"
                            type="year"
                            placeholder="选择年份"
                            format="yyyy"
                            value-format="yyyy"
                            class="selects"
                            style="width: 120px;">
                        </el-date-picker>
                    </el-form-item>
                  
                    <el-form-item>
                        <el-input size="small" placeholder="请输入内容" v-model="input3" class="input-with-select" @keyup.enter.native="handleSearch">
   
                        <el-button slot="append" icon="el-icon-search" @click="handleSearch"></el-button>
                    </el-input>
                       
                    </el-form-item>
                    <el-form-item>
                      
                            <span class="el-dropdown-link">
                                <el-button type="primary" @click="btnDan" size="small" class="tianjia">添加</el-button>
                            </span>
                          
                     

                    </el-form-item>
                </el-form>
            </div>
        </div>
        <div class="content-table">
            <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="title" label="论文标题" align="center" width="500px" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="first_author" label="第一作者" align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="journal_type" label="期刊类型" align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="journal_name" label="期刊名称" align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="publish_date" label="发表日期" align="center" width="120">
                    <template slot-scope="scope">
                        {{ formatDate(scope.row.publish_date) }}
                    </template>
                </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 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>

      <!-- 添加部门 -->
      <el-dialog :visible.sync="dialogVisible" width="52%">
            <div class="dialog-header">添加职工</div>
            <div class="contents">
                <div class="container">
                    <el-table :data="tableData" border style="width: 100%">
                        <el-table-column prop="date" label="姓名" width="150" align="center">
                        </el-table-column>
                        <el-table-column prop="name" label="所属部门" width="150" align="center">
                            <el-select v-model="value" placeholder="请选择">
                                <el-option v-for="item in options" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-table-column>
                        <el-table-column prop="address" label="职位" width="150" align="center">
                            <el-select v-model="value" placeholder="请选择" >
                                <el-option v-for="item in options" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-table-column>
                        <el-table-column prop="address" label="员工来源" width="150" align="center">
                            <el-select v-model="value" placeholder="请选择" >
                                <el-option v-for="item in options" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-table-column>
                        <el-table-column prop="address" label="雇佣关系" width="150" align="center">
                            <el-select v-model="value" placeholder="请选择" >
                                <el-option v-for="item in options" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-table-column>
                        <el-table-column prop="address" label="职称" width="150" align="center">
                            <el-select v-model="value" placeholder="请选择" >
                                <el-option v-for="item in options" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-table-column>
                    </el-table>
                    <el-table :data="tableData2" border style="width: 100%">
                        <el-table-column prop="date" label="入职时间" width="150" align="center">
                        </el-table-column>
                        <el-table-column prop="name" label="联系电话" width="150" align="center">
                            <el-select v-model="value" placeholder="请选择">
                                <el-option v-for="item in options" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-table-column>
                        <el-table-column prop="address" label="学历" width="150" align="center">
                            <el-select v-model="value" placeholder="请选择">
                                <el-option v-for="item in options" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-table-column>
                        <el-table-column prop="address" label="身份证号">
                            <el-input v-model="input" placeholder="请输入内容"></el-input>
                        </el-table-column>
                       
                    
                    </el-table>
                </div>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false" size="small">取 消</el-button>
                <el-button type="primary" style="background-color: #5165f7;" @click="dialogVisible = false"
                    size="small">确
                    定</el-button>
            </div>
        </el-dialog>


     
    </div>
</template>
<script>
import {list } from '@/api/resource/achievement/paper'
export default {
    data() {
        return {
            value:"",
            input3:"",
            tableData2:[],
            listDate:[
                {
                    value1:"",
                    value2:"",
                    value3:"",
                },
                {
                    value1:"",
                    value2:"",
                    value3:"",
                }
            ],
            performanceShow:false,
            input:"",
            dialogVisible: false,
            currentPage: 1,
            pageSize: 10,
            total: 0,
            tableData: [],
            options3: [
                {
                    value: 1,
                    label: "有效"
                },
                {
                    value: 2,
                    label: "无效"
                }
            ],
            options2: [
                {
                    value: 1,
                    label: "本年 (期)"
                },
                {
                    value: 2,
                    label: "2025"
                }
            ],
            options: [
                {
                    value: 1,
                    label: "全部"
                },
                {
                    value: 2,
                    label: "2025"
                }
            ],
            form: {
                value3: "",
                publish_date: "", // 发表年度（年份）
                value2: "本年 (期)"
            }
        }
    },
    mounted() {
        this.getList()
    },
    watch: {
        'form.publish_date'() {
            // 发表年度变化时重新获取列表
            this.currentPage = 1
            this.getList()
        }
    },
    methods: {
        // 获取列表数据
        async getList() {
            try {
                const params = {
                    page: String(this.currentPage),
                    limit: String(this.pageSize),
                    orderBy: 'id',
                    orderDir: 'desc'
                }
                // 添加筛选条件
                // 发表年度：如果有选择年份，传递年份
                if (this.form.publish_date && this.form.publish_date.trim()) {
                    params.publish_date = this.form.publish_date.trim()
                }
                // 作者搜索：如果有输入，传递作者名称
                if (this.input3 && this.input3.trim()) {
                    params.first_author = this.input3.trim()
                }
                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('获取列表失败，请稍后重试')
            }
        },
        // 搜索
        handleSearch() {
            this.currentPage = 1
            this.getList()
        },
        // 序号计算方法
        indexMethod(index) {
            return (this.currentPage - 1) * this.pageSize + index + 1
        },
        // 格式化日期
        formatDate(dateString) {
            if (!dateString) return '-'
            // 如果是时间戳，转换为日期
            if (typeof dateString === 'number') {
                const date = new Date(dateString * 1000)
                const year = date.getFullYear()
                const month = String(date.getMonth() + 1).padStart(2, '0')
                const day = String(date.getDate()).padStart(2, '0')
                return `${year}-${month}-${day}`
            }
            // 如果是日期字符串，直接返回
            if (typeof dateString === 'string') {
                // 如果是 YYYY-MM-DD 格式，直接返回
                if (dateString.match(/^\d{4}-\d{2}-\d{2}/)) {
                    return dateString.split(' ')[0] // 去掉时间部分
                }
                // 尝试解析其他格式
                const date = new Date(dateString)
                if (!isNaN(date.getTime())) {
                    const year = date.getFullYear()
                    const month = String(date.getMonth() + 1).padStart(2, '0')
                    const day = String(date.getDate()).padStart(2, '0')
                    return `${year}-${month}-${day}`
                }
            }
            return dateString
        },
        btnpiliang(){
            this.$emit('getPiliang')
        },
         //单个添加
         btnDan() {
            this.$emit('adds')
        },
        //提交添加
        btnJixiao(){
           
        },
        
        // 分页
        handleSizeChange(val) {
            this.pageSize = val
            this.currentPage = 1
            this.getList()
        },
        handleCurrentChange(val) {
            this.currentPage = val
            this.getList()
        },

        handleClick(row) {
            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>
.input-with-select{
border: 1px solid #3333;
position: relative;
top: -4px;
}
.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;
}


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

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

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

.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>