ListDetailsApe.js 9.1 KB
//*
// 列表详情模块
// */

import Loger from "../Loger";
import Ape from "./Ape";
import $ from "jquery";
import ClassDataProxy from "proxy/ClassDataProxy";
import MessageTypes from "../MessageTypes";

let loger = Loger.getLoger('PC-ListDetailsApe');
class ListDetailsApe extends Ape {
    constructor() {
        super();
        this.addEvent();
        this.isDate = 0;
        this._id = '';
        this.init();
    }

    init() {
        $('#liveContentAllBox ').on('click','.classifyList',this._curriculumListHandler.bind(this));//直播详情页
        $('#liveListBox ').on('click','.classifyList',this._curriculumListHandler.bind(this));//首页 进入 直播详情页

        $('#lanclassAllBox ').on('click','.classifyList',this._liveListHandler.bind(this));//互动详情页
        $('#lanclassList ').on('click','.classifyList',this._liveListHandler.bind(this));//首页 进入 互动详情页

        $('#teacherIntroAllBox ').on('click','.classifyList',this._teacherInfoHandler.bind(this));//老师详情页
        $('#teacherIntro ').on('click','.classifyList',this._teacherInfoHandler.bind(this));//首页 进入 老师详情页
    }

    addEvent() {

    }
    _curriculumListHandler(evt){

      /*  let buttonIsCheck = $('#orderBtn').attr('value','1');
        if($('#orderBtn').attr('value') == '1'){
            $('#orderBtn').attr('disabled',true)
            $('#orderBtn').css('background','#3498db')
        }*/
        let _id = $(evt.currentTarget).attr('data');
        this._id = _id;
        this.classInfoDetail(_id);
        this.collectInfoDetail(_id);
        this.commonalityClass();
        //查看当前点击的列表是否收藏
        this._emit(MessageTypes.IS_COLLECT,{id : _id});
    }
    _liveListHandler(evt){
        let _id = $(evt.currentTarget).attr('data');
        this._id = _id;
        this.liveInfoDetail(_id);
        this.collectInfoDetail(_id);
        this.commonalityClass();
    }
    commonalityClass(){
        $('#slideshow').hide();
        $('#defaultBox').hide();
        $('#liveContentAllBox').hide();
        $('#lanclassAllBox').hide();
        $('#teacherIntroAllBox').hide();
    }
    _teacherInfoHandler(evt){
        let _id = $(evt.currentTarget).attr('data');
        this._id = _id;
        this.teacherInfoDetail(_id);
        this.commonalityClass();
    }
    _slideshowInfo(_id){
        let that = this;
        let data = {
            id: _id,
            siteId:ClassDataProxy.siteId
        }
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/meeting/getMeeting';
        this.detailPage(_url,data,function(_data){
            if(_data){
              //  loger.log('detailPage',_data)
                that._gainClassData(_data.returnData.data);
            }
        })
        this.commonalityClass();
    }
    classInfoDetail(_id){
        let that = this;
        let data = {
            id: _id,
            meetingType:2,
            siteId:ClassDataProxy.siteId
        }
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/meeting/getMeeting';
        this.detailPage(_url,data,function(_data){
            if(_data){
             //   loger.log('detailPage',_data)
                that._gainClassData(_data.returnData.data);
            }
        })
    }
    liveInfoDetail(_id){
        let that = this;
        let data = {
            id: _id,
            meetingType:1,
            siteId:ClassDataProxy.siteId
        }
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/meeting/getMeeting';
        this.detailPage(_url,data,function(_data){
            if(_data){
              //  loger.log('detailPage',_data)
                that._gainClassData(_data.returnData.data);
            }
        })
    }
    //收藏
    collectInfoDetail(_id){
        let that = this;
        let data = {
            studentId:ClassDataProxy.id,
            meetingId:_id,
            siteId:ClassDataProxy.siteId
        }
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/studentMeeting/isAppointment';
        this.detailPage(_url,data,function(_data){
            if(_data && _data.code == 200){
                let _dataList = _data.returnData.data;
                if(_dataList && _dataList.length > 0 ){
                    that._collectNoClick();
                }else{
                    that._collectYesClick();
                }
            }
        })
    }
    teacherInfoDetail(_id){
        let that = this;
        let data = {
            id: _id,
            siteId:ClassDataProxy.siteId,
            userType : 1
        }
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/users/getUser';
        this.detailPage(_url,data,function(_data){
            if(_data){
                that._classDateContent(_data.returnData.data);
            }
        })
    }
    _gainClassData(_data){
       if(_data){
           let _dataList = _data.meetingInfo;
           if(_dataList){
               this._liveRender(_dataList[0]);
           }
       }
    }
    _classDateContent(_data){
        if(_data){
            let teacherList = _data.users;
            if(teacherList){
                this._lanclassRender(teacherList[0]);
            }
        }
    }
    //老师
    _lanclassRender(_dataList){
        if(_dataList){
            $('#defaultBox').hide();
            $('.curriculumBox').hide();
            $('#teacherDetailBox').show();
            $('#teacherDetailBox').attr('data',this._id);
            let _img = _dataList.userPhoto;
            let defaultImg = 'images/u373.png'
            $('#teacherDetailInfoImg').attr('src',_img?_img:defaultImg);//老师授课标题图片
            $('#teacherDetailInfoDetailName').text(_dataList.userName);//老师名字
            $('#teacherDetailInfoDetailSex').text();//老师性别
            $('#teacherDetailInfoDetailPoint').text();//老师专长
            $('#teacherDetailInfoDetailAge').text(3+'年');//老师教龄
            $('#teacherDetailInfoDetailGrade').text();//老师评分
            $('#teacherDetailReferralContent').text();//老师授课内容
            $('#teacherDetailPost').text();//老师职称
            $('#teacherDetailEducation').text();//老师学历
            $('#teacherDetailAcademy').text();//老师院校
            $('#teacherDetailWay').text();//老师授课方式
            $('#teacherDetailArea').text();//老师授课地区
            $('#teacherDetailSynopsis').text();//老师授课简介
        }

    }
    //课堂
    _liveRender(_dataList){
        if(_dataList){
            $('#defaultBox').hide();
            $('.curriculumBox').hide();
            $('#lanclassBox').show();
            $('#lanclassBox').attr('data',this._id);
            let _img = _dataList.meetingPhoto;
            let classImg;
            if(_img){
                classImg = _img;
            }else {
                classImg = null;
            }
            let defaultImg = 'images/u373.png'
            $('#lanclassContentCover').attr('src',_img?_img:defaultImg);//老师授课标题图片
            $('#lanclassContentTitle').text(_dataList.meetingName);//老师授课标题

            let _teacherImg = _dataList.teacherPhoto;
            let teacherDefault = 'images/u293.png';
            $('#lanclassContentInfoPortrait').attr('src',_teacherImg?_teacherImg:teacherDefault);//老师授课老师头像
            $('#lanclassContentInfoName').text(_dataList.create_user);//老师授课老师名字
            $('#teacherInfoName').text(_dataList.create_user);//老师授课老师名字
            $('#lanclassContentInfoTimeStart').text(_dataList.beginTime);//老师授课开始时间
            $('#lanclassContentInfoTimeEnd').text(_dataList.endTime);//老师授课结束时间
            $('#collectYes');//老师授课是否收藏
            $('#collectNo');//老师授课是否收藏
            $('#lanclassIntroduceDescription').text();//老师授课课程介绍
            $('#teacherInfoSchool').text();//老师学院
            $('#teacherInfoContent').text();//老师专业等级信息
        }
    }

    detailPage(url,data,callback){
        $.ajax({
            type: "POST",
            url: url,
            timeout:5000,
            data : data,
            headers: {siteId:ClassDataProxy.siteId,
                'token':ClassDataProxy.token},
            success:function(_data){
                //获取我的课程数据
                if(_data && _data.code == 200){
                    if(callback){
                        callback(_data);
                    }
                }else{
                    if(callback){
                        callback(null);
                    }
                }
            },
            error:function(error){
                if(callback){
                    callback(null);
                }
                loger.log(error,'直播数据获取失败')
            }
        })
    }
    _collectYesClick(){
        $('#collectYes ').hide();
        $('#collectNo ').show();
    }
    _collectNoClick(){
        $('#collectYes ').show();
        $('#collectNo ').hide();
    }
}
export default ListDetailsApe;