/*!
* Copyright © 2015-2020 JeePlus All rights reserved.
*
* 通用公共方法
* @author jeeplus
* @version 2014-4-29
*/
$(document).ready(function() {
try{
// 链接去掉虚框
$("a").bind("focus",function() {
if(this.blur) {this.blur()};
});
//所有下拉框使用select2
$("select").select2();
}catch(e){
// blank
}
});
// 引入js和css文件
function include(id, path, file){
if (document.getElementById(id)==null){
var files = typeof file == "string" ? [file] : file;
for (var i = 0; i < files.length; i++){
var name = files[i].replace(/^\s|\s$/g, "");
var att = name.split('.');
var ext = att[att.length - 1].toLowerCase();
var isCSS = ext == "css";
var tag = isCSS ? "link" : "script";
var attr = isCSS ? " type='text/css' rel='stylesheet' " : " type='text/javascript' ";
var link = (isCSS ? "href" : "src") + "='" + path + name + "'";
document.write("<" + tag + (i==0?" id="+id:"") + attr + link + ">" + tag + ">");
}
}
}
// 获取URL地址参数
function getQueryString(name, url) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
if (!url || url == ""){
url = window.location.search;
}else{
url = url.substring(url.indexOf("?"));
}
r = url.substr(1).match(reg)
if (r != null) return unescape(r[2]); return null;
}
//获取字典标签
function getDictLabel(data, value, defaultValue){
for (var i=0; i1 && b==false){
p = false;
}
if(i>1 && b==true){
p = true;
}
var c = name.charCodeAt(i);
//单字节加1
if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
w++;
b = false;
}else {
w+=2;
s++;
b = true;
}
if(w>maxLength && i<=name.length-1){
if(b==true && p==true){
nameSub = name.substring(0,i-2)+"...";
}
if(b==false && p==false){
nameSub = name.substring(0,i-3)+"...";
}
if(b==true && p==false){
nameSub = name.substring(0,i-2)+"...";
}
if(p==true){
nameSub = name.substring(0,i-2)+"...";
}
break;
}
}
if(w<=maxLength){
return name;
}
return nameSub;
}
//打开对话框(添加修改)
function openDialog(title,url,width,height,target){
if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端,就使用自适应大小弹窗
width='auto';
height='auto';
}else{//如果是PC端,根据用户设置的width和height显示。
}
top.layer.open({
type: 2,
area: [width, height],
title: title,
maxmin: true, //开启最大化最小化按钮
content: url ,
btn: ['确定', '关闭'],
yes: function(index, layero){
var body = top.layer.getChildFrame('body', index);
var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();
var inputForm = body.find('#inputForm');
var top_iframe;
if(target){
top_iframe = target;//如果指定了iframe,则在改frame中跳转
}else{
top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
}
inputForm.attr("target",top_iframe);//表单提交成功后,从服务器返回的url在当前tab中展示
if(iframeWin.contentWindow.doSubmit() ){
// top.layer.close(index);//关闭对话框。
setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒,对应360 7.1版本bug
}
},
cancel: function(index){
}
});
}
//打开对话框(审批)
function openDialogSP(title,url,width,height,target){
if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端,就使用自适应大小弹窗
width='auto';
height='auto';
}else{//如果是PC端,根据用户设置的width和height显示。
}
top.layer.open({
type: 2,
area: [width, height],
title: title,
maxmin: true, //开启最大化最小化按钮
content: url ,
btn: ['通过','不通过', '关闭'],
yes: function(index, layero){
var body = top.layer.getChildFrame('body', index);
var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();
var inputForm = body.find('#inputForm');
var top_iframe ;
/* console.log(typeof iframeWin);
console.log(iframeWin);
console.log(typeof inputForm);
console.log(inputForm);
console.log($(inputForm).find('#approvalNo').val());
console.log($(inputForm).find('#approvalNo').val("1"));
console.log($(inputForm).find('#approvalNo').val());
*/
$(inputForm).find('#approvalNo').val("1");
//iframeWin.tg();
//debugger;
if(target){
top_iframe = target;//如果指定了iframe,则在改frame中跳转
}else{
top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
}
inputForm.attr("target",top_iframe);//表单提交成功后,从服务器返回的url在当前tab中展示
if(iframeWin.contentWindow.doSubmit() ){
// top.layer.close(index);//关闭对话框。
setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒,对应360 7.1版本bug
}
},
btn2: function(index, layero){
var body = top.layer.getChildFrame('body', index);
var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();
var inputForm = body.find('#inputForm');
//console.log(body);//设置为通过
$(inputForm).find('#approvalNo').val("0");//设置为通过
//btg();
//debugger;
if(target){
top_iframe = target;//如果指定了iframe,则在改frame中跳转
}else{
top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
}
inputForm.attr("target",top_iframe);//表单提交成功后,从服务器返回的url在当前tab中展示
if(iframeWin.contentWindow.doSubmit() ){
// top.layer.close(index);//关闭对话框。
setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒,对应360 7.1版本bug
}
},
cancel: function(index){
}
});
}
/**
* 带回调方法的弹出窗口
* @param title
* @param url
* @param width
* @param height
* @param target
* @param callback 回调函数,带参数 index, layero
* @returns
*/
function openDialogCallBack(title,url,width,height,target,callback){
if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端,就使用自适应大小弹窗
width='auto';
height='auto';
}else{//如果是PC端,根据用户设置的width和height显示。
}
top.layer.open({
type: 2,
area: [width, height],
title: title,
maxmin: true, //开启最大化最小化按钮
content: url ,
btn: ['确定', '关闭'],
yes: function(index, layero){
callback(index, layero);
setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒,对应360 7.1版本bug
},
cancel: function(index){
}
});
}
//打开对话框(查看)
function openDialogView(title,url,width,height){
if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端,就使用自适应大小弹窗
width='auto';
height='auto';
}else{//如果是PC端,根据用户设置的width和height显示。
}
top.layer.open({
type: 2,
area: [width, height],
title: title,
maxmin: true, //开启最大化最小化按钮
content: url ,
btn: ['关闭'],
cancel: function(index){
}
});
}
//打开对话框(查看)
function openDialogView2(title,url,width,height){
if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端,就使用自适应大小弹窗
width='auto';
height='auto';
}else{//如果是PC端,根据用户设置的width和height显示。
}
top.layer.open({
type: 2,
area: [width, height],
title: title,
shadeClose: true,
shade: 0.3,
content: url
});
}
function search(){//查询,页码清零
$("#pageNo").val(0);
$("#searchForm").submit();
return false;
}
function resetAll(){//重置,页码清零
$("#pageNo").val(0);
$("#searchForm input").val("");
$("#searchForm select").val("");
$("#searchForm").submit();
return false;
}
function sortOrRefresh(){//刷新或者排序,页码不清零
$("#searchForm").submit();
return false;
}
function page(n,s){//翻页
$("#pageNo").val(n);
$("#pageSize").val(s);
$("#searchForm").submit();
$("span.page-size").text(s);
return false;
}