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.

390 lines
14 KiB
JavaScript

12 months ago
Ext.namespace('Shipping');
String.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); }
//#region 当前日期格式
Date.prototype.format = function (format) {
var o = {
"M+": this.getMonth() + 1, //month
"d+": this.getDate(), //day
"h+": this.getHours(), //hour
"m+": this.getMinutes(), //minute
"s+": this.getSeconds(), //cond
"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
"S": this.getMilliseconds() //millisecond
}
if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o) if (new RegExp("(" + k + ")").test(format))
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
return format;
}
var xhr = new XMLHttpRequest();
var currdate = new Date();
xhr.open("HEAD", location.href, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var datestr = xhr.getResponseHeader("Date");
currdate = new Date(datestr);
}
}
xhr.send(null);
//#endregion
//#region 关闭窗口前的判断
function getSaved() {
var changelines = panelEdit.storeDetailList.getModifiedRecords();
var changecount = changelines.length;
var delcount = panelEdit.DelBody.length;
var AllDirty = true;
if (changecount == 0 && delcount == 0) { return false; }
if (panelEdit.formHead.getForm().isDirty() == true || AllDirty == true) { return true; }
else { return false };
}
//#endregion
Shipping.RptCwPLEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.Shipping.RptCwPLEdit.superclass.constructor.call(this);
};
Ext.extend(Shipping.RptCwPLEdit, Ext.Panel, {
ParentWin: null,
StoreList: null,
EditRecord: null,
initUIComponents: function () {
this.serialNo = 0;
this.itemindex = 1;
this.DelBody = [];
//#region formSearch 下拉框信息加载
//科目加载
this.storeCwAccitems = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsShipping.ux.CwAccitemsGlModel',
proxy: { url: '/CommMng/BasicDataRef/GetCwAccitemsGl' }
});
//this.storeCwAccitems.load();
this.storeCwAccitems.load({ params: { condition: "ISENABLE=1"} });
this.comboxACCNAME = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '科目',
store: this.storeCwAccitems,
forceSelection: true, //输入值是否严格为待选列表中存在的值
id: 'ACCNAME',
name: 'ACCNAME',
valueField: 'ACCID',
displayField: 'ACCIDNAME',
allowBlank: false,
enableKeyEvents: true, //激活键盘事件
listeners: {
scope: this,
'keyup': {
fn: function (_field, e) {
if (e.getKey() == 118) {//F7
DsOpenEditWin('/MvcShipping/MsCwAccitemsGl/Index', "科目信息", "500", "800", (window.screen.availHeight / 2 - 150), (window.screen.availWidth / 2 - 500));
}
},
scope: this
}
}
});
//运算符号
Ext.define('OPERATORSModel', { extend: 'Ext.data.Model', fields: [{ name: 'Name', type: 'string' }]});
var dataOPERATORS = [{ "Name": "+" }, { "Name": "-" }];
var storeOPERATORS = Ext.create('Ext.data.Store', { model: 'OPERATORSModel', data: dataOPERATORS });
this.comboxOPERATORS = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '运算符号',
store: storeOPERATORS,
forceSelection: true,
allowBlank: false,
id: 'OPERATORS',
name: 'OPERATORS',
valueField: 'Name',
displayField: 'Name',
value: '+'
});
//#endregion
//#region 编辑formHead 基本信息
this.formHead = Ext.widget('form', {
region: 'north',
frame: true,
bodyPadding: 5,
trackResetOnLoad: true,
fieldDefaults: {
labelAlign: 'right',
labelWidth: 60,
msgTarget: 'qtip'
},
items: [{
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [this.comboxACCNAME, this.comboxOPERATORS]
}]
});
//#endregion
//#region 定义数据集
this.storeDetailList = Ext.create('Ext.data.Store', {
model: 'RptCwPLDetailModel',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/MvcShipping/RptCwPL/GetDetailList',
reader: {
id: 'GID',
root: 'data',
totalProperty: 'totalCount'
}
}
});
//#endregion
//#region 列定义
this.girdcolums = [{
sortable: false,
dataIndex: 'GID',
header: '', //唯一编码
hidden: true,
width: 0
}, {
sortable: false,
dataIndex: 'ACCIDNAME',
header: '科目',
width: 300
}, {
sortable: false,
dataIndex: 'OPERATORS',
header: '运算符号',
width: 80
}, {
sortable: false,
dataIndex: 'QTYBLC',
header: '本月金额',
align: 'right',
width: 120,
summaryType: 'sum',
//summaryRenderer: Ext.util.Format.numberRenderer('00.00'),
renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {
value = usMoney(value, 2, '', true);
if (parseFloat(value) < 0) {
return '<SPAN style="COLOR: red">' + value + '</SPAN>';
}
return value;
},
summaryRenderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {
value = usMoney(value, 2, '', true);
return value;
}
}, {
sortable: false,
dataIndex: 'QTYLASTBLC',
header: '本年累计金额',
align: 'right',
width: 120,
summaryType: 'sum',
//summaryRenderer: Ext.util.Format.numberRenderer('00.00'),
renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {
value = usMoney(value, 2, '', true);
if (parseFloat(value) < 0) {
return '<SPAN style="COLOR: red">' + value + '</SPAN>';
}
return value;
},
summaryRenderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {
value = usMoney(value, 2, '', true);
return value;
}
}];
//#endregion
//#region gridList列表显示信息
this.gridListCellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1 //1单击2双击
});
this.gridList = new Ext.grid.GridPanel({
region: 'center',
store: this.storeDetailList,
enableHdMenu: false, //是否显示表格列的菜单
hideHeaders: false, //是否隐藏表头
//disableSelection: false, //是否禁止选择表格行或列默认为false
//trackMouseOver: true, //高亮显示鼠标所在的行默认为true,
//stripeRows: true, //斑马线效果
rowLines: true,
columnLines: true,
loadMask: { msg: "数据加载中,请稍等..." },
plugins: [this.gridListCellEditing],
selType: 'cellmodel',
columns: this.girdcolums,
features: [{
ftype: 'summary'//Ext.grid.feature.Summary表格汇总特性
}]
});
//#endregion
//#region 按钮Toolbar/框架
this.panelBtn = new Ext.Panel({
region: "north",
tbar: [{
xtype: 'label',
style: 'font-size:16px',
width: 90,
html: "<a><font color='#6B8E23'><B>编辑公式</B></font></a>"
}, {
id: 'btnSave',
text: "添加公式",
tooltip: '添加公式',
iconCls: "btnsave",
handler: function (button, event) {
this.Save();
},
scope: this
}, {
text: '删除公式',
tooltip: '删除公式',
id: "btndel",
iconCls: "btndelete",
handler: function (button, event) {
this.onDelClick(button, event);
},
scope: this
}, '-', {
text: "刷新",
iconCls: "btnrefresh",
handler: function (button, event) {
this.onRefreshClick(button, event);
},
scope: this
}, {
text: "关闭",
handler: function (button, event) {
window.close();
},
scope: this
}]
}); //end 按钮Toolbar
this.panelTop = new Ext.Panel({
layout: "border",
region: "north",
height: 70,
items: [this.panelBtn, this.formHead]
});
Ext.apply(this, {
items: [this.panelTop, this.gridList]
});
//#endregion
//#region 页面加载
this.InitData();
//#endregion
},
//#region 加载事件
InitData: function () {
parentWin = window.parent.opener;
if (parentWin) {
var ret = parentWin.OprationSwap();
this.EditRecord = ret[0];
}
this.onRefreshClick();
},
//#endregion
//#region 按钮函数
Save: function (type) {
if (!this.formHead.getForm().isValid()) {
return;
}
var dataHead = this.formHead.getForm().getValues(false, false, false);
var AccitemsList = DsStoreQueryBy(this.storeCwAccitems, 'ACCID', Ext.getCmp("ACCNAME").getValue());
if (AccitemsList.length > 0) {
var AccitemsRaw = AccitemsList.getAt(0);
if (AccitemsRaw != null) {
dataHead.ACCNAME = AccitemsRaw.data.GID.toString();
}
}
//
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/MvcShipping/RptCwPL/SaveEdit',
scope: this,
params: {
data: Ext.JSON.encode(dataHead),
LINKGID: this.EditRecord.data.GID.toString(),
ACCDATE: this.EditRecord.data.ACCDATE.toString()
},
callback: function (options, success, response) {
if (success) {
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) {
var returnData = jsonresult.Data;
this.onRefreshClick();
} else {
Ext.Msg.show({ title: '错误', msg: jsonresult.Message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK });
}
Ext.MessageBox.hide();
} else {
Ext.Msg.show({ title: '请重试',
msg: '服务器响应出错',
icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK
});
}
}
});
}, //end save
onDelClick: function () {
var selectedRecords = this.gridList.selModel.getSelection();
var rec = selectedRecords[0];
Ext.MessageBox.confirm('提示', '确定删除该记录吗?', function (btn) {
if (btn == 'yes') {
Ext.Msg.wait('正在删除数据...');
Ext.Ajax.request({
waitMsg: '正在删除数据...',
url: '/MvcShipping/RptCwPL/DeleteDetail',
params: {
data: Ext.JSON.encode(rec.data)
},
callback: function (options, success, response) {
if (success) {
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) {
//this.storeDetailList.remove(rec);
this.onRefreshClick();
Ext.Msg.show({ title: '提示', msg: jsonresult.Message, icon: Ext.Msg.INFO, buttons: Ext.Msg.OK });
}
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 });
},
scope: this
}); //end Ext.Ajax.request
}
}, this);
},
onRefreshClick: function (button, event) {
var condition = "LINKGID='" + this.EditRecord.data.GID + "'";
this.storeDetailList.load({ params: { ACCDATE: this.EditRecord.data.ACCDATE, condition: condition }, waitMsg: "正在刷新数据...", scope: this });
},
OprationSwap2: function () {
var ret = new Array();
ret[0] = this.gridList.getSelectionModel().getSelection();
ret[1] = this.comboxACCNAME;
return ret;
}
//#endregion
});