var lvid = getParameter('lvid');
var sign = getParameter('sign');
var type = Number($('body').attr('type'));
var noticeIdArr = new Array();
var printDate = {
	lvid:lvid,
	sign:sign,
	noticemode:type,
	pageindex:1,
	pagesize:20
}

function goPage(num) {
   printDate['pageindex'] = num ++ ;
   verifyNotice();
}
function verifyNotice(){
	var html = '';
	$.ajax({
		url:requestUrlMap['noticeList']['url'],
		data:printDate,
		dataType:'jsonp',
		success:function(data){
			if (data.errorid != 0) {
				return;
			}
			if (data.zongcount == 0) {
				$('.cont').addClass('nothingbg');
				return;
			}
			$('.cont').removeClass('nothingbg');
			var pageTotal = Math.ceil(data.zongcount / 20);
			var json = data.noticelist.collearray;
			var msgObj='',tip;
			var userid = data.loginuserid;
			for(var i = 0;i<json.length;i++){
				msgObj = json[i];
				var user = msgObj.user;
				var userSend = msgObj.user;
				var notice = json[i].notice;
				var time = $.formatDateStyle3(new Date(json[i].notice.createtime * 1000));
				var titleName = user.nickname.replaceAll('>', '&gt;');
				var sliceName = user.nickname.length > 10 ? user.nickname.slice(0,10) + '...' : user.nickname;
				var notice_verifymsg = decodeURIComponent(notice.verifymsg);
				html += '<li>';
				html += '<dt class="news_left clearfix">';
				html += 	'<p class="paper">';
				html += 		'<a class="col" onclick=\"lookUserView(' + msgObj.user.lvid + ',' + msgObj.user.userid + ')\" href="javascript:">('+msgObj.user.lvid+')</a>' +msgObj.user.nickname;
				html += 	'</p><p class="time">'+time+'</p></dt>';
				html += '<dd>';
				if(notice.noticetype == 1){
					switch (notice.accepttype){
						case 0: //待处理
							html += '<p class="info"><span>附加信息：'+notice_verifymsg+'</span></p>';
							html += '<div class="verFdBut" id="verify_person_' + userSend['lvid'] + '">';
							html += '<div class="ver-tongyiBut">';
							html += '<div class="verAgree" onclick="verifyPerson(' + notice['id'] + ',1,' + userSend['lvid'] + ')"><span>同意</span></div>';
							html += '<div class="verXuanze">';
							html += '<div class="verXuanze-popup">';
							html += "<div>";
							html += '<p onclick="verifyPerson(' + notice['id'] + ',1,' + userSend['lvid'] + ')">同意</p>';
							html += "</div>";
							html += "<div>";
							html += '<p onclick="verifyPerson(' + notice['id'] + ',2,' + userSend['lvid'] + ')">拒绝</p>';
							html += "</div>";
							html += '</div>';
							html += '</div>';
							html += '</div>';
							html += '<div class="ver-ElideBut" onclick="verifyPerson(' + notice['id'] + ',3,' + userSend['lvid'] + ')"><span>忽略</span></div>';
							html += "</div>";
							break;
						case 1: //已同意
							html += '<p class="info"><span>附加信息：'+notice_verifymsg+'</span></p>';
							html += '<div class="verFdBut"><div class="ver-yesBut">已同意</div></div>';
							break;
						case 2: //已拒绝
							html += '<p class="info"><span>附加信息：'+notice_verifymsg+'</span></p>';
							html += '<div class="verFdBut"><div class="ver-yesBut">已拒绝</div></div>';
							break;
						case 3: //已忽略
							html += '<p class="info"><span>附加信息：'+notice_verifymsg+'</span></p>';
							html += '<div class="verFdBut"><div class="ver-yesBut">已忽略</div></div>';
							break;
						case 4: //对方已拒绝
							html += '<p class="info"><span>附加信息：'+notice_verifymsg+'</span></p>';
							break;
						}
				}else{
					mth = 'verifyGroup';
					if (notice['noticetype'] == 2) { //请求加入云组
						tip = '申请';
					} else { //邀请加入云组
						if (notice.senduserid == userid) {
							tip = '受邀';
						} else {
							tip = '邀请您';
						};
					};

					if (notice['noticetype'] == 5 || notice['noticetype'] == 4 || notice['noticetype'] == 7 || notice['noticetype'] == 8 || notice['noticetype'] == 9) {
						html += '<p class="info"><span>附加信息：'+notice_verifymsg+'</span></p>';
					}else {
						tip = notice['noticetype'] == 6 ? '&nbsp;加入群组&nbsp;' : '&nbsp;' + tip + '加入群组&nbsp;';
						html += "<div class='_Left'><xmp class='vername col' title=" + titleName + " onclick=\"lookUserView(" + msgObj.user.lvid + "," + msgObj.user.userid + ")\">" + sliceName + "</xmp>" + tip + "<xmp onclick=\"lookGroupView("+notice.groupid+")\" class='col dename' style='cursor:pointer' title="+msgObj.group.cloudgroupname+">"+msgObj.group.cloudgroupname+"</xmp></div>";

						if (notice_verifymsg == '') {
							notice_verifymsg = '无'
						};
						if (notice_verifymsg && notice_verifymsg.length > 21) {
							notice_verifymsg = notice_verifymsg.substring(0, 21) + "...";
						};
					};
					switch (notice['accepttype']) {
						case 0: //待处理
							if(notice['noticetype'] == 7){
								break;
							}else if(notice['noticetype'] == 8){
								break;
							}
							html += '<div style="position: absolute;right: 10px;bottom: 5px;"><div class="ver-tongyiBut">';
							html += '<div class="verAgree" onclick="' + mth + '(' + notice.id + ',1)"><span>同意</span></div>';
							html += '<div class="verXuanze">';
							html += "<div class=\"verXuanze-popup\">";
							html += "<div>"
							html += '<p onclick="' + mth + '(' + notice.id + ',1)">同意</p>';
							html += "</div>"
							html += "<div>"
							html += '<p onclick="' + mth + '(' + notice.id + ',2)">拒绝</p>';
							html += "</div>"
							html += "</div>";
							html += "</div>";
							html += "</div>";
							html += '<div class="ver-ElideBut" onclick="' + mth + '(' + notice.id + ',3)"><span>忽略</span></div></div>';
							break;
						case 1: //已同意
							if (notice['noticetype'] < 3) {
								html += '<div class="ver-yesBut">已同意</div>';
								break;
							};
							/*if (notice['noticetype'] == 5) {
								html += '<div class="verAgree" style="float:right" onclick="addMyGroup(' + notice.groupid + ')"><a class="btns"><span>邀请好友</span></a></div>';
							};*/
							break;
						case 2: //已拒绝
							html += '<div class="ver-yesBut">已拒绝</div>';
							break;
						case 3: //已忽略
							html += '<div class="ver-yesBut">已忽略</div>';
							break;
					};
				}
				html += '</dd>';
				html += '</li>';
			}
			$('.news').html(html)
			printPage(pageTotal);
		}
	})
}

//好友验证
function verifyPerson(noticeid, acceptType, senderLvid) {
	var tip;
	switch (acceptType) {
		case 1: //同意
			tip = '已同意';
			break;
		case 2: //拒绝
			tip = '已拒绝';
			break;
		case 3: //忽略
			tip = '已忽略';
			break;
	}
	var buttonid = "verify_person_" + senderLvid;
	var buttonhtml = '<div class="ver-yesBut">' + tip + '</div>';
	$("#" + buttonid).html(buttonhtml);
	if ($.inArray(noticeid, noticeIdArr) > -1) {
		return;
	}
	noticeIdArr.push(noticeid);
	var params = {
		'lvid': lvid,
		'noticeid': noticeid,
		'accepttype': acceptType,
		'sign': sign
	};
	$.getJSON(requestUrlMap['updateNotice']['url'], params, function(data) {
		if (data.errorid != 0) {
			var paramStr = "{title:'提示',cat:0,content:'" + data.errmsg + "！'}";
			var params = "{command:9006,params:" + paramStr + "}";
			sendCommand(params);
			return;
		}
		//load(Verify.PERSON);
		verifyNotice();
	});
}
function verifyGroup(noticeid, acceptType) {
	var tip;
	switch (acceptType) {
		case 1: //同意
			tip = '已同意';
			break;
		case 2: //拒绝
			tip = '已拒绝';
			break;
		case 3: //忽略
			tip = '已忽略';
			break;
	};
	var buttonid = "verify_group_" + noticeid;
	var buttonhtml = '<div class="ver-yesBut">' + tip + '</div>';
	$("#" + buttonid).html(buttonhtml);
	if ($.inArray(noticeid, noticeIdArr) > -1) {
		return;
	};
	noticeIdArr.push(noticeid);
	var params = {
		'lvid': lvid,
		'noticeid': noticeid,
		'accepttype': acceptType,
		'sign': sign
	};
	$.getJSON(requestUrlMap['updateNotice']['url'], params, function(data) {
		if (data.errorid != 0) {
			var paramStr = "{title:'提示',cat:0,content:'" + data.errmsg + "！'}";
			var params = "{command:9006,params:" + paramStr + "}";
			sendCommand(params);
			return;

		};
		//load(Verify.GROUP);
		verifyNotice();
	});
}
function addMyGroup(groupid) {
	var params = "{command:1005,params:{groupid:" + groupid + ",myuserid:" + userid + "}}";
	var resultS = sendCommand(params);
};

function lookUserView(lvid, userid) {
	var params = "{command:1003,params:{userid:" + userid + ",lvid:" + lvid + "}}";
	sendCommand(params);
};

function lookGroupView(groupid) {
	var params = "{command:3002,params:{groupid:" + groupid + "}}";
	sendCommand(params);
};

$(document).on('click','.verXuanze',function() {
	$(this).find(".verXuanze-popup").show();
});
$(document).ready(function(){
	verifyNotice();
})