You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

728 lines
24 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

String.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); }
function NewGuid() {
var guid = "";
for (var i = 1; i <= 32; i++) {
var n = Math.floor(Math.random() * 16.0).toString(16);
guid += n;
if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
guid += "-";
}
return guid.toUpperCase();
}
function DsOpenEditWin(url, caption, height, width, top, left) {
var pageinfo = "height=";
/*
if (typeof caption == undefined) { var _caption = "添加提单"; }
else { var _caption = caption; }
if (typeof height == undefined) { var _height = "650"; }
else { var _height = height; }
if (typeof width == undefined) { var _width = "1000"; }
else { var _width = width; }*/
if (caption == undefined) { var _caption = "添加提单"; }
else { var _caption = caption; }
// //alert(height);
if (height == undefined || height == "") { pageinfo = pageinfo.concat("" + (window.screen.availHeight - 50) + ""); } //"650"
else { pageinfo = pageinfo.concat(height); }
pageinfo = pageinfo.concat("px, width=");
if (width == undefined || width == "") { pageinfo = pageinfo.concat("" + (window.screen.availWidth - 10) + ""); } //"900"
else { pageinfo = pageinfo.concat(width); }
pageinfo = pageinfo.concat("px, top=");
if (top == undefined || top == "") { pageinfo = pageinfo.concat("0"); }
else { pageinfo = pageinfo.concat(top); }
pageinfo = pageinfo.concat("px, left=");
if (left == undefined || left == "") { pageinfo = pageinfo.concat("0"); }
else { pageinfo = pageinfo.concat(left); }
pageinfo = pageinfo.concat("px,center:yes,resizable=yes,status=yes,menubar=no,scrollbars=yes");
//pageinfo = pageinfo.concat("width=" + (window.screen.availWidth - 10) + ",height=" + (window.screen.availHeight - 30) + ",top=0,left=0,resizable=yes,status=yes,menubar=no,scrollbars=yes");
//alert(pageinfo);
return window.open(url, _caption, pageinfo);
//return window.open(url, _caption, 'width=' + (window.screen.availWidth - 10) + ',height=' + (window.screen.availHeight - 55) + ',top=0,left=0,resizable=yes,status=yes,menubar=no,scrollbars=yes');
// return window.open(url, "添加提单", "height=600px, width=900px,center:yes,help:no,toolbar=no,menubar=no,scrollbars=no,resizable=0,location=no,status=no");
}
function DsOpenMultiEditWin(url, caption, height, width, top, left) {
var pageinfo = "height=";
if (caption == undefined) { var _caption = "添加提单"; }
else { var _caption = caption; }
if (height == undefined || height == "") { pageinfo = pageinfo.concat("" + (window.screen.availHeight - 50) + ""); } //"650"
else { pageinfo = pageinfo.concat(height); }
pageinfo = pageinfo.concat("px, width=");
if (width == undefined || width == "") { pageinfo = pageinfo.concat("" + (window.screen.availWidth - 10) + ""); } //"900"
else { pageinfo = pageinfo.concat(width); }
pageinfo = pageinfo.concat("px, top=");
if (top == undefined || top == "") { pageinfo = pageinfo.concat("0"); }
else { pageinfo = pageinfo.concat(top); }
pageinfo = pageinfo.concat("px, left=");
if (left == undefined || left == "") { pageinfo = pageinfo.concat("0"); }
else { pageinfo = pageinfo.concat(left); }
pageinfo = pageinfo.concat("px,center:yes,resizable=yes,status=yes,menubar=no,scrollbars=yes");
//pageinfo = pageinfo.concat("width=" + (window.screen.availWidth - 10) + ",height=" + (window.screen.availHeight - 30) + ",top=0,left=0,resizable=yes,status=yes,menubar=no,scrollbars=yes");
//alert(pageinfo);
return window.open(url,null, pageinfo,null);
//return window.open(url, _caption, 'width=' + (window.screen.availWidth - 10) + ',height=' + (window.screen.availHeight - 55) + ',top=0,left=0,resizable=yes,status=yes,menubar=no,scrollbars=yes');
// return window.open(url, "添加提单", "height=600px, width=900px,center:yes,help:no,toolbar=no,menubar=no,scrollbars=no,resizable=0,location=no,status=no");
}
/*
function DsOpenEditWin(url, caption) {
return window.open(url, caption, "height=650px, width=900px,center:yes,help:no,toolbar=no,menubar=no,scrollbars=no,resizable=0,location=no,status=no");
}
function DsOpenEditWin(url) {
return window.open(url, "添加提单", "height=600px, width=900px,center:yes,help:no,toolbar=no,menubar=no,scrollbars=no,resizable=0,location=no,status=no");
}*/
function DsOpenAtMain(url, caption, MainCenter) {
var finded = false;
// var MainCenter = Ext.getCmp('MainCenter');
if (MainCenter != NaN && MainCenter != null) {
var children = MainCenter.items;
if (children) {
for (var i = 0, len = children.length; i < len; i++) {
if (children.items[i].id) {
if (children.items[i].id == 'pnl' + caption) {
MainCenter.setActiveTab(i);
finded = true;
}
}
}
}
if (finded == false) {
var paneltabitems = new Ext.Panel({
id: 'pnl' + caption,
layout: "fit",
region: "center",
autoScroll: true,
frame: false,
closable: true,
bodyStyle: {
// background: 'rgba(0, 0, 0, 1) none repeat scroll 0 0 !important'
},
title: caption,
html: ' <iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="' + url + '"> </iframe>'
});
MainCenter.add(paneltabitems);
MainCenter.setActiveTab(paneltabitems);
MainCenter.doLayout();
}
}
}
function FindAtMain(pnlid, MainCenter) {
var finded =null;
// var MainCenter = Ext.getCmp('MainCenter');
if (MainCenter != NaN && MainCenter != null) {
var children = MainCenter.items;
if (children) {
for (var i = 0, len = children.length; i < len; i++) {
if (children.items[i].id) {
if (children.items[i].id == pnlid) {
finded = children.items[i];
}
}
}
}
}
return finded;
}
//combox的前台模糊查询过滤
function FilterCombox(e) {
var combo = e.combo;
if (!e.forceAll) {
var value = e.query.replace(/^\s*|\s*$/g, "").toUpperCase();
combo.store.filterBy(function (record, id) {
var text = record.get(combo.displayField).toUpperCase();
return (text.indexOf(value) != -1);
});
var field = combo.displayField;
combo.store.sort({
property: field,
//direction: state,
direction: "ASC",
//排序规则(重点)
sorterFn: function (v1, v2) {
v1 = v1.get(field);
v2 = v2.get(field);
return v1.indexOf(value) > v2.indexOf(value) ? 1 : (v1.indexOf(value) < v2.indexOf(value) ? -1 : 0);
}
});
combo.expand();
return false;
}
}
//获取目前表最大的Serialno
function DsGetCurSerialNo(store,serialno) {
var result = serialno;
if (result == 0) {
for (var i = 0; i < store.getCount(); i += 1) {
var member = store.getAt(i);
if (member.data.SerialNo > result) {
result = member.data.SerialNo;
}
}
}
return result;
}
//获取目前新SerialNo
function DsGetNewSerialNo(store, serialno) {
var result = DsGetCurSerialNo(store,serialno) + 1;
return result;
}
//获取字段名为fieldname字段值为value记录集合
function DsStoreQueryBy(store, fieldname, value) {
return store.queryBy(function (rec) {
if (rec.get(fieldname) == value) {
return true;
} else {
return false;
}
});
}
//获取字段名为fieldname字段值like为value记录集合
function DsStoreQueryLikeBy(store, fieldname,num,value) {
return store.queryBy(function (rec) {
var str = rec.get(fieldname);
if (str.substring(0,num) == value) {
return true;
} else {
return false;
}
});
}
Number.prototype.toFixed = function (len) {
var add = 0;
var s, temp;
var s1 = this + "";
var start = s1.indexOf(".");
if (start >= 0) {
s1 = s1 + "0";
if (s1.substr(start + len + 1, 1) >= 5) add = 1;
var temp = Math.pow(10, len);
s = Math.floor(this.mul(temp)) + add;
return s / temp;
} else return this;
}
function accDiv(arg1, arg2) {
var t1 = 0, t2 = 0, r1, r2;
try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
with (Math) {
r1 = Number(arg1.toString().replace(".", ""))
r2 = Number(arg2.toString().replace(".", ""))
return (r1 / r2) * pow(10, t2 - t1);
}
}
Number.prototype.div = function (arg) {
return accDiv(this, arg);
}
function parseFloatDef(num, defnum) {
if (num == '') return defnum;
var anum = parseFloat(num);
if (anum == NaN)
return defnum
else
return anum
}
function accMul(arg1, arg2) {
var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
try { m += s1.split(".")[1].length } catch (e) { }
try { m += s2.split(".")[1].length } catch (e) { }
return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
}
Number.prototype.mul = function (arg) {
return accMul(arg, this);
}
function accAdd(arg1, arg2) {
var r1, r2, m;
try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
m = Math.pow(10, Math.max(r1, r2))
return (arg1 * m + arg2 * m) / m
}
Number.prototype.add = function (arg) {
return accAdd(arg, this);
}
function Add(a, b, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = parseFloat(a).add(parseFloat(b)).toFixed(parseInt(length));
return parseFloat(_r);
}
function Cut(a, b, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = parseFloat(a).add(parseFloat(0) - parseFloat(b)).toFixed(parseInt(length));
return parseFloat(_r);
}
function Mul(a, b, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = parseFloat(a).mul(parseFloat(b))
var _r2 = _r.toFixed(parseInt(length));
return parseFloat(_r2);
}
function Mul3(a, b, c, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = (parseFloat(a).mul(parseFloat(b)).mul(parseFloat(c))).toFixed(parseInt(length));
return parseFloat(_r);
}
function Mul4(a, b, c, d, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = (parseFloat(a).mul(parseFloat(b)).mul(parseFloat(c)).mul(parseFloat(d))).toFixed(parseInt(length));
return parseFloat(_r);
}
function Mul5(a, b, c, d, e, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = (parseFloat(a).mul(parseFloat(b)).mul(parseFloat(c)).mul(parseFloat(d)).mul(parseFloat(e))).toFixed(parseInt(length));
return parseFloat(_r);
}
function Div(a, b, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = parseFloat(a).div(parseFloat(b)).toFixed(parseInt(length));
return parseFloat(_r);
}
function returnfloat(value) {
if (value=="***") return value;
var value = Math.round(parseFloat(value) * 100) / 100;
var xsd = value.toString().split(".");
if (xsd.length == 1) {
value = value.toString() + ".00";
return value;
}
if (xsd.length > 1) {
if (xsd[1].length < 2) {
value = value.toString() + "0";
}
return value;
}
}
function English(a) {
var arr1 = new Array("", " thousand", " million", " billion"),
arr2 = new Array("zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"),
arr3 = new Array("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"),
arr4 = new Array("ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen");
strRet = "";
if (a.length == 3 && a.substr(0, 3) != "000") {
if (a.substr(0, 1) != "0") {
strRet += arr3[a.substr(0, 1)] + " hundred";
if (a.substr(1, 2) != "00") strRet += " and "
}
a = a.substring(1)
}
if (a.length == 2) if (a.substr(0, 1) == "0") a = a.substring(1);
else if (a.substr(0, 1) == "1") strRet += arr4[a.substr(1, 2)];
else {
strRet += arr2[a.substr(0, 1)];
if (a.substr(1, 1) != "0") strRet += "-";
a = a.substring(1)
}
if (a.length == 1 && a.substr(0, 1) != "0") strRet += arr3[a.substr(0, 1)];
return strRet
};
function ToEn(a) {
var arr1 = new Array("", " thousand", " million", " billion");
var b = a.length,
f,
h = 0,
g = "",
e = Math.ceil(b / 3),
k = b - e * 3;
g = "";
for (f = k; f < b; f += 3) {
++h;
num3 = f >= 0 ? a.substring(f, f + 3) : a.substring(0, k + 3);
strEng = English(num3);
if (strEng != "") {
if (g != "") g += " ";
g += English(num3) + arr1[e - h]
}
}
return g
}
//#region 合并单元格
/**
* Kunoy
* 合并单元格
* @param {} grid 要合并单元格的grid对象
* @param {} cols 要合并哪几列 [1,2,4]。另外如果有check列需要合并则放到最后[1,2,4,0]
*/
var mergeCells = function (grid, cols) {
var arrayTr = document.getElementById(grid.getId() + "-body").firstChild.firstChild.firstChild.getElementsByTagName('tr');
var trCount = arrayTr.length;
var arrayTd;
var td;
var merge = function (rowspanObj, removeObjs) { //定义合并函数
if (rowspanObj.rowspan != 1) {
arrayTd = arrayTr[rowspanObj.tr].getElementsByTagName("td"); //合并行
td = arrayTd[rowspanObj.td - 1];
td.rowSpan = rowspanObj.rowspan;
td.vAlign = "middle";
Ext.each(removeObjs, function (obj) { //隐身被合并的单元格
arrayTd = arrayTr[obj.tr].getElementsByTagName("td");
arrayTd[obj.td - 1].style.display = 'none';
});
}
};
var rowspanObj = {}; //要进行跨列操作的td对象{tr:1,td:2,rowspan:5}
var removeObjs = []; //要进行删除的td对象[{tr:2,td:2},{tr:3,td:2}]
var col;
var lastCol = 0;
Ext.each(cols, function (colIndex) { //逐列去操作tr
var rowspan = 1;
var divHtml = null; //单元格内的数值
var isCF = "";
for (var i = 1; i < trCount; i++) { //i=0表示表头等没用的行
arrayTd = arrayTr[i].getElementsByTagName("td");
var cold = 0;
Ext.each(arrayTd, function (Td) { //获取RowNumber列和check列
if (Td.getAttribute("class").indexOf("x-grid-cell-special") != -1)
cold++;
});
col = colIndex + cold; //跳过RowNumber列和check列
if (!divHtml) {
if (col == 0) {
divHtml = arrayTd[col].innerHTML;
}
else {
divHtml = arrayTd[col - 1].innerHTML;
}
rowspanObj = { tr: i, td: col, rowspan: rowspan }
} else {
var cellText = arrayTd[col].innerHTML;
if (col != 0) {
cellText = arrayTd[col - 1].innerHTML;
}
var addf = function () {
rowspanObj["rowspan"] = rowspanObj["rowspan"] + 1;
removeObjs.push({ tr: i, td: col });
if (i == trCount - 1)
merge(rowspanObj, removeObjs); //执行合并函数
};
var mergef = function () {
merge(rowspanObj, removeObjs); //执行合并函数
divHtml = cellText;
rowspanObj = { tr: i, td: col, rowspan: rowspan }
removeObjs = [];
};
if (cellText == divHtml) {
if (colIndex != cols[0]) {
//取得上一个合并的列号
//var iCol = col;
//if (colIndex != lastCol) {
// iCol = lastCol;
//}
var iCol = lastCol + 1; //取得第一个合并的列号
var leftDisplay = arrayTd[iCol - 1].style.display; //判断左边单元格值是否已display
if (iCol >= 2) {
leftDisplay = arrayTd[iCol - 2].style.display; //判断左边单元格值是否已display
}
if (leftDisplay == 'none')
addf();
else
mergef();
} else {
addf();
lastCol = col; //取得第一个合并的列号;
}
} else {
mergef();
}
}
}
//lastCol = col; //取得上一个合并的列号
});
};
//#endregion
function getAfterDATE(startdate,days) {
var myDate = new Date(Date.parse(startdate.toString()));
myDate.setDate(myDate.getDate() + (parseInt(days) -1));
var lsDate = Ext.util.Format.date(myDate, 'Y-m-d');
if (lsDate.indexOf("-00-") > -1) {
lsDate = (myDate.getFullYear() - 1) + "-12-" + myDate.getDate();
}
return lsDate;
};
//数值添加小数位数后的“.00”
function usMoney(v) {
if (v == null || v == "") {
v = 0;
}
v = (Math.round((v - 0) * 100)) / 100;
v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
v = String(v);
var ps = v.split('.');
var whole = ps[0];
var sub = ps[1] ? '.' + ps[1] : '.00';
var r = /(\d+)(\d{3})/;
while (r.test(whole)) {
whole = whole.replace(r, '$1' + ',' + '$2');
}
v = whole + sub;
if (v.charAt(0) == '-') {
return '-' + v.substr(1); //'-$'
}
return v; //"$"
};
//数值添加小数位数后的“.0”、货币“符号”、“,”分隔符v数值dl小数位数symbol符号isComma是否用“,”分隔数值
function usMoney(v, dl, symbol, isComma) {
if (v == null || v == "") {
v = 0;
}
//数值添加小数位数后的“0”
var iChengShu = 1;
var sXiaoShu = ".";
for (var n = 1; n <= dl; n++) {
iChengShu = Math.pow(10, n);
sXiaoShu += "0";
}
v = (Math.round((v - 0) * iChengShu)) / iChengShu;
//v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
if (v == Math.floor(v)) {
v = v + sXiaoShu;
}
else {
var sValue = v.toString();
sValue = sValue.substr(sValue.indexOf(".") + 1);
var iVLength = sValue.length;
var iChengShu2 = 1;
for (var k = (1 + iVLength); k <= dl; k++) {
iChengShu2 = iChengShu2 * Math.pow(10, k);
if ((v * iChengShu2) == Math.floor(v * iChengShu2)) {
v = v + "0";
}
}
}
//是否用“,”分隔数值
v = String(v);
if (isComma) {
//第一种方法
var ps = v.split('.');
var whole = ps[0];
var sub = ps[1] ? '.' + ps[1] : sXiaoShu;
var r = /(\d+)(\d{3})/;
while (r.test(whole)) {
whole = whole.replace(r, '$1' + ',' + '$2');
}
v = whole + sub;
//第二种方法
//var zhs = v.substr(v, v.indexOf("."));
//if (v.indexOf(".") > -1) {
// zhs = v.substr(v, v.indexOf("."));
//}
//var iLength = zhs.length / 3;
//var iLengthC = zhs.length / 3;
//var zhs2 = "";
//for (var i = 1; i <= iLengthC; i++) {
// zhs2 = "," + zhs.substring((iLength - 3*i),3);
//}
}
//添加符号
if (v.charAt(0) == '-') {
return '-' + symbol + v.substr(1); //'-$'
}
return symbol + v; //"$"
};
function CheckISSTOP(_store, _fieldname, _value) {
var field = DsStoreQueryBy(_store, 'name', _value);
if (field.getCount() > 0) {
var fielddata = field.getAt(0).data;
if (fielddata.ISSTOP == "True") {
return true;
} else {
return false;
}
}
};
//#region 用于排序列
//最初用在importTrade模块上
//http://dev.sencha.com/deploy/ext-4.0.2a/examples/grid/multiple-sorting.html
function doSort() {
store.sort(getSorters());
}
function changeSortDirection(button, changeDirection) {
var sortData = button.sortData,
iconCls = button.iconCls;
if (sortData) {
if (changeDirection !== false) {
button.sortData.direction = Ext.String.toggle(button.sortData.direction, "ASC", "DESC");
button.setIconCls(Ext.String.toggle(iconCls, "sort-asc", "sort-desc"));
}
store.clearFilter();
doSort();
}
}
function getSorters() {
var sorters = [];
Ext.each(tbar.query('button'), function (button) {
sorters.push(button.sortData);
}, this);
return sorters;
}
function createSorterButtonConfig(config) {
config = config || {};
Ext.applyIf(config, {
listeners: {
click: function (button, e) {
changeSortDirection(button, true);
}
},
iconCls: 'sort-' + config.sortData.direction.toLowerCase(),
reorderable: true,
xtype: 'button'
});
return config;
}
//#endregion
function isRealNum(val) {
// isNaN()函数 把空串 空格 以及NUll 按照0来处理 所以先去除,
if (val === "" || val == null) {
return false;
}
if (!isNaN(val)) {
//对于空数组和只有一个数值成员的数组或全是数字组成的字符串isNaN返回false例如'123'、[]、[2]、['123'],isNaN返回false,
//所以如果不需要val包含这些特殊情况则这个判断改写为if(!isNaN(val) && typeof val === 'number' )
return true;
}
else {
return false;
}
}
function isNullorEmpty(exp) {
var a = !exp;
var b = typeof (exp);
if (exp == null) return true;
if (b == "object") return false;
if (typeof (exp) == "undefined") return true;
if (exp == true || exp == false) {
try {
//在这里运行代码
if (exp.trim() == "") return true;
}
catch (err) {
//在这里处理错误
}
return false;
}
if (isRealNum(exp)) return false;
if (exp.trim() == "") return true;
return false;
}
//#region 对象是否为false
function isFalse(str) {
if (str == '0' || str == '' || str == false || str == 'false' || str == 'False' || isNullorEmpty(str)) {
return true;
} else {
return false;
}
}
//#endregion
//#region 对象是否为true
function isTrue(str) {
if (isNullorEmpty(str)) return false;
if (str == true || str.toUpperCase() == 'true'.toUpperCase() || str.toUpperCase() == "true".toUpperCase() || str == '1' || str == "1" || str == 1) {
return true;
} else {
return false;
}
}
//#endregion