<template>
  	<section class="font-style">
        <teacherTop></teacherTop>
        
        <div class="teach-opt">
            <div class="tea-detail">
                <div class="head-img">
                    <img v-lazy="doctorParm.doctor.app_image_url">
                </div>
                <p class="detail-name">{{doctorParm.doctor.name}}</p>
                <p class="detail-intr">
                  {{doctorParm.doctor.hospital}} {{doctorParm.doctor.title}}
                </p>
                <div class="detail-info">
                    <div class="info-item">
                        <span class="detail-count">{{doctorParm.studyCount}}</span>
                        <p>学习人数</p>

                    </div>
                    <div class="info-item">
                        <span class="detail-count">{{doctorParm.followCount}}</span>
                        <p>关注人数</p>
                    </div>
                </div>
            </div>
            <div class="tea-new-title plr15">新课上线</div>
            <div class="tea-new-line plr15">
                <div class="item-new-box">
                    <div class="item-line" v-for="(item,index) in newsList">
                        <div class="line-img" @click="goToPage(item)">
                            <img v-lazy="item.imageUrl">
                            <span class="tag" v-if="item.structureName">{{item.structureName}}</span>
                            <span class="line-play" @click.stop="goToPage(item)">
                                <img src="../../images/grey-play.png">
                            </span>
                        </div>
                        <div class="line-name">
                            {{item.courseName}}
                        </div>
                        <div class="line-info">
                            <span>{{item.publishTime}} | {{item.joinNum}}人已学</span>
                            <span @click.stop="collectFun(item.favorFlag,item.courseId)" :class="item.favorFlag == 2 ? 'btn collect' : 'btn collected'">
                               {{item.favorFlag == 2?'收藏':'已收藏'}}
                            </span>
                            <!-- <span class='btn collected'>已收藏</span> -->
                        </div>
                    </div>
                    <div class="no-more" v-if="newsList.length == 0">暂无数据</div>
                </div>
                
            </div>
            <div class="grey-box"></div>
            <div class="teach-title plr15">课程教学</div>
            <div class="opt-span plr15">
                <span class="" @click="sortFun">学习人数
                    <img src="../../images/sort-d.png" v-if="dir == 2">
                    <img src="../../images/sort-u.png" v-if="dir == 1">
                </span>
            </div>
            <div class="teach-list plr15">
                <div :class="index%2==1?'list-item mr0':'list-item'" v-for="(item,index) in list" @click="goToPage(item)">
                    <div class="tea-img">
                        <img v-lazy="item.imageUrl">
                        <span class="learn-p">{{item.joinNum}}人已学</span>
                    </div>
                    <div class="tea-txt">
                       <!--  <p class="tea-name">{{item.doctorName}}</p> -->
                        <div class="tea-position">
                            {{item.courseName}}
                        </div>
                    </div>
                </div>
                <div class="no-more" v-if="list.length == 0">暂无数据</div>
            </div>
        </div>
    </section>
</template>

<script>
import teacherTop from '../../components/teachers/teach-top';
export default {
    components:{
        teacherTop
    },
    data(){
        return {
            list:[],
            newsList:[],
            dir:2,
            doctorId:'',
            doctorParm:{
                studyCount:0,
                followCount:0,
                doctor:{
                    app_image_url:'',
                    name:'',
                    title:'',
                }
            }
        }
    },
	mounted(){
        this.doctorId = this.$route.query.id;
        this.getBaseData();
        this.getNewClass();
        this.getCourse();
    },
    computed:{
       
    },
    methods:{

        //跳转
        goToPage(item){
            let itemData={
                "title":item.name,
                "imageUrl":"",
                "appModuleInfo":{
                  "code":"M200",
                  "type":4,
                  "name":"课程介绍页",
                  "paramFlag":1,
                  "paramList":[
                      {
                          "key":"className",
                          "value":"com.picahealth.yunque.activitys.courseplaynew.CourseIntroduceActivity###WeexCourseIntroViewController",
                          "type":4,
                          "seqNo":1
                      },
                      {
                          "key":"courseId",
                          "value":`${item.courseId}`,
                          "type":1,
                          "seqNo":2
                      }
                  ]
                }
            };
            let paramList = this.setEventByModuleCode(itemData);
            rocNative.dispatchEventByModuleCode({
                modeCode: itemData.appModuleInfo.code,
                jsonString: paramList
            })
        },

        collectFun(status,id){
            status = status == 1 ? 2 : 1;
            let _this = this,
            parm = {
                token:_this.$route.query.userToken,
                type:status,
                courseId:id,
                setEntry: 'headers'
            }
            _this.POST('contents/favors',parm).then(function(res){

                if(res.code === '000000'){
                    
                    _this.handelData(id,status);
                }
            })
        },
        handelData(id,status){
            
            let d = this.newsList;
            for(let i=0;i<d.length;i++){
                if(id == d[i].courseId){
                   
                    d[i].favorFlag = status;
                }
            }
           
        },

        sortFun(){
            this.dir = this.dir == 2 ? 1 : 2;
            this.getCourse();
        },

        //课程教学
        getCourse(){
            let _this = this, 
            para = {
  
                token:_this.$route.query.userToken,
                setEntry: 'headers'
            }
            let url = '/contents/courseDoctor/courseList/'+_this.doctorId+'/orderby/1/dir/'+_this.dir;
            this.GET(url, para).then(res => {
                if(res.code == '000000'){
                    _this.list = res.data || [];
                }
            })
        },

        //新课程
        getNewClass(){
            let _this = this, 
            para = {
  
                token:_this.token,
                setEntry: 'headers'
            }
            let url = '/contents/courseDoctor/latestCourseList/'+_this.doctorId;
            this.GET(url, para).then(res => {
                if(res.code == '000000'){
                    _this.newsList = res.data || [];
                }
            })
        },

        //基础信息
        getBaseData(){
            let _this = this, 
            para = {
  
                token:_this.token,
                setEntry: 'headers'
            }
            let url = '/contents/courseDoctor/doctorDetail/'+_this.doctorId;
            this.GET(url, para).then(res => {
                if(res.code == '000000'){
                    _this.doctorParm = {
                        followCount:res.data.followCount,
                        studyCount:res.data.studyCount,
                        doctor:res.data.doctor
                    }
                    
                }
            })
        }
       
    }
}

</script>
<style>
    body{background: #fff;height: auto;}
</style>
<style lang="scss" scoped>
body{background: #fff}
    @import '../../style/mixin';

    .mint-header {
        background-color: rgba($color: #000000, $alpha: 0)
    }
    .font-style {
        width: 100%;
        overflow: hidden;
       
        @include sc(0.6rem, #666);
    }
    .tea-detail{
        height: px2rem(154px);
        position: absolute;
        width: 100%;
        left: 0;
        top:-(px2rem(64px));
        z-index: 10;
         @include bis('../../images/detaiBg.png');
         .head-img{
            width: px2rem(45px);
            height: px2rem(45px);
           
            border-radius: 100%;
            margin: -(px2rem(10px)) auto 0;
            background: #D8D8D8;
            text-align: center;
            img{
                width: px2rem(45px);
                height: px2rem(45px);
                
                border-radius: 50%;
            }
        }
        .detail-name{
            margin-top:px2rem(3px);
            line-height: px2rem(20px);
            font-size: px2rem(14px);
            color:#333;
            text-align: center;
        }
        .detail-intr{
             text-align: center;
             line-height: px2rem(17px);
             height: px2rem(17px);
             overflow: hidden;
            width: 90%;
            margin:0 auto;
            font-size: px2rem(12px);
            color:#666;
        }
        .detail-info{
            overflow: hidden;
            margin-top: px2rem(12px);
            .info-item{
                width: 50%;
                float: left;
                text-align: center;
                span{
                    line-height: px2rem(20px);
                    font-size: px2rem(14px);
                    color:#333;
                }
                p{
                    line-height: px2rem(17px);
                    font-size: px2rem(12px);
                    color:#666;
                }
            }
        }
         
    }
    .tea-new-title{
        font-size: px2rem(18px);
        margin: px2rem(15px) 0;
        color:#333;
    }
    .tea-new-line.plr15{padding-left:px2rem(17px);}
    .tea-new-line{
        width: 100%;
        overflow: hidden;
        overflow-x: scroll;
        -webkit-tap-highlight-color:rgba(0,0,0,0);
        outline: 0;
        -webkit-overflow-scrolling : touch;
        height: px2rem(273px);
        .item-new-box{
            width: px2rem(10000000px);
        }
        .item-line{
            width: px2rem(345px);
            padding-bottom: px2rem(23px);
            float: left;
            margin-right: px2rem(10px);
            .line-img{
                width: px2rem(345px);
                height: px2rem(191px);
                position: relative;
                .line-play{
                    position: absolute;
                    width: px2rem(60px);
                    height: px2rem(60px);
                    left:50%;
                    top:50%;
                    margin:-(px2rem(30px)) 0 0 -(px2rem(30px));
                }
                .tag{
                    display: inline-block;
                    background: #fff;
                    border:1px solid #C3DCFB;
                    position: absolute;
                    top:px2rem(5px);
                    left: px2rem(5px);
                    font-size: px2rem(10px);
                    line-height: px2rem(16px);
                    padding: 0 px2rem(10px);
                    border-radius: px2rem(2px);
                    color:#4A87D4;
                }
                img{
                    width: 100%;
                    height:100%;
                }
            }
            .line-name{
                margin-top: px2rem(10px);
                font-size: px2rem(16px);
                line-height: px2rem(16px);
                width: 100%;
                overflow: hidden;
                height: px2rem(16px);
                color:#333;
            }
            .line-info{
                overflow: hidden;
                margin-top: px2rem(10px);
                span{
                    display: inline-block;
                    font-size:  px2rem(12px);
                    color: #999;
                    line-height: px2rem(18px);
                    float: left;
                }
                .btn{
                    color:#666;
                    background: #F7F8F9;
                    padding: 0 px2rem(5px);
                    float: right;
                    margin-right: px2rem(5px);
                }
                .collected{
                    color: #F47A48;
                    background: RGBA(244, 122, 72, 0.04);
                }
            }
        }
    }
    .grey-box{
        width: 100%;
        height: px2rem(6px);
        background: #F8F8F8;
    }
    .plr15{
        padding-right: px2rem(15px);
        padding-left: px2rem(15px);
    }
    .teach-opt{
        padding:px2rem(90px)  0 px2rem(30px) 0;
         position: relative;
        .teach-title{

            font-size: px2rem(18px);
            padding-bottom: px2rem(15px);
            padding-top: px2rem(15px);
            color:#333;
        }
        .teach-list{
            overflow: hidden;
        }
        .no-more{
            text-align: center;
            color:#999;
            font-size: px2rem(12px);
        }
        .opt-span{
            span{
                color:#449284;
                font-size: px2rem(13px);
                display: inline-block;
                vertical-align: middle;
                height: px2rem(15px);
                line-height: px2rem(15px);
                img{
                    display: inline-block;
                    width: px2rem(15px);
                    height: px2rem(15px);
                    vertical-align: middle;
                }
            }
        }
        .list-item{
            width: px2rem(170px);
            margin-right: px2rem(5px);
            margin-top: px2rem(15px);
           
            float: left;
            box-shadow: 0 px2rem(4px) px2rem(6px) RGBA(0, 0, 0, 0.06);
        }
        .mr0{
            margin-right: 0
        }
        .tea-txt{
            padding:px2rem(7px);
        }

        .tea-img{
            width: px2rem(170px);
            height: px2rem(96px);
            position: relative;
           
            img{
                width: 100%;
                height: 100%;
                display: block;
                border-radius: px2rem(3px) px2rem(3px) 0 0 ;
            }
            .learn-p{
                padding-left: px2rem(5px);
                position: absolute;
                width: 100%;
                left:0;
                bottom: 0;
                background: #333;
                background: -webkit-linear-gradient(left, RGBA(0, 0, 0, 0.2),RGBA(0, 0, 0, 0)); 
                background: -o-linear-gradient(right, RGBA(0, 0, 0, 0.2),RGBA(0, 0, 0, 0)); 
                background: -moz-linear-gradient(right, RGBA(0, 0, 0, 0.2),RGBA(0, 0, 0, 0)); 
                background: linear-gradient(to right, RGBA(0, 0, 0, 0.2),RGBA(0, 0, 0, 0)); 
                color:#fff;
                font-size: px2rem(11px);
                height: px2rem(20px);
                line-height: px2rem(20px);
            }
        }
        .tea-name{
            color:#333;
            font-size: px2rem(14px);
            padding: px2rem(7px) 0 px2rem(3px) 0;
        }
        .tea-position{
            height: px2rem(38px);
            font-size: px2rem(14px);
            line-height: px2rem(19px);
            color:#333;
            overflow: hidden;
            text-overflow: ellipsis;
            -webkit-line-clamp: 2;
        }
    }
    .home-header {
        height: px2rem(185px);
        @include bis('../../images/headerTop.png');
        .logo_img{
            height: px2rem(85px);
            width: px2rem(345px);
            text-align: center;
        }
    }
</style>
