<style lang="scss">
    .sub_detail{
        h1{
            display: inline-block;
            margin-bottom: 10px;
            vertical-align: top;
            width: 75%;
            .name{
                font-size: 16px;
                color: #333;
                margin-bottom: 10px;
            }
            .desc{
                color: #666;
                font-size: 14px;
                line-height: 26px;
            }
        }
        
    }
</style>
<template>
    <section class="sub_detail">
        <p v-if='type==2'><span>刊群导览 > </span><span @click="$router.go(-1)">学科 > </span>学科详情</p>
        <p v-if='type==1'><span>刊群导览 > </span><span @click="$router.go(-1)">主办单位 > </span>单位详情</p>
        <div class="content">
             
            <img style="margin-right:20px;" v-if='type==1' :src="form.img" width="100" alt="">
            <h1> 
                <p class="name">{{form.name}}</p>
                 <p class="desc">{{form.desc}}</p>
            </h1>
            <el-button v-if='type==1' @click='$router.push({ path: "/journal/journal/add",query:{oid:form.id} })' style="float:right;margin-bottom:10px;" type='primary' size="small">添加期刊</el-button>
           <el-button v-if='type==2' @click='$router.push({ path: "/journal/journal/add",query:{sid:form.id} })' style="float:right;margin-bottom:10px;" type='primary' size="small">添加期刊</el-button>
            <el-table
                class="table"
                :data="list"
                border
                style="width: 100%"
            >
                <el-table-column prop="img" label="期刊封面">
                <template slot-scope="scope">
                    <img :src="scope.row.img" alt="" height="80" width="60" />
                </template>
                </el-table-column>
                <el-table-column prop="name" width="180" label="期刊名称">
                </el-table-column>
                <el-table-column prop="wxcode" label="微信号"> </el-table-column>
                <el-table-column prop="article_count" label="文章数"> </el-table-column>
                <el-table-column prop="desc" width="500" label="简介">
                </el-table-column>
                <el-table-column prop="zip" width="150" align="center"  label="操作" fixed="right">
                <template slot-scope="scope">
                    <el-button class="edit" type="text" @click="edit(scope.row)">编辑</el-button>
                    <el-button class="del" @click="del" type="text">删除</el-button>
                </template>
                </el-table-column>
            </el-table>
            <Page
                ref="pageButton"
                :current="query.page"
                :page_size="query.page_size"
                :total="total"
                @pageChange="gopage"
            />
        </div>
    </section>
</template>
<script>
import Page from "../../components/Page";
export default {
    components: {
        Page,
    },
    data() {
        return {
            query: {page: 1, page_size: 20 },
            total: 1,
            list:[],
            form:{},
            id:'',
            type:''
        };
    },
    methods: {
       gopage(size) {
            if (size) {
                this.query.page_size = size;
            }
            this.query.page = this.$refs.pageButton.page;
            this.getData();
        },
        getData() {
            let parm=this.query
            if(this.type == 1){
                parm.organizer_id=this.id
            }else{
                parm.subject_id=this.id
            }
            this.$api.getJournalList(parm).then((res) => {
                this.list = res.data.data.list;
                this.total = res.data.data.total;
            });
        },
        edit(row) {
            this.$router.push({
                path: "/journal/journal/add",
                query: { id: row.id },
            });
        },
        del(id) {
            this.$confirm("确定删除吗", "提示", {
                type: "warning",
            }).then(() => {
                this.$api.deleteEnterprise({ id: id }).then((res) => {
                this.$message({
                    message: "删除成功",
                    type: "success",
                });
                this.getData();
                });
            });
        },
    },
    created() {
        if(this.$route.path.indexOf('organizer')>=0){
            this.type=1    //主办单位
        }else{
            this.type=2    //学科
        }
        if(this.$route.query.id){
            this.id=this.$route.query.id;
            this.getData()
            if(this.type == 1){
                this.$api.getOrganizer({id:this.id}).then(res=>{
                    if(res.data.code != 0){
                        this.$message({
                                message: res.data.message,
                                type: 'error'
                        })
                        return
                    }
                    this.form=res.data.data
                })
            }else{
                this.$api.getSubject({id:this.id}).then(res=>{
                    if(res.data.code != 0){
                        this.$message({
                                message: res.data.message,
                                type: 'error'
                        })
                        return
                    }
                    this.form=res.data.data
                })
            }
            
        }
    },
    beforeRouteEnter(to,from,next){
        next(vm=>{
            if(from.path.indexOf('add')>=0){
                vm.getData()
            }
        })
    }
};
</script>