赞
踩
Ext.define('JsApp.com.Util', {
/**
*显示新建视图
* title:新建界面显示的标题
* xtype:新建界面的别名
*/
showCreatingView: function (title, xtype, maxorder, ordername) {
var me = this,
form = Ext.create({
xtype: xtype
});
if (maxorder != undefined && maxorder != null) {
form.getForm().findField(ordername).setValue(maxorder);
}
me.shrink.formType = 'create';
me.shrink.setConfig({
title: title,
iconCls: 'fa fa-user fa-lg'
}).animShow(form);
},
/**
*显示编辑视图
* record:编辑界面上的数据
* title:编辑界面上显示的标题
* xtype:编辑界面的别名
* datelist:时间控件
* radiolist:radio集合
*/
showEditingView: function (formType, record, title, xtype, uneditname, datelist, radiolist) {
var me = this,
form = Ext.create({
xtype: xtype
});
//Ext.Array.each(record.data, function (data) {
// for (var key in data) {
// if (key.indexOf('Amount') != -1) {
// data[key] = Ext.util.Format.number(data[key], '0,000.00');
// }
// }
//});
if (form.parentView == null) {
form.parentView = record;
}
form.loadRecord(record);
if (form.xtype == "contractmanageform") {
Ext.Array.each(form.items.items[0].items.items[1].items.items, function (items) {
if (items.xtype == "panel") {
Ext.Array.each(items.items.items, function (item) {
if (item.xtype == "combo") {
var store = item.store;
store.load({
callback: function (records, option, success) {
var data = record.data;
var code = item.name;
var name = code.replace('Code', 'Name');
form.getForm().findField(code).setValue(data[code]);
form.getForm().findField(code).setRawValue(data[name]);
}
});
}
});
}
});
}
if (uneditname != undefined) {
Ext.Array.each(uneditname, function (name) {
form.getForm().findField(name).addPlugin("formfielduneditable");
});
}
me.shrink.formType = formType;
me.shrink.setConfig({
title: title,
iconCls: 'fa fa-user'
}).animShow(form);
if (datelist != undefined) {
if (datelist.length > 0) {
Ext.Array.each(datelist, function (date) {
form.getForm().findField(date).setValue(me.renderDate(record.data[date]));
});
}
}
if (radiolist != undefined) {
if (radiolist.length > 0) {
Ext.Array.each(radiolist, function (radio) {
var radiofieldlist = form.query("radiofield[name=" + radio + "]");
Ext.Array.each(radiofieldlist, function (radiofield) {
if (radiofield.inputValue == (record.data[radio] == false ? 0 : 1)) {
radiofield.setValue(true);
}
});
});
}
}
},
/**
*显示查看视图
* record:编辑界面上的数据
* title:编辑界面上显示的标题
* xtype:编辑界面的别名
*/
showDetailView: function (record, title, xtype, width) {
var me = this,
form = Ext.create({
xtype: xtype
});
me.shrink.formType = 'detail';
form.loadRecord(record);
if (form.parentView == null) {
form.parentView = record;
}
if (width != null && width != undefined) {
form.width = width;
}
me.shrink.setConfig({
title: title,
iconCls: 'fa fa-user'
}).animShow(form);
},
/**
*显示查看视图
* record:编辑界面上的数据
* title:编辑界面上显示的标题
* xtype:编辑界面的别名
*/
showLeftDetailView: function (record, title, xtype, width) {
var me = this,
form = Ext.create({
xtype: xtype
});
me.shrinkleft.formType = 'detail';
form.loadRecord(record);
if (form.parentView == null) {
form.parentView = record;
}
if (width != null && width != undefined) {
form.width = width;
}
me.shrinkleft.setConfig({
title: title,
iconCls: 'fa fa-user'
}).animLeftShow(form);
},
/**
*删除数据
* url:删除数据地址
* params:传递的参数
* store:界面上的数据存储库
*/
deleteRecords: function (url, params, store) {
var me = this;
Ext.Ajax.request({
url: url,
params: params,
success: function (response, opts) {
response = Ext.JSON.decode(response.responseText);
if (response.success) {
me.shrink.hide();
me.toastNo(response.msg);
}
else {
me.toastNo(response.msg);
}
store.reload();
},
failure: function (response, opts) {
me.toastNo('操作失败');
}
});
},
/**
*刷新界面
* emptyname:清空的插叙数据框
* store:界面上的数据存储库
* filtername:需要过滤的字段
*/
viewRefresh: function (store, emptyname, filtername) {
var me = this,
refs = me.getReferences(),
paramHold = store.paramHold;
Ext.Array.each(emptyname, function (name) {
refs[name].setValue('');
});
paramHold && paramHold.clear();
if (filtername != undefined && filtername != null) {
Ext.Array.each(filtername, function (name) {
paramHold.params[name] = refs[name].getValue();
});
}
store.loadPage(1);
},
/**
*刷新grid界面
* emptyname:清空的插叙数据框
* store:界面上的数据存储库
*/
gridViewRefresh: function () {
var me = this,
items = me.view.header.items.items,
store = me.view.store,
paramHold = store.paramHold;
Ext.Array.each(items, function (item) {
if (item.xtype == "combo" || item.xtype == "textfield") {
item.setValue('')
}
});
paramHold && paramHold.clear();
store.loadPage(1);
},
/*
* 查询
* page:页数
* params:查询参数
* store:数据存储库
*/
search: function (page, params, store) {
var me = this,
paramHold = store.paramHold;
if (paramHold != undefined) {
paramHold.clear();
}
//else {
// paramHold = new Array();
//}
if (Ext.isObject(page)) {
params = page;
page = store.currentPage;
}
if (!Ext.isNumber(page)) {
page = store.currentPage;
}
params = params || {};
if (paramHold != undefined) {
paramHold.add(params);
}
else {
store.getProxy().extraParams = params;
}
store.loadPage(page);
},
/*
* 动态给grid增加数据
* store:表单中的数据存储库
* dataname:store中的显示字段
* model:显示字段的映射规则
*/
addgriddata: function (store, dataname, model) {
store.add(Ext.create(model, dataname));
},
/*
* 验证grid中的数据
* form:表单界面
* store:表单中的动态添加的数据存储库
* fields:grid中的列表列名称
* cells:grid中的列表列号
* grid:列表
*/
griddatavalidation: function (form, store, fields, cells, grid) {
var items = store.data.items;
if (form != null) {
if (!form.isValid()) {
return false;
}
}
for (var i = 0; i < items.length; i++) {
for (var j = 0; j < fields.length; j++) {
var name = items[i].data[fields[j]];
if ((name == "" && parseInt(name) != 0)|| name == undefined) {
grid.getView().getCell(i, cells[j]).style.backgroundColor = '#ffb3a7';
return false;
}
}
}
return true;
},
/*
* 收集grid中的数据
* store:数据存储仓库
* fields:需要整理的数据名称
*/
griddatacollection: function (store, fields) {
var me = this,
items = store.data.items,
list = new Array();
for (var i = 0; i < items.length; i++) {
var data = {};
var sign = 0;
for (var j = 0; j < fields.length; j++) {
var name = items[i].data[fields[j]];
if (name == "NaN") {
data[fields[j]] = 0;
}
else {
data[fields[j]] = name;
}
sign = 1;
}
if (sign != 0) {
list.push(data);
}
}
return list;
},
/**
* 整合store中的数据
* store:参数存储库
* items:列表集合
* names:不做对比的列名称
*/
verificationStore: function (store, items, names) {
for (var i = 0; i < store.data.items.length; i++) {
var item = items[i];
var characteristic = 0;
for (var name in item.data) {
if (names.join('-').indexOf(name) == -1) {
if (item.data[name] != "") {
characteristic = 1;
}
}
}
if (characteristic == 0) {
store.remove(item);
--i;
}
}
return store;
},
/*
* 跳转回父级界面
* controller:控制器
* record:父级界面需要显示的数据
* formview:父级界面的别名
* title:标题
*/
showParentView: function (controller, record, formview, title) {
var me = controller,
form = Ext.create({
xtype: formview
});
form.loadRecord(record);
form.parentView = record;
me.shrink.setConfig({
title: title,
iconCls: 'fa fa-user'
}).animShow(form);
},
/**
* 数据赋值
* View:需要赋值的视图
* Names:需要赋值的字段名称
* Data:赋值的数据
* unEditableNames:不可编辑的字段名称
* EditableNames:可编辑的字段名称
*/
windowAssignment: function (View, Names, Data, unEditableNames, editableNames) {
Ext.Array.each(Names, function (name) {
View.query('textfield[name = ' + name + ']')[0].setValue(Data[name]);
});
Ext.Array.each(unEditableNames, function (unEditableName) {
View.query('textfield[name = ' + unEditableName + ']')[0].setEditable(false);
});
Ext.Array.each(editableNames, function (editableName) {
View.query('textfield[name = ' + editableName + ']')[0].setEditable(true);
});
},
/**
* 对列表界面上的数据进行调整显示
* value:需要格式化显示的数据
*/
showData: function (value) {
if (value != null) {
var datas = value.split(',');
var _html = "";
var length = datas.length - 1;
if (length > 5) {
length = 5;
}
for (var i = 0; i < length; i++) {
_html += datas[i] + "</br>";
}
if (datas.length > 5) {
_html = _html + "...";
}
else {
_html = _html.substring(0, _html.length - 5);
}
return _html;
}
else {
return "";
}
},
/**
* 使用post方法导出
* obj.Url:导出的链接地址
* obj.PostParams:导出数据的参数
*/
downloadbypost: function (obj) {
var me = this,
fileUri = obj.Url,
arrParams = obj.PostParams,
path = Ext.getPath(obj.Url),
oIpt;
if (me.isNullOrWhiteSpace(fileUri)) {
return;
}
//创建一个form元素
var oForm = document.createElement("form");
oForm.id = "forPost";
oForm.method = "post";
oForm.action = path;
oForm.target = "_self";
for (var tmpName in arrParams) {
oIpt = document.createElement("input");
oIpt.type = "hidden";
oIpt.name = tmpName;
oIpt.value = arrParams[tmpName];
oForm.appendChild(oIpt);
}
document.body.appendChild(oForm);
oForm.submit();
//删除创建的form
var oOldFrm = document.getElementById("forPost");
if (oOldFrm) {
document.body.removeChild(oOldFrm);
}
},
/**
* 数据导出
* store:界面store
* visibleColumns:需要导出的列
* columns:界面上的所有列
* identifier:界面标识
* title:导出名称
*/
Export: function (store, visibleColumns, columns, title, url) {
var me = this;
for (var i = 0; i < columns.length; i++) {
var item = columns[i];
if (!item.isHidden() && item.text != '操作') {
visibleColumns[item.dataIndex] = item.text;
}
}
//store.paramHold.params.identifier = identifier;
store.paramHold.params.filename = title + Ext.Date.format(new Date(), 'Y-m-d') + ".xls";
store.paramHold.params.columns = JSON.stringify(visibleColumns);
me.downloadbypost({ Url: url, PostParams: store.paramHold.params });
},
/**
* 数据时间格式化
*/
getDate: function (value) {
var time = value;
//如果时间格式为"2018-02-02 00:00:00"格式的话,返回日期;
//如果时间格式为"2018-02-02T00:00:00"格式的话,返回日期;
//if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/.test(value) || /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(value)) {
if (/^\d{4}-\d{2}-\d{2}T|\s\d{2}:\d{2}:\d{2}(?:\.\d{1,2})?$/.test(value)) {
value = value.replace(/-/g, "/");
value = value.replace("T", " ");
value = value.split('.')[0];
time = new Date(value);
}
//如果时间格式为"/Date(1517846400000)/"格式的话,返回日期;
else if (Ext.isMSDate(value)) {
var minValue = -62135596800000;
var currentDate = parseInt(value.slice(6));
if (minValue == currentDate) {
return "";
}
time = new Date(currentDate);
}
//其他情况不处理,直接返回;
else {
return value;
}
return time;
},
/**
* 渲染日期.如果是最小时间,则认为不是有效值
* @param {string} value 头像地址.
*/
renderDate: function (value) {
if (value != "" && value != null) {
var time = this.getDate(value);
return Ext.Date.format(time, 'Y-m-d');
}
},
//将数据转换为时间格式。
renderDateTime: function (value) {
var time = this.getDate(value);
return Ext.Date.format(time, 'Y-m-d H:i:s');
},
/**
* 判断上传附件是否符合要求
* value:上传附件名称
* suffixpararms:设置的可上传附件的类型
*/
complianceSuffix: function (value, suffixpararms) {
var fileFormat = /\.[a-zA-Z]+$/.exec(value)[0].substring(1);
var compliance = suffixpararms.join('-').indexOf(fileFormat);
if (compliance != -1) {
return true;
}
else {
return false;
}
},
//ie8中getElementsByClassName返回单个obj
getElementsByClassName: function (dom, referenceClassname) {
var Elements = dom.getElementsByTagName('*');
for (var i = 0; i < Elements.length; i++) {
var classname = Elements[i].className;
if (classname.indexOf(referenceClassname) != -1) {
return Elements[i];
}
}
},
//ie8中getElementsByClassName返回集合
getElementsByClassNameList: function (dom, referenceClassname) {
var Result = [];
var Elements = dom.getElementsByTagName('*');
for (var i = 0; i < Elements.length; i++) {
var classname = Elements[i].className;
if (classname.indexOf(referenceClassname) != -1) {
Result.push(Elements[i]);
}
}
return Result;
},
//判断是否是ie浏览器并返回ie版本
ieVersion: function () {
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
if (isIE) {
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if (fIEVersion == 7) {
return 7;
} else if (fIEVersion == 8) {
return 8;
} else if (fIEVersion == 9) {
return 9;
} else if (fIEVersion == 10) {
return 10;
} else {
return 6;//IE版本<=7
}
} else if (isEdge) {
return 'edge';//edge
} else if (isIE11) {
return 11; //IE11
} else {
return -1;//不是ie浏览器
}
},
//显示高级筛选界面
showFilterView: function (view, header) {
var me = this,
storename = header.findParentByType('grid').store.id;
document.activeElement.blur();
if (me.shrink.storename != storename) {
view.getForm().reset();
}
me.shrink.storename = storename;
me.shrinkFilter.animShow(view);
},
//高级筛选界面重置
resetingFilter: function () {
var me = this,
storename = me.shrink.storename,
store = Ext.StoreManager.get(storename),
paramHold = store.paramHold,
form = me.getView().getForm();
form.reset();
paramHold.clear();
},
//高级筛选界面查询
okFilter: function (e) {
if (e.keyCode == Ext.EventObjectImpl.ENTER || e.keyCode == undefined || e.keyCode == 0) {
var me = this,
storename = me.shrink.storename;
me.filter(storename);
me.shrinkFilter.hide();
}
},
//高级筛选
filter: function (storename) {
var me = this,
store = Ext.StoreManager.get(storename),
form = me.getView().getForm(),
paramHold = store.paramHold,
values = form.getValues();
if (paramHold != undefined && paramHold.params['operationState'] != undefined && paramHold.params['operationState'] != null) {
values['operationState'] = paramHold.params['operationState'];
}
me.search(1, values, store);
},
//行编辑
showFormOrDetailView: function (grid, record, name, uneditname, datelist, radiolist) {
var me = this;
if (!me.shrink.executed && me.shrink.executed != undefined && me.shrink.executed != null) {
if (me.shrink.formType == "detail" && me.shrink.name==name) {
me.showDetailView(record, me.shrink.titlename, me.shrink.name)
}
if (me.shrink.formType == "edit" && me.shrink.name == name) {
me.showEditingView("edit", record, me.shrink.titlename, me.shrink.name, uneditname, datelist, radiolist);
}
}
else {
me.shrink.executed = false;
return true;
}
}
});
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。