CollectApe.js
3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//*
// 收藏模块
// */
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){
let that = this;
let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/studentMeeting/addStudentMeeting';
let status = $(evt.currentTarget).attr('data');
let id = $('#lanclassBox').attr('data');
loger.log('收藏数据信息',status,id)
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)
}
})
}
_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){
//获取我的课程数据
loger.log('收藏数据信息',_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();
}
//工具类
_format(str, obj) {
return str.replace(/\{(\w+)\}/g, function (match, group, index) {
return obj[group];
});
};
}
export default CollectApe;