var base_url = location.origin; var usre_info = {}; layui.use(['layer','form'], function(){ window.layer = layui.layer; window.form = layui.form; }); layui.use('form', function(){ var form = layui.form; form.verify({ codeCheck:function(value, item){ //value:表单的值、item:表单的DOM对象 if(!new RegExp("^\\w+$").test(value)){ return "只能为数字英文与下划线"; } }, maxNumCheck:function(value, item){ //value:表单的值、item:表单的DOM对象 if(value >= 10000){ return "不能大于10000"; } }, positiveNumber:[ /^[0-9]*[1-9][0-9]*$/, "只能为正整数" ], nonnegativeInteger:[ /^[1-9]\d*|0$/, "必填且只能为非负整数" ], nonNegativeNumber: function(value, item){ //value:表单的值、item:表单的DOM对象 if(value < 0){ return '不能为负数'; } }, positive_decimal:[ /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d{1,2})$/, "只能为正数,小数点后最多两位" ], mobile_no_validate:[ /^[1][0-9]{10}$/, "手机号格式不正确" ], is_url_validate:function(value, item){ //value:表单的值、item:表单的DOM对象 var strRegex = '^((https|http)?://)' +'?(([0-9a-z_!~*().&=+$%-]+: )?[0-9a-z_!~*().&=+$%-]+@)?' //ftp的user@ + '(([0-9]{1,3}.){3}[0-9]{1,3}' // IP形式的URL- 199.194.52.184 + '|' // 允许IP和DOMAIN(域名) + '([0-9a-z_!~*()-]+.)*' // 域名- www. + '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].' // 二级域名 + '[a-z]{2,6})' // first level domain- .com or .museum + '(:[0-9]{1,4})?' // 端口- :80 + '((/?)|' // a slash isn't required if there is no file name + '(/[0-9a-z_!~*().;?:@&=+$,%#-]+)+/?)$'; var re=new RegExp(strRegex); if (!re.test(value)){ return "url地址格式不正确"; } }, identity_no_validate:function(value, item){ //value:表单的值、item:表单的DOM对象 // 1 "验证通过!", 0 //校验不通过 // id为身份证号码 var format = /^(([1][1-5])|([2][1-3])|([3][1-7])|([4][1-6])|([5][0-4])|([6][1-5])|([7][1])|([8][1-2]))\d{4}(([1][9]\d{2})|([2]\d{3}))(([0][1-9])|([1][0-2]))(([0][1-9])|([1-2][0-9])|([3][0-1]))\d{3}[0-9xX]$/; //号码规则校验 if(!format.test(value)){ return "身份证号码不合规"; } //区位码校验 //出生年月日校验 前正则限制起始年份为1900; var year = value.substr(6,4),//身份证年 month = value.substr(10,2),//身份证月 date = value.substr(12,2),//身份证日 time = Date.parse(month+'-'+date+'-'+year),//身份证日期时间戳date now_time = Date.parse(new Date()),//当前时间戳 dates = (new Date(year,month,0)).getDate();//身份证当月天数 if(time>now_time||date>dates){ return "出生日期不合规"; } //校验码判断 var c = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2); //系数 var b = new Array('1','0','X','9','8','7','6','5','4','3','2'); //校验码对照表 var id_array = value.split(""); var sum = 0; for(var k=0;k<17;k++){ sum+=parseInt(id_array[k])*parseInt(c[k]); } if(id_array[17].toUpperCase() != b[sum%11].toUpperCase()){ return "身份证校验码不合规"; } }, user_name_validate:[ /^[\u4e00-\u9fa5]{2,4}$/, "姓名格式不正确" ], amount_of_money_validate:[ /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/, "格式不正确" ] }); }); //模拟post请求 function post(URL, PARAMS) { var temp = document.createElement("form"); temp.action = URL; temp.method = "post"; temp.style.display = "none"; // temp.target = "_bank"; for (var x in PARAMS) { var opt = document.createElement("textarea"); opt.name = x; opt.value = PARAMS[x]; // alert(opt.name) temp.appendChild(opt); } document.body.appendChild(temp); temp.submit(); return temp; } // 设置全局ajax $.ajaxSetup({ xhrFields: { withCredentials: true }, beforeSend: function(jqXHR, settings) { //在请求前给修改url(增加一个时间戳参数) settings.url += settings.url.match(/\?/) ? "&" : "?"; settings.url += "menuId=" + window.g_menu_id; }, cache: false, //关闭AJAX相应的缓存 dataFilter : function(res, type){ if(type == "json"){ var res2 = JSON.parse(res); if(res2.errorCode == "003"){ location.href = res2.data.loginUrl; } } return res; } }); // 带常用搜索部门的部门多选 function trigger_auto_matchwrap_show2(that,event,url,type) { $(that).siblings(".auto_matchwrap").toggle(); if($(that).siblings(".auto_matchwrap").is(':visible')){ $(that).siblings(".auto_matchwrap").find(".auto_matchinput").val("").focus(); $(that).parents(".layui-inline").siblings(".layui-inline").find(".auto_matchwrap").hide(); }else{ }; $.ajax({ type: 'POST', url: base_url+url, data:JSON.stringify({ params:{ "queryStr":"", "type":type } }), dataType: 'json', contentType: "application/json", success: function (res) { if(res.resultCode == 1){ if(res.data.list){ $(that).siblings(".auto_matchwrap").find(".fuzzy_matching_wrap").show(); $(that).siblings(".auto_matchwrap").find(".fuzzy_matching_inner_wrap").html(template('fuzzy_matching_tpl', res.data)); $(that).siblings(".auto_matchwrap").find(".fuzzy_matching_inner_wrap").find(".fuzzy_matching_multi_select_input").each(function () { if($.inArray($(this).val(), $(that).siblings(".auto_complateval").val().split(",")) == -1){ $(this).prop('checked',false); }else{ $(this).prop('checked',true); } }); layui.use(['form'], function () { var form = layui.form; form.render(); }); }else{ $(that).siblings(".auto_matchwrap").find(".fuzzy_matching_wrap").hide(); } }else{ layer.msg(res.errorDesc); } } }); event.stopPropagation(); } // 带常用搜索部门的部门多选 function trigger_auto_matchwrap_show(that,event,url) { $(that).siblings(".auto_matchwrap").toggle(); if($(that).siblings(".auto_matchwrap").is(':visible')){ $(that).siblings(".auto_matchwrap").find(".auto_matchinput").val("").focus(); $(that).parents(".layui-inline").siblings(".layui-inline").find(".auto_matchwrap").hide(); }else{ }; $.ajax({ type: 'POST', url: base_url+url, data:JSON.stringify({ }), dataType: 'json', contentType: "application/json", success: function (res) { if(res.resultCode == 1){ if(res.data.list){ $(that).siblings(".auto_matchwrap").find(".fuzzy_matching_wrap").show(); $(that).siblings(".auto_matchwrap").find(".fuzzy_matching_inner_wrap").html(template('fuzzy_matching_tpl', res.data)); $(that).siblings(".auto_matchwrap").find(".fuzzy_matching_inner_wrap").find(".fuzzy_matching_multi_select_input").each(function () { if($.inArray($(this).val(), $(that).siblings(".auto_complateval").val().split(",")) == -1){ $(this).prop('checked',false); }else{ $(this).prop('checked',true); } }); layui.use(['form'], function () { var form = layui.form; form.render(); }); }else{ $(that).siblings(".auto_matchwrap").find(".fuzzy_matching_wrap").hide(); } }else{ layer.msg(res.errorDesc); } } }); event.stopPropagation(); } function fuzzy_matching_multi_select_unit_click(that) { $(that).find(".fuzzy_matching_multi_select_input").trigger("click"); } function fuzzy_matching_multi_select_input(that) { if($(that).parents(".auto_matchwrap").siblings(".auto_complateval").val()){ var id_array = $(that).parents(".auto_matchwrap").siblings(".auto_complateval").val().split(","); var name_array = $(that).parents(".auto_matchwrap").siblings(".multi_select_department_wrap").val().split(","); }else{ var id_array = []; var name_array = []; } if($(that).is(':checked') && $.inArray($(that).val(), id_array) == -1){ id_array.push($(that).val()); name_array.push($(that).siblings(".fuzzy_matching_multi_select_name").text()); }else{ id_array = $.grep(id_array, function(n,i){ return n != $(that).val(); }); name_array = $.grep(name_array, function(n,i){ return n != $(that).siblings(".fuzzy_matching_multi_select_name").text(); }); } $(that).parents(".auto_matchwrap").siblings(".auto_complateval").val(id_array.join(",")); $(that).parents(".auto_matchwrap").siblings(".multi_select_department_wrap").val(name_array.join(",")); $(that).parents(".auto_matchwrap").siblings(".multi_select_department_wrap").attr("title",name_array.join(",")); $(that).parents(".auto_matchwrap").siblings(".empty_inputbtn2").show(); $(that).parents(".auto_matchwrap").siblings(".drop_down_btn").hide(); } function fuzzy_matching_multi_select_input_click(event) { event.stopPropagation(); } function empty_inputfunc3(that,event){ $(that).siblings(".multi_select_department_wrap").val(""); $(that).siblings(".multi_select_department_wrap").removeAttr("title"); $(that).siblings(".auto_complateval").val(""); $(that).parents(".auto_matchwrap").find(".fuzzy_matching_inner_wrap").find(".fuzzy_matching_multi_select_input").each(function () { $(this).prop('checked',false); }); $(that).hide(); $(that).siblings(".drop_down_btn").show(); event.stopPropagation(); } function stop_close_event_propagation(event) { event.stopPropagation(); } // 切换模糊匹配备选项(多选) function change_list_item3(that) { var _that = $(that).parents(".auto_matchwrap"); if(_that.is(":visible")){ if(window.event.keyCode == 38 && _that.find(".fuzzy_matching_multi_select_unit").index(_that.find(".list_item_active")) != 0){ _that.find(".list_item_active").removeClass("list_item_active").prev(".fuzzy_matching_multi_select_unit").addClass("list_item_active"); _that.scrollTop(_that.find(".fuzzy_matching_multi_select_unit").index(_that.find(".list_item_active"))*38); }else if(window.event.keyCode == 40 && _that.find(".fuzzy_matching_multi_select_unit").index(_that.find(".list_item_active")) != _that.find(".fuzzy_matching_multi_select_unit").length - 1){ _that.find(".list_item_active").removeClass("list_item_active").next(".fuzzy_matching_multi_select_unit").addClass("list_item_active"); _that.scrollTop(_that.find(".fuzzy_matching_multi_select_unit").index(_that.find(".list_item_active"))*38); }else if(window.event.keyCode == 13){ _that.find(".list_item_active").trigger("click"); _that.hide(); } }else{ } } // 带常用搜索的模糊匹配多选组件 function input_match_multi_select_department(that,url) { //console.log($(that).val()); var _insert_str = $.trim($(that).val()); $.ajax({ type: 'POST', url: base_url+url, data:JSON.stringify({ params:{ "queryStr":_insert_str } }), dataType: 'json', contentType: "application/json", success: function (res) { if(res.resultCode == 1) { if (res.data.list) { $(that).parents(".auto_matchwrap").find(".fuzzy_matching_wrap").show(); $(that).parents(".auto_matchwrap").find(".fuzzy_matching_inner_wrap").html(template('fuzzy_matching_tpl', res.data)); $(that).parents(".auto_matchwrap").find(".fuzzy_matching_inner_wrap").find(".fuzzy_matching_multi_select_input").each(function () { if ($.inArray($(this).val(), $(that).parents(".auto_matchwrap").siblings(".auto_complateval").val().split(",")) == -1) { $(this).prop('checked', false); } else { $(this).prop('checked', true); } }); layui.use(['form'], function () { var form = layui.form; form.render(); }); } else { $(that).parents(".auto_matchwrap").find(".fuzzy_matching_wrap").hide(); } }else{ layer.msg(res.errorDesc); } } }); } // 带常用搜索的模糊匹配多选组件 function input_match_multi_select_department2(that,url,type) { //console.log($(that).val()); var _insert_str = $.trim($(that).val()); $.ajax({ type: 'POST', url: base_url+url, data:JSON.stringify({ params:{ "queryStr":_insert_str, "type":type } }), dataType: 'json', contentType: "application/json", success: function (res) { if(res.resultCode == 1) { if (res.data.list) { $(that).parents(".auto_matchwrap").find(".fuzzy_matching_wrap").show(); $(that).parents(".auto_matchwrap").find(".fuzzy_matching_inner_wrap").html(template('fuzzy_matching_tpl', res.data)); $(that).parents(".auto_matchwrap").find(".fuzzy_matching_inner_wrap").find(".fuzzy_matching_multi_select_input").each(function () { if ($.inArray($(this).val(), $(that).parents(".auto_matchwrap").siblings(".auto_complateval").val().split(",")) == -1) { $(this).prop('checked', false); } else { $(this).prop('checked', true); } }); layui.use(['form'], function () { var form = layui.form; form.render(); }); } else { $(that).parents(".auto_matchwrap").find(".fuzzy_matching_wrap").hide(); } }else{ layer.msg(res.errorDesc); } } }); } $("body").click(function () { $(".auto_matchwrap").hide(); }); // 表单字段三级判断并赋值 function g_form_field_3level_ctrl(id_str,data_field) { // 是否显示 if(data_field.visible){ // 是否可编辑 if(data_field.writeAble){ $('#'+id_str).attr("readOnly",false); // 字段是否必填 if(data_field.required){ $('#'+id_str).attr("lay-verify","required"); } } $('#'+id_str).val(data_field.value); }else{ $('#'+id_str).parents(".layui-inline").remove(); } } //artTemplate模板内部取外部变量 template.defaults.imports.$window = window;