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/MsInfoSaleProfitShareSet/MsInfoSaleProfitShareSetEdi...

1018 lines
33 KiB
JavaScript

3 years ago
Ext.namespace('Shipping');
Shipping.MsInfoSaleProfitShareSetEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.Shipping.MsInfoSaleProfitShareSetEdit.superclass.constructor.call(this);
};
Ext.extend(Shipping.MsInfoSaleProfitShareSetEdit, Ext.Panel, {
ParentWin: null,
OpStatus: 'add',
StoreList: null,
EditRecord: null,
initUIComponents: function () {
this.serialNo = 0;
this.workSerialNo = 0;
this.bodyDel = [];
//#region 编辑form
//枚举参照相关(编辑form)
//表参照相关(编辑form)
//编辑form
this.formEdit = Ext.widget('form', {
region: 'center',
frame: true,
bodyPadding: 5,
autoScroll: true,
fieldDefaults: {
margins: '2 2 2 2',
labelAlign: 'right',
flex: 1,
labelWidth: 90,
msgTarget: 'qtip'
},
items: [
{//fieldset 1
xtype: 'fieldset',
defaultType: 'textfield',
layout: 'anchor',
defaults: {
anchor: '100%'
},
items: [{
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: 'GID',
name: 'GID', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '方案名称',
allowBlank: false,
name: 'PLANNAME'
}, {
fieldLabel: '死账月数',
name: 'ISSTOPMONTH'
}, {
fieldLabel: '允许误差天数',
name: 'POORDAY'
}, {
fieldLabel: '月结误差天数',
name: 'MONTHPOORDAY'
}, {
fieldLabel: '录入人',
readOnly:true,
name: 'CREATEUSER'
}, {
fieldLabel: '录入日期',
readOnly: true,
name: 'CREATETIME'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '说明',
name: 'REMARK'
}]
}
]//end items(fieldset 1)
}//end fieldset 1
]//end root items
}); //end this.formEdit
//#endregion
//#region 按钮Toolbar
this.panelBtn = new Ext.Panel({
region: "north",
tbar: [
{
text: "保存",
iconCls: "btnsave",
handler: function (button, event) {
this.Save('0');
},
scope: this
},
{
text: "保存并关闭",
handler: function (button, event) {
this.Save('1');
},
scope: this
},
'-',
{
text: "保存并新建",
handler: function (button, event) {
this.Save('2');
},
scope: this
},
'-',
{
text: "复制新建", //"复制新建",
handler: function (button, event) {
var basicForm = this.formEdit.getForm();
this.opStatus = 'add';
basicForm.findField('GID').setDisabled(false);
var field = basicForm.findField('GID');
field.setValue(NewGuid());
basicForm.findField('GID').setDisabled(true);
field = basicForm.findField('CREATEUSER');
field.setValue('');
field = basicForm.findField('PLANNAME');
field.setValue('');
for (var j = 0; j < this.storeBodyList.getCount(); j += 1) {
var memberbody = this.storeBodyList.getAt(j);
memberbody.set("PLANID", '*');
memberbody.commit();
};
for (var j = 0; j < this.storeWorkList.getCount(); j += 1) {
var memberbody = this.storeWorkList.getAt(j);
memberbody.set("PLANID", '*');
memberbody.commit();
};
},
scope: this
}
]
}); //end 按钮Toolbar
//#endregion
//#region 明细表
//明细表表格相关
//明细表-数据集
this.storeBodyList = Ext.create('Ext.data.Store', {
model: 'InfoSaleProfitShareDetail',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/MvcShipping/MsInfoSaleProfitShareSet/GetSaleProfitDetailDataList',
reader: {
root: 'data',
totalProperty: 'totalCount'
}
}
});
//明细表表格
this.gridListCellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
this.storeSource = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsShipping.ux.SourceModel',
proxy: { url: '/CommMng/BasicDataRef/GetSource' }
});
this.storeSource.load();
this.comboxBSSOURCE = Ext.create('DsExt.ux.RefTableCombox', {
store: this.storeSource,
name: 'BSSOURCE',
valueField: 'SourceName',
displayField: 'SourceName'
});
this.gridList = new Ext.grid.GridPanel({
store: this.storeBodyList,
enableHdMenu: false,
region: 'center',
loadMask: { msg: "数据加载中,请稍等..." },
trackMouseOver: true,
disableSelection: false,
plugins: [this.gridListCellEditing],
selType: 'cellmodel',
tbar: [{
text: '增加方案明细',
tooltip: '增加方案明细',
iconCls: "btnadddetail",
handler: function (button, event) {
this.onAddDetailClick(button, event, 1);
},
scope: this
}, '-', {
text: '删除方案明细',
tooltip: '删除方案明细',
iconCls: "btndeletedetail",
handler: function (button, event) {
this.onDelDetailClick(button, event, 1);
},
scope: this
}],
columns: [{
sortable: true,
dataIndex: 'GID',
header: 'GID',
hidden: true,
width: 100
}, {
sortable: true,
dataIndex: 'PLANID',
header: 'PLANID',
hidden: true,
width: 100
}, {
sortable: true,
dataIndex: 'MONTHNUM',
header: '月份',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
decimalPrecision: 2,
selectOnFocus: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
width: 70
}, {
sortable: true,
dataIndex: 'PROFITDOWN',
header: '利润起',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
decimalPrecision: 2,
selectOnFocus: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {
try {
var lsValue = usMoney(value, 2, '', false);
if (lsValue != "NaN") {
value = lsValue; if (parseFloat(lsValue) < 0) {
return '<SPAN style="COLOR: red">' + lsValue + '</SPAN>';
}
}
else {
return value;
}
}
catch (e) {
return value;
}
return value;
},
width: 70
}, {
sortable: true,
dataIndex: 'PROFITUP',
header: '利润至',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
decimalPrecision: 2,
selectOnFocus: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {
try {
var lsValue = usMoney(value, 2, '', false);
if (lsValue != "NaN") {
value = lsValue; if (parseFloat(lsValue) < 0) {
return '<SPAN style="COLOR: red">' + lsValue + '</SPAN>';
}
}
else {
return value;
}
}
catch (e) {
return value;
}
return value;
},
width: 70
}, {
dataIndex: 'BSSOURCE',
header:'业务来源', //'称重方式',
width: 60,
editor: this.comboxBSSOURCE
}, {
sortable: true,
dataIndex: 'SHAREPR',
header: '提成比率',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
decimalPrecision: 2,
selectOnFocus: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
width: 70
}, {
sortable: true,
dataIndex: 'BEFORESHAREPR',
header: '拖至本月提成比率',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
decimalPrecision: 2,
selectOnFocus: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
width: 70
}, {
sortable: true,
dataIndex: 'REMARKS',
header: '备注',
editor: {
xtype: 'textfield',
selectOnFocus: true,
enableKeyEvents: true
},
width: 150
}
]
});
this.storeWorkList = Ext.create('Ext.data.Store', {
model: 'InfoSaleProfitShareLx',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/MvcShipping/MsInfoSaleProfitShareSet/GetSaleProfitLxDataList',
reader: {
root: 'data',
totalProperty: 'totalCount'
}
}
});
//明细表表格
this.gridworkListCellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
this.gridWorkList = new Ext.grid.GridPanel({
store: this.storeWorkList,
enableHdMenu: false,
region: 'center',
loadMask: { msg: "数据加载中,请稍等..." },
trackMouseOver: true,
disableSelection: false,
plugins: [this.gridworkListCellEditing],
selType: 'cellmodel',
tbar: [{
text: '增加明细',
tooltip: '增加明细',
iconCls: "btnadddetail",
handler: function (button, event) {
this.onAddSortDetailClick(button, event, 2);
},
scope: this
}, '-', {
text: '删除明细',
tooltip: '删除明细',
iconCls: "btndeletedetail",
handler: function (button, event) {
this.onDelSortDetailClick(button, event, 2);
},
scope: this
}],
columns: [{
sortable: true,
dataIndex: 'GID',
header: 'GID',
hidden: true,
width: 100
}, {
sortable: true,
dataIndex: 'PLANID',
header: 'PLANID',
hidden: true,
width: 100
}, {
sortable: true,
dataIndex: 'BDAY',
header: '开始天数',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
decimalPrecision: 2,
selectOnFocus: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
width: 70
}, {
sortable: true,
dataIndex: 'EDAY',
header: '结束天数',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
decimalPrecision: 2,
selectOnFocus: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
width: 70
}, {
sortable: true,
dataIndex: 'DEDUCTIN',
header: '利率',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
decimalPrecision: 2,
selectOnFocus: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
width: 70
}, {
sortable: true,
dataIndex: 'REMARKS',
header: '备注',
editor: {
xtype: 'textfield',
selectOnFocus: true,
enableKeyEvents: true
},
width: 150
}
]
});
this.panelService = new Ext.Panel({
title: '提成方案明细',
layout: "border",
region: 'west',
width: 480,
margin: '5 10',
items: [this.gridList]
});
this.storeCqList = Ext.create('Ext.data.Store', {
model: 'InfoSaleProfitShareLx',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/MvcShipping/MsInfoSaleProfitShareSet/GetSaleProfitCqDataList',
reader: {
root: 'data',
totalProperty: 'totalCount'
}
}
});
//明细表表格
this.gridcqListCellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
this.gridCqList = new Ext.grid.GridPanel({
store: this.storeCqList,
enableHdMenu: false,
region: 'center',
loadMask: { msg: "数据加载中,请稍等..." },
trackMouseOver: true,
disableSelection: false,
plugins: [this.gridcqListCellEditing],
selType: 'cellmodel',
tbar: [{
text: '增加明细',
tooltip: '增加明细',
iconCls: "btnadddetail",
handler: function (button, event) {
this.onAddCqDetailClick(button, event, 2);
},
scope: this
}, '-', {
text: '删除明细',
tooltip: '删除明细',
iconCls: "btndeletedetail",
handler: function (button, event) {
this.onDelCqDetailClick(button, event, 2);
},
scope: this
}],
columns: [{
sortable: true,
dataIndex: 'GID',
header: 'GID',
hidden: true,
width: 100
}, {
sortable: true,
dataIndex: 'PLANID',
header: 'PLANID',
hidden: true,
width: 100
}, {
sortable: true,
dataIndex: 'BDAY',
header: '开始天数',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
decimalPrecision: 2,
selectOnFocus: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
width: 70
}, {
sortable: true,
dataIndex: 'EDAY',
header: '结束天数',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
decimalPrecision: 2,
selectOnFocus: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
width: 70
}, {
sortable: true,
dataIndex: 'DEDUCTIN',
header: '发放比例',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
decimalPrecision: 2,
selectOnFocus: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
width: 70
}, {
sortable: true,
dataIndex: 'REMARKS',
header: '备注',
editor: {
xtype: 'textfield',
selectOnFocus: true,
enableKeyEvents: true
},
width: 150
}
]
});
this.panelcq = new Ext.Panel({
title: '超期提成设置',
layout: "border",
height:300,
region: 'south',
margin: '5 10',
items: [this.gridCqList]
});
this.panelwork = new Ext.Panel({
title: '扣息',
layout: "border",
region: 'center',
margin: '5 10',
items: [this.gridWorkList, this.panelcq]
});
this.paneldetail = new Ext.Panel({
layout: "border",
region: "center",
items: [
this.panelService, this.panelwork
]
});
//#endregion 明细表
//#region 布局
//控件布局
this.panelTop = new Ext.Panel({
layout: "border",
region: "north",
height: 120,
items: [this.panelBtn, this.formEdit]
});
Ext.apply(this, {
items: [this.panelTop, this.paneldetail]
});
//#endregion
//绑定查询窗体
this.ParentWin = window.parent.opener;
//初始化数据
this.InitData();
//绑定事件
this.gridList.on('edit', function (editor, e, eOpts) {
this.gridAfterEdit(editor, e, eOpts);
}, this);
this.storeBodyList.on('beforeload', function (store) {
var cargoid = 0;
if (this.opStatus == 'edit') {
cargoid = this.editRecord.get('GID');
}
var sql = " d.PLANID='" + cargoid + "'";
Ext.apply(store.proxy.extraParams, { condition: sql });
}, this);
this.storeWorkList.on('beforeload', function (store) {
var cargoid = 0;
if (this.opStatus == 'edit') {
cargoid = this.editRecord.get('GID');
}
var sql = " PLANID='" + cargoid + "'";
Ext.apply(store.proxy.extraParams, { condition: sql });
}, this);
this.storeCqList.on('beforeload', function (store) {
var cargoid = 0;
if (this.opStatus == 'edit') {
cargoid = this.editRecord.get('GID');
}
var sql = " d.PLANID='" + cargoid + "'";
Ext.apply(store.proxy.extraParams, { condition: sql });
}, this);
}, //end initUIComponents
InitData: function () {
this.opStatus = 'add';
var condition = '';
if (this.ParentWin) {
var ret = this.ParentWin.OprationSwap();
this.opStatus = ret[0];
this.StoreList = ret[1];
this.editRecord = ret[2];
}
if (this.opStatus == 'edit')
condition = " GID='" + this.editRecord.get('GID') + "'";
this.LoadData(this.opStatus, condition);
}, //end InitData
LoadData: function (opstatus, condition) {
this.serialNo = 0;
this.workSerialNo = 0;
this.bodyDel = [];
this.opStatus = opstatus;
Ext.Ajax.request({
waitMsg: '正在查询主表数据...',
url: '/MvcShipping/MsInfoSaleProfitShareSet/GetData',
params: {
handle: opstatus,
condition: condition
},
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;
}
var data = result.data;
this.formEdit.getForm().reset();
this.formEdit.getForm().setValues(data);
} else {
Ext.MessageBox.alert('请求出现错误,请重试', response.responseText);
}
},
scope: this
});
var billno = '*';
var cargoid = 0;
if (this.opStatus == 'edit') {
cargoid = this.editRecord.get('GID');
}
this.storeBodyList.load({ params: { condition: "d.PLANID='" + cargoid + "'"} });
this.storeWorkList.load({ params: { condition: " PLANID='" + cargoid + "'"} });
this.storeCqList.load({ params: { condition: " d.PLANID='" + cargoid + "'" } });
}, // end LoadDate
Save: function (type) {
var basicForm = this.formEdit.getForm();
if (!basicForm.isValid()) {
return;
}
//判断表格数据是否合法
if (!validateEditorGridPanel(this.gridList)) {
return;
}
basicForm.findField('GID').setDisabled(false);
var data = basicForm.getValues();
basicForm.findField('GID').setDisabled(true);
if (this.opStatus == 'add') {
data.GID = NewGuid();
}
var bodydatas = [];
for (var i = 0; i < this.storeBodyList.getCount(); i += 1) {
var member = this.storeBodyList.getAt(i);
bodydatas.push(member);
}
var workdatas = [];
for (var i = 0; i < this.storeWorkList.getCount(); i += 1) {
var member = this.storeWorkList.getAt(i);
workdatas.push(member);
}
var cqdatas = [];
for (var i = 0; i < this.storeCqList.getCount(); i += 1) {
var member = this.storeCqList.getAt(i);
cqdatas.push(member);
}
var jsonBody = ConvertRecordsToJsonAll(bodydatas);
var workBody = ConvertRecordsToJsonAll(workdatas);
var cqBody = ConvertRecordsToJsonAll(cqdatas);
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/MvcShipping/MsInfoSaleProfitShareSet/Save',
scope: this,
params: {
opstatus: this.opStatus,
data: Ext.JSON.encode(data),
body: jsonBody,
bodywork: workBody,
bodycq: cqBody
},
callback: function (options, success, response) {
if (success) {
Ext.MessageBox.hide();
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) {
var returnData = jsonresult.Data;
this.formEdit.getForm().setValues(returnData);
if (this.opStatus == 'add') {
var arrNewRecords = this.StoreList.add(returnData);
this.editRecord = arrNewRecords[0];
}
else if (this.opStatus == 'edit') {
var editp = Ext.create('InfoSaleProfitSharePlan', returnData);
this.editRecord.fields.each(function (field) {
if (field.persist) {
name = field.name;
if (name != 'id')
this.editRecord.set(name, editp.get(name));
}
}, this);
this.editRecord.commit();
}
if (type == '0') {
this.opStatus = 'edit';
basicForm.findField('GID').setDisabled(true);
for (var j = 0; j < this.storeBodyList.getCount(); j += 1) {
var memberbody = this.storeBodyList.getAt(j);
memberbody.set("PLANID", this.editRecord.get('GID'));
memberbody.commit();
};
for (var j = 0; j < this.storeWorkList.getCount(); j += 1) {
var memberwork = this.storeWorkList.getAt(j);
memberwork.set("PLANID", this.editRecord.get('GID'));
memberwork.commit();
};
for (var j = 0; j < this.storeCqList.getCount(); j += 1) {
var membercq = this.storeCqList.getAt(j);
membercq.set("PLANID", this.editRecord.get('GID'));
membercq.commit();
};
} else if (type == '1') {
window.close();
} else {
this.LoadData('add', '');
basicForm.findField('GID').setDisabled(false);
}
} 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
});
}
}
});
}, //end save
onAddDetailClick: function (button, event, type) {
this.addDetail(type);
}, //end onAddDetailClick
onDelDetailClick: function (button, event, type) {
this.deleteDetail(type);
}, //onDelDetailClick
onAddSortDetailClick: function (button, event, type) {
this.addSortDetail(type);
}, //end onAddDetailClick
onDelSortDetailClick: function (button, event, type) {
this.deleteSortDetail(type);
}, //onDelDetailClick
onAddCqDetailClick: function (button, event, type) {
this.addCqDetail(type);
}, //end onAddDetailClick
onDelCqDetailClick: function (button, event, type) {
this.deleteCqDetail(type);
}, //onDelDetailClick
gridAfterEdit: function (editor, e, eOpts) {
//需要自己实现里面的事件
},
addDetail: function (type) {
var newSerialno = 0;
store = this.storeBodyList;
var record = Ext.create('InfoSaleProfitShareDetail', {
GID: '',
PLANID: '*',
MONTHNUM: 0,
PROFITDOWN:0,
PROFITUP: 0,
SHAREPR: 0,
BEFORESHAREPR: 0,
REMARKS:''
});
store.add(record);
var n = store.getCount();
this.gridListCellEditing.startEditByPosition({ row: n - 1, column: 1 });
},
deleteDetail: function (type) {
var selectedRecords = this.gridList.selModel.getSelection();
for (var i = 0; i < selectedRecords.length; i++) {
var rec = selectedRecords[i];
Ext.Msg.wait('正在删除数据...');
Ext.Ajax.request({
waitMsg: '正在删除数据...',
url: '/MvcShipping/MsInfoSaleProfitShareSet/DeleteSaleProfitDetail',
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.storeBodyList.remove(rec);
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 });
},
success: function (response, options) {
},
scope: this
}); //end Ext.Ajax.request
}
},
addSortDetail: function (type) {
var newSerialno = 0;
store = this.storeWorkList;
var newSerialno = this.storeWorkList.getCount() + 1;
var record = Ext.create('InfoSaleProfitShareLx', {
GID: '',
PLANID: '*',
BDAY: 0,
EDAY:0,
DEDUCTIN: 0,
REMARKS: ''
});
store.add(record);
this.gridworkListCellEditing.startEditByPosition({ row: n - 1, column: 1 });
},
deleteSortDetail: function (type) {
var selectedRecords = this.gridWorkList.selModel.getSelection();
for (var i = 0; i < selectedRecords.length; i++) {
var rec = selectedRecords[i];
this.storeWorkList.remove(rec);
}
},
addCqDetail: function (type) {
var newSerialno = 0;
store = this.storeCqList;
var newSerialno = this.storeCqList.getCount() + 1;
var record = Ext.create('InfoSaleProfitShareLx', {
GID: '',
PLANID: '*',
BDAY: 0,
EDAY: 0,
DEDUCTIN: 0,
REMARKS: ''
});
store.add(record);
this.gridcqListCellEditing.startEditByPosition({ row: n - 1, column: 1 });
},
deleteCqDetail: function (type) {
var selectedRecords = this.gridCqList.selModel.getSelection();
for (var i = 0; i < selectedRecords.length; i++) {
var rec = selectedRecords[i];
this.storeCqList.remove(rec);
}
}
});