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/MvcShipping/Viewsjs/MsCodeOpStatus/MsCodeOpStatusEdit.js

510 lines
18 KiB
JavaScript

Ext.namespace('Shipping');
Shipping.MsCodeOpStatusEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.Shipping.MsCodeOpStatusEdit.superclass.constructor.call(this);
};
Ext.extend(Shipping.MsCodeOpStatusEdit, Ext.Panel, {
ParentWin: null,
OpStatus: 'add',
StoreList: null,
EditRecord: null,
initUIComponents: function () {
this.serialNo = 0;
this.workSerialNo = 0;
this.bodyDel = [];
//#region 编辑form
//枚举参照相关(编辑form)
//表参照相关(编辑form)
this.storeOpType = Ext.create('DsExt.ux.RefEnumStore', {});
this.storeOpType.load({ params: { enumTypeId: 96005} });
this.comboxOpType = Ext.create('DsExt.ux.RefEnumCombox', {
fieldLabel: '业务类型',
store: this.storeOpType,
valueField: 'EnumValueName',
displayField: 'EnumValueName',
allowBlank: false, name: 'OPTYPE'
});
this.storeAddDCType = Ext.create('Ext.data.Store', {
fields: ['DC', 'NAME']
});
this.storeAddDCType.add({ "DC": "1", "NAME": "业务状态" });
this.storeAddDCType.add({ "DC": "2", "NAME": "费用状态" });
this.comboxaddDCType = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '状态类型',
store: this.storeAddDCType,
valueField: 'DC',
displayField: 'NAME',
allowBlank: false, forceSelection: true,
name: 'STTYPE',
value: '1'
});
//定义颜色
this.storeColor = Ext.create('Ext.data.Store', {
fields: ['id', 'name']
});
this.storeColor.add({ "id": "#FFFF00", "name": "<i style='background-color:#FFFF00;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>黄色" });
this.storeColor.add({ "id": "#FF6100", "name": "<i style='background-color:#FF6100;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>橙色" });
this.storeColor.add({ "id": "#0000FF", "name": "<i style='background-color:#0000FF;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>蓝色" });
this.storeColor.add({ "id": "#802A2A", "name": "<i style='background-color:#802A2A;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>棕色" });
this.storeColor.add({ "id": "#f05b72", "name": "<i style='background-color:#f05b72;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>蔷薇色" });
this.storeColor.add({ "id": "#70a19f", "name": "<i style='background-color:#70a19f;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>水浅葱" });
this.storeColor.add({ "id": "#c37e00", "name": "<i style='background-color:#c37e00;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>金黄色" });
this.storeColor.add({ "id": "#b2d235", "name": "<i style='background-color:#b2d235;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>黄绿色" });
this.storeColor.add({ "id": "#FF0000", "name": "<i style='background-color:#FF0000;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>红色" });
this.storeColor.add({ "id": "#009ad6", "name": "<i style='background-color:#009ad6;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>青色" });
this.storeColor.add({ "id": "#B22222", "name": "<i style='background-color:#B22222;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>砖红" });
this.storeColor.add({ "id": "#494e8f", "name": "<i style='background-color:#494e8f;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>绀蓝" });
this.storeColor.add({ "id": "#00C957", "name": "<i style='background-color:#00C957;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>绿色" });
this.storeColor.add({ "id": "#A020F0", "name": "<i style='background-color:#A020F0;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>紫色" });
this.storeColor.add({ "id": "#007d65", "name": "<i style='background-color:#007d65;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>青绿" });
this.storeColor.add({ "id": "#2e3a1f", "name": "<i style='background-color:#2e3a1f;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>蓝海松茶" });
this.storeColor.add({ "id": "#03A89E", "name": "<i style='background-color:#03A89E;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>锰蓝" });
this.storeColor.add({ "id": "#708069", "name": "<i style='background-color:#708069;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>石板灰" });
this.storeColor.add({ "id": "#B03060", "name": "<i style='background-color:#B03060;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>栗色" });
this.storeColor.add({ "id": "#3D59AB", "name": "<i style='background-color:#3D59AB;width:10px;height:10px;display: inline-block;margin-right: 5px;'></i>钴色" });
this.comboxaddColor = Ext.create('DsExt.ux.RefTableCombox', {
store: this.storeColor,
valueField: 'id',
displayField: 'name',
allowBlank: false,
forceSelection: true,
name: 'COLOR'
});
//编辑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'
}, this.comboxOpType,this.comboxaddDCType,{
fieldLabel: '说明',
name: 'DESCRIPTION'
}
]
}
]//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
}
]
}); //end 按钮Toolbar
//#endregion
//#region 明细表
//明细表表格相关
//明细表-数据集
this.storeBodyList = Ext.create('Ext.data.Store', {
model: 'MsCodeOpStatusDetail',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/MvcShipping/MsCodeOpStatus/GetBodyList',
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.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: 'OPSTATUS',
header: '状态名称',
editor: {
xtype: 'textfield',
selectOnFocus: true
},
width: 160
}, {
sortable: true,
dataIndex: 'COLOR',
header: '颜色标识',
editor: this.comboxaddColor,
width: 160
}, {
sortable: true,
dataIndex: 'REMARKS',
header: '状态说明',
editor: {
xtype: 'textfield',
selectOnFocus: true
},
width: 160
}
]
});
this.panelService = new Ext.Panel({
title: '业务状态',
layout: "border",
region: 'center',
margin: '5 10',
items: [this.gridList]
});
//#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.panelService]
});
//#endregion
//绑定查询窗体
this.ParentWin = window.parent.opener;
//初始化数据
this.InitData();
//绑定事件
this.gridList.on('edit', function (editor, e, eOpts) {
this.gridAfterEdit(editor, e, eOpts);
}, 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 = " OPTYPE='" + this.editRecord.get('OPTYPE') + "'";
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/MsCodeOpStatus/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('OPTYPE');
}
this.storeBodyList.load({ params: { condition: " OPTYPE='" + 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 jsonBody = ConvertRecordsToJsonAll(bodydatas);
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/MvcShipping/MsCodeOpStatus/Save',
scope: this,
params: {
opstatus: this.opStatus,
data: Ext.JSON.encode(data),
body: jsonBody
},
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('MsCodeOpStatus', 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("GID", this.editRecord.get('GID'));
memberbody.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
gridAfterEdit: function (editor, e, eOpts) {
//需要自己实现里面的事件
},
addDetail: function (type) {
var newSerialno = 0;
store = this.storeBodyList;
newSerialno = DsGetNewSerialNo(store, this.serialNo);
this.serialNo = newSerialno;
var record = Ext.create('MsCodeOpStatusDetail', {
GID: '',
SerialNo: newSerialno,
OPSTATUS: "",
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];
this.storeBodyList.remove(rec);
}
}
});