<template>
<section>
    <GroupTitle :groupNum="groupNum" :showTitle="showTitle" :showOrder="showOrder"/>
    <!-- <div class="cource-teach">
        <div class="couse-list">
            <div 
              :class="index % 2 == 1 ? 'course-item end-left' : 'course-item'" 
                v-for="(item, index) in cParmData" :key="index">
                <div class="course-pic" @click="goToPage(item)">
                    <img v-lazy="item.courseInfoUrl" class="pic-tec" />
                    <span class="course-tag">{{item.disName}}</span>
                </div>
                <p class="course-txt" v-html="item.name">
                    
                </p>
                <div class="course-opt">
                    <span class="opt-info">{{!item.showTime ? '' : item.showTime + ' |'}} {{item.joinNum}}人已学</span>
                    <span :class="item.whetherFavors==2?'opt collect':'opt collected'"@click="collectFun(item.whetherFavors,item.id,item.name)">
              {{item.whetherFavors==2?'收藏':'已收藏'}}
            </span>

                </div>
            </div>
        </div>
        <div v-if="cParmData.length==0" class="noSource">暂无最新教程数据</div>
    </div> -->
    <!-- <article class="course-list">
        <div class="course-list-item"
            v-for="(item, index) in cParmData" :key="index"
            >
            <img v-lazy="item.courseInfoUrl"/>
            <div class="course-list-item-desc">
                <span style="line-height:20px;position:relative;top:-8px">
                    <span class="course-list-item-desc-type">{{item.typeName}}</span><div class="course-list-item-desc-name" v-html="item.name"></div>
                </span>
                <span>1</span>
                <span>12</span>
            </div>
        </div>
    </article> -->
        <div class="hot-teacher">
            <!-- <div :class="index>1 && (index+1 == cParmData.length)?'teacher-item item-end' : 'teacher-item'" :key="index"  -->
            <div :class="index>1 && (index+1 == cParmData.length)?'teacher-item item-end' : 'teacher-item'" :key="index" 
                v-for="(item,index) in cParmData" @click="goToPage(item)">
                    <div class="teacher-itemimg">
                        <img v-lazy="item.courseInfoUrl"/>
                    </div>
                    <div class="five-text">
                        <div class="teacher-itemname fs14 ellipsis-2" >
                            <span v-show="item.typeName" class="teacher-itemname-tag">{{item.typeName}}</span>
                            <span class="teacher-itemname-name" v-html="item.highLightName"></span>
                        </div>
                        <div class="fs13 ellipsis-1" >
                            <span class="five-text-shourtcut">{{item.shortcut}}</span>
                        </div>
                        <div class="fs13 five-text-teacher">
                            <img src="../../images/teacher-icon.png" /><span class="five-text-teacher-name" v-for="(doctor, dIndex) in item.doctors" :key="dIndex">
                                {{doctor.doctorName}}
                                <!-- {{item.doctors[0].doctorName}} -->
                            </span>
                        </div>
                </div>
            </div>
        </div>

</section>
</template>

<script>
//import { setEventByModuleCode } from '@/utils/index'
import GroupTitle from '@/components/business/group-title';
let mapDesc = ['', '课程名', '关键字', '一句话简介', '章', '节']
export default {
    name: 'CourseList',
    data() {
        return {
            list: [],
            title: '最新课程',
            pageNo: 1,
            pageSize: 6,
            needShow: true
            // parmData: []
        }
    },
    props: {
        userToken: {
            type: String,
            default: ''
        },
        parmData: {
            type: Array,
            default: () => []
        },
        groupNum: {
            type: String,
            default: '0'
        },
        showTitle: {
            type: Boolean,
            default: true
        },
        showOrder: {
            type: Boolean,
            default: false
        }
    },
    computed: {
        cParmData() {
            let cParmDataw = this.parmData.map(function(item){
                let cItem = Object.assign({}, item)
                if(cItem.highLightField) {
                    cItem.name = cItem.name + ' (' + mapDesc[cItem.highLightField] + ')'
                }
                return cItem
            })
            return cParmDataw
        },
        // groupNum() {
        //     return this.parmData.length + ''
        // }
    },
    components: {
        GroupTitle
    },
    mounted() {
        // this.getData()
        // this.list = this.parmData;
    },
    // filters: {
    //     filterName(name, highLightField){
    //         return name + highLightField
    //     }
    // },
    methods: {
        getDescByMap(index) {
            
        },
        showAllItem(index) {
            // this.needShow = !this.needShow
        },
        //跳转
        goToPage(item) {
            this.$emit("setRefrshParm", {
                isclick: true
            })
            this.pageBurialPoin({
                menuLevel: 1,
                menuCode: 'm_home',
                functionCode: 'f_new_course',
                actionCode: 'c_course',
                labelId: item.id,
                labelValue: item.name,
            })
            let itemData = {};

            if (item == '') {

                itemData = {
                    "title": item.name,
                    "imageUrl": "",
                    "appModuleInfo": {
                        "code": "M200",
                        "type": 4,
                        "name": "课程介绍页",
                        "paramFlag": 1,
                        "paramList": [{
                                "key": "className",
                                "value": "com.picahealth.yunque.activitys.famousteacherschool.AllDiseaseActivity###MicroProfessionMoreTableController",
                                "type": 4,
                                "seqNo": 1
                            },
                            {
                                "key": "disCategoryId",
                                "value": '-1',
                                "type": 1,
                                "seqNo": 2
                            }
                        ]
                    }
                };
            } else {
                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.id}`,
                                "type": 1,
                                "seqNo": 2
                            }
                        ]
                    }
                };
            }

            let paramList = this.setEventByModuleCode(itemData);
            rocNative.dispatchEventByModuleCode({
                modeCode: itemData.appModuleInfo.code,
                jsonString: paramList
            })

        },

        //收藏 取消收藏
        collectFun(status, id, name) {
            // alert(this.userToken)
            status = status == 1 ? 2 : 1;
            this.pageBurialPoin({
                menuLevel: 1,
                menuCode: 'm_home',
                functionCode: 'f_new_course',
                actionCode: 'c_collect',
                labelId: id,
                labelValue: name,
            })
            let _this = this,
                parm = {
                    token: _this.userToken,
                    type: status,
                    courseId: id,
                    setEntry: 'headers'
                }
            _this.POST('contents/favors', parm).then(function (res) {
                if (res.code === '000000') {
                    _this.handelData(id, status);
                } else {
                    rocNative.showNativeToast({
                        message: '注册登陆后才能收藏哦'
                    })
                }
            })
        },
        handelData(id, status) {
            let d = this.parmData;
            for (let i = 0; i < d.length; i++) {
                if (id == d[i].id) {
                    d[i].whetherFavors = status;
                }
            }
        },
        getData() {
            //alert("最新课程");
            let _this = this,
                parm = {
                    pageNo: _this.pageNo,
                    pageSize: _this.pageSize,
                    token: _this.userToken,
                    setEntry: 'headers'
                }
            _this.GET('/contents/HomeNewCourse/NewCourseInformation', parm).then(function (res) {

                if (res.code === '000000') {
                    _this.parmData = res.data.contentAppModels || [];
                }
            })
        }

    }
}
</script>

<style lang="scss" scoped>
@import '../../style/global.scss';
@import '../../style/mixin.scss';
.course-list {
    margin: 0 px2rem(15px);
    &-item {
        display: flex;
        flex-direction: row;
        img {
            height: px2rem(56px);
            width: px2rem(100px);
            margin-right: px2rem(10px);
            border-radius: px2rem(6px);
        }
        &-desc {
            display: flex;
            flex-direction: column;
            position: relative;
            // span {
            //     display: inline-flex;
            // }
            &-type {
                display: inline-flex;
                height: px2rem(18px);
                width: px2rem(30px);
                padding: 0 px2rem(2px);
                margin-right: px2rem(5px);
                font-size: px2rem(11px);
                border-radius: px2rem(2px);
                background-color: #6A9FE9;
                color: #fff;
            }
            &-name {
                display: inline-flex;
                font-size: px2rem(16px);
                height: px2rem(16px);
                width: px2rem(200px);
                line-height: px2rem(16px);
                color: #333333;
            }
        }
    }
}

</style>

<style lang="scss" scoped>
@import '../../style/mixin.scss';
@import '../../style/global.scss';

.hot-teacher {
    width: 100%;
    background-color: #fff;
    padding: 0 px2rem(15px) 0;
    .img {
        width: px2rem(109px);
        height: px2rem(22px);
    }

    .thorw-icon {
        width: px2rem(8px);
        height: px2rem(8px);

    }

    .five-more {
        border: 1px solid RGBA(169, 174, 183, 1);
        border-radius: px2rem(16px);
        height: px2rem(16px);
        line-height: px2rem(16px);
        padding: 0 px2rem(5px) 0 px2rem(6px);
        vertical-align: middle;
    }

    .teacher-item {
        width: 100%;
        height: px2rem(106px);
        position: relative;
        margin: px2rem(4px) 0 px2rem(15px);
        padding-top: px2rem(4px);
        &:not(:last-child) {
            border-bottom: 1px solid RGBA(240, 240, 240, 1);
        }

        .teacher-itemimg {
            width: px2rem(100px);
            height: px2rem(56px);
            margin-right: px2rem(10px);
            border-radius: px2rem(3px);
            box-shadow: 0 px2rem(2px) px2rem(3px) RGBA(0, 78, 64, 0.1);
            float: left;
            img {
                width: 100%;
                height: 100%;
                display: inline-block;
                border-radius: px2rem(3px);
            }
        }

        .five-text {
            margin-left: px2rem(70px);
            height: px2rem(38px);
            &-shourtcut {
                font-size: px2rem(14px);
                color: #777;
            }
            &-teacher {
                margin-top: px2rem(4px);
                height: px2rem(20px);
                line-height: px2rem(20px);
                margin-left: px2rem(40px);
                img {
                    width: px2rem(10px);
                    height: px2rem(10px);
                    margin-right: px2rem(2px);
                    color: #777;
                }
                &-name {
                    // margin-left:40px;
                    // padding-top:10px;
                    margin-left: 0 !important;
                    padding-left: 0;
                    font-size: px2rem(13px);
                    color: #999;
                }
            }
        }

        .teacher-itemname {
            color: RGBA(102, 102, 102, 1);
            height: px2rem(36px);
            line-height: px2rem(19px);
            font-size: px2rem(13px);
            margin-bottom: px2rem(5px);
            &-tag {
                vertical-align: top;
                height: px2rem(20px);
                line-height: px2rem(20px);
                padding: px2rem(2px) px2rem(3px) px2rem(1px);
                border-radius: px2rem(2px);
                font-size: px2rem(12px);
                color: #fff;
                background: rgba(106,159,233,1);
            }
            &-name {
                height: px2rem(18px);
                line-height: px2rem(18px);
                font-size: px2rem(16px);
                color: #333;
            }
        }

        .five-tag {
            position: relative;
            padding-right: px2rem(25px);
            .m-tag {
                height: px2rem(17px);
                line-height: px2rem(17px);
                padding: 0 px2rem(5px);
                color: #BF9E15;
                border-radius: 0 px2rem(3px) px2rem(3px) px2rem(3px);
                background: #FFFDFA;
                /* background-color: px2rem(17px);*/
                border: 1px solid #FAE5AF;
            }
        }

        .m-play {
            width: px2rem(28px);
            height: px2rem(28px);
            display: inline-block;
            position: absolute;
            right: 0;
            bottom: 0;
            .play-opt {
                position: relative;
                width: px2rem(28px);
                height: px2rem(28px);
                border: 1px solid #56c3bb;
                border-radius: 50%;
                span {
                    width: px2rem(3px);
                    height: px2rem(5px);
                    bottom: px2rem(5px);
                    position: absolute;
                    background: #56c3bb;
                    border-radius: 2px 2px 0 0;
                }
            }
            .play-stop {
                span:first-child {
                    left: px2rem(8px);
                    height: px2rem(5px);
                }
                span:nth-child(2) {
                    left: px2rem(12px);
                    height: px2rem(15px);
                }
                span:nth-child(3) {
                    left: px2rem(16px);
                    height: px2rem(10px);
                }
            }

            .play-start {
                span {
                    -webkit-animation: bodong 0.5s infinite ease-in-out alternate;
                    animation: bodong 0.5s infinite ease-in-out alternate;
                }

                span:first-child {
                    left: px2rem(8px);
                    -webkit-animation-delay: .1s;
                    animation-delay: .1s;
                }

                span:nth-child(2) {
                    left: px2rem(12px);
                    -webkit-animation-delay: .3s;
                    animation-delay: .3s;
                }

                span:nth-child(3) {
                    left: px2rem(16px);
                    -webkit-animation-delay: .5s;
                    animation-delay: .5s;
                }

                @-webkit-keyframes bodong {
                    0% {
                        height: px2rem(5px);
                    }

                    30% {
                        height: px2rem(10px);
                    }

                    60% {
                        height: px2rem(15px);
                    }

                    80% {
                        height: px2rem(10px);
                    }

                    100% {
                        height: px2rem(5px);
                    }
                }

                @keyframes bodong {
                    0% {
                        height: px2rem(5px);
                    }

                    30% {
                        height: px2rem(10px);
                    }

                    60% {
                        height: px2rem(15px);
                    }

                    80% {
                        height: px2rem(10px);
                    }

                    100% {
                        height: px2rem(5px);
                    }
                }
            }

            img {
                width: 100%;
                height: 100%;
                display: block;
            }
        }
    }

    .item-end {
        height: px2rem(92px);
    }
}
.ellipsis-1 {
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-line-clamp: 1;
    white-space: nowrap;
}
.ellipsis-2 {
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-line-clamp: 2;
    // white-space: nowrap;
}
</style>
