<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> Manuscripts list
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-select v-model="query.journal" @change="getdate" placeholder="Please select journal">
                    <el-option :key="0" label="All journals" :value="0"></el-option>
                    <el-option
                        v-for="item in items"
                        :key="item.journal_id"
                        :label="item.title"
                        :value="item.journal_id"
                    ></el-option>
                </el-select>
                <el-select v-model="query.state" @change="getdate" placeholder="Please select status" style="margin-left:5px;">
                    <el-option :key="-1" label="All status" :value="-1"></el-option>
                    <el-option :key="0" :label="$t('artstate.state0')" :value="0" :disabled="query.act==2"></el-option>
                    <el-option :key="1" :label="$t('artstate.state1')" :value="1" :disabled="query.act==2"></el-option>
                    <el-option :key="2" :label="$t('artstate.state2')" :value="2" :disabled="query.act==2"></el-option>
                    <el-option :key="3" :label="$t('artstate.state3')" :value="3" :disabled="query.act==1"></el-option>
                    <el-option :key="4" :label="$t('artstate.state4')" :value="4" :disabled="query.act==2"></el-option>
                    <el-option :key="5" :label="$t('artstate.state5')" :value="5" :disabled="query.act==1"></el-option>
                </el-select>
                <el-select v-model="query.act" @change="getdate" placeholder="Please select status" style="margin-left:5px;">
                    <el-option :key="1" :label="$t('artstate.act1')" :value="1"></el-option>
                    <el-option :key="2" :label="$t('artstate.act2')" :value="2"></el-option>
                </el-select>
                <el-input v-model="query.name" placeholder="Title" class="handle-input mr10" style="margin-left:5px;"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">Search</el-button>
            </div>
            <el-table
                :data="tableData"
                border
                stripe
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
            >
                >
                <el-table-column type="index" label="No." width="55" align="center"></el-table-column>
                <el-table-column prop="accept_sn" label="Manuscript ID" width="180" align="center"></el-table-column>
                <!-- <el-table-column prop="article_id" label="ID" width="55" align="center"></el-table-column> -->
                <el-table-column prop="title" label="Title" align="center">
                    <template slot-scope="scope">
                        <el-badge is-dot :hidden="scope.row.author_act==1?false:true" class="item">
                            {{scope.row.title}}
                        </el-badge>
                    </template>
                </el-table-column>
                <el-table-column prop="journalname" label="Journal" width="250" align="center"></el-table-column>
                <el-table-column
                    prop="state"
                    label="Status"
                    :formatter="stateFormat"
                    align="center"
                    width="110"
                ></el-table-column>
                <el-table-column prop="remarks" label="Remarks" align="center"></el-table-column>
                <el-table-column label="" width="230" align="center">
                    <template slot-scope="scope">
                        <el-button
                            size="mini"
                            type="primary"
                            plain
                            icon="el-icon-tickets"
                            @click="showdetaileditor(scope.row)"
                        >Detail</el-button>
                        <el-button
                            size="mini"
                            type="primary"
                            plain
                            icon="el-icon-user-solid"
                            @click="articleReviewer(scope.row)"
                        >Review</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="Total"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name:'articleListEditor',
    data() {
        return {
            items: '',
            query: {
                username: localStorage.getItem('ms_username'),
                journal: 0,
                name: '',
                state:-1,
                act:1,
                pageIndex: 1,
                pageSize: 10
            },
            tableData: [],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            Total: 0
            // form: {},
            // idx: -1,
            // id: -1
        };
    },
    created() {
        this.initselect();
        this.getdate();
    },
    methods: {
        //初始化期刊选项
        initselect() {
            this.$api
                .post('api/Article/getJournal',{'username':this.query.username})
                .then(res => {
                    this.items = res;
                })
                .catch(err => {
                    console.log(err);
                });
        },
        // 获取数据
        getdate() {
            this.$api
                .post('api/Article/getArticleForEditor', this.query)
                .then(res => {
                    this.Total = res.total;
                    this.tableData = res.data;
                })
                .catch(err => {
                    console.log(err);
                });
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'pageIndex', 1);
            this.getdate();
        },
        //文章送审
        articleReviewer(row){
            this.$router.push({ path: 'articleReviewer', query: { id: row.article_id } });
        },
        //格式化状态输出
        stateFormat(row, column) {
            let str = '';
            switch (row.state) {
                case 0:
                    str = this.$t('artstate.state0');
                    break;
                case 1:
                    str = this.$t('artstate.state1');
                    break;
                case 2:
                    str = this.$t('artstate.state2');
                    break;
                case 3:
                    str = this.$t('artstate.state3');
                    break;
                case 4:
                    str = this.$t('artstate.state4');
                    break;
                case 5:
                    str = this.$t('artstate.state5');
                    break;
                default:
                    str = 'error!!';
            }
            return str;
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getdate();
        },
        showdetaileditor(row) {
            this.$router.push({ path: 'articleDetailEditor', query: { id: row.article_id } });
        },
        tableRowClassName({ row, rowIndex }) {

            if (row.state == 1 || row.state == 2) {
                return 'normol-row';
            } else if (row.state == 3) {
                return 'red-row';
            } else if (row.state == 4) {
                return 'warning-row';
            } else if (row.state == 5) {
                return 'success-row';
            } else {
                return '';
            }
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
.item{
    margin-top: 5px;
}
</style>
