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/MsOpFenDetail/MsOpFenDetailIndex.js

1072 lines
45 KiB
JavaScript

2 years ago
Ext.namespace('Shipping');//创建用于范围变量和类的命名空间,指定的最后一个节点的命名空间隐式创建的所有其他节点
Shipping.MsOpFenDetailIndex = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.Shipping.MsOpFenDetailIndex.superclass.constructor.call(this);
};
var _this;//当前实例
Ext.extend(Shipping.MsOpFenDetailIndex, Ext.Panel, {
NowIndex:0,
OprationStatus: null, //仅当弹出界面时使用
SelectedRecord: null,
initUIComponents: function () {
this.bsnoNum = null,
this.toolBarItems = [
{
text: "新增",
iconCls: "btnadd",
handler: function (button, event) {
this.addDetail();
},
scope: this
}, '-', {
text: "删除",
iconCls: "btndelete",
handler: function (button, event) {
this.onDeleteClick(button, event);
},
scope: this
}, '-', {
text: "保存",
iconCls: "btnsave",
handler: function (button, event) {
this.onPostDetailClick(button, event);
},
scope: this
}, '-', {
text: "查询",
iconCls: "btnsearch",
handler: function (button, event) {
this.onRefreshClick(button, event);
},
scope: this
}, '-', {
text: "分箱",
iconCls: "fenxiang",
handler: function (button, event) {
this.onFenXiangClick(button, event);
},
scope: this
}, '-', {
text: "导入",
iconCls: "openfolder",
handler: function (button, event) {
this.onImportClick(button, event);
},
scope: this
}];
this.toolBar = new Ext.Toolbar({
items: this.toolBarItems
});
this.GridCheckBoxModel = Ext.create('Ext.selection.CheckboxModel');
this.storeList = Ext.create('Ext.data.Store',
{
model: 'MsOpFenDetail',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/MvcShipping/MsOpFenDetail/GetList',
reader: {
id: 'GID',
root: 'data',
totalProperty: 'totalCount'
}
}
});
this.storeList_1 = Ext.create('Ext.data.Store',
{
model: 'MsOpFenDetail',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/MvcShipping/MsOpFenDetail/GetList',
reader: {
id: 'GID',
root: 'data',
totalProperty: 'totalCount'
}
}
});
this.gridListCellEditing = Ext.create('Ext.grid.plugin.CellEditing',
{
clicksToEdit: 1
});
this.gridList = new Ext.grid.GridPanel({
store: this.storeList,
enableHdMenu: false,
region: 'center',
loadMask: { msg: "数据加载中,请稍等..." },
plugins: [this.gridListCellEditing],
trackMouseOver: true,
disableSelection: false,
selType: 'cellmodel',
selModel: this.GridCheckBoxModel,
columns: [
{
sortable: true,
dataIndex: 'GID',
header: '主键',
hidden: true
},
{
header: '序号',
width: 50,
sortable: true,
renderer: function (value, metadata, record, rowIndex) {
return rowIndex + 1; // 获取序号方法2
}
},
{
sortable: true,
dataIndex: 'COILNO',
header: '批次号',
width: 160,
editor: {
xtype: 'textfield',
selectOnFocus: true
}
}, {
sortable: true,
dataIndex: 'SIZE',
header: '规格',
width: 100,
editor: {
xtype: 'textfield',
selectOnFocus: true
}
}, {
sortable: true,
dataIndex: 'COLOUR',
header: '颜色',
width: 160,
editor: {
xtype: 'textfield',
selectOnFocus: true
}
}, {
sortable: true,
dataIndex: 'NWKGS',
header: '净重',
width: 160,
xtype: 'numbercolumn',
renderer: function (value) {
return Ext.util.Format.number(value, '0.0000');;
},
editor: {
xtype: 'numberfield',
selectOnFocus: true,
allowDecimals: true,
decimalPrecision: 3
}
}, {
sortable: true,
dataIndex: 'GWKGS',
header: '毛重',
width: 160,
xtype: 'numbercolumn',
renderer: function (value) {
return Ext.util.Format.number(value, '0.0000');;
},
editor: {
xtype: 'numberfield',
selectOnFocus: true,
allowDecimals: true,
decimalPrecision: 3
}
}, {
sortable: true,
dataIndex: 'NLENGTH',
header: '长度',
width: 160,
editor: {
xtype: 'numberfield',
selectOnFocus: true,
allowDecimals: true,
decimalPrecision: 0
}
}
]
});
this.gridList_1 = new Ext.grid.GridPanel({
store: this.storeList_1,
id:'grid_1',
enableHdMenu: false,
region: 'center',
loadMask: { msg: "数据加载中,请稍等..." },
trackMouseOver: true,
disableSelection: true,
selType: 'cellmodel',
columns: [
{
sortable: true,
dataIndex: 'GID',
header: '主键',
hidden: true
},
{
header: '序号',
width: 50,
sortable: true,
renderer: function (value, metadata, record, rowIndex) {
return rowIndex + 1; // 获取序号方法2
},
align: 'center'
},
{
sortable: true,
dataIndex: 'FXCOLNO',
header: '业务编号',
width: 120,
align:'center'
},
{
sortable: true,
dataIndex: 'COILNO',
header: '批次号',
width: 120,
align: 'center'
}, {
sortable: true,
dataIndex: 'SIZE',
header: '规格',
width: 120,
align: 'center'
}, {
sortable: true,
dataIndex: 'COLOUR',
header: '颜色',
width: 120,
align: 'center'
}, {
sortable: true,
dataIndex: 'FXNO',
header: '分箱编号',
width: 80,
align: 'center'
}, {
sortable: true,
dataIndex: 'NWKGS',
header: '净重',
width: 80,
xtype: 'numbercolumn',
renderer: function (value) {
return Ext.util.Format.number(value, '0.0000');;
},
align: 'center'
}, {
sortable: true,
dataIndex: 'GWKGS',
header: '毛重',
width: 80,
xtype: 'numbercolumn',
renderer: function (value) {
return Ext.util.Format.number(value, '0.0000');;
},
align: 'center'
}, {
sortable: true,
dataIndex: 'TGKGS',
header: '标签毛重',
width: 80,
xtype: 'numbercolumn',
align: 'center'
},{
sortable: true,
dataIndex: 'NLENGTH',
header: '长度',
width: 80,
align: 'center'
}, {
dataIndex: null,
header: '件数',
width: 60,
align: 'center'
}, {
dataIndex: null,
header: '毛重(kg)',
width: 80,
align: 'center'
}, {
dataIndex: null,
header: '箱号',
width: 80,
align: 'center'
}, {
dataIndex: null,
header: '铅封号',
width: 80,
align: 'center'
}, {
dataIndex: null,
header: '箱皮重',
width: 80,
align: 'center'
}
]
});
this.panelBtn = new Ext.Panel({
region: "north",
tbar: this.toolBar
});
this.panelTop = new Ext.Panel({
layout: "border",
region: "north",
height: 30,
items: [this.panelBtn]
});
this.panelCtn = new Ext.Panel({
layout: "border",
title: '鼎世钢卷(未分箱)',
id: 'pnlctn',
region: "center",
items: [this.gridList],
listeners: {
activate: function () {
_this.NowIndex = 0;
_this.onRefreshClick();
//动态修改tbar
_this.toolBar.removeAll(false);
_this.toolBar.add(_this.toolBarItems);
}
}
});
this.panelCtn_1 = new Ext.Panel({
layout: "border",
title: '鼎世钢卷(已分箱)',
id: 'pnlctn_1',
region: "center",
items: [this.gridList_1],
listeners: {
activate: function () {
_this.NowIndex = 1;
_this.onRefreshClick();
_this.toolBar.removeAll(false);
//动态修改tbar
_this.toolBar.add([{
text: "查询",
iconCls: "btnsearch",
handler: function (button, event) {
_this.onRefreshClick(button, event);
},
scope: this
},'-',{
id: "exportBtn",
text: "导出",
iconCls: "download",
handler: function (button, event) {
_this.onExportClick(button, event);
},
scope: this
}, '-',{
id: "exportBtn_11",
text: "历史导出",
iconCls: "download",
handler: function (button, event) {
_this.onHistoryExportClick(button, event);
},
scope: this
}]);
}
}
});
this.MainCenter = new Ext.TabPanel({
activeTab: 0,
autoWidth: true,
border: true,
frame: false,
region: 'center',
enableTabScroll: true,
items:
[
this.panelCtn, this.panelCtn_1
]
});
Ext.apply(this,{items: [this.panelTop, this.MainCenter]});
this.storeList.on('beforeload',
function (store) {
var sql = this.getCondition();
Ext.apply(store.proxy.extraParams, { condition: sql, sort: '' });
},
this);
this.storeList_1.on('beforeload',
function (store) {
var sql = this.getCondition();
Ext.apply(store.proxy.extraParams, { condition: sql, sort: '' });
},this);
this.onRefreshClick();
this.gridList_1.getStore().on('load',
function () {
_this.MerginCells(_this.gridList_1, [6], true);
},this);
_this = this;
},
onRefreshClick: function (button, event) {
this.bsnoNum = null;//初始化
var sql = this.getCondition();
if (this.NowIndex == 0) {
this.storeList.load({
params: { start: 0, limit: 1000, sort: '', condition: sql },
waitMsg: "正在查询数据...",
scope: this
});
} else {
this.storeList_1.load({
params: { start: 0, limit: 1000, sort: '', condition: sql },
waitMsg: "正在查询数据...",
scope: this
});
}
}, //查询
getCondition: function () { //拼sql语句 查询条件
var sqlstr = " FXMARK='" + this.NowIndex + "' AND IOMARK='0'";
if (this.bsnoNum != null)
sqlstr = " FXCOLNO='" + this.bsnoNum +"' AND IOMARK='1'";
return sqlstr;
}, //拼sql语句
addDetail: function () {
var record = Ext.create('MsOpFenDetail', {
GID: '',
COILNO: '',
SIZE: '',
COLOUR: '',
NWKGS: '0.00',
GWKGS: '0.00',
NLENGTH: '',
TGKGS: '0.00',
FXNO: '',
XMODEL: '',
LIKGS: '0.00',
FXMARK: '0',
IOMARK:'0',
FXCOLNO: '',
OPERUSER:'',
OPERTIME:new Date()
});
this.storeList.add(record);
var n = this.storeList.getCount();
this.gridListCellEditing.startEditByPosition({ row: n - 1, column: 1 });
},//新增
onDeleteClick: function (button, event) {
var selections = this.gridList.getSelectionModel().getSelection();
if (selections.length == 0) {
Ext.Msg.show({ title: '提示', msg: '请先选择单据!', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK });
return;
}
var record = [];
for(var item in selections) if (selections.hasOwnProperty(item)) record.push(selections[item].data);
Ext.MessageBox.confirm('提示', '确定删除该记录吗?', function (btn) {
if (btn === 'yes') {
Ext.Msg.wait('正在删除数据...');
Ext.Ajax.request({
waitMsg: '正在删除数据...',
url: '/MvcShipping/MsOpFenDetail/Delete',
params: {
data: Ext.JSON.encode(record)
},
callback: function (options, success, response) {
if (success) {
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) {
this.storeList.remove(selections);
Ext.Msg.hide();
}
else {
Ext.Msg.show({ title: '错误', msg: jsonresult.Message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK });
}
}
},
failure: function (response, options) {
Ext.Msg.show({ title: '警告', msg: '服务器响应出错,请重试', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK });
},
success: function (response, options) {
},
scope: this
});
}
}, this);
},//删除
onPostDetailClick: function (button, event) {
var bodyDrChFeeDatas = [];
for (var i = 0; i < this.storeList.getCount(); i += 1) {
var memberyf = this.storeList.getAt(i);
bodyDrChFeeDatas.push(memberyf);
};
var jsonChFeeBody = ConvertGIDRecordsToJson(bodyDrChFeeDatas);
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/MvcShipping/MsOpFenDetail/Save',
scope: this,
params: {
body: jsonChFeeBody
},
callback: function (options, success, response) {
if (success) {
Ext.MessageBox.hide();
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) {
this.onRefreshClick();
} 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
});
}
}
});
},//保存
onFenXiangClick: function (button, event) {
var selections = this.GridCheckBoxModel.getSelection();
if (selections.length > 0) {
if (Ext.get("optionWin") == null) {
this.storeCtn = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsShipping.ux.CodeCtnModel',
proxy: { url: '/CommMng/BasicDataRef/GetCodeCtnList' }
});
this.storeCtn.load();
var limitWeight = Ext.create('Ext.form.field.Number',
{
region: "north",
margins: '6 12 6 12',
name: 'LIKGS',
fieldLabel: "限重",
labelAlign: 'right',
labelWidth: 30,
//value: 18.000,
maxValue: 100000,
width: 180,
minValue: 0,
allowDecimals: true,
decimalPrecision: 3
}); //限重
var comboxCtn = Ext.create('DsExt.ux.RefTableCombox',
{
id:"ctnCombo",
region: "north",
store: this.storeCtn,
margins: '12 12 6 12',
forceSelection: true,
fieldLabel: '箱型',
labelAlign: 'right',
labelWidth: 30,
name: 'XMODEL',
valueField: 'DLIKGS',//默认限重
displayField: 'CTN',
listeners: {
afterRender: function (combo) {
this.getStore().on("load", function (s, r, o) {
comboxCtn.setValue(r[5].get('DLIKGS'));//第一个值
});
},
change: function(obj,value) {
limitWeight.setValue(value);
}
}
}); //箱型
var buttonCtn = Ext.create('Ext.Button',
{
text: '确认分箱',
renderTo: Ext.getBody(),
region: "south",
margins: '6 12 6 12',
handler: function() {
//Ajax分箱处理
var record = [];
for (var item in selections) if (selections.hasOwnProperty(item)) record.push(selections[item].data);
Ext.Msg.wait('正在做分箱处理...');
Ext.Ajax.request({
waitMsg: '正在分箱...',
url: '/MvcShipping/MsOpFenDetail/FenXiangOpera',
params: {
data: Ext.JSON.encode(record),
limit: limitWeight.getValue(),
xmodel: comboxCtn.getDisplayValue()
},
callback: function (options, success, response) {
if (success) {
var jsonresult = Ext.JSON.decode(response.responseText);
//成功
if (jsonresult.Success) {
//关闭提示框
Ext.Msg.close();
//关闭分箱窗体
Ext.getCmp("optionWin").close();
//切换到已分箱Tab页
_this.MainCenter.setActiveTab("pnlctn_1");
}
//异常
else {
Ext.Msg.show({
title: '错误',
msg: jsonresult.Message,
icon: Ext.Msg.ERROR,
buttons: Ext.Msg.ERROR
});
}
}
},
failure: function (response, options) {
Ext.Msg.show({ title: '警告', msg: '服务器响应出错,请重试', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK });
},
success: function (response, options) {
},
scope: this
});
}
}); //确认分箱
var layerPanel = new Ext.Panel({
layout: "border",
width: 200,
height: 160,
id: 'pnlctn_11',
region: "center",
items: [comboxCtn, limitWeight, buttonCtn]
});
var win = Ext.create('Ext.window.Window',
{
title: '分箱',
layout: 'fit',
id: 'optionWin',
draggable: true, //拖动
x: event.clientX,
y: event.clientY,
resizable: false,
items: { // Let's put an empty grid in just to illustrate fit layout
xtype: 'panel',
border: true,
items: [layerPanel]
}
});
win.show();
} //弹层判断
} //获取选中项
else {
Ext.Msg.show({
title: '缺少必要操作',
msg: '请先选择要分箱的钢卷'
});
}
},//分箱
onImportClick: function (button, event) {
if (Ext.get("importWin") == null) {
var upform = Ext.create('Ext.form.Panel', {
width: 500,
bodyPadding: '6 6 6 6',
id: "upform",
defaults: {
anchor: '100%',
allowBlank: false,
msgTarget: 'side',
labelWidth: 100
},
items: [{
xtype: 'filefield',
id: 'form-file',
emptyText: '请选择文件',
fieldLabel: '文件路径',
name: 'file',
buttonText: '浏览',
regex: /^.+\.(xls|xlsx)$/,
regexText: "只能选择xls|xlsx格式的文件",
buttonConfig: {
iconCls: 'upload-icon'
}
}],
buttons: [{
text: '开始导入',
handler: function () {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
method: 'post',
url: '/mvcshipping/msopfendetail/FileUpload',
waitMsg: '正在上传您的文件,请耐心等候...',
success: function (form, action) {
_this.storeList.add(eval(action.result.data));
Ext.getCmp("importWin").close();
Ext.Msg.alert("提示信息", "导入成功!");
},
failure: function (form, action) {
Ext.Msg.alert("提示信息", "导入失败,请重试!");
}
});
}
}
}, {
text: '重置',
handler: function () {
this.up('form').getForm().reset();
}
}]
});
var win = Ext.create('Ext.window.Window',
{
title: '导入文件',
layout: 'fit',
id: 'importWin',
draggable: true, //拖动
x: event.clientX,
y: event.clientY,
resizable: false,
items: {
xtype: 'panel',
border: true,
items: [upform]
}
});
win.show();
}
},//导入
onExportClick: function (button, event) {
var downTab = Ext.getDom("grid_1").getElementsByTagName('table')[0].cloneNode(true);//深度克隆对象,克隆节点以及节点下面的子内容
var columns = ["", "序号", "业务编号", "批次号", "规格", "颜色", "分箱编号", "净重", "毛重", "标签毛重", "长度", "件数", "毛重(kg)", "箱号", "铅封号", "箱皮重"];
var colnRow = downTab.rows[0].cloneNode(true);//克隆空行
var insertArry = [];//分箱件数数组
var gweightArry = [];//分箱毛重数组
var gwTotal = 0.000;//当前总毛重
var ctTotal = 0;//当前总件数
//增加表头
for (var i = 0; i < columns.length; i++)
downTab.rows[0].cells[i].innerHTML = columns[i];
//移除隐藏的cell
var elementsByClassName = downTab.getElementsByClassName("hiddenTd");
for (var k = elementsByClassName.length-1; k >= 0; k--)
elementsByClassName[k].parentNode.removeChild(elementsByClassName[k]);
//加总计行、加颜色处理、加小数格式处理
for (var j = 0; j < downTab.rows.length; j++) {
downTab.rows[j].cells[1].style.textAlign = "center";//排序列
downTab.rows[j].cells[2].style.textAlign = "center";//业务编号列
downTab.rows[j].cells[3].style.textAlign = "center";//批次列
downTab.rows[j].cells[4].style.textAlign = "center";//规格列
var colCellObj = downTab.rows[j].cells[5];//COLOUR 列
colCellObj.style.textAlign = "center";
var rowCellObj = downTab.rows[j].cells[6];//分箱列
//* 被合并的行的列索引【列索引 - 1】
var nwCellObj = downTab.rows[j].cells[6];//净重
var gwCellObj = downTab.rows[j].cells[7];//毛重
var tgCellObj = downTab.rows[j].cells[8];//标签毛重
var leCellObj = downTab.rows[j].cells[9];//长度
var ctCellObj = downTab.rows[j].cells[10];//件数
var zwCellObj = downTab.rows[j].cells[11];//总毛重
if (rowCellObj.hasAttribute('rowspan')) {
if (j !== 1) {
insertArry.push(ctTotal);
gweightArry.push(gwTotal);
gwTotal = 0.000;//初始化总毛重
ctTotal = 0;//初始化总件数
}
//修正 rowspan 列索引
nwCellObj = downTab.rows[j].cells[7];//净重
gwCellObj = downTab.rows[j].cells[8];//毛重
tgCellObj = downTab.rows[j].cells[9];//标签毛重
leCellObj = downTab.rows[j].cells[10];//长度
ctCellObj = downTab.rows[j].cells[11];//件数
zwCellObj = downTab.rows[j].cells[12];//总毛重
}
//去掉td中的div
nwCellObj.innerHTML = nwCellObj.innerText;//净重
gwCellObj.innerHTML = gwCellObj.innerText;//毛重
tgCellObj.innerHTML = tgCellObj.innerText;//标签
zwCellObj.innerHTML = zwCellObj.innerText;//总毛
leCellObj.innerHTML = leCellObj.innerText;//长度
ctCellObj.innerHTML = ctCellObj.innerText;//件数
//小数保留3位
nwCellObj.className += ' numcell';//净重
gwCellObj.className += ' numcell';//毛重
tgCellObj.className += ' numcell';//标签毛重
zwCellObj.className += ' numcell';//总毛重
//保留整数
leCellObj.className += ' intcell';//长度
ctCellObj.className += ' intcell';//件数
//累加毛重
gwTotal += j === 0 ? 0 : parseFloat(gwCellObj.innerText);
ctTotal += j === 0 ? 0 : 1;
switch (colCellObj.innerText) {
case "MAROON RED":
colCellObj.style.color = "#D20000";
break;
case "RED MERAPI":
colCellObj.style.color = "#984806";
break;
case "GREEN":
colCellObj.style.color = "#00B050";
break;
default:
colCellObj.style.color = "#000";
break;
}
}
//最后一组分箱数据
insertArry.push(ctTotal);//件数
gweightArry.push(gwTotal);//毛重
var rowIndex = 0;//统计行索引
var ctTotalS = 0;//批次总件数
var gwTotalS = 0.000;//批次总毛重
for (var l = 0; l < insertArry.length; l++) {
var ncolnRow = colnRow.cloneNode(true);//再次克隆节点
rowIndex += insertArry[l]+1;
downTab.childNodes[0].insertBefore(ncolnRow, downTab.rows[rowIndex]);//downTab.childNodes[0]==(tbody)
downTab.rows[rowIndex].cells[10].innerText = "单箱小计:";
downTab.rows[rowIndex].cells[10].style.textAlign = "right";
//计算总件数
downTab.rows[rowIndex].cells[11].innerText = insertArry[l];
//计算总毛重
downTab.rows[rowIndex].cells[12].innerText = gweightArry[l];
ctTotalS += insertArry[l];
gwTotalS += gweightArry[l];
}
//添加总计行
downTab.childNodes[0].appendChild(colnRow);
downTab.rows[downTab.rows.length - 1].cells[10].innerText = "合计:";
downTab.rows[downTab.rows.length - 1].cells[10].style.textAlign = "right";
downTab.rows[downTab.rows.length - 1].cells[11].innerText = ctTotalS;
downTab.rows[downTab.rows.length - 1].cells[12].innerText = gwTotalS;
// 使用outerHTML属性获取整个table元素的HTML代码包括<table>标签然后包装成一个完整的HTML文档设置charset为urf-8以防止中文乱码
var html ="<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel'><meta charset='utf-8' />";
html += "<!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>Sheet1</x:Name>";
html +="<x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->";
html +="<style>body{border:.5pt solid #ccc;}td{color:black;border:.5pt solid #999;height:14pt}tr{height:14pt}.numcell{mso-number-format:'0\.000_\)\;\[Red\]\\\(0\.000\\\)'}.intcell{mso-number-format:'0_\)\;\[Red\]\\\(0\\\)'}</style>";
html += "<body>" + downTab.outerHTML + "</body></html>";
// 实例化一个Blob对象其构造函数的第一个参数是包含文件内容的数组第二个参数是包含文件类型属性的对象
var blob = new Blob([html], { type: "application/vnd.ms-excel" });
var a = document.createElement("a");
// 利用URL.createObjectURL()方法为a元素生成blob URL
a.href = URL.createObjectURL(blob);
// 设置文件名目前只有Chrome和FireFox支持此属性
try {
var bsno = _this.storeList_1.data.items[0].raw.FXCOLNO;
a.download = "鼎世钢卷分箱_" + bsno + ".xls";
//更新导出标记
if (_this.storeList_1.data.items[0].raw.IOMARK === 0) {//未导出过时更新标记
Ext.Ajax.request({
url: '/MvcShipping/MsOpFenDetail/UpdateImport',
scope: this,
params: { bsno: bsno }
});
}
} catch (e) {
Ext.Msg.alert("错误信息", "信息有误!");
} finally {
//iE不兼容问题
if (navigator.appVersion.toString().indexOf('.NET') > 0)
window.navigator.msSaveBlob(blob, a.download);
else {
a.click();
}
}
},//导出
onHistoryExportClick: function(button, even) {
if (Ext.get("optionWin") == null) {
this.storeCtn_1 = Ext.create('DsExt.ux.RefTableStore', {
model: 'MsOpFenDetail',
proxy: { url: '/MvcShipping/MsOpFenDetail/GetListAll' }
});
this.storeCtn_1.load();
var comboxCtn = Ext.create('DsExt.ux.RefTableCombox',
{
id: "ctnCombo_bsno",
region: "north",
store: this.storeCtn_1,
margins: '12 12 6 12',
forceSelection: true,
fieldLabel: '业务编号',
labelAlign: 'right',
labelWidth: 60,
name: 'FXCOLNO',
valueField: 'FXCOLNO',
displayField: 'FXCOLNO',
listeners: {
afterRender: function (combo) {
this.getStore().on("load", function (s, r, o) {
comboxCtn.setValue(r[0].get('FXCOLNO'));//第一个值
});
}
}
}); //业务编号
var buttonCtn = Ext.create('Ext.Button',
{
text: '查看',
renderTo: Ext.getBody(),
region: "south",
margins: '6 12 6 12',
handler: function () {
_this.bsnoNum = comboxCtn.getValue();//公共变量-业务编号赋值
var sql = _this.getCondition();
_this.storeList_1.load({
params: { start: 0, limit: 1000, sort: '', condition: sql },
waitMsg: "正在查询数据...",
scope: _this
});
//关闭分箱窗体
Ext.getCmp("optionWin_bsno").close();
}
}); //查看列表
var layerPanel = new Ext.Panel({
layout: "border",
width: 200,
height: 160,
id: 'pnlctn_12',
region: "center",
items: [comboxCtn, buttonCtn]
});
var win = Ext.create('Ext.window.Window',
{
title: '历史导出',
layout: 'fit',
id: 'optionWin_bsno',
draggable: true, //拖动
x: event.clientX,
y: event.clientY,
resizable: false,
items: { // Let's put an empty grid in just to illustrate fit layout
xtype: 'panel',
border: true,
items: [layerPanel]
}
});
win.show();
} //弹层判断
},//历史导出
OprationSwap: function () {
var ret = new Array();
ret[0] = this.OprationStatus;
ret[1] = this.storeList;
ret[2] = this.SelectedRecord;
return ret;
},
/**
* 合并Grid的数据列
* @param grid {Ext.Grid.Panel} 需要合并的Grid
* @param colIndexArray {Array} 需要合并列的Index(序号)数组从0开始计数序号也包含
* @param isAllSome {Boolean} 是否2个tr的colIndexArray必须完成一样才能进行合并true完成一样false不完全一样
**/
MerginCells: function (grid, colIndexArray, isAllSome) {
isAllSome = isAllSome == undefined ? true : isAllSome; // 默认为true
// 1.是否含有数据
var gridView = document.getElementById(grid.getView().getId());
if (gridView == null) {
return;
}
// 2.获取Grid的所有tr
var trArray = [];
if (grid.layout.type == 'table') { // 若是table部署方式获取的tr方式如下
trArray = gridView.childNodes;
} else {
trArray = gridView.getElementsByTagName('tr');
}
// 3.进行合并操作
if (isAllSome) { // 3.1 全部列合并只有相邻tr所指定的td都相同才会进行合并
var lastTr = trArray[0]; // 指向第一行
// 1)遍历grid的tr从第二个数据行开始
for (var i = 1, trLength = trArray.length; i < trLength; i++) {
var thisTr = trArray[i];
var isPass = true; // 是否验证通过
// 2)遍历需要合并的列
for (var j = 0, colArrayLength = colIndexArray.length; j < colArrayLength; j++) {
var colIndex = colIndexArray[j];
// 3)比较2个td的列是否匹配若不匹配就把last指向当前列
if (lastTr.childNodes[colIndex].innerText != thisTr.childNodes[colIndex].innerText) {
lastTr = thisTr;
isPass = false;
break;
}
}
// 4)若colIndexArray验证通过就把当前行合并到'合并行'
if (isPass) {
for (var j = 0, colArrayLength = colIndexArray.length; j < colArrayLength; j++) {
var colIndex = colIndexArray[j];
// 5)设置合并行的td rowspan属性
if (lastTr.childNodes[colIndex].hasAttribute('rowspan')) {
var rowspan = lastTr.childNodes[colIndex].getAttribute('rowspan') - 0;
rowspan++;
lastTr.childNodes[colIndex].setAttribute('rowspan', rowspan);
} else {
lastTr.childNodes[colIndex].setAttribute('rowspan', '2');
}
lastTr.childNodes[colIndex].style['text-align'] = 'center';; // 水平居中
lastTr.childNodes[colIndex].style['vertical-align'] = 'middle';; // 纵向居中
thisTr.childNodes[colIndex].style.display = 'none';
thisTr.childNodes[colIndex].className +=' hiddenTd';
}
}
}
} else { // 3.2 逐个列合并:每个列在前面列合并的前提下可分别合并
// 1)遍历列的序号数组
for (var i = 0, colArrayLength = colIndexArray.length; i < colArrayLength; i++) {
var colIndex = colIndexArray[i];
var lastTr = trArray[0]; // 合并tr默认为第一行数据
// 2)遍历grid的tr从第二个数据行开始
for (var j = 1, trLength = trArray.length; j < trLength; j++) {
var thisTr = trArray[j];
// 3)2个tr的td内容一样
if (lastTr.childNodes[colIndex].innerText == thisTr.childNodes[colIndex].innerText) {
// 4)若前面的td未合并后面的td都不进行合并操作
if (i > 0 && thisTr.childNodes[colIndexArray[i - 1]].style.display != 'none') {
lastTr = thisTr;
continue;
} else {
// 5)符合条件合并td
if (lastTr.childNodes[colIndex].hasAttribute('rowspan')) {
var rowspan = lastTr.childNodes[colIndex].getAttribute('rowspan') - 0;
rowspan++;
lastTr.childNodes[colIndex].setAttribute('rowspan', rowspan);
} else {
lastTr.childNodes[colIndex].setAttribute('rowspan', '2');
}
lastTr.childNodes[colIndex].style['text-align'] = 'center';; // 水平居中
lastTr.childNodes[colIndex].style['vertical-align'] = 'middle';; // 纵向居中
thisTr.childNodes[colIndex].style.display = 'none'; // 当前行隐藏
thisTr.childNodes[colIndex].className += ' hiddenTd';
}
} else {
// 5)2个tr的td内容不一样
lastTr = thisTr;
}
}
}
}
},//合并单元格
/**
* 取消合并Grid的数据列
* @param grid {Ext.Grid.Panel} 需要合并的Grid
* @param colIndexArray {Array} 需要合并列的Index(序号)数组从0开始计数序号也包含
**/
CancelMergeGrid: function (grid, colIndexArray) {
// 1.是否含有数据
var gridView = document.getElementById(grid.getView().getId());
if (gridView == null) {
return;
}
// 2.获取Grid的所有tr
var trArray = [];
if (grid.layout.type == 'table') {
// 若是table部署方式获取的tr方式如下
trArray = gridView.childNodes;
} else {
trArray = gridView.getElementsByTagName('tr');
}
for (var i = 0, len = colIndexArray.length; i < len; i++) {
var colIndex = colIndexArray[i];
// 2.遍历grid的tr从第第二个数据开始。
for (var j = 0, trLength = trArray.length; j < trLength; j++) {
var thisTr = trArray[j];
if (thisTr.childNodes[colIndex].hasAttribute('rowspan')) {
thisTr.childNodes[colIndex].removeAttribute('rowspan'); // 移除rowspan属性
}
if (thisTr.childNodes[colIndex].style.display == 'none') {
thisTr.childNodes[colIndex].style.display = ''; // 移除display属性
}
}
}
}//取消合并单元格
});