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.
DS7/DSWeb/Areas/MvcShipping/Viewsjs/Comm/PubFunction.js

1393 lines
43 KiB
JavaScript

2 years ago
function getUrlParam(param) {
var params = Ext.urlDecode(location.search.substring(1));
return param ? params[param] : params;
}
function isEmptyObject(e) {
var t;
for (t in e)
return !1;
return !0
}
function checkzimu(value) {
var Regx = /^[a-z]*$/;
if (Regx.test(value)) {
return true;
}
else {
return false;
}
}
function formatDate(date) {
var myyear = date.getFullYear();
var mymonth = date.getMonth() + 1;
var myweekday = date.getDate();
if (mymonth < 10) {
mymonth = "0" + mymonth;
}
if (myweekday < 10) {
myweekday = "0" + myweekday;
}
return (myyear + "-" + mymonth + "-" + myweekday);
}
function getMonthDays(myMonth) {
var now = new Date(); //当前日期
var nowYear = now.getFullYear(); //当前年
var monthStartDate = new Date(nowYear, myMonth, 1);
var monthEndDate = new Date(nowYear, myMonth + 1, 1);
var days = (monthEndDate - monthStartDate) / (1000 * 60 * 60 * 24);
return days;
}
function CheckFileExt(extstr, exg) {
var extstr = extstr.substring(extstr.lastIndexOf(".")).toLowerCase();
if (!extstr.match(exg)) {
return false;
}
return true;
}
function DateToStr(dt){
var str="";
if(dt.getFullYear){
var y,m,d;
y=formatNumber(dt.getFullYear(),'0000');
m=formatNumber((dt.getMonth()+1),'00'); //01-12
d=formatNumber(dt.getDate(),'00');
str= y+"-"+m+"-"+d;
}
return str;
}
function DateTimeToStr(dt){
var str="";
if(dt.getFullYear){
var y,m,d,h,mi,s;
y=formatNumber(dt.getFullYear(),'0000');
m=formatNumber((dt.getMonth()+1),'00'); //01-12
d=formatNumber(dt.getDate(),'00');
h=formatNumber(dt.getHours(),'00');
mi=formatNumber(dt.getMinutes(),'00');
s=formatNumber(dt.getSeconds(),'00');
str= y+"-"+m+"-"+d+" "+h+":"+mi+":"+s;
}
return str;
}
function StrToDate(str){
var arys= new Array();
arys=str.split('-');
var newDate=new Date(arys[0],arys[1]-1,arys[2]);
return newDate;
}
function getDays(strDateStart, strDateEnd) {
var strSeparator = "-"; //日期分隔符
var oDate1;
var oDate2;
var iDays;
oDate1 = strDateStart.split(strSeparator);
oDate2 = strDateEnd.split(strSeparator);
var strDateS = new Date(oDate1[0], oDate1[1] - 1, oDate1[2]);
var strDateE = new Date(oDate2[0], oDate2[1] - 1, oDate2[2]);
iDays = parseInt(Math.abs(strDateS - strDateE) / 1000 / 60 / 60 / 24)//把相差的毫秒数转换为天数
return iDays;
}
function getNewDay(dateTemp, days) {
var dateTemp = dateTemp.split("-");
var nDate = new Date(dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]); //转换为MM-DD-YYYY格式
var millSeconds = Math.abs(nDate) + (days * 24 * 60 * 60 * 1000);
var rDate = new Date(millSeconds);
var year = rDate.getFullYear();
var month = rDate.getMonth() + 1;
if (month < 10) month = "0" + month;
var date = rDate.getDate();
if (date < 10) date = "0" + date;
return (year + "-" + month + "-" + date);
}
/*
数字格式化函数
, (半角的豆号) 如果有的话看豆号到小数点如果有的话前有几位则按几位划分整数部分
0数字零 如果该位上没有数字就补0
#井号 如果该位上有数字就输出数字没有则不输出
*/
function formatNumber(number,pattern){
var str = number.toString();
var strInt;
var strFloat;
var formatInt;
var formatFloat;
if(/\./g.test(pattern)){
formatInt = pattern.split('.')[0];
formatFloat = pattern.split('.')[1];
}else{
formatInt = pattern;
formatFloat = null;
}
if(/\./g.test(str)){
if(formatFloat!=null){
var tempFloat = Math.round(parseFloat('0.'+str.split('.')[1])*Math.pow(10,formatFloat.length))/Math.pow(10,formatFloat.length);
strInt = (Math.floor(number)+Math.floor(tempFloat)).toString();
strFloat = /\./g.test(tempFloat.toString())?tempFloat.toString().split('.')[1]:'0';
}else{
strInt = Math.round(number).toString();
strFloat = '0';
}
}else{
strInt = str;
strFloat = '0';
}
if(formatInt!=null){
var outputInt = '';
var zero = formatInt.match(/0*$/)[0].length;
var comma = null;
if(/,/g.test(formatInt)){
comma = formatInt.match(/,[^,]*/)[0].length-1;
}
var newReg = new RegExp('(\\d{'+comma+'})','g');
if(strInt.length<zero){
outputInt = new Array(zero+1).join('0')+strInt;
outputInt = outputInt.substr(outputInt.length-zero,zero)
}else{
outputInt = strInt;
}
var outputInt = outputInt.substr(0,outputInt.length%comma)+outputInt.substring(outputInt.length%comma).replace(newReg,(comma!=null?',':'')+'$1')
outputInt = outputInt.replace(/^,/,'');
strInt = outputInt;
}
if(formatFloat!=null){
var outputFloat = '';
var zero = formatFloat.match(/^0*/)[0].length;
if(strFloat.length<zero){
outputFloat = strFloat+new Array(zero+1).join('0');
//outputFloat = outputFloat.substring(0,formatFloat.length);
var outputFloat1 = outputFloat.substring(0,zero);
var outputFloat2 = outputFloat.substring(zero,formatFloat.length);
outputFloat = outputFloat1+outputFloat2.replace(/0*$/,'');
}else{
outputFloat = strFloat.substring(0,formatFloat.length);
}
strFloat = outputFloat;
}else{
if(pattern!='' || (pattern=='' && strFloat=='0')){
strFloat = '';
}
}
return strInt+(strFloat==''?'':'.'+strFloat);
}
function ConvertFormValue(formvalue){
var ResultObject = new Object();
var dt = formvalue; //字符串转化为日期
ResultObject= "\\/Date("+Date.UTC(dt.getFullYear(),dt.getMonth(),dt.getDate(),dt.getHours(),dt.getMinutes(),dt.getSeconds())+")\\/"; //转化为UTC日期
return ResultObject;
}
//用于转换日期格式
function WebPosDateTimeToStr(dt){
var str = "";
if(dt!=null)
{
var obj = eval("new " + dt.substr(1,dt.length-2));//.toString();
//str=Ext.util.Format.date(obj,'Y-m-d H:i:s');
str=DateTimeToStr(obj);
}
return str;
}
function WebPosDateToStr(dt){
var str = "";
if(dt!=null)
{
var obj = eval("new " + dt.substr(1,dt.length-2));
str=DateToStr(obj);
}
return str;
}
//用于添加SQL语句的函数
function getAndConSql(sql,valuestr,constr){
if (valuestr == '' || valuestr == null || valuestr== undefined)
{
return '';
}
else
{
if (sql == '') {
return constr;
}
else {
return ' and ' + constr;
}
}
}
function getAndConSqlTwo(sql,constr){
if(sql=='')
{
return constr;
}
else
{
return ' and ' + constr;
}
}
//此函数验证EditGrid并显示需要的错误
//The function returns false if there is an error else it returns true.
function validateEditorGridPanel(grid) {
//var grid = Ext.getCmp(gridId);
var rows = grid.store.data.length;
var columns = grid.columns;
var editingPlugin = grid.editingPlugin;
for (var row = 0; row < rows; row++) {
var record = grid.store.getAt(row);
for (var col = 0; col < columns.length; col++) {
var column = columns[col];
var cellEditor = column.getEditor(record); //grid.colModel.getCellEditor(col, row);
if (cellEditor != undefined) {
if (!cellEditor.isValid()) {
editingPlugin.startEditByPosition({ row: row, column: col });
return false;
}
}
}
}
return true;
}
//把表格中显示的记录转为Json数据(只转修改的)
function ConvertRecordsToJson(items) {
if (items.length == 0) {
return "";
}
var jsonData = "[";
for (var i = 0; i < items.length; i++) {
var record = items[i];
if (record.dirty) {
jsonData += Ext.JSON.encode(record.data) + ",";
}
}
if (jsonData != "[") {
jsonData = jsonData.substring(0, jsonData.length - 1) + "]";
} else
jsonData = "";
return jsonData;
}
//把表格中显示的记录转为Json数据
function ConvertRecordsToJsonAll(items)
{
if(items.length==0)
{
return "";
}
var jsonData = "[";
for(i=0;i<items.length;i++) {
var record = items[i];
jsonData += Ext.JSON.encode(record.data) + ",";
}
if(jsonData!="[")
{
jsonData = jsonData.substring(0,jsonData.length-1) + "]";
}
else
jsonData="";
return jsonData;
}
function ConvertFeeRecordsToJson(items) {
if (items.length == 0) {
return "";
}
var jsonData = "[";
for (var i = 0; i < items.length; i++) {
var record = items[i];
if (record.dirty || record.data.BsNo=='*') {
jsonData += Ext.JSON.encode(record.data) + ",";
}
}
if (jsonData != "[") {
jsonData = jsonData.substring(0, jsonData.length - 1) + "]";
} else
jsonData = "";
return jsonData;
}
function ConvertBSNORecordsToJson(items) {
if (items.length == 0) {
return "";
}
var jsonData = "[";
for (var i = 0; i < items.length; i++) {
var record = items[i];
if (record.dirty || record.data.BSNO == '*') {
jsonData += Ext.JSON.encode(record.data) + ",";
}
}
if (jsonData != "[") {
jsonData = jsonData.substring(0, jsonData.length - 1) + "]";
} else
jsonData = "";
return jsonData;
}
function ConvertWMSRecordsToJson(items) {
if (items.length == 0) {
return "";
}
var jsonData = "[";
for (var i = 0; i < items.length; i++) {
var record = items[i];
if (record.dirty || record.data.ASSOCIATEDNO == '') {
jsonData += Ext.JSON.encode(record.data) + ",";
}
}
if (jsonData != "[") {
jsonData = jsonData.substring(0, jsonData.length - 1) + "]";
} else
jsonData = "";
return jsonData;
}
function ConvertCtnrRecordsToJson(items,bsno) {
if (items.length == 0) {
return "";
}
var jsonData = "[";
for (var i = 0; i < items.length; i++) {
var record = items[i];
if (record.dirty || bsno == '') {
jsonData += Ext.JSON.encode(record.data) + ",";
}
}
if (jsonData != "[") {
jsonData = jsonData.substring(0, jsonData.length - 1) + "]";
} else
jsonData = "";
return jsonData;
}
function ConvertGIDRecordsToJson(items) {
if (items.length == 0) {
return "";
}
var jsonData = "[";
for (var i = 0; i < items.length; i++) {
var record = items[i];
if (record.dirty || record.data.GID == '*' || record.phantom) {
jsonData += Ext.JSON.encode(record.data) + ",";
}
}
if (jsonData != "[") {
jsonData = jsonData.substring(0, jsonData.length - 1) + "]";
} else
jsonData = "";
return jsonData;
}
//把表格中显示的记录转为Json数据
//function convertArraysToString(items)
//{
// if(items.length==0)
// {
// return "";
// }
// var jsonData = "";
// for(i=0;i<items.length;i++) {
// var record = items[i];
// jsonData += Ext.JSON.encode(record) + ",";
// }
// jsonData = jsonData.substring(0,jsonData.length-1);
// return jsonData;
//}
function convertArraysToJson(items) {
if (items.length == 0) {
return "";
}
var jsonData = "[";
for (i = 0; i < items.length; i++) {
var record = items[i];
jsonData += Ext.JSON.encode(record) + ",";
}
jsonData = jsonData.substring(0, jsonData.length - 1);
jsonData += "]";
return jsonData;
}
//判断如果Form中的控件为ReadOnly那么则设置为disable
function setFormCmpDisable(form)
{
form.getForm().items.each(function(item){
if(item.readOnly)
item.disable();
});
}
//判断如果Form中的控件为ReadOnly那么则设置为enable
function setFormCmpEnable(form)
{
form.getForm().items.each(function(item){
if(item.readOnly)
item.enable();
});
}
/*这里开始时UrlEncode和UrlDecode函数*/
UrlEncode = function(str)
{
str = str.replace(/./g,function(sHex)
{
window.EnCodeStr = "";
window.sHex = sHex;
window.execScript('window.EnCodeStr=Hex(Asc(window.sHex))',"vbscript");
return window.EnCodeStr.replace(/../g,"%$&");
});
return str;
}
function trim(str){
for(var i = 0 ; i<str.length && str.charAt(i)==" " ; i++ ) ;
for(var j =str.length; j>0 && str.charAt(j-1)==" " ; j--) ;
if(i>j) return "";
return str.substring(i,j);
}
function Billstrnum(str,len) {
var result = "";
if (str == '') return result;
var slist = str.split("\n");
for (var i = 0; i < slist.length; i += 1) {
var member = slist[i];
if (member.length > len) {
if (result=='')
result = result + (i + 1) + '行';
else
result = result+','+ (i + 1) + '行';
}
}
if (result != '') result = "&nbsp<font color='red'>第" + result + '字符超过' + len + "</font>";
return result;
}
function ExportExcel(gridPanel, config) {
if (gridPanel) {
var tmpStore = gridPanel.getStore();
var tmpExportContent = '';
//以下处理分页grid数据导出的问题从服务器中获取所有数据需要考虑性能
var tmpParam = Ext.clone(tmpStore.lastOptions); //此处克隆了原网格数据源的参数信息
// if (tmpParam && tmpParam.params) {
// delete (tmpParam.params[tmpStore.paramNames.start]); //删除分页参数
// delete (tmpParam.params[tmpStore.paramNames.limit]);
// }
var tmpAllStore = new Ext.data.Store({//重新定义一个数据源
proxy: tmpStore.proxy,
reader: tmpStore.reader
});
tmpAllStore.on('load', function (store) {
config.store = store;
tmpExportContent = gridPanel.getExcelXml(false, config); //此方法用到了一中的扩展
if (Ext.isIE || Ext.isSafari || Ext.isSafari2 || Ext.isSafari3 || Ext.isChrome) {//在这几种浏览器中才需要IE8测试不能直接下载了
if (!Ext.fly('frmDummy')) {
var frm = document.createElement('form');
frm.id = 'frmDummy';
frm.name = id;
frm.className = 'x-hidden';
document.body.appendChild(frm);
}
Ext.Ajax.request({
//将生成的xml发送到服务器端,需特别注意这个页面的地址
url: '/CommMng/PubSys/ExportGrid',
method: 'POST',
form: Ext.fly('frmDummy'),
callback: function (o, s, r) {
//alert(r.responseText);
},
isUpload: true,
params: { ExportContent: tmpExportContent, ExportFile: gridPanel.id + '.xls' }
});
} else {
document.location = 'data:application/vnd.ms-excel;base64,' + Base64.encode(tmpExportContent);
}
});
tmpAllStore.load(tmpParam); //获取所有数据
}
};
function GridExportExcelPage(grid) {
var vExportContent = grid.getExcelXml();
if (Ext.isIE6 || Ext.isIE7 || Ext.isIE8 || Ext.isIE9 || Ext.isSafari || Ext.isSafari2 || Ext.isSafari3 || Ext.isChrome) {
if (!Ext.fly('frmDummy')) {
var frm = document.createElement('form');
frm.id = 'frmDummy';
frm.name = ''; //id;
frm.className = 'x-hidden';
document.body.appendChild(frm);
}
Ext.Ajax.request({
url: '/CommMng/PubSys/ExportGrid',
method: 'POST',
form: Ext.fly('frmDummy'),
callback: function (o, s, r) {
//alert(r.responseText);
},
isUpload: true,
params: {
ExportContent: Base64.encode(vExportContent),
ExportFile: '导出数据.xls'
}
});
} else {
document.location = 'data:application/vnd.ms-excel;base64,' + Base64.encode(vExportContent);
}
}
function PrintComm(printType, sql1, sql2, sql3, sql4, sql5, sql6, billno, rpid, rptmode, Mailid,bsno) {
//Ext.Msg.wait('正在准备打印数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在准备打印数据...',
url: '/CommMng/Print/GetPrintInfo',
scope: this,
params: {
type: printType,
sql1: sql1,
sql2: sql2,
sql3: sql3,
sql4: sql4,
sql5: sql5,
sql6: sql6,
billno: billno,
RpID:rpid,
RptMode: rptmode,
bsno: bsno
},
callback: function (options, success, response) {
if (success) {
if (Ext.MessageBox.isVisible()) {
Ext.MessageBox.hide();
}
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) {
var printUrl = "print://?comp=" + jsonresult.CompanyID + "&type=" + printType + "&dbid=" + jsonresult.DbSourceID + "&uid=" + jsonresult.UserId; //alert(printUrl);
if (jsonresult.PrServer != NaN && jsonresult.PrServer != null && jsonresult.PrServer != "") {
if (Mailid != undefined && Mailid !='') {
printUrl = "print://?comp=" + jsonresult.CompanyID + "&type=" + printType + "&dbid=" + jsonresult.DbSourceID + "&uid=" + jsonresult.UserId + "&PrServer=" + jsonresult.PrServer + "&dbStr=" + jsonresult.dbStr
+ "&RpID=" + jsonresult.RpID + "&RptMode=" + jsonresult.RptMode + "&Mailid=" + Mailid; //alert(printUrl);
}
else {
printUrl = "print://?comp=" + jsonresult.CompanyID + "&type=" + printType + "&dbid=" + jsonresult.DbSourceID + "&uid=" + jsonresult.UserId + "&PrServer=" + jsonresult.PrServer + "&dbStr=" + jsonresult.dbStr
+ "&RpID=" + jsonresult.RpID + "&RptMode=" + jsonresult.RptMode; //alert(printUrl);
}
}
window.location.href = window.location.href;
location.href = printUrl;
} else {
Ext.Msg.show({ title: '错误', msg: jsonresult.Message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK });
}
} else {
Ext.Msg.show({ title: '请重试',
msg: '服务器响应出错',
icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK
});
}
}
});
}
function GridExportExcel(gridPanel, config) {
if (!config) {
config = {
store: null, //因为后续可能需要处理分页因此此处一般不直接传递GridPanel的数据源
title: '', //需要显示标题
limit: 4000
};
}
if (gridPanel) {
var tmpStore = gridPanel.getStore();
var vExportContent = '';
//以下处理分页grid数据导出的问题从服务器中获取所有数据需要考虑性能
var tmpParam = Ext.ux.constructor(tmpStore.lastOptions); //此处克隆了原网格数据源的参数信息
//alert(tmpParam.params[tmpStore.paramNames.limit]);
//此处作者原先为Ext.ux.clone(tmpStore.lastOptions)方法,但不好使
var tmpAllStore = new Ext.data.Store({//重新定义一个数据源
proxy: tmpStore.proxy,
reader: tmpStore.reader
});
tmpParam.params[tmpStore.paramNames.limit] = config.limit;
tmpAllStore.load(tmpParam); //获取所有数据
tmpAllStore.on('load', function (store) {
config.store = store;
vExportContent = gridPanel.getExcelXml(false, config); //此方法用到了一中的扩展
if (Ext.isIE6 || Ext.isIE7 || Ext.isIE8 || Ext.isSafari || Ext.isSafari2 || Ext.isSafari3) {
if (!Ext.fly('frmDummy')) {
var frm = document.createElement('form');
frm.id = 'frmDummy';
frm.name = id;
frm.className = 'x-hidden';
document.body.appendChild(frm);
}
Ext.Ajax.request({
url: '/PubSys/ExportGrid',
method: 'POST',
form: Ext.fly('frmDummy'),
callback: function (o, s, r) {
},
isUpload: true,
params: {
ExportContent: Base64.encode(vExportContent),
ExportFile: '导出数据.xls'
}
});
} else {
document.location = 'data:application/vnd.ms-excel;base64,' + Base64.encode(vExportContent);
}
});
}
};
function GridExportBySql(Condition, formname,filename) {
if (!Ext.fly('frmDummy')) {
var frm = document.createElement('form');
frm.id = 'frmDummy';
frm.name = 'frmDummy';
frm.className = 'x-hidden';
document.body.appendChild(frm);
}
Ext.Ajax.request({
waitMsg: '正在导出数据...',
url: '../../CommMng/PubSys/ExcelRptIndex',
scope: this,
form: Ext.fly('frmDummy'),
method: 'POST',
isUpload: true,
params: {
strCondition: Condition,
formname: formname,
filename: filename
},
callback: function (options, success, response) {
if (success) {
Ext.MessageBox.hide();
var jsonresult = Ext.JSON.decode(response.responseText);
if (!jsonresult.success) Ext.Msg.show({ title: '错误', msg: jsonresult.message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK });
} else {
Ext.Msg.show({
title: '请重试',
msg: '服务器响应出错',
icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK
});
}
}
});
};
function saveQuerySetting(formname, form,isvisible,issavevalue) {
var form = form.getForm();
var fieldvalue = form.getValues();
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/MvcShipping/MsBaseInfo/SaveUserQuerySetting',
scope: this,
params: {
formname: formname,
isvisible: isvisible,
issavevalue: issavevalue,
querydetail: Ext.JSON.encode(fieldvalue)
}
});
}
function LoadQueryData(formname, form,checkbox) {
Ext.Ajax.request({
waitMsg: '正在查询主表数据...',
url: '/MvcShipping/MsBaseInfo/GetUserQuerySetting',
params: {
formname: formname
},
callback: function (options, success, response) {
if (success) {
var result = Ext.JSON.decode(response.responseText);
if (!result.success) {
Ext.Msg.show({ title: '提示', msg: result.Message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK });
return false;
}
data = result.data;
if (data.ISSAVEVALUE == true) {
form.getForm().reset();
if (data.FIELDVALUES !== "") {
form.getForm().setValues(Ext.JSON.decode(data.FIELDVALUES));
}
if (checkbox != null && checkbox != undefined) {
checkbox.setValue(true);
}
} else if (checkbox != NaN && checkbox != null)
{ checkbox.setValue(false); }
return true;
} else {
Ext.MessageBox.alert('请求出现错误,请重试', response.responseText);
return false;
}
},
scope: this
});
return true;
}
function formatRMB(num) {
var _F = "";
if (num < 0) {
_F = "负";
num = 0 - num;
}
//#region 转换人民币金额大小写
var c = "零壹贰叁肆伍陆柒捌玖".split("");
// ["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"]
var _c = {}; // 反向对应关系
for (var i = 0; i < c.length; i++) {
_c[c[i]] = i;
};
var d = "元***万***亿***万";
var e = ",拾,佰,仟".split(",");
function unit4(arr) {
var str = "", i = 0;
while (arr.length) {
var t = arr.pop();
str = (c[t] + (t == 0 ? "" : e[i])) + str;
i++;
}
str = str.replace(/[零]{2,}/g, "零");
str = str.replace(/^[零]/, "");
str = str.replace(/[零]$/, "");
if (str.indexOf("零") == 0) {
str = str.substring(1);
}
if (str.lastIndexOf("零") == str.length - 1) {
str = str.substring(0, str.length - 1);
}
return _F+str;
}
function _formatD(a) {
// 转化整数部分
var arr = a.split(""), i = 0, result = "";
while (arr.length) {
var arr1 = arr.splice(-4, 4);
var dw = d.charAt(i), unit = unit4(arr1);
if (dw == '万' && !unit) {
dw = "";
}
result = unit + dw + result;
i += 4;
}
return result == "元" ? "" : result;
}
function _formatF(b) {
// 转化小数部分
b = b || "";
switch (b.length) {
case 0:
return "整";
case 1:
return c[b] + "角";
default:
return c[b.charAt(0)] + "角" + c[b.charAt(1)] + "分";
}
}
function _format(n) {
var a = ("" + n).split("."), a0 = a[0], a1 = a[1];
return _formatD(a0) + _formatF(a1);
}
function parse4(u4) {
var res = 0;
while (t = /([零壹贰叁肆伍陆柒捌玖])([拾佰仟]?)/g.exec(u4)) {
var n = _c[t[1]], d = {
"": 1,
"拾": 10,
"佰": 100,
"仟": 1000
}[t[2]];
res += n * d;
u4 = u4.replace(t[0], "");
}
var result = ("0000" + res);
return result.substring(result.length - 4);
}
function _parseD(d) {
var arr = d.replace(/[零]/g, "").split(/[万亿]/), rs = "";
for (var i = 0; i < arr.length; i++) {
rs += parse4(arr[i]);
}
;
return rs.replace(/^[0]+/, "");
};
function _parseF(f) {
var res = "", t = f.replace(/[^零壹贰叁肆伍陆柒捌玖]+/g, "").split(""); // 去掉单位
if (t.length) {
res = ".";
} else {
return "";
}
;
for (var i = 0; (i < t.length && i < 2); i++) {
res += _c[t[i]];
}
;
return res;
};
function _parse(rmb) {
var a = rmb.split("元"), a1 = a[1], a0 = a[0];
if (a.length == 1) {
a1 = a0;
a0 = "";
}
return _parseD(a0) + _parseF(a1);
};
//小写转大写
function formatRMB(num) {
var n = Number(num);
if (!isNaN(num)) {
if (num == 0) {
return "零元整";
} else {
return _format(n);
}
} else {
return false;
}
}
//大写转小写
function parseRMB(rmb) {
if (/^[零壹贰叁肆伍陆柒捌玖元万亿拾佰仟角分整]{2,}$/.test(rmb)) {
var result = _parse(rmb);
return rmb == this.formatRMB(result) ? result : result + "(?)";
} else {
return false;
}
};
/*小写转大写*/
var xcc = "12.22";
//document.write(xcc + "=>" + formatRMB(xcc) + "<br/>");
/*大写转小写*/
var rrrr = "壹拾贰元贰角贰分";
//document.write(rrrr + "=>" + parseRMB(rrrr));
//#endregion
return formatRMB(num);
}
function formatUSD(num) {
var _F = "";
if (num < 0) {
_F = "负";
num = 0 - num;
}
//#region 转换人民币金额大小写
var c = "零壹贰叁肆伍陆柒捌玖".split("");
// ["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"]
var _c = {}; // 反向对应关系
for (var i = 0; i < c.length; i++) {
_c[c[i]] = i;
};
var d = "元***万***亿***万";
var e = ",拾,佰,仟".split(",");
function unit4(arr) {
var str = "", i = 0;
while (arr.length) {
var t = arr.pop();
str = (c[t] + (t == 0 ? "" : e[i])) + str;
i++;
}
str = str.replace(/[零]{2,}/g, "零");
str = str.replace(/^[零]/, "");
str = str.replace(/[零]$/, "");
if (str.indexOf("零") == 0) {
str = str.substring(1);
}
if (str.lastIndexOf("零") == str.length - 1) {
str = str.substring(0, str.length - 1);
}
return _F + str;
}
function _formatD(a) {
// 转化整数部分
var arr = a.split(""), i = 0, result = "";
while (arr.length) {
var arr1 = arr.splice(-4, 4);
var dw = d.charAt(i), unit = unit4(arr1);
if (dw == '万' && !unit) {
dw = "";
}
result = unit + dw + result;
i += 4;
}
return result == "元" ? "" : result;
}
function _formatF(b) {
// 转化小数部分
b = b || "";
switch (b.length) {
case 0:
return "整";
case 1:
return c[b] + "拾美分";
default:
{
if (c[b.charAt(0)] !="0") {
return c[b.charAt(0)] + "拾" + c[b.charAt(1)] + "美分";
} else {
return c[b.charAt(1)] + "美分";
}
}
}
}
function _format(n) {
var a = ("" + n).split("."), a0 = a[0], a1 = a[1];
return _formatD(a0) + _formatF(a1);
}
function parse4(u4) {
var res = 0;
while (t = /([零壹贰叁肆伍陆柒捌玖])([拾佰仟]?)/g.exec(u4)) {
var n = _c[t[1]], d = {
"": 1,
"拾": 10,
"佰": 100,
"仟": 1000
}[t[2]];
res += n * d;
u4 = u4.replace(t[0], "");
}
var result = ("0000" + res);
return result.substring(result.length - 4);
}
function _parseD(d) {
var arr = d.replace(/[零]/g, "").split(/[万亿]/), rs = "";
for (var i = 0; i < arr.length; i++) {
rs += parse4(arr[i]);
}
;
return rs.replace(/^[0]+/, "");
};
function _parseF(f) {
var res = "", t = f.replace(/[^零壹贰叁肆伍陆柒捌玖]+/g, "").split(""); // 去掉单位
if (t.length) {
res = ".";
} else {
return "";
}
;
for (var i = 0; (i < t.length && i < 2); i++) {
res += _c[t[i]];
}
;
return res;
};
function _parse(rmb) {
var a = rmb.split("元"), a1 = a[1], a0 = a[0];
if (a.length == 1) {
a1 = a0;
a0 = "";
}
return _parseD(a0) + _parseF(a1);
};
//小写转大写
function formatRMB(num) {
var n = Number(num);
if (!isNaN(num)) {
if (num == 0) {
return "零美元整";
} else {
var _r = _format(n);
// _t=_r.replace('元', '美元')
return _r;
}
} else {
return false;
}
}
//大写转小写
function parseRMB(rmb) {
if (/^[零壹贰叁肆伍陆柒捌玖元万亿拾佰仟角分整]{2,}$/.test(rmb)) {
var result = _parse(rmb);
return rmb == this.formatRMB(result) ? result : result + "(?)";
} else {
return false;
}
};
/*小写转大写*/
var xcc = "12.22";
//document.write(xcc + "=>" + formatRMB(xcc) + "<br/>");
/*大写转小写*/
var rrrr = "壹拾贰元贰角贰分";
//document.write(rrrr + "=>" + parseRMB(rrrr));
//#endregion
return formatRMB(num);
}
//在js中获取当前日期(参数0)或当前日期前后某天(参数1为后一天-2为两天前)
function GetDateStr(AddDayCount) {
var dd = new Date();
dd.setDate(dd.getDate() + AddDayCount); //获取AddDayCount天后的日期
var y = dd.getFullYear();
var m = dd.getMonth() + 1; //获取当前月份的日期
var d = dd.getDate();
return y + "-" + m + "-" + d;
}
/**
* Created with IntelliJ IDEA.
* User: zhuhq
* Date: 14-3-17
* Time: 下午12:26
* To change this template use File | Settings | File Templates.
*/
/**
*
* function grid2Excel(grid,filename)
* @param grid Extjs grid panel
* @param filename Excel 文件名称
*
* **/
(function () {
var format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) };
var tableToExcel = function (table, fileName) {
var uri = 'data:application/vnd.ms-excel;base64,'
, fileName = fileName || 'excelexport'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office"' +
' xmlns:x="urn:schemas-microsoft-com:office:exc el" xmlns="http://www.w3.org/TR/REC-html40"><head>' +
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' +
'<!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets>' +
'<x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/>' +
'</x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml>' +
'<![endif]--></head><body>{table}</body></html>';
var ctx = { worksheet: 'Worksheet', table: table };
var a = document.createElement('a');
document.body.appendChild(a);
a.hreflang = 'zh';
a.charset = 'utf8';
a.type = "application/vnd.ms-excel";
a.href = uri + Base64.encode(format(template, ctx));
a.target = '_blank';
a.download = fileName + '.xls';
a.click();
};
window.grid2Excel = function (grid, fileName) {
// var columns = grid.initialConfig.columns || [],
var columns = grid.columns || [],
store = grid.getStore(),
headLevel1 = [], headLevel2 = [], headLevel = 1, isGroup = false,
dataIndex = [], tableStr = '<table><thead>{thead}</thead><tbody>{tbody}</tbody></table>';
columns.forEach(function (column) {
if ((column.columns&&column.columns.length!=0)|| (column.items&&column.items.length!=0)){
isGroup = true;
return false;
}
});
if (isGroup) {
headLevel = 2; //只支持二级表头
}
columns.forEach(function (column) {
if (column.hidden!=true){
if (column.columns == undefined && (column.items == undefined||column.items.length==0)) {
column.colspan = 1;
column.rowspan = headLevel;
headLevel1.push(column);
dataIndex.push(column);
} else {
if (column.columns!=undefined){
var items = column.columns || [];
} else items = column.items.items || [];
column.rowspan = 1;
headLevel1.push(column);
var colspan=0;
items.forEach(function (item) {
if (item.hidden!=true){
item.colspan = 1;
item.rowspan = 1;
headLevel2.push(item);
dataIndex.push(item);
colspan=colspan+1;
}
})
column.colspan =colspan;
}
}
});
var headLevel1Str = '<tr>';
headLevel1.forEach(function (head) {
headLevel1Str += '<th colspan = "' + head.colspan +
'" rowspan="' + head.rowspan + '">' + head.text + '</th>';
});
headLevel1Str += '</tr>';
var headLevel2Str = '';
if (headLevel2.length > 0) {
headLevel2Str += '<tr>';
headLevel2.forEach(function (head) {
headLevel2Str += '<th colspan = "' + head.colspan +
'" rowspan="' + head.rowspan + '">' + head.text + '</th>';
});
headLevel2Str += '</tr>'
}
var theadStr = headLevel1Str + headLevel2Str,
tbodyStr = '', defRenderer = function (value) {
return value;
};
store.each(function (r) {
tbodyStr += '<tr>';
dataIndex.forEach(function (c) {
var renderere = c.renderer || defRenderer;
tbodyStr += '<td>' + renderere.call(r, r.get(c.dataIndex)) + '</td>'
});
tbodyStr += '</tr>'
});
tableStr = format(tableStr, {
thead: theadStr,
tbody: tbodyStr
});
tableToExcel(tableStr, fileName);
}
})();
function SetFormReadOnly(form, readOnly) {
var fields = form.getForm().getFields();
for (var i = 0, len = fields.length; i < len; i++) {
fields.items[i].setReadOnly(readOnly);
}
}
function BoxSelectgetStrValue(list) {
var _list = [];
for (var _i = 0; _i < list.length; _i++) {
_list.push("'" + list[_i] + "'");
}
return _list;
}
function getStoreFieldCount(store, fieldname) {
var _List = [];
for (var i = 0; i < store.getCount(); i += 1) {
var member = store.getAt(i);
var _fieldvalue = member.get(fieldname);
if (_List.indexOf(_fieldvalue) >= 0) {
} else {
_List.push(member.get(fieldname));
}
}
return _List.length;
}
function GetDirty (store1, Delstore1) {
var changelines = store1.getModifiedRecords();
var delcount = Delstore1.length;
var changecount = changelines.length;
if (delcount == 0 && changecount == 0)
{ return false; }
else { return true; }
}
function GetDirty1 (store1) {
var changelines = store1.getModifiedRecords();
if (changelines == 0)
{ return false; }
else { return true; }
}
//用于树型结构的父子节点联动
////
/** 递归遍历父节点 子节点有未选中的则父节点改为不选中**/
travelParentUnChecked = function (node, checkStatus, opts) {
//父节点
var upNode = node.parentNode;
if (upNode != null) {
var opts = {};
opts["isPassive"] = true;
//父节点当前选中状态
var upChecked = upNode.data.checked;
//选中状态,遍历父节点,判断有父节点下的子节点是否都全选
if (checkStatus) {
var allChecked = true;
//此时父节点不可能是选中状态
//如果有一个节点未选中,可以判断,当前父节点肯定是未选中状态,所以此时不必向上遍历
upNode.eachChild(function (child) {
if (!child.data.checked) {
allChecked = false;
return false;
}
});
upNode.set('checked', allChecked);
if (allChecked) {
travelParentUnChecked(upNode, allChecked, opts);
} else {//如果后台传递数据时,选择状态正确的话,此处不需要执行
//travelParentUnChecked(upNode, allChecked, opts);
}
} else {//未选中,让父节点全都 不选
if (upNode.data.checked) {
upNode.set('checked', checkStatus);
travelParentUnChecked(upNode, checkStatus, opts);
} else {
//travelParentUnChecked(upNode, allChecked, opts);
}
}
}
}
/** 递归遍历子节点,复选框 选中父节点时选中全部子节点**/
travelChildrenChecked = function (node, checkStatus, eOpts) {
var isLeaf = node.data.leaf;
if (!isLeaf) {
node.expand(false, function () {
if (eOpts["isPassive"] == null) {//主动点击
node.eachChild(function (child) {
child.set('checked', checkStatus);
travelChildrenChecked(child, checkStatus, eOpts);
//child.fireEvent('checkchange',child, checked);//不知什么原因,不起作用
});
}
});
}
node.set('checked', checkStatus);
}
/** 递归遍历父节点 子节点有 选中的 则父节点改为 选中**/
travelParentChecked = function (node, checkStatus, opts) {
//父节点
var upNode = node.parentNode;
if (upNode != null) {
var opts = {};
opts["isPassive"] = true;
//父节点当前选中状态
//var upChecked = upNode.data.checked;
//选中状态,遍历父节点,判断有父节点下的子节点是否有选中
if (checkStatus) {
upNode.set('checked', checkStatus);
travelParentChecked(upNode, checkStatus, opts);
} else {//未选中,如父节点下方没有选中项 才改为不选中;只要有一个子项选中即设置为选中
var allUnChecked = true;//
//此时父节点不可能是选中状态
//如果有一个节点未选中,可以判断,当前父节点肯定是未选中状态,所以此时不必向上遍历
upNode.eachChild(function (child) {
if (child.data.checked) {
allUnChecked = false;
return false;
}
});
upNode.set('checked', !allUnChecked);
if (allUnChecked) {
travelParentChecked(upNode, !allUnChecked, opts);
} else {//如果后台传递数据时,选择状态正确的话,此处不需要执行
//travelParentUnChecked(upNode, allChecked, opts);
}
}
}
}
getTreeLeafNodes = function (tree) {
return getNodes(tree.getRootNode(),null,true);
}
getNodes = function (node, NodeArr, isOnlyLeaf)///参数依次为 1-tree节点2-调用时直接传null3-传true表示只要叶du节点
{
//调用方式 var allLeafArr=getNodes(root,null,true);//root是tree根节点
var nodeArr;
if (!NodeArr) nodeArr = new Array();//没有传zhi递第二个参数时初始为新数组dao
else nodeArr = NodeArr;
if (node.data.leaf ) nodeArr.push(node);//如果是叶节点,加入数组
if (!node.childNodes || node.childNodes.length == 0) return nodeArr;//没有子节点,返回
for (var i = 0; i <= node.childNodes.length - 1; i++) {
getNodes(node.childNodes[i], nodeArr, isOnlyLeaf);//对每一个子节点进行递归调用将其中的叶节点添加到数组
}
return nodeArr;
}
//把List<string>转化成json
function ConvertStringListToJson(List) {
if (List.length == 0) {
return "";
}
var jsonData = "[";
for (i = 0; i < List.length; i++) {
jsonData += Ext.JSON.encode(List[i]) + ",";
}
if (jsonData != "[") {
jsonData = jsonData.substring(0, jsonData.length - 1) + "]";
}
else
jsonData = "";
return jsonData;
}