userModule.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. var flag = true;
  2. function submitUserForm(){//保存
  3. //alert("保存!");
  4. // if(!checkUserName())return;
  5. var saveobject = window.document.theForm ;
  6. /*if(!flag){
  7. return;
  8. }*/
  9. if(saveobject == null || saveobject == ""){
  10. addError("当前没有用户需要保存!");
  11. return;
  12. }
  13. if(window.document.theForm.userName.value.replace(/(^\s*)|(\s*$)/g, "") == ''){
  14. addFieldError("userName","请输入用户名!");
  15. return;
  16. }
  17. // if((window.document.theForm.userName.value.length <4)){
  18. // addFieldError("userName","至少4位的用户名!");
  19. // return;
  20. // }
  21. var reg = /^[0-9]\w+$/;
  22. if(reg.test(window.document.theForm.userName.value)){
  23. addFieldError("userName","用户名为非数字开头的字母和数字组合!");
  24. return;
  25. }
  26. if(window.document.theForm.position != null){
  27. if (window.document.theForm.position.value == '') {
  28. addFieldError("position","请选择职位!");
  29. return;
  30. }
  31. }
  32. /*if(window.document.theForm.birthday != null){
  33. if (window.document.theForm.birthday.value == '') {
  34. addFieldError("birtherror","请选择生日!");
  35. return;
  36. }
  37. } */
  38. if(window.document.theForm.desktop_phone.value.replace(/(^\s*)|(\s*$)/g, "") == ''){
  39. } else {
  40. var reg = /^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{2,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/;
  41. if(!reg.test(window.document.theForm.desktop_phone.value)){
  42. addFieldError("desktop_phone","请输入合法的工作电话!");
  43. return;
  44. }
  45. }
  46. if(window.document.theForm.fax.value != ''){
  47. var reg = /^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{2,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/;
  48. if(!reg.test(window.document.theForm.fax.value)){
  49. addFieldError("fax","请输入合法的传真号码!");
  50. return;
  51. }
  52. }
  53. //if(window.document.theForm.email.value.replace(/(^\s*)|(\s*$)/g, "") == ''){
  54. //addFieldError("email","请输入电子邮箱!");
  55. //return;
  56. //}else
  57. if(window.document.theForm.email.value.replace(/(^\s*)|(\s*$)/g, "") != ''){
  58. var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/ ;
  59. if(!reg.test(window.document.theForm.email.value)){
  60. addFieldError("email","请输入合法的电子邮箱!");
  61. return;
  62. }
  63. }
  64. if(window.document.theForm.qqnum.value != ''){
  65. var reg = /^[1-9]\d{4,10}$/;
  66. if(!reg.test(window.document.theForm.qqnum.value)){
  67. addFieldError("qqnum","请输入合法的QQ号码!");
  68. return;
  69. }
  70. }
  71. if(window.document.theForm.msnnum.value != ''){
  72. var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
  73. if(!reg.test(window.document.theForm.msnnum.value)){
  74. addFieldError("msnnum","请输入合法的MSN号码!");
  75. return;
  76. }
  77. }
  78. if(window.document.theForm.address.value != ''){
  79. if( window.document.theForm.address.value.length>100){
  80. addFieldError("address","请输入100位以内的地址!");
  81. return;
  82. }
  83. }
  84. if(window.document.theForm.homeno.value != ''){
  85. var reg = /^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{2,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/;
  86. if(!reg.test(window.document.theForm.homeno.value)){
  87. addFieldError("homeno","请输入合法的电话号码!");
  88. return;
  89. }
  90. }
  91. var phone = $("#contact_tel1").val();
  92. var phone1 = $("#fixed_phone").val();
  93. if(phone == phone1&&phone){
  94. addFieldError("fixed_phone","两个手机号相同!");
  95. return;
  96. }
  97. if ($("#recMsg").attr("checked")){
  98. $("#recMsg").val("1");
  99. }else{
  100. $("#recMsg").val("0");
  101. }
  102. if ($("#recSms").attr("checked")){
  103. $("#recSms").val("1");
  104. }else{
  105. $("#recSms").val("0");
  106. }
  107. if ($("#recMail").attr("checked")){
  108. $("#recMail").val("1");
  109. }else{
  110. $("#recMail").val("0");
  111. }
  112. if(!validateDept()){
  113. return;
  114. }
  115. if(!checkUserName()){
  116. return;
  117. }
  118. if(!checkPhone('contact_tel1')){
  119. return;
  120. }
  121. if(!checkPhone('fixed_phone')){
  122. return;
  123. }
  124. if(!validateFace()){
  125. return;
  126. }
  127. // if(!checkAttendanceId()){
  128. // return;
  129. // }
  130. var isFollow = $("input[name='isFollow']:checked").parent().parent();
  131. var isLogin = $("input[name='isdLogin']:checked").parent().parent();
  132. var seleceFollowValue = $("[name='othergroupid']",isFollow).val();
  133. if(!seleceFollowValue&&isAdmin=='0'){
  134. addFieldError($(isFollow).attr("id"),"请设定主岗部门!");
  135. return;
  136. }
  137. var seleceFollowPosition = $("[name='otherposname']",isFollow).val();
  138. var seleceLoginValue = $("[name='othergroupid']",isLogin).val();
  139. var seleceLoginPosition = $("[name='otherposname']",isLogin).val();
  140. $("input[name='isFollow']:checked").val(seleceFollowValue+"_"+seleceFollowPosition);
  141. $("input[name='isdLogin']:checked").val(seleceLoginValue+"_"+seleceLoginPosition);
  142. if(window.checkmobile("contact_tel1")&&window.checkpixed_phone("fixed_phone")){
  143. var defaultRole = $("#defaultRole").val();
  144. if(defaultRole==''){
  145. yrConfirm("系统没有默认角色,新建用户没有任何权限,是否继续?",backValidate);
  146. }
  147. else{
  148. window.document.theForm.submit();
  149. }
  150. }
  151. }
  152. function getUserName(){
  153. var name = $("#name").val();
  154. name = codefans_net_CC2PY(name);
  155. if($("#userName").attr('type')!='hidden'){
  156. $("#userName").val(name);
  157. }
  158. }
  159. function checkUserNameProcess(data){
  160. if(data != null && data !=""){
  161. addFieldErrors("userName","该用户名已存在!");
  162. flag=false ;
  163. }else{
  164. flag=true;
  165. }
  166. }
  167. function checkUserName(){
  168. clearSingelMsg("userName");
  169. var initname = $("#initUserName").val();
  170. var url = "checkMessage.do?date="+new Date()+"&action=checkUserName";
  171. if (theForm.userName.value != initname) {
  172. var param = {'name':$("#userName").val()};
  173. sendAjaxParam(param,url,"text",checkUserNameProcess);
  174. }else{
  175. flag=true;
  176. }
  177. return flag;
  178. }
  179. var obj;
  180. function checkPhoneProcess(data){
  181. if(data != null && data !=""){
  182. addFieldErrors(obj,"该手机号已被使用!");
  183. flag=false ;
  184. }else{
  185. flag=true;
  186. }
  187. }
  188. function checkPhone(id){
  189. clearSingelMsg(id);
  190. obj = id;
  191. var vPhone = $("#"+id).val();
  192. var userId = $("#userId").val();
  193. if(!vPhone){
  194. return flag;
  195. }
  196. var url = "checkMessage.do?date="+new Date()+"&action=checkPhone";
  197. var param = {'userId':userId,'phone':vPhone};
  198. sendAjaxParam(param,url,"text",checkPhoneProcess);
  199. return flag;
  200. }
  201. function backValidate(r){
  202. if(r==true){
  203. window.document.theForm.submit();
  204. }
  205. }
  206. function validateDept(){
  207. var temp = "";
  208. var b = true;
  209. $(".formselect").each(function(){
  210. var deptId = $(this).val();
  211. var posId = $(this).next().val();
  212. var id = $(this).parent().attr("id");
  213. var r = deptId+"_"+posId;
  214. if(r!="_"){
  215. if(temp =="")temp = r;
  216. else if(temp.indexOf(r)!=-1){
  217. addFieldError(id,"该部门职位已经选择!");
  218. b = false;
  219. }else{
  220. temp += ","+r;
  221. }
  222. }
  223. });
  224. return b;
  225. }
  226. function checkmobile(formname){
  227. var mobile=document.getElementById(formname).value;
  228. if(mobile.length!=0){
  229. if(mobile.length!=11)
  230. {
  231. addFieldError("contact_tel1","请输入合法的手机号码!");
  232. document.getElementById(formname).focus();
  233. return false;
  234. }
  235. var myreg = /^1[1-9][0-9]\d{8}$/
  236. if(!myreg.test(mobile)){
  237. addFieldError("contact_tel1","请输入合法的手机号码!");
  238. document.getElementById(formname).focus();
  239. return false;
  240. }
  241. }
  242. return true;
  243. }
  244. function checkpixed_phone(formname){
  245. var pixed_phone=document.getElementById(formname).value;
  246. if(pixed_phone.length!=0){
  247. var myreg = /(^\d{3}\-\d{7,8}$)|(^\d{4}\-\d{7,8}$)|(^\d{3}\d{7,8}$)|(^\d{4}\d{7,8}$)|(^\d{7,8}$)/;
  248. if(!myreg.test(pixed_phone)){
  249. addFieldError("fixed_phone","请输入合法的电话号码!");
  250. document.getElementById(formname).focus();
  251. return false;
  252. }
  253. }
  254. return true;
  255. }
  256. function bindDept(){
  257. $(".add a").bind("click",function(){
  258. var o = $(this).parent().parent();
  259. addOtherDept(o);
  260. });
  261. $(".del a").bind("click",function(){
  262. delOtherDept(this);
  263. });
  264. }
  265. function bindFace(){
  266. $(".addFace a").bind("click",function(){
  267. var o = $(this).parent().parent();
  268. addOtherFace(o);
  269. });
  270. $(".delFace a").bind("click",function(){
  271. delOtherDept(this);
  272. });
  273. }
  274. function addOtherDept(o){
  275. var deptPosition = $(".dept-position").clone();
  276. var len = $(".dept-position-remove").length+1;
  277. $(".error_msg",deptPosition).remove();
  278. $(deptPosition).addClass("dept-position-remove");
  279. $(deptPosition).removeClass("inputError");
  280. $(deptPosition).attr("id","dept-position"+len);
  281. $("#name_0",deptPosition).attr("id","name_"+len);
  282. $("#gid_0",deptPosition).attr("id","gid_"+len);
  283. $("select",deptPosition).each(function(){
  284. $(this).get(0).options[0].selected = true;
  285. });
  286. $(deptPosition).removeClass("dept-position");
  287. $(".add a",deptPosition).html("删除");
  288. $(".add a",deptPosition).unbind("click");
  289. $(".add a",deptPosition).bind("click",function(){
  290. delOtherDept(this);
  291. });
  292. $(".add",deptPosition).removeClass("add");
  293. $(".add",deptPosition).addClass("del");
  294. $("[name='isFollow']",deptPosition).attr("checked",false);
  295. $("[name='isdLogin']",deptPosition).attr("checked",false);
  296. $(o).parent().append(deptPosition);
  297. }
  298. function addOtherFace(o){
  299. var facePosition = $(".face-position").clone();
  300. var len = $(".face-position-remove").length+1;
  301. $(".error_msg",facePosition).remove();
  302. $(facePosition).addClass("face-position-remove");
  303. $(facePosition).removeClass("inputError");
  304. $(facePosition).attr("id","face-position"+len);
  305. $("#name_0",facePosition).attr("id","name_"+len);
  306. $("#gid_0",facePosition).attr("id","gid_"+len);
  307. $("input[type='text']", facePosition).val('');
  308. $("select",facePosition).each(function(){
  309. $(this).get(0).options[0].selected = true;
  310. });
  311. $(facePosition).removeClass("face-position");
  312. $(".addFace a",facePosition).html("删除");
  313. $(".addFace a",facePosition).unbind("click");
  314. $(".addFace a",facePosition).bind("click",function(){
  315. delOtherDept(this);
  316. });
  317. $(".addFace",facePosition).removeClass("addFace");
  318. $(".addFace",facePosition).addClass("delFace");
  319. $(o).parent().append(facePosition);
  320. }
  321. function delOtherDept(e){
  322. $(e).parent().parent().remove();
  323. }
  324. function isRelacePos(e){
  325. var v = $(e).val();
  326. var posSelect = $(e).next().next();
  327. if(v == ''||v==undefined){
  328. $(posSelect).prepend("<option value='' selected='selected'>--请选择--</option>");
  329. $(posSelect).get(0).options[0].selected = true;
  330. }else{
  331. $("option[value='']",posSelect).remove();
  332. }
  333. }
  334. function addFlowDept(){
  335. $("select[name='othergroupid']").each(function(){
  336. var id = this.id;
  337. $(this).val(id);
  338. });
  339. }
  340. function checkAttendanceId(serialno, attendance_id){
  341. console.log("000")
  342. clearSingelMsg("attendance_id");
  343. console.log(1111)
  344. var userId = $("#userId").val();
  345. if(!attendance_id){
  346. return flag;
  347. }
  348. var url = "checkMessage.do?date="+new Date()+"&action=checkAttendanceId";
  349. var param = {'userId':userId,'attendance_id':attendance_id, 'serialno':serialno};
  350. sendAjaxParam(param,url,"text",checkAttendanceIdProcess);
  351. return flag;
  352. }
  353. function checkAttendanceIdProcess(data){
  354. if(data != null && data !=""){
  355. console.log(data,"考勤data")
  356. addFieldErrors("attendance_id",data);
  357. return flag ;
  358. }else{
  359. return flag;
  360. }
  361. }
  362. function validateFace(){
  363. var temp = "";
  364. var b = true;
  365. var userId = $("#userId").val();
  366. $("select[name='otherSerialno']").each(function(){
  367. var serialno = $(this).val();
  368. var attendance_id = $(this).next().val();
  369. var id = $(this).parent().attr("id");
  370. if(serialno.length > 0) {
  371. if(attendance_id == '') {
  372. addFieldError(id,"请输入考勤ID!");
  373. b = false;
  374. } else {
  375. var r = serialno+"_"+"attendance_id";
  376. if(r!="_"){
  377. if(temp =="") {
  378. temp = r;
  379. } else if(temp.indexOf(r)!=-1){
  380. addFieldError(id,"该设备已选择!");
  381. b = false;
  382. } else {
  383. temp += ","+r;
  384. }
  385. var url = "checkMessage.do?date="+new Date()+"&action=checkAttendanceId";
  386. var param = {'userId':userId,'attendance_id':attendance_id, 'serialno':serialno};
  387. sendAjaxParam(param,url,"text",function(data) {
  388. if(data != null && data !=""){
  389. console.log(data,"考勤data")
  390. addFieldError(id, data);
  391. b = false ;
  392. }
  393. });
  394. }
  395. }
  396. }
  397. });
  398. return b;
  399. }