send.js 33.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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
var curWwwPath = window.document.location.href;
var posi = curWwwPath.lastIndexOf('/');
var localhostPaht = curWwwPath.substring(0, posi);
var post = localhostPaht.lastIndexOf('/');
var localhostPaht = curWwwPath.substring(0, post);
var nophone="";//数据库中没有电话的用户 chris add 2018/01/10
var nowxid="";//没有绑定微信的用户 chris add 2018/01/10
var noDdid="";//没有绑定钉钉用户

/**
 * 每次打开表单都根据id保存,
 * 关闭的时候也要根据id获取值,通过判断是否存在来确定是否要重新打开新页面
 * 将cookie
 * @param pid
 */
//function closeForm(pid){
//	//该公文在打开第一次时关闭才执行更新数据库
//	if(!openStatus){
//		updateOpendFormById(pid,"N");
//	}
//}
function sendDX(){
	var data = '{"phones":"18700850426","content":"请查收短信"}';
	$.ajax({
		type:"post",
//		url:"http://xasj.nnghj.gov.cn:8085/DxService//sendDx/send",
		url:"http://127.0.0.1:8086/sendDx/send",
		data:data,
		contentType:"application/json",
		dataType: "json",//请求参数类型
		success: function (result) {
			console.log("12316546448");
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			console.log("0000000");
		}
	});	
}
/**
 * 保存更新数据
 * @returns
 */
function saveOrUpdateForm(type,documenttype){
	var formdetailjson=getdata("save");
	var formdetail = JSON.stringify(formdetailjson);
	$.post(global.contextPath + global.modelctls.document.save,
			{	formdetail:formdetail,
			type:type
		  }, 
		 function (result) {   
			  $("#delete,#filing").css('display','inline');	
			  var status=$("#status").val();
			  if(status==0){
			  var ids= new Array(); //定义一数组 
			  ids=result.split(",");
			  if(result!=""){
			     pid=ids[0];
				 fid=ids[1];						
				$('#pid').val(pid);
				$('#fid').val(fid);
				 }
			  $('#outdispatches').val("cy");			 
				  updatefjlog(ids[0]);
			  }
				  pid=$('#pid').val();
				  saveOrUpdateNbview(pid);
			  //非新建的时候才执行同步
//			  if(status!=0){
//				  websocketAsy(loginname_now,pid,action);
//			  }else{
				  replaceUrl(documenttype);
//			  }
       });

	
}

function isdeleteing(){
	layer.confirm('是否删除该记录!', {
  	btn: ['确定','取消'] //按钮
}, function(){
  	layer.confirm('保存成功,2s后关闭当前页!', {
  	btn: ['关闭'] //按钮
}, function(){
  closewindowtab();
});
	setTimeout('closewindowtab()',2000);
}, function(){
	layer.closeAll();
});
}
/**
 * 发送回退操作
 * @param action
 */
function sendback(action,formdetail){	
	var str="";
	if(action=="rollback"){
		str="回退";
		$.ajaxSetup({async:false});
		$.post(global.contextPath +global.modelctls.document.rollbackUser,
				 {formdetail:formjsonstr
				  }, 
				 function (data){   	   
					var touser=data;
					str=str+"至"+touser.loginname;
					  
		        });		
		
	}else if(action=="startcountersign"){
			str="会签";
	}
	layer.open({
		content: '是否'+str+'?',
		btn: ['确认', '取消'],
		shadeClose: true,
		icon: 3,
		yes: function(){
			$.ajax({
				type: "POST",
				async: false,
				contentType:"application/json",
				url: documentserver + global.modelctls.document.updateForwardlogs,
				crossDomain:true,
				data: JSON.stringify(formdetail),
				success:function(data, textStatus, jqXHR) {
				//状态改为已办后 意见表isshow 改为 Y
					var view = $("#hqOpinion").val();
					if(view==""){
						layer.closeAll();
						layer.msg('请填写会签意见',{icon:2});
						return;
					}
					var arg={"userid":logginUserId,"isshow":"Y","viewtype":"会签意见"};
					$.ajax({
						type: "POST",
						async: false,
						contentType:"application/json",
						url: documentserver + "/api/viewinfors/updateViewByUserid",
						crossDomain:true,
						data: JSON.stringify(arg),
						success: function(data, textStatus, jqXHR) {
							newclose(action,status);
							refleshList(listType);
							layer.closeAll();
						}
						
					});
					
				},
				error:function(jqXHR, textStatus, errorThrown) {
						console.log(errorThrown);
				}
			});
	       
		}
	});
}

/**
 * 保存或更新拟办意见
 */
function saveOrUpdateNBview(content,viewtype,pid){
	  if(content!=null)
	  {
		  if(pid!=undefined||pid!=null){
		    	updateview(content,viewtype,pid);						    
			  }else{
				  addview(content,viewtype,pid);
			  }
	  }
	  
}
/*传阅公文列表弹出选人窗口*/
function selectnumbers(url){
var index=parent.layer.open({	
  type: 2,
  title: '文号类型',
  shadeClose: true,
  shade: 0.3,
  area: ['350px', '450px'],
  offset:['50px'],
  content: url,
   yes:function(index,layero){},
   end:function(index,layero){}
}); 
return index;
}

/*
*保存成功提示
*/
function saveformSuccess(){
	layer.msg('保存成功',{icon: 1});
}

/*
*发送成功不关闭页面
*
*/
function sendSuccessNotClose(){
	layer.msg('发送成功',{icon: 1});
}
/*
*提醒成功不关闭页面
*
*/
function RemindSuccessNotClose(){
	layer.msg('提醒成功',{icon: 1});
}
/*
*督办成功不关闭页面
*
*/
function SupervisionSuccessNotClose(){
	layer.msg('督办成功',{icon: 1});
}
/*
*打印不关闭页面
*
*/
function printSuccessNotClose(){
	layer.alert('打印预览(打印发文签)');
}
/*
*取回成功不关闭页面
*
*/
function backSuccessNotClose(){
	layer.msg('取回成功',{icon: 1});
}

/*
*归档成功不关闭页面
*
*/
function archivefileSuccessNotClose(){
	layer.msg('办结成功',{icon: 1});
}
/*
*删除不关闭页面
*/
function deleteSuccessNotClose(action){
	var flag=false;
	var str="";
	if(action=="filing"){
		str="办结";
	}else if(action=="delete"){
		str="删除";
	}
layer.confirm('是否'+str+'!', {
  	btn: ['确定','取消'] //按钮
}, function(){
	flag=true;
}, function(){
	flag=false;
});
	return flag;
}
/*
*发送成功并提示关闭当前标签页
*/
function sendSucess(action){

}

/*
*归档成功并提示关闭当前标签页
*/
function archivefileSucess(){
	layer.confirm('办结成功,2s后关闭当前页!', {
  	btn: ['关闭'] //按钮
}, function(){
  closewindowtab();
});
	setTimeout('closewindowtab()',2000);
}

/*
*关闭当前标签页
*/
function closewindowtab(){
	self.close();
	window.opener.location.reload();
}

function sendUser(path,selected,action,doctype,formdetail,arg,pidParam){
	var index=parent.layer.open({	
		type: 2,
		title: '选择用户',
		shadeClose: true,
		shade: 0.3,
		area: ['640px', '550px'],
		content: path,
		btn: ['发送', '取消'],
		yes:function(index,layero){
		   var body = layer.getChildFrame('body', index);
		   var iframeWin = parent.window[layero.find('iframe')[0]['name']];
		   var tousers=iframeWin.users();
		   var checkMessage=iframeWin.setMessageConetent();
		   var content = iframeWin.dWxWconContent();	
		   //获取短信和微信的发送勾选
		   var checkWeChatAndMessage = iframeWin.checkMessage();
  	if(tousers==""||tousers==null||tousers==undefined){
  		parent.layer.msg('请选择人员',{icon: 2});
  		return;
  	 } 
  	// 控制办公室核改和会签不能同时发送
  	if(tousers.length > 1){
  		var nameStr = "";
  		for(var t in tousers){
  			nameStr += tousers[t].username + ",";
  		}
  		if(nameStr.indexOf("办公室核改人") != -1){
  			parent.layer.msg('办公室核改和会签请勿同时选取,会签完后会发送到办公室核改',{icon: 2});
  			return;
  		}
  	}
  	
 // ------------------------分局内部流转则人为制定节点信息-------------------------------------------------------------
// 	if(logginParentUnit.name != "西安市自然资源和规划局"){  // 现在不需要内部流转
// 		for(var t in tousers){
// 			var fuser = {id:tousers[t].userid};
// 			var user = getUser(fuser); // 获得选择的用户信息
// 			var dept = findDeptById(user.id);
// 			if(dept.dept_parentname != "西安市自然资源和规划局" && dept.dept_parentname.indexOf("分局") != -1){ // 判断选择发送的人是否为分局的人
// 				if('' != user.position && null != user.position && user.position.indexOf("信息员") != -1){ // 判断是 信息员
// 					if("" != tousers[t].stagename && tousers[t].stagename != null && tousers[t].stagename != undefined){
// 						
// 					} else {
// 						tousers[t].stagename = "分局信息员";
// 					}
// 				} else { // 不是信息员则人为指定一个节点
// 					tousers[t].stagename = "内部流转";
// 				}
// 			} 
////				else if(dept.dept_parentname != "西安市自然资源和规划局" && dept.dept_parentname.indexOf("分局") == -1){ // 以及不为市局也不为分局
////				if('' != user.position && null != user.position && user.position.indexOf("信息员") != -1){ // 判断是 信息员
////					if("" != tousers[t].stagename && tousers[t].stagename != null && tousers[t].stagename != undefined){
////						
////					} else {
////						tousers[t].stagename = "处室信息员";
////					}
////				} else { // 不是信息员则人为指定一个节点
////					tousers[t].stagename = "内部流转";
////				}
// //			}
// 		}
// 	}
 // ------------------------分局内部流转则人为制定节点信息-------------------------------------------------------------
		   parent.layer.open({
			   content: '是否发送?',
			   btn: ['确认', '取消'],
			   shadeClose: true,
			   icon: 3,
			   yes: function(){		
				   $("#lingdao").css("display","none");
					$("#chushi").css("display","none");
				   if(arg){
					   if(status=="0"){
						   if(doctype = "fw"){ // 给发文添加拟稿人
							   formdetail.seeker = JSON.parse($.cookie('cookieuser')).user.loginname;
						   }
//							莫潇楠 2018年4月16日(星期一) 新建公文时可添加意见				
							var nbyjText = $('#nb_view .div-opinion-content label:first').text().trim();
							if(nbyjText){
								saveForm(formdetail,listType,"send",nbyjText);
							}else{
								saveForm(formdetail,listType,"send");
							}
					   }else{
						   updateFormData(formdetail,"send");
					   }
					   isSaveNumber=true;
					   selected=$("#fid").val();
				   }
				   sendDD(tousers,checkMessage,content);
				   massSend(selected,tousers,action,doctype,checkMessage,content,pidParam, checkWeChatAndMessage);		  	
			   }
		   }); 
		},
		end:function(index,layero){
			$("#iframecontent").css('display','block');
			//2017/7/31     再点击发送之后会影响父页面发送、归档、新建发文等按钮的样式
			$(".button-operation").css('display','block');
		}
	}); 
}
/**
 * 列表批量发送
 * @param selected
 * @param tousers
 * @param action
 * @param doctype
 * @param checkMessage
 * @returns
 */   
// 不用此发送先注释

function massSend(selected,tousers,action,doctype,checkMessage,content,pidParam, checkWeChatAndMessage){
	var agentid = CONF_DOCUMENT_AGENTID ? CONF_DOCUMENT_AGENTID : "";
//	var agentid = "";
	var wxMobileInfo = getWxMobileInfo(tousers);
	if(selected.constructor==Array){
		for(var i = 0;i<selected.length;i++){
			var ids=selected[i];
			var userid=	logginUserId;
			var username=loggin_realname;
			var nextstage=stage==null?"":stage.nextstage;
			var senderArg={
					counterSign:stage.counterSign,
					userDetail:tousers,
					fid:ids,
					sender:username,
					senderid:userid,
					action:action,
					nextStage:nextstage,
//					把发送短/微信放到后台
					content:content,
					agentid:agentid,
					wxname:wxMobileInfo.wxname,
					mobile:wxMobileInfo.mobile,
					checkWeChatAndMessage:JSON.stringify(checkWeChatAndMessage)
			}
//			 莫潇楠 2018年4月9日(星期一) 修改公文管理可发送给所有人,且环节为局内会签或会签,只有公文管理会传pid
			if(pidParam){
				senderArg.pid = pidParam;
			}
			$.ajax({
				type: "POST",
				async: true,
				dataType:'json',
				contentType:"application/json",
				url: documentserver + global.modelctls.document.send,
				crossDomain:true,
				data: JSON.stringify(senderArg),
				success:function(data, textStatus, jqXHR) {
//					getMobileAndWeChat(tousers,checkMessage, checkWeChatAndMessage);
					if(listType){
						refleshList(listType);
					}else{
						refleshList(doctype);
					}
					console.log("发送插入日志表");
					//若不为空 则说明存在发送给收文信息员,则将附件复制到新建的分局公文中
					if(data.newDocEntityList.length>0){
//						copyFileByPid(data.newDocEntityList);
						//更新分局信息员的所在部门
						updateDepartment(data.newDocEntityList);
					}
					parent.layer.closeAll();
					listType=$("#listType").val();
					//防止首页点进详情页发送后报错的问题
					//refleshList(listType);
					newclose(action,1);
				},
				error:function(jqXHR, textStatus, errorThrown) {
						console.log(errorThrown);
						alert(errorThrown);
				}
			});
		}
	}else{
		var ids=selected;
		var userid=	logginUserId;
		var username=loggin_realname;
		var nextstage=stage==null?"":stage.nextstage;
		var senderArg={
				counterSign:stage.counterSign,
				userDetail:tousers,
				fid:ids,
				sender:username,
				senderid:userid,
				action:action,
				nextStage:nextstage,
//				莫潇楠 2018年7月2日 星期二 把发送短/微信放到后台
				content:content,
				agentid:agentid,
				wxname:wxMobileInfo.wxname,
				mobile:wxMobileInfo.mobile,
				checkWeChatAndMessage:JSON.stringify(checkWeChatAndMessage),
				curunit:JSON.parse($.cookie('cookieuser')).units[0].name
		}
//		 莫潇楠 2018年4月9日(星期一) 修改公文管理可发送给所有人,且环节为局内会签或会签,只有公文管理会传pid
		if(pidParam){
			senderArg.pid = pidParam;
		}
		$.ajax({
			type: "POST",
			async: false,
			dataType:'json',
			contentType:"application/json",
			url: documentserver + global.modelctls.document.send,
			crossDomain:true,
			data: JSON.stringify(senderArg),
			success:function(data, textStatus, jqXHR) {
//				getMobileAndWeChat(tousers,checkMessage, checkWeChatAndMessage);
				try{
					if(listType){
						refleshList(listType);
					}else{
						refleshList(doctype);
					}
				}catch(err){
					console.log(err);
				}finally{
					console.log("发送插入日志表");
					//若不为空 则说明存在发送给收文信息员,则将附件复制到新建的分局公文中
					if(data.newDocEntityList.length>0){ 
//						copyFileByPid(data.newDocEntityList);
						//更新分局信息员的所在部门
						updateDepartment(data.newDocEntityList);
					}
					parent.layer.closeAll();
					listType=$("#listType").val();
					//防止首页点进详情页发送后报错的问题
					//refleshList(listType);
					newclose(action,1);
				}
				
			},
			error:function(jqXHR, textStatus, errorThrown) {
					console.log(errorThrown);
			}
		});
	}
	//列表刷新
	
}
function updateDepartment(data){
	var touserid;
	var tousername;
	var dataArr;
	var entity;
	var docEntity;
	for(var i=0;i<data.length;i++){
		dataArr=data[i];
		for(var j=0;j<dataArr.length;j++){
			entity=dataArr[j];
			touserid=entity.touserid;
			tousername=entity.tousername;
			docEntity=entity.document;
			ajaxUpdateDocDepartment(docEntity,touserid);
		}
	}
}
/**
 * 更新数据入库
 */
function ajaxUpdateDocDepartment(data,userid){
	var pid=data.id;
	//获取发送人的部门
	var userInfo=getUserInfoById(userid);
	var logginUnitid = userInfo.units[0].id;
	logginParentUnit = getLogginParentUnit(logginUnitid);
	var arg={
			id:pid,
			department:logginParentUnit.name
	}
	$.ajax({
		type : "POST",
		async : false,
		contentType : "application/json",
		url : documentserver + global.modelctls.document.updateForm,
		crossDomain : true,
		data :  JSON.stringify(arg),
		success : function(data, textStatus, jqXHR) {
			
		},
		error : function(jqXHR, textStatus, errorThrown) {
			
		}
	});
}

/*
*发送微信或者短信的判断
* chris add 2018/01/08
*/
/*function checkSend(checkMessage,tousers,content){
	if(checkMessage=="message"){
		 sendMessage(tousers,content);
	}else if(checkMessage=="wechat"){
		sendWechat(tousers,checkMessage,content);
	}else if(checkMessage=="messagewechat"){
		sendMessage(tousers,content);
		sendWechat(tousers,checkMessage,content);
	}
	if(checkMessage.indexOf("message")!=-1){
//		sendMessage(tousers,content);
	}
	if(checkMessage.indexOf("wechat")!=-1){
//		sendWechat(tousers,checkMessage,content);
	}
	 if(checkMessage.indexOf("dd")!=-1 && $.cookie('CONF_STATE_URL')=='1'){
		 sendDD(tousers,checkMessage,content);
	}
}*/

/**
 * 发送钉钉js处理 
 * chris modify 2018/01/08
 */
function sendDD(tousers,checkMessage,content){
	var userddids="";
	for(var i=0;i<tousers.length;i++){
		var userDetail=tousers[i];
		if(userDetail.ddid!="null" && userDetail.ddid!=""){
			userddids+=userDetail.ddid+",";
		}else{
			if(i==tousers.length-1){
				noDdid+=userDetail.username;
			}else{
				noDdid+=userDetail.username+",";
			}
		}
	}
	if(userddids.length>0){
		$.ajax({
				type:"POST",
				url: CONF_SENDDD,
				async : false,
				data:{
					users:userddids,
					//agentid:CONF_AGENTID,
					content:content,
					url:"eapp://page/pages/index/index"   //添加点击跳转地址,跳转到钉钉应用的首页 by zj 2018-11-12
					},
					crossDomain:true,
				success: function (result) {
					console.log(result);
					if(result.errmsg=="ok"&result.invaliduser=="")
					{
						msg="ok";
					}
					},error: function(XMLHttpRequest, textStatus, errorThrown) {
						msg="error";
						console.log(XMLHttpRequest);
						console.log(textStatus);
						console.log(errorThrown);
					}
				});
	}
	/*var userDetail;
	var touserInfo;
	var towxname;
	var flag=false;
	for(var i=0;i<tousers.length;i++){
		userDetail=tousers[i];
		touserInfo=getUserInfoById(userDetail.userid);
		towxname=touserInfo.user.wxname;
		if(!towxname){
			flag=true;
			continue;
		}
		SendWxMessage(towxname,CONF_AGENTID,checkMessage);
	}
	if(flag&&sendWechat){
		layer.msg('含有未绑定微信的用户',{icon: 2});
	}*/
}

/**
 * 发送微信提醒
 */
/*function sendWeChatMessage(wxname, content) {
	var agentid = CONF_DOCUMENT_AGENTID ? CONF_DOCUMENT_AGENTID : "";
	$.ajax({
		type:"POST",
		async: true,
		url: CONF_WX_SERVERURL+"/TextMessageServlet",
		data:{
			touser: wxname,
			agentid: agentid,
			content: content
		},
		success: function(result) {
			console.log(result);
			//layer.msg("微信发送成功!", {icon : 0});
		},
		error: function(e) {
			console.log(e);
			//layer.msg("微信发送失败!", {icon : 2});
		}
		});	
}*/
/**
 * 发送短信
 */
/*function sendSMSMessage(mobile, content) {
	$.ajax({
		type:"POST",
		async: true,
		url: CONF_MESSAGE_SERVERURL+ "/api/message/sendMessage",
		data:{
			recivers : mobile,
			content:content,
			sendTime: '',
			curuser:JSON.parse($.cookie('cookieuser')).user.realname,
			curunit:JSON.parse($.cookie('cookieuser')).units[0].name
		},
		success: function(result) {
			console.log(result);
			//layer.msg("短信发送成功!", {icon : 0});
		},
		error: function(e) {
			console.log(e);
			//layer.msg("短信发送失败!", {icon : 2});
		}
		});	
}*/
/**
 * 通过返回的数据 复制附件到新建的公文
 */
//function copyFileByPid(list){
//	var documents;
//	var document;
//	var oldFilePath="";
//	var oldpid="";
//	var newFilePath="";
//	var tousername="";
//	var touserid="";
//	var entity;
//	var touser;
//	var touserUnit;
//	var arg={};
//	for(var i=0;i<list.length;i++){
//		documents=list[i];
//		for(var j=0;j<documents.length;j++){
//			document=documents[j];
//			tousername=document.tousername;
//			touserid=document.touserid;
//			entity=document.document;
//			oldpid=entity.memo;
//			newFilePath=entity.docattachmentpath;
//			$.ajax({
//				   type: "POST",
//				   async: false,
//				   url: documentserver + global.modelctls.document.forminfo,
//				   data: {pid:oldpid},
//				   dataType: "json",//请求参数类型
//				   success: function(data){
//					   oldFilePath= data.docattachmentpath;
//					   documentCopyfile(newFilePath,oldFilePath,tousername,touserid);
//					   
//				   },error: function(err) {
//			        	console.log("get progress data fail:"+err); 
//			        }
//				});
//			
//			touser=getUserInfoByUserid(touserid);
//			touserUnit=getLogginParentUnit(touser.units[0].id);
//			arg={
//					id:entity.id,
//					department:touserUnit.name
//			};
//			updateDocByArg(arg);
//		}
//	}
//}
/**
 * 自动选取当前角色下的用户
 */
function autoSeletedUser(rolename){
	if(status=='0'||outdispatches=='拟稿'||isDarfter==true){
		//根据客户需求。拟稿的时候直接发给主任意见:先获取同单位下角色为办公室主任的用户
		getUserByrole(rolename);
	}  
}
function getNextStageRole(){
	if(stage==null){return roles}
	var nextstage=stage.nextstage;
	if(nextstage==null){return roles;}
	var unitname=stage.unitname;
	var arr=[];
	if(nextstage.indexOf(",")!=-1){
		var nextStageArr=nextstage.split(",");
	
		var next;
		var stages;
		var roleStr=null;
		var roleid="";
		var role=null;
		var roleidArr=null;
		for(var i=0;i<nextStageArr.length;i++){
			var stageJson={};
			var roles=[];
			next=nextStageArr[i];
			if(next==""){continue;}
			stages=getStage(documenttype,unitname,next);
			if(!stages){continue;}
			roleStr=stages.roleids;
			if(roleStr==null){continue;}
			if(roleStr.indexOf(",")!=-1){
				roleidArr=roleStr.split(",");
				for(var j=0;j<roleidArr.length;j++){
					roleid=roleidArr[j];
					if(roleid!=""){
						role=getRoleByRoleid(roleid);
						if(role){roles.push(role);}
					}
				}
			}
			stageJson.stage=stages;
			stageJson.role=roles;
			arr.push(stageJson);
		}
	}
	return arr;
}

function getUserByrole(rolename){
	$.ajax({
		type: "POST",
		headers:{
    		"token":$.cookie('ftoken')
	    },
		async: false,
		dataType:'json',
		contentType:"application/json",
		url: userserver + global.modelctls.user.getuserlist,
		crossDomain:true,
		data: JSON.stringify(user),
		success:function(data, textStatus, jqXHR) {
			if(data.length<0){
				layer.msg("未登录",{icon: 2});
				return;
			}
			loggin_realname=data[0].realname;
			logginUserId=data[0].id;
			var id=data[0].id;
//			getUserInfo(data[0].id);
			
		},
		error:function(jqXHR, textStatus, errorThrown) {
				console.log(errorThrown);
		}
	});
	$.post(global.contextPath + global.modelctls.document.getUnitusersByRole,
			{rolename:rolename}, 
			 function (result) {  
			 if(result==null||result==undefined){
				 layer.msg('发送失败,未找到角色',{icon: 2});
				 return;
			 } 				 
			var user=result.theUser;
			var touserunit=result.theUnit;
		  touser={
				  id:user.id,
				  level:'3',
				  loginname:user.loginname,
				  userUnit:touserunit.name,
				  userUnitId:touserunit.id,
				  theRoles:result.theRoles
				  };
	       });
}
/**
 * 最新需求关闭窗口方式 2016-6-13 hepo
 * 5秒自动关闭
 */
function newclose(action,arg){
	var content = "";
	var source = "";
	$.ajax({
		url: CONF_BACK_SERVERURL+ "/mvc/sctips/tiplist.do",
		async:false,
		headers:{
    		"token":$.cookie('ftoken')
	    },
		success:function(data){
			if(data.length>0){
				var index = Math.floor(Math.random()*data.length);
				content = data[index].content;
				source = data[index].source;
			}
		},
		error:function(){
			console.log("获取小贴士菜单出错");
		}
	})
	//hyh 新增  让出现自动关闭的页面不出现滚动条  2017/12/27
	$("#divPrompt").css("max-height","100%").css("width","45%").css("position","absolute").css("top","50%").css("left","50%").css("transform","translate(-50%, -50%)");
	$("#centerFooter").css("display","none");
	
	
	//$(".button-operation").css('display','none');
	$(".button-operation-from").css('display','none');
	
	$("#button_load").css('display','none');
	 //发送成功后右侧滚动条隐藏
	 $(".mCSB_dragger_bar").css("display","none");
	 $("#bodycontent").mCustomScrollbar("scrollTo","top");
	var  handle="";
	if(action=="send"){
		 handle="发送"
	}else if(action=="delete"||action=="overDelete"){
		 handle="删除"
	}else if(action=="countersign"){
		handle="发起会签"
	}else if(action=="startcountersign"){
		handle="会签"
	}else if(action.indexOf("filing")!=-1){
		 handle="办结"
	}else if (action=="overFiling"){
		if($("#filing") && $("#filing").text()=="办结"){
			handle="办结";
		}else{
			handle="归档";
		}
	}else if(action=="saveAsdraft"){
		 handle="存草稿"
	}else if(action=="rollback"){
		handle="回退"
	}else if(action=="save"){
		handle="保存"
	}else if(action=="takeback"){
		handle="取回"
	}else if(action=="nosupervise"){
		handle="取消督办"
	}else if(action=="supervise"){
		handle="督办"
	}
	
	//var tip_logo = getTipLogo();
	//var str=$("#action");
	//$("#divPrompt").html("<div><img style='width:108px;height:99px;' src='../../../"+tip_logo+"' /><span style='margin-left:20px;font-size:40px'>每日提醒:</span></div>"
	//					+"<div style='margin-top:53px'><span style='font-size:24px'>&nbsp&nbsp&nbsp"+content+"</span></div>"
	//					+"<div style='margin-top:73px'><span style='position:absolute;right:0px;font-size:24px'>----------《"+source+"》</span></div>");
	//$("#bodyContent").before("<div style='text-align:center;color:#0196ea;font-size:24px;position:fixed;top:50px;left:50%;transform:translate(-50%, 0)'><span>"+handle+"成功!窗口将在<label id=\"timeInterval\">5</label>秒后关闭!</span></div>");
	//$("#form").css('display','none');
	//$("#divPrompt").css('display','block');  
	//$(window).unbind('beforeunload');
	//var status=$("#status").val();
	//if(arg||status=="0"){
	//	setInterval("timestrigger()",1000);
	//}
		//var str=$("#action");xiewenlong2018.11.2
	//$("#divPrompt  span").html(handle+"成功!窗口将在<label id=\"timeInterval\">5</label>秒后关闭!");
  //暂不需要提醒
/*	if(nophone.length<=0 && nowxid.length<=0 && noDdid.length>0){
			$("#divPrompt  span").append("<span>"+noDdid+"没有绑定钉钉,无法发送钉钉提醒</span>");
	}else if(nophone.length<=0 && nowxid.length>0&& noDdid.length<=0 ){
		$("#divPrompt  span").append("<span>"+nowxid+"没有绑定微信,无法发送微信提醒</span>");
	}else if(nophone.length>0 && nowxid.length<=0 && noDdid.length<=0){
			$("#divPrompt  span").append("<span>"+nophone+"没有绑定手机号,无法发送短信提醒</span>");
	}else if(nophone.length>0 && nowxid.length>0 && noDdid.length>0){
		$("#divPrompt  span ").append("<span>"+noDdid+"没有绑定钉钉,无法发送钉钉提醒</span>");
		$("#divPrompt  span span").append("<span>"+nowxid+"没有绑定微信,无法发送微信提醒</span>");
		$("#divPrompt  span span span").append("<span>"+nophone+"没有绑定手机号,无法发送短信提醒</span>");
	}*/
	$("#form").css('display','none');
	//$("#divPrompt").css('display','block');  
	var status=$("#status").val();
	if(arg||status=="0"){
		//setInterval("timestrigger()",1000);
		closewindowtab();
	}
}

function timestrigger(){
	var times=$("#timeInterval").html();
	times=times-1;
	$("#divPrompt").find("span").html("操作成功!窗口将在<label style=\"color:red; font-size:14px\">"+times+"</label>秒后关闭!");
	$("#timeInterval").html(times);
	if(times==0){
		clearInterval();
		closewindowtab();
		}
}

function getTipLogo(){
	var tip_logo;
	$.ajax({
		type:"POST",
		url:CONF_BACK_SERVERURL+ "/mvc/resource/finResourceByName.do",
		async:false,
		headers:{
    		"token":$.cookie('ftoken')
	    },
	    dataType:"json",
	    data:{name:"小贴士"},
		success:function(data){
			tip_logo = data.iconCls;
		},
		error:function(e){
			tip_logo = "";
			console.log("获取图标出错!");
		}
	})
	return tip_logo;
}

/**
 * 每秒执行一次
 */

function timestrigger(){
	var times=$("#timeInterval").html();
	times=times-1;
	//$("#divPrompt").find("span").html("操作成功!窗口将在<label style=\"color:red; font-size:14px\">"+times+"</label>秒后关闭!");
	$("#timeInterval").html(times);
	if(times==0){
		clearInterval();
		closewindowtab();
		}
}

/**
 * 关闭弹出窗口,并且关闭当前网页
 * @param index
 */
function closehadle(index,action){
	layer.closeAll();
	if(action==undefined){//hyh 新增判断,审批改派用到,但是传进来的是undefined,所以在这里加个判断
		
	}else{
		newclose(action);
	}
}

function rollback(formjsonstr,opnion,signOrNot,type){
		 $.post(global.contextPath +global.modelctls.document.rollback,
				 {formdetail:formjsonstr,
			 	  opnion:opnion,
			 	  signOrNot:signOrNot,
			 	  type:type
				  }, 
				 function (data){   	       
				//  alert(data);
		        });	
}

function allSend(tousers,checkMessage,content){
	$.ajaxSetup({
		async : false // 取消以下异步请求 即执行会按顺序执行,不会跳出最后再执行function(result)内的代码
	});	
	$.post(global.contextPath + global.modelctls.sms.sendAll,{
		jsonUserId:tousers,
		content:content,
		checkMessage:checkMessage
	},function(result){
		var dXmsg = "";
		var wXmsg = "";
		if(result[0]!=""){
			result[0]=(result[0].substring(result[0].length-1)==',')?result[0].substring(0,result[0].length-1):result[0];
			dXmsg = result[0]+"号码不存在";
		}
		if(result[1]!=""){
			result[1]=(result[1].substring(result[1].length-1)==',')?result[1].substring(0,result[1].length-1):result[1];
			wXmsg += result[1]+"微信号未绑定"
		}
		if(checkMessage=="message"){
//			if(dXmsg=="")
//				layer.msg("已发送短信提醒",{icon: 1});
//			else
//				layer.msg(dXmsg,{icon: 2});
		}else if(checkMessage=="wechat"){
//			if(wXmsg=="")
//				layer.msg("已发送微信提醒",{icon: 1});
//			else
//				layer.msg(wXmsg,{icon: 2});
		}else{
			var msg = dXmsg+","+wXmsg;
//			if(msg==",")
//				layer.msg("提醒成功",{icon: 1});
//			else{
//				msg = (msg.substr(0,1)==',')?msg.substr(1):msg;
//				layer.msg(msg,{icon: 2});
//			}
		}
	});
}


function alertimg(){
layer.open({
  type: 1,
  title: false,
  closeBtn: 0,
  area: '516px',
  skin: 'layui-layer-nobg', //没有背景色
  shadeClose: true,
  content: $('#guidang')
});
}

//tabid格式如:subMenuApprovalTask_0,其中subMenuApprovalTask为二级目录div的id
function iframeLoad(url, tabname, tabid) {
	 $("#iframecontent").attr("src", url);
	    var submenuid = tabid.split("_")[0]
	    displayLeftContent("none");//隐藏首页左侧
	    $("#" + submenuid).show();//显示二级目录
	    //$(".menuitem-selected").attr("class", "menuitem waves-effect");
	    if (tabid != null && tabid != "") {
	        var submenuid = tabid.split("_")[0];
	        displayLeftContent("none");//隐藏首页左侧
	        $("#" + submenuid).show();//显示二级目录
	        menuItemSelected(submenuid.replace("subMenu", "btnMenu"));//一级菜单选中效果
	        $(".submenuitem").attr("class", "submenuitem waves-effect");
	        // $("#" + submenuid + " div:first-child").attr("class", "submenuitem waves-effect submenuitem-selected");
	        $("#" + submenuid).find('.submenuitem')[tabid.split("_")[1]].setAttribute("class", "submenuitem waves-effect submenuitem-selected");
	    }         
}
/**
 * 表单最终归档
 * @param fid
 * @returns
 */
function finnalFiling(fid){
	layer.open({
		content: '是否归档?',
		btn: ['确认', '取消'],
		shadeClose: true,
		icon: 3,
		yes: function(){
			filling("overFiling",fid,documenttype);
			parent.layer.closeAll();
		}
	});
	
}
function filingHandle(pid,fid,action,filingDoctype){
	var selected = fid;
	layer.open({
		content: '是否办结?',
		btn: ['确认', '取消'],
		shadeClose: true,
		icon: 3,
		yes: function(){
			filling(action,selected,filingDoctype);
//			newclose(action,'status');
			layer.closeAll();
		}
	});
}

/**
 * 删除当前用户所拥有的公文
 * 20170106
 */
function deleteByfid(selectedId,action){
	var index=null;
	//getdealedlist(currentPage)
	
	//列表删除
	if(action=="cg_delete"||action=="btnRemove"||action=="cy_delete"){
		
		index=parent.layer.confirm('是否删除!', 
				{
		  	btn: ['确定','取消'], //按钮
		  	icon: 3,
		}, function(){
			if(action=="btnRemove"){

				action="overDelete";
			}else{

				action="delete";
			}
			var actions = filling(action,selectedId);
			parent.layer.closeAll();
			
		});
	}else{
		//var ids=pid+"/"+fid;
		//表单详情删除
		index=layer.confirm('是否删除!', {
		  	btn: ['确定','取消'], //按钮
		  	icon: 3,
		}, function(){
			parent.layer.msg();
			if(action == "cy_delete"){
				action="delete";
			}
			filling(action,selectedId);
			//getdealedlist(currentPage);
//			newclose(action,status);
			layer.closeAll();
		});
	}
	
	
}
function getWxMobileInfo(users){
	var mobile = [];
	var no_mobile = []; //没有绑定电话号码的用户
	var wxname = [];
	var no_wxname = []; //没有绑定微信号的用户
	var wxMobileInfo = {}
	for(var i=0; i<users.length; i++) {
		users[i].usermobile ? mobile.push(users[i].usermobile) : no_mobile.push(users[i].realname);
		users[i].userwx ? wxname.push(users[i].userwx) : no_wxname.push(users[i].realname);
	}
	no_mobile = no_mobile.join(), mobile = mobile.join();
	no_wxname = no_wxname.join(), wxname = wxname.join('|');
	wxMobileInfo.mobile = mobile;
	wxMobileInfo.wxname = wxname;
	return wxMobileInfo;
}
function getUser(_user){ // 20181211 添加用于查找用户信息
	var user=_user;
	var finduser = null;
	$.ajax({
		type: "POST",
		async: false,
		headers:{
    		"token":$.cookie('ftoken')
	    },
		dataType:'json',
		contentType:"application/json",
		url: CONF_OURP_SERVERURL + global.modelctls.user.getuserlist,
		crossDomain:true,
		data: JSON.stringify(user),
		success:function(data, textStatus, jqXHR) {
			finduser = data[0];
		},
		error:function(jqXHR, textStatus, errorThrown) {
			finduser = '';
		}
	});
	return finduser;
}

function getRolesById(userid){ // 根据用户id获得角色
	var roles;
	$.ajax({
    	type: "GET",
		dataType: "json",
		headers:{
    		"token":$.cookie('ftoken')
	    },
		url: CONF_OURP_SERVERURL + "/api/v1/role/user/"+userid,
     	async: false,
     	headers:{
     		"token":$.cookie('ftoken')
 	    },
 		success: function (result) {
 			roles = result;
      	}
 	    ,erro:function(result){
 	    	roles = '';
 	    }
	});
	return roles;
}

function findDeptById(_id){ // 根据用户id查找部门
	var id = _id;
	var _dept='';
	$.ajax({
		cache:false,
		async: false,
		headers:{
     		"token":$.cookie('ftoken')
 	    },
		type:"POST",
		url:CONF_OURP_SERVERURL+global.modelctls.user.findDeptById,
		data:id,
		contentType: "application/json",
		success:function(data){
			_dept=data;
		},
		error:function(error){
			_dept='';
		}
	})
	return _dept;
}