SubscribeApe.js 3.2 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-SubscribeApe');
class SubscribeApe extends Ape {
    constructor() {
        super();
        this.id = '';
        this.addEvent();
        this.init();
    }

    init() {
        $('#lanclassContentApply').on('click',this._applyHandler.bind(this));//我要报名
        $('#orderBtn').on('click',this._orderHandler.bind(this));//我要预约
    }

    addEvent() {

    }
    _applyHandler(evt){
        let status = $(evt.currentTarget).attr('data');
        let id = $('#lanclassBox').attr('data');
        this._lanclassContentApplyHandler(status,id);
    }
    _orderHandler(evt){
        let status = $(evt.currentTarget).attr('data');
        let id = $('#teacherDetailBox').attr('data');
        this._lanclassContentApplyHandler(status,id);
        loger.log('查看当前点击的dataid',id,status)
    }
    _lanclassContentApplyHandler(status,id){
        if(ClassDataProxy.userType == 0){
            this.toLogin();
            return;
        }
        let that = this;
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/studentMeeting/addStudentMeeting';
        this.id = id;
        $.ajax({
            type: "POST",
            url: _url,
            data:{siteId:ClassDataProxy.siteId,
                "studentId":ClassDataProxy.id,
                "status":parseInt(status),
                "meetingId":id
            },
            headers: {siteId:ClassDataProxy.siteId,
                'token':ClassDataProxy.token},
            success:function(_data){
                let arr = ['收藏成功!','预约成功!','报名成功!']
                //获取课堂数据
                loger.log('获取课堂数据',_data)
                if(_data && _data.code == 200){
                    loger.log(_data,'预约信息')
                    ClassDataProxy.getMarginTopHandler($('#teacherDetailReminders'));//显示预约成功弹框
                    $('#teacherDetailRemindersBox').show();
                    that._emit(MessageTypes.ORDER_FINISH);
                }else if(_data.returnData.data.msg == '您已预约这堂课' && ClassDataProxy.loginName){
                    ClassDataProxy.getMarginTopHandler($('#warnHintBox'));//修改信息输入框
                    ErrorApe.showWarnError('您已预约这堂课');
                }else {
                    ClassDataProxy.getMarginTopHandler($('#warnHintBox'));//修改信息输入框
                    ErrorApe.showWarnError('预约失败,请稍后再试~');
                }
            },
            error:function(error){
                //alert('首页数据获取失败')
                console.log(error,'预约数据获取失败')
            }
        })
    }
    toLogin(){
        ClassDataProxy.getMarginTopHandler($('#userLogin'));
        $('#userLoginBox').show();
    }
    //工具类
    _format(str, obj) {
        return str.replace(/\{(\w+)\}/g, function (match, group, index) {
            return obj[group];
        });
    };
}
export default SubscribeApe;