<template>
    <div>
        <div class="reviewer-search-toolbar">
            <div class="reviewer-search-filters">
                <span style="font-size: 14px; color: #606266; margin: 0 10px 0 0">{{ $t('reviewerAdd.researchDirection') }}</span>
                <el-input
                    v-model="messform.email"
                    clearable
                    :placeholder="$t('reviewerAdd.enterEmail')"
                    style="width: 190px; display: inline-block; margin: 0 10px 0 0"
                ></el-input>
                <el-input
                    v-model="messform.field"
                    clearable
                    :placeholder="$t('reviewerAdd.enterField')"
                    style="width: 190px; display: inline-block; margin: 0 10px 0 0"
                ></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">{{ $t('reviewerAdd.search') }}</el-button>
            </div>
            <!-- <div class="invite-sort-bar">
                <span class="invite-sort-label">{{ $t('reviewerAdd.latestInvitation') }}</span>
                <el-radio-group v-model="timeOrder" size="small">
                    <el-radio label="desc" :title="$t('reviewerAdd.orderDescTip')">{{ $t('reviewerAdd.orderDesc') }}</el-radio>
                    <el-radio label="asc" :title="$t('reviewerAdd.orderAscTip')">{{ $t('reviewerAdd.orderAsc') }}</el-radio>
                </el-radio-group>
            </div> -->
        </div>
        <el-table
            :data="revTable"
            border
            stripe
            class="table"
            ref="multipleTable"
            header-cell-class-name="table-header"
            :empty-text="$t('reviewerAdd.emptyTable')"
        >
            <el-table-column width="360" :label="$t('reviewerAdd.colBaseInfo')">
                <template slot-scope="scope">
                    <p class="tab_tie_col">
                        <span>{{ $t('reviewerAdd.realname') }}</span><b style="font-size: 14px">{{ scope.row.realname }}</b><el-button 
                         
                                    size="mini"
                                    type="success"
                                    plain
                                    icon="el-icon-tickets"
                                    @click="openDetail(scope.row)"
                                    style="margin-left: 10px;padding:4px;float: right;"
                                    >{{ $t('reviewerAdd.detail') }}</el-button
                                >
                    </p>
                    <p class="tab_tie_col"><span>{{ $t('reviewerAdd.account') }}</span>{{ scope.row.account }}</p>
                    <p class="tab_tie_col"><span>{{ $t('reviewerAdd.email') }}</span>{{ scope.row.email }}</p>
                    <p class="tab_tie_col"><span>{{ $t('reviewerAdd.latestInvitationLabel') }}</span>{{ formatInviteTime(scope.row) }}</p>
                </template>
            </el-table-column>
            <el-table-column :label="$t('reviewerAdd.colOtherInfo')">
                <template slot-scope="scope">
                    <p class="tab_tie_col" v-if="scope.row.company != ''"><span>{{ $t('reviewerAdd.affiliation') }}</span>{{ scope.row.company }}</p>
                    <p class="tab_tie_col" v-if="scope.row.field != ''"><span>{{ $t('reviewerAdd.field') }}</span>{{ scope.row.field }}</p>
                    <!-- <p class="tab_tie_col" v-if="scope.row.majorstr != ''"><span>Major: </span>{{ scope.row.majorstr }}</p> -->
                </template>
            </el-table-column>
            <el-table-column :label="$t('reviewerAdd.colResearchAreas')" width="260">
                        <template slot-scope="scope">
                            <commonMajorTableList
                                :user_id="scope.row.user_id"
                                :baseInfo="scope.row"
                                :key="scope.row.user_id"
                                :disabled="true"
                            ></commonMajorTableList>
                        </template>
                    </el-table-column>
            <el-table-column prop="rs_num" :label="$t('reviewerAdd.colReviewRecord')" width="180">
                <template slot-scope="scope">
                    {{ $t('reviewerAdd.majorReview') }}: {{ scope.row.major_times }} ({{ scope.row.major_rate }}%)
                    <br />
                    {{ $t('reviewerAdd.cancelReview') }}: {{ scope.row.rd_num }}

                    <!-- <font style="margin-left: 5px">(Reviewing:{{ scope.row.now }})</font> -->
                </template>
            </el-table-column>
            <el-table-column prop="rs_num" :label="$t('reviewerAdd.colReviewedTimes')" width="140">
                <template slot-scope="scope">
                    {{ $t('reviewerAdd.total') }}: {{ scope.row.rs_num }}
                    <br />
                    <div>
                        <i class="el-icon-check" style="font-weight: bold; color: green; margin-right: 4px"> </i>
                        <span style="margin-right: 4px; color: green">{{ scope.row.right_times }}</span>
                        <span>({{ scope.row.right_rate }}%)</span>
                    </div>
                    <div>
                        <i class="el-icon-close" style="font-weight: bold; color: red; margin-right: 4px"> </i>
                        <span style="margin-right: 4px; color: red">{{ scope.row.error_times }}</span>
                        <span>({{ scope.row.error_rate }}%)</span>
                    </div>
                    <!-- <font style="margin-left: 5px">(Reviewing:{{ scope.row.now }})</font> -->
                </template>
            </el-table-column>
            <!-- <el-table-column prop="rd_num" label="Fail number" width="140"></el-table-column> -->
            <el-table-column label="" width="120" align="center">
                <template slot-scope="scope">
                    <!-- <el-button size="mini" type="success" plain icon="el-icon-tickets" @click="openDetail(scope.row)">Detail</el-button> -->
                    <el-button size="mini" type="primary" plain icon="el-icon-check" @click="openSelect(scope.row)">{{ $t('reviewerAdd.select') }}</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="pagination">
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page="messform.page"
                :page-size="messform.size"
                :total="Total"
                @current-change="handlePageChange"
            ></el-pagination>
        </div>
    </div>
</template>

<script>
import commonMajorTableList from '../page/components/major/tableList.vue';

export default {
    components: {
        commonMajorTableList
    },
    data() {
        return {
            timeOrder: 'desc',
            messform: {
                article_id: this.$route.query.id,
                email: '',
                field: '',
                page: 1,
                size: 15
            },
            revTable: [],
            mesOpen: [],
            mesOpenVisble: false,
            loading: false,
            Total: 0,
            majors_a: [],
            majors_b: [],
            majors_c: [],
            allFileds: [], // 全部领域
            fieldsProps: {
                checkStrictly: true,
                value: 'major_id',
                label: 'major_title',
                children: 'children'
            },
            selectFileds: []
        };
    },
    created() {
        this.getDate();
    },
    methods: {
        formatInviteTime(row) {
            const raw =
                row.invited_time != null && row.invited_time !== ''
                    ? row.invited_time
                    : row.last_invite_time != null && row.last_invite_time !== ''
                      ? row.last_invite_time
                      : row.invite_time != null && row.invite_time !== ''
                        ? row.invite_time
                        : row.invitation_time != null && row.invitation_time !== ''
                          ? row.invitation_time
                          : row.invit_time != null && row.invit_time !== ''
                            ? row.invit_time
                            : row.inviteTime;
            if (raw == null || raw === '') {
                return '-';
            }
            if (typeof raw === 'string' && /[-/]/.test(raw) && isNaN(Number(raw))) {
                return raw;
            }
            let ts = Number(raw);
            if (!ts) {
                return '-';
            }
            if (ts < 1e12) {
                ts *= 1000;
            }
            const date = new Date(ts);
            if (isNaN(date.getTime())) {
                return String(raw);
            }
            const Y = date.getFullYear() + '-';
            const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
            const D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
            const h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
            const m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
            return Y + M + D + ' ' + h + ':' + m;
        },
        // 获取编辑列表数据
        getDate() {
            this.$emit('loading', true);
            this.$api
                .post('/api/Recommend/lists', this.messform)
                .then((res) => {
                    this.$emit('loading', false);
                    this.revTable = res.data.lists;
                    this.Total = res.data.total;

                    // this.loading = false;
                })
                .catch((err) => {
                    console.log(err);
                    this.$emit('loading', false);
                });
        },

        // 关键字搜索
        handleSearch() {
            this.messform.page = 1;
            this.getDate();
        },

        // 审稿人详情
        openDetail(row) {
            this.$emit('openDetail', row);
        },
        // 保存添加操作
        openSelect(row) {
            this.$emit('openSelect', row);
        },

        // 分页导航
        handlePageChange(val) {
            this.$set(this.messform, 'page', val);
            this.getDate();
        }
    }
};
</script>

<style scoped>
.table {
    width: 100%;
    font-size: 14px;
}
.tab_tie_col {
    margin-bottom: 5px;
    color: #333;
}

.tab_tie_col > span {
    color: #888;
    margin: 0 5px 0 0;
    font-size: 13px;
}
.reviewer-search-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
    margin-bottom: 20px;
    gap: 10px 12px;
}
.reviewer-search-filters {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 12px;
}
.invite-sort-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-left: auto;
    font-size: 14px;
    color: #606266;
}
.invite-sort-label {
    white-space: nowrap;
    font-weight: 500;
}
.invite-sort-bar ::v-deep .el-radio {
    margin-right: 14px;
}
.invite-sort-bar ::v-deep .el-radio:last-child {
    margin-right: 0;
}
</style>
