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/MsCrmClient/MsCrmClientVisitEdit.js

467 lines
16 KiB
JavaScript

2 years ago
Ext.namespace('Shipping');
Shipping.MsCrmClientVisitEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.Shipping.MsCrmClientVisitEdit.superclass.constructor.call(this);
};
Ext.extend(Shipping.MsCrmClientVisitEdit, Ext.Panel, {
ParentWin: null,
OpStatus: 'add',
StoreList: null,
EditRecord: null,
initUIComponents: function () {
this.serialNo = 0;
this.workSerialNo = 0;
this.bodyDel = [];
this.custid = '';
//#region 编辑form
//枚举参照相关(编辑form)
//表参照相关(编辑form)
//编辑form
//客户加载_委托单位
this.storeCustCode = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsShipping.ux.CustomRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetCustomRefListRm' }
});
this.storeCustCode.load({ params: { CODENAME: "", isall: "1" } });
//委托单位
_this = this;
this.comboxCustCode = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel:'客户名称', //'委托单位',
store: this.storeCustCode,
queryMode: 'remote',
matchFieldWidth: false,
allowBlank: true,
minChars: 1,
queryParam: 'CODENAME',
name: 'CLIENTGID',
valueField: 'GId',
displayField: 'CodeAndName',
enableKeyEvents: true,
listeners: {
scope: this,
'select': function (combo, records, eOpts) {
if (records.length > 0) {
this.formEdit.getForm().findField('SHORTNAME').setValue(records[0].data.CustName);
var s = " LINKID='" + combo.value + "'";
this.storeInfoClientContact.load({
params: { condition: s },
callback: function (r, options, success) {
if (success) {
if (this.storeInfoClientContact.getCount() > 0) {
var member = this.storeInfoClientContact.getAt(0);
this.formEdit.getForm().findField('CONTACTNAME').setValue(member.data.SHOWNAME);
} else {
this.formEdit.getForm().findField('CONTACTNAME').setValue('');
}
}
},
scope: this
});
}
},
specialkey: function (field, e) {
if (e.keyCode == 9) {
if (field.value == null) {
_rec = _this.storeCustCode.getAt(0);
_this.formEdit.getForm().findField('SHORTNAME').setValue(_rec.data.CustName);
}
}
}
}
});
this.storeInfoClientContact = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsShipping.ux.InfoClientContactModel',
proxy: { url: '/CommMng/BasicDataRef/GetInfoClientContactList' }
});
this.comboxInfoClientContact = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '客户联系人', //'客户操作',
store: this.storeInfoClientContact,
name: 'CONTACTNAME',
valueField: 'SHOWNAME',
displayField: 'SHOWNAME',
listeners: {
scope: this,
'select': function (combo, records, eOpts) {
if (records.length > 0) {
}
}
}
});
this.storeSaleCode = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsShipping.ux.UserRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetUserLinkRefListRm' }
});
this.storeSaleCode.load();
this.comboxSALE = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel:'销售', //'揽货人',
store: this.storeSaleCode,
forceSelection: true,
queryMode: 'remote',
allowBlank: true,
minChars: 0,
queryParam: 'CODENAME',
name: 'SALE',
valueField: 'UserName',
displayField: 'CodeAndName',
enableKeyEvents: true
});
this.storeVISITWAY = Ext.create('DsExt.ux.RefEnumStore', {});
this.storeVISITWAY.load({ params: { enumTypeId: 96015 } });
this.comboxVISITWAY = Ext.create('DsExt.ux.RefEnumCombox', {
fieldLabel: '拜访方式', //'揽货人',
store: this.storeVISITWAY,
forceSelection: true,
name: 'VISITWAY'
});
this.formEdit = Ext.widget('form', {
region: 'center',
frame: true,
bodyPadding: 5,
autoScroll: true,
fieldDefaults: {
margins: '2 2 2 2',
labelAlign: 'right',
flex: 1,
labelWidth: 80,
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: 'SHORTNAME',
name: 'SHORTNAME', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: 'VISITSTATUS',
name: 'VISITSTATUS', flex: 0, hidden: true, margins: '0',value:'拜访'
},{
fieldLabel: '拜访主题',
flex: 2,
allowBlank: true,
name: 'VISITTITLE'
}, {
fieldLabel: '拜访时间', //'截港日期',
format: 'Y-m-d',
flex: 1,
xtype: 'datefield',
name: 'VISITDATE'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [this.comboxCustCode, this.comboxInfoClientContact, this.comboxVISITWAY, this.comboxSALE
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
xtype: 'textareafield',
grow: true,
flex: 2,
fieldLabel:'拜访内容', //'备注',
height: 100,
name: 'VISITCONTENT',
anchor: '100%'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '下次拜访主题',
flex: 2,
name: 'NEXTACTION'
}, {
fieldLabel: '下次拜访时间', //'截港日期',
format: 'Y-m-d',
flex: 1,
xtype: 'datetimefield',
name: 'NEXTDATE'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
xtype: 'textareafield',
grow: true,
flex: 2,
fieldLabel: '下次拜访内容', //'备注',
height: 100,
name: 'NEXTCONTENT',
anchor: '100%'
}
]
}
]//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 布局
//控件布局
Ext.apply(this, {
items: [this.panelBtn, this.formEdit]
});
//#endregion
//绑定查询窗体
this.ParentWin = window.parent.opener.panelIndex.panelVisitIndex;
if (this.ParentWin == undefined || this.ParentWin == null || this.ParentWin == NaN) {
this.ParentWin = window.parent.opener;
}
//初始化数据
this.InitData();
}, //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];
this.custid = ret[3];
}
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/MsCrmClient/GetVisitData',
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);
this.formEdit.getForm().findField('VISITSTATUS').setValue('拜访');
if (opstatus == 'add') {
this.formEdit.getForm().findField('CLIENTGID').setValue(this.custid);
var myDate = new Date();
var mydatestr = Ext.util.Format.date(myDate, 'Y-m-d');
this.formEdit.getForm().findField('VISITDATE').setValue(mydatestr);
var s = " LINKID='" + this.custid + "'";
this.storeInfoClientContact.load({
params: { condition: s },
callback: function (r, options, success) {
if (success) {
if (this.storeInfoClientContact.getCount() > 0) {
var member = this.storeInfoClientContact.getAt(0);
this.formEdit.getForm().findField('CONTACTNAME').setValue(member.data.SHOWNAME);
} else {
this.formEdit.getForm().findField('CONTACTNAME').setValue('');
}
}
},
scope: this
});
}
} else {
Ext.MessageBox.alert('请求出现错误,请重试', response.responseText);
}
},
scope: this
});
}, // end LoadDate
Save: function (type) {
var basicForm = this.formEdit.getForm();
if (!basicForm.isValid()) {
return;
}
basicForm.findField('GID').setDisabled(false);
var data = basicForm.getValues();
basicForm.findField('GID').setDisabled(true);
if (this.opStatus == 'add') {
data.GID = NewGuid();
}
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/MvcShipping/MsCrmClient/SaveVisit',
scope: this,
params: {
opstatus: this.opStatus,
data: Ext.JSON.encode(data)
},
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('MsCrmClientVisit', 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);
} 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
});
}
}
});
}
});