xuchunyang 8 vuotta sitten
vanhempi
commit
afa44751ed
2 muutettua tiedostoa jossa 112 lisäystä ja 5 poistoa
  1. 7 5
      app/html/resinforbrow.html
  2. 105 0
      app/js/resinforbrow.js

+ 7 - 5
app/html/resinforbrow.html

@ -38,7 +38,8 @@
38 38
				</div>
39 39
			</div>
40 40
			<div class="attentbtn mui-pull-left">
41
				<em class="mui-iocn iconfont icon-favor"></em><!--已经关注icon-favorfill-->
41
				<em class="mui-iocn iconfont icon-favor" id="yesExpert"></em>
42
				<em class="mui-iocn iconfont icon-favorfill" style="display:none;" id="noExpert"></em><!--已经关注icon-favorfill-->
42 43
			</div>
43 44
		</nav>
44 45
		<!-- 主页面内容容器 -->
@ -139,16 +140,17 @@
139 140
140 141
        </div>
141 142
		
142
		
143
		<script src=" ../js/public/mui.min.js"></script>
143
		<script src="../js/public/mui.min.js"></script>
144
		<script src="../js/public/base.js"></script>
145
		<script src="../js/resinforbrow.js"></script>
144 146
		<script type="text/javascript">
145
			mui.init();
147
			/*mui.init();
146 148
			var shareBtn = document.getElementById("shareBtn");
147 149
			var shareBox = document.getElementById("shareBox");
148 150
			
149 151
			shareBtn.addEventListener("tap",function(){
150 152
				shareBox.style.display = 'block';
151
			});
153
			});*/
152 154
			
153 155
		</script>
154 156
	</body>

+ 105 - 0
app/js/resinforbrow.js

@ -0,0 +1,105 @@
1
//资源信息页面 
2

3
mui.plusReady(function() {
4
	var yesExpert = document.getElementById("yesExpert");
5
	var noExpert = document.getElementById("noExpert");
6
	var userid = plus.storage.getItem('userid');
7
	var self = plus.webview.currentWebview();
8
	var resourceId = self.resourceId;
9

10
	ifCollection();
11

12
	yesExpert.addEventListener('tap', function() {
13
		var $this = this;
14
		collectionExpert($this);
15
	});
16
	
17
	noExpert.addEventListener('tap',function() {
18
		var $this=this;
19
		cancelCollectionExpert($this);
20
	});
21

22
	/*判断是否收藏资源*/
23
	function ifCollection() {
24
		mui.ajax(baseUrl + '/ajax/watch/hasWatch', {
25
			data: {
26
				"professorId": userid,
27
				"watchObject": resourceId
28
			},
29
			dataType: 'json', //数据格式类型
30
			type: 'get', //http请求类型
31
			timeout: 10000,
32
			async: false,
33
			success: function(data) {
34
				if(data.success && data.data != null) {
35
					yesExpert.style.display = "none";
36
					noExpert.style.display = "block";
37
				} else {
38
					yesExpert.style.display = "block";
39
					noExpert.style.display = "none";
40
				}
41
			},
42
			error: function() {
43
				plus.nativeUI.toast("服务器链接超时", toastStyle);
44
			}
45
		});
46
	}
47

48
	/*收藏资源*/
49
	function collectionExpert($this) {
50
		mui.ajax(baseUrl + '/ajax/watch', {
51
			data: {
52
				"professorId": userid,
53
				"watchObject": resourceId,
54
				"watchType": 2
55
			},
56
			dataType: 'json', //数据格式类型
57
			type: 'POST', //http请求类型
58
			timeout: 10000,
59
			async: false,
60
			success: function(data) {
61
				console.log(data.success)
62
				if(data.success) {
63
					$this.style.display = "none";
64
					noExpert.style.display = "block";
65
					//resourceId = data.data;
66
					//console.log(resourceId)
67
					plus.nativeUI.toast("资源收藏成功", toastStyle);
68
				}
69
			},
70
			error: function() {
71
				plus.nativeUI.toast("服务器链接超时", toastStyle);
72
			}
73
		});
74
	}
75

76
	/*取消收藏资源*/
77
	function cancelCollectionExpert($this) {
78
		//console.log(returnId)
79
		// console.log(userid)
80
		mui.ajax({
81
			url: baseUrl + '/ajax/watch/delete',
82
			data: {
83
				professorId: userid,
84
				watchObject: resourceId
85
			},
86
			dataType: 'json', //数据格式类型
87
			type: 'post', //http请求类型
88
			timeout: 10000,
89
			async: true,
90
			success: function(data) {
91
				console.log(data.success)
92
				if(data.success) {
93
					$this.style.display = "none";
94
					yesExpert.style.display = "block";
95
					plus.nativeUI.toast("取消收藏资源", toastStyle);
96
				}
97
			},
98
			error: function(data) {
99
				plus.nativeUI.toast("服务器链接超时", toastStyle);
100
			}
101
		});
102

103
	}
104

105
});