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/RptCwCfs/RptCwCfsEdit.js

392 lines
14 KiB
JavaScript

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.RptCwCfsEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.Shipping.RptCwCfsEdit.superclass.constructor.call(this);
};
Ext.extend(Shipping.RptCwCfsEdit, Ext.Panel, {
ParentWin: null,
StoreList: null,
EditRecord: null,
OprationStatus: 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: '+'
});
//取数规则
Ext.define('ACCESSModel', { extend: 'Ext.data.Model', fields: [{ name: 'Name', type: 'string'}] });
var dataACCESS = [{ "Name": "损益发生额" }, { "Name": "借方发生额" }, { "Name": "贷方发生额" }, { "Name": "期初数" }];
var storeACCESS = Ext.create('Ext.data.Store', { model: 'ACCESSModel', data: dataACCESS });
this.comboxACCESS = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '取数规则',
store: storeACCESS,
forceSelection: true,
allowBlank: false,
id: 'ACCESS',
name: 'ACCESS',
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, this.comboxACCESS]
}]
});
//#endregion
//#region 定义数据集
this.storeDetailList = Ext.create('Ext.data.Store', {
model: 'RptCwCfsDetailModel',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/MvcShipping/RptCwCfs/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: 'ACCESS',
header: '取数规则',
width: 80
}, {
sortable: false,
dataIndex: 'QTYBLC',
header: '本月数',
align: 'right',
width: 120,
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;
}
}, {
sortable: false,
dataIndex: 'QTYLASTBLC',
header: '本年数',
align: 'right',
width: 120,
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;
}
}];
//#endregion
//#region gridList列表显示信息
this.gridList = new Ext.grid.GridPanel({
region: 'center',
store: this.storeDetailList,
enableHdMenu: false, //是否显示表格列的菜单
hideHeaders: false, //是否隐藏表头
rowLines: true,
columnLines: true,
loadMask: { msg: "数据加载中,请稍等..." },
columns: this.girdcolums
});
//#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
}, //end initUIComponents
//#region 加载事件
InitData: function () {
parentWin = window.parent.opener;
if (parentWin) {
var ret = parentWin.OprationSwap();
this.EditRecord = ret[0];
this.OprationStatus = ret[1];
}
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/RptCwCfs/SaveEdit',
scope: this,
params: {
data: Ext.JSON.encode(dataHead),
LINKGID: this.EditRecord.data.GID.toString(),
sACCDATE: 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;
var form = this.formHead.getForm();
form.reset();
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/RptCwCfs/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.hide();
//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: { sACCDATE: 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
});