CollectApe.js 4.0 KB
//*
// 收藏模块
// */

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

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

    init() {
        $('#collectYes').on('click',this._collectYesHandler.bind(this));//取消收藏
        $('#collectNo').on('click',this._collectNoHandler.bind(this));//收藏
    }

    addEvent() {

    }
    _collectNoHandler(evt){
        if(ClassDataProxy.userType == 0){
            this.toLogin();
            return;
        }
        let that = this;
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/studentMeeting/addStudentMeeting';
        let status = $(evt.currentTarget).attr('data');
        let id = $('#lanclassBox').attr('data');
        let data = {siteId:ClassDataProxy.siteId,
            "studentId":ClassDataProxy.id,
            "status":parseInt(status),
            "meetingId":id
            }
        this.detailPage(_url,data,function(_data){
            if(_data && _data.code == 200){
                that._collectNoClick();
                ClassDataProxy.getMarginTopHandler($('#warnHintBox'));
                ErrorApe.showWarnError('收藏成功');
                loger.log('收藏数据信息',_data)
            }/*else{
                ClassDataProxy.getMarginTopHandler($('#warnHintBox'));//
                ErrorApe.showWarnError('您已收藏这堂课');
            }*/

        })
    }
    _collectYesHandler(evt){
        let that = this;

        let id = $('#lanclassBox').attr('data');
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/studentMeeting/delStudentMeetingBySite/'+id+'/'+ClassDataProxy.siteId;
        $.ajax({
            type: "delete",
            url: _url,
            timeout:5000,
            headers: {
                siteId:ClassDataProxy.siteId,
                'token':ClassDataProxy.token
            },
            data:{siteId:ClassDataProxy.siteId,id:ClassDataProxy.id},
            success:function(_data){
                //获取课堂数据
                if(_data && _data.code == 200){
                    that._collectYesClick();
                    ClassDataProxy.getMarginTopHandler($('#warnHintBox'));
                    ErrorApe.showWarnError('取消收藏');
                }
            },
            error:function(error){
                console.log(error,'失败')
            }
        })
    }
    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){
                    if(callback){
                        callback(_data);
                    }
                }else{
                    if(callback){
                        callback(null);
                    }
                }
            },
            error:function(error){
                if(callback){
                    callback(null);
                }
                loger.log(error,'收藏数据获取失败')
            }
        })
    }
    toLogin(){
        $('#userLoginBox').show();
    }
    _collectYesClick(){
        $('#collectYes ').hide();
        $('#collectNo ').show();
    }
    _collectNoClick(){
        $('#collectYes ').show();
        $('#collectNo ').hide();
    }
    toLogin(){
        ClassDataProxy.getMarginTopHandler($('#userLogin'));
        $('#userLoginBox').show();
    }
    //工具类
    _format(str, obj) {
        return str.replace(/\{(\w+)\}/g, function (match, group, index) {
            return obj[group];
        });
    };
}
export default CollectApe;