String.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); }
Date.prototype.format = function (fmt) {
var o = {
"M+": this.getmonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
}
}
return fmt;
}
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_NoUrl(url, caption, height, width, top, left) {
var pageinfo = "height=";
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.concat(",location=no");
return window.open(url, _caption, pageinfo);
}
function DsOpenEditWin_FullUrl(url, caption, height, width, top, left) {
var pageinfo = "height=";
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.concat(",location=no");
return window.open("https://" + url, _caption, pageinfo);
}
/*
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: ' '
});
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, limit = 1) {
if(e.query.length < limit) return;
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;
}
}
//写在combox的按键事件中 形如:
// specialkey: function (combo, e) {
// //将回车13转义成tab9
// GetComboxFirstValueOnTableClick(combo, e);
// }
//用于在点击回车或table键,跳转至下一输入框时,在combox当中取目前第一条选项作为值
function GetComboxFirstValueOnTableClick(combo, e) {
//var combo = e.combo;
if (e.getKey() == e.ENTER) {
e.keyCode = 9;
}
if (e.keyCode == 9) {
//将combo
//alert(field.value);
if (combo.value == null) {
_name = combo.store.data.keys[0];
combo.setValue(_name);
} else {
if (combo.value.replace(/\s*/g, "") == "") {
_name = combo.store.data.keys[0];
combo.setValue(_name);
}
}
}
}
//获取目前表最大的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;
}
});
}
function DsStoreQueryBy2(store, fieldname, value, fieldname2, value2) {
return store.queryBy(function (rec) {
if (rec.get(fieldname) == value && rec.get(fieldname2) == value2) {
return true;
} else {
return false;
}
});
}
String.prototype.replaceAll = function (s1, s2) {
return this.replace(new RegExp(s1, "gm"), s2);
}
//#region 结果无错的加减乘除 Add Cut Mul Div
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
//}
function accAdd(arg1, arg2) {
if (isNaN(arg1)) {
arg1 = 0;
}
if (isNaN(arg2)) {
arg2 = 0;
}
arg1 = Number(arg1);
arg2 = Number(arg2);
var r1, r2, m, c;
try {
r1 = arg1.toString().split(".")[1].length;
}
catch (e) {
r1 = 0;
}
try {
r2 = arg2.toString().split(".")[1].length;
}
catch (e) {
r2 = 0;
}
c = Math.abs(r1 - r2);
m = Math.pow(10, Math.max(r1, r2));
if (c > 0) {
var cm = Math.pow(10, c);
if (r1 > r2) {
arg1 = Number(arg1.toString().replace(".", ""));
arg2 = Number(arg2.toString().replace(".", "")) * cm;
} else {
arg1 = Number(arg1.toString().replace(".", "")) * cm;
arg2 = Number(arg2.toString().replace(".", ""));
}
} else {
arg1 = Number(arg1.toString().replace(".", ""));
arg2 = Number(arg2.toString().replace(".", ""));
}
return (arg1 + arg2) / 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 isnnumber = 0;
if (a < 0 || b < 0) {
if (b > 0) {
var _r = (Math.abs(parseFloat(a)).mul(parseFloat(b)))
isnnumber = 1;
}
else if (a > 0) {
var _r = (parseFloat(a).mul(Math.abs(parseFloat(b))))
isnnumber = 1;
}
else
var _r = parseFloat(a).mul(parseFloat(b));
} else
var _r = parseFloat(a).mul(parseFloat(b))
var _r2 = _r.toFixed(parseInt(length));
if (isnnumber == 1) _r2 = -_r2;
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);
}
//#endregion
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 "
} else {
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
//#region 获取某日之后days天数的日期
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;
}
//#endregion
//#region 获取两个日期的天数间隔,只考虑日期差。1月1日与1月2日差为1.
function datediff(data1str, data2str) {
if (isNullorEmpty(data1str) || isNullorEmpty(data2str))
return 0;
data1 = new Date(data1str);
data2 = new Date(data2str);
aDay = 24 * 60 * 60 * 1000;
diffDay = (data2 - data1) / aDay;
if (diffDay < 0) diffDay = -diffDay;
return diffDay;
}
//#endregion
//#region 数字转化为指定金额格式
//数值添加小数位数后的“.00”
function usMoney(v) {
if (v == null || v == "" || v == NaN) {
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; //"$"
};
//下面函数的使用例子
// a=1234.567
// usMoney(a,4,"$",true) => $1,234.5670
//数值添加小数位数后的“.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; //"$"
};
//#endregion
//#region 返回一个store的一个字段值为value的记录 其“ISSTOP”值是否为 true/1
function CheckISSTOP(_store, _fieldname, _value) {
var field = DsStoreQueryBy(_store, 'name', _value);
if (field.getCount() > 0) {
var fielddata = field.getAt(0).data;
if (isTrue(fielddata.ISSTOP)) {
return true;
} else {
return false;
}
}
};
//#endregion
//#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
//#region 集成的grid内combox选择后事件
//获取store内,字段名为fieldname,字段值为value 的 记录集合
function StoreQueryBy(store, fieldname, value) {
return store.queryBy(function (rec) {//此处rec表示store内的记录
if (rec.get(fieldname) == value) {
return true;
} else {
return false;
}
});
}
//为列表中的下拉菜单设定选择后的值。
function SetComboxValue(combox, currrecord, REFFieldname) {
//combox的store;grid的当前行record;combox的valuefieldname;combox当前的valuefield值,grid此列的名字
var comboxrecords = StoreQueryBy(combox.store, combox.valueField, currrecord.value);
if (comboxrecords.getCount() > 0) {
var ForeignData = comboxrecords.getAt(0);
currrecord.record.set(REFFieldname, ForeignData.get(combox.displayField));
} else {
currrecord.record.set(REFFieldname, '');
}
}
//#endregion
//#region 令指定combox的store按照params:condition重新加载
function LoadCombox(combox, condition) {
combox.store.load({
async: false,
params: { condition: condition }
});
}
//#endregion
function ImgWindow(url) {
if (url !== null || typeof (url) == "undefined" || url !== '')
{
if (Ext.getCmp("pic_i")) { Ext.getCmp("pic_i").close(); }
if (Ext.getCmp("pic_p")) { Ext.getCmp("pic_p").close(); }
var height = 0;
var width = 0;
var a = new Image();
a.src = url;
a.onload = function () {
height = a.height;
width = a.width;
c = Ext.getCmp("pic_i");
c.width = getwidth(width);
c.height = getheight(height);
c.doLayout();
d = Ext.getCmp("pic_p");
d.width = getwidth(width) + 33;
d.height = getheight(height) + 50;
d.doLayout();
};
new Ext.Window({
id: "pic_p",
//renderTo: Ext.getBody(),
bodyStyle: 'padding:10px;', //加个内边框好看一点
items: [{
id: "pic_i",
width: 200,
height: 200,
html: '