Ext.define('saas.view.sys.config.FormPanel', {
extend: 'Ext.form.Panel',
xtype: 'sys-config-formpanel',
controller: 'sys-config-formpanel',
viewModel: 'sys-config-formpanel',
//工具类
FormUtil: Ext.create('saas.util.FormUtil'),
BaseUtil: Ext.create('saas.util.BaseUtil'),
//字段属性
_idField: 'id',
_readUrl:'http://192.168.253.31:8560/api/account/company/read/current',
_saveUrl:'http://192.168.253.31:8560/api/account/company/save',
//基础属性
frame:true,
initId: 0,
layout: 'vbox',
autoScroll: true,
border: 1,
bodyPadding: 5,
fieldDefaults: {
margin: '0 5 5 30',
labelAlign: 'right',
labelWidth: 90,
width:300,
blankText: '该字段不能为空'
},
bbar:{
frame:true,
items:['->',{
text:'保存',
formBind:true,
name:'save'
},'->']
},
items: [{
bind:'{id}',
xtype: 'hidden',
name: 'id',
fieldLabel: 'id',
allowBlank: true,
width:600
},{
bind:'{name}',
xtype: 'textfield',
name: 'name',
fieldLabel: '公司名称',
allowBlank: true,
editable:false,
readOnly:true,
width:600
},{
bind:'{address}',
xtype: 'textfield',
name: 'address',
fieldLabel: '公司地址',
beforeLabelTextTpl : "*",
allowBlank: false,
width:600
},{
bind:'{tel}',
xtype: 'textfield',
name: 'tel',
fieldLabel: '电话',
beforeLabelTextTpl : "*",
allowBlank: false,
width:500
},{
bind:'{fax}',
xtype: 'textfield',
name: 'fax',
fieldLabel: '传真',
allowBlank: true,
width:500
}
// ,{
// bind:'{en_begindate}',
// xtype : "datefield",
// name : "en_begindate",
// format:'Y-m-d H:i:s',
// fieldLabel : "开账日期",
// allowBlank : true,
// editable:false,
// hideTrigger:true,
// readOnly:true,
// width:500
// }
// ,{
// bind:'{en_pricemethod}',
// displayField : "display",
// editable:false,
// hideTrigger : false,
// maxLength : 100.0,
// width:500,
// minValue : null,
// queryMode : "local",
// valueField : "value",
// xtype : "combo",
// value:'WACC',
// store:{
// fields: ['display', 'value'],
// data : [
// {"display":"加权平均法", "value":'WACC'},
// {"display":"先进先出法", "value":'FIFO'}
// ]
// },
// name : "en_pricemethod",
// beforeLabelTextTpl : "*",
// fieldLabel : "库存计算方式",
// allowBlank : false,
// }
// ,{
// ignore:true,
// bind:'{updateTime}',
// xtype : "datefield",
// name : "updateTime",
// fieldLabel : "更新时间",
// allowBlank : true,
// hideTrigger:true,
// format:'Y-m-d H:i:s',
// editable:false,
// readOnly:true,
// width:500,
// }
,{
xtype: 'form',
width:600,
frame: false,
border: false,
minHeight: 22,
bodyStyle: 'padding:2px;',
layout: 'hbox',
items:[{
bind:'{signet}',
name : "signet",
allowBlank : true,
hidden:true,
xtype:'numberfield'
},{
allowBlank : true,
width:500,
fieldLabel:'打印章上传',
xtype: 'filefield',
emptyText: '请选择图片',
buttonText: '',
buttonConfig: {
iconCls: 'x-fa fa-picture-o',
},
createFileInput : function() {
var me = this;
me.fileInputEl = me.button.el.createChild({
name: me.getName(),
cls: Ext.baseCSSPrefix + 'form-file-input',
tag: 'input',
type: 'file',
size: 1,
accept:"image/*"
}).on('change', me.onFileChange, me);
},
listeners: {
afterrender:function(field,ops){
var fileEl = field.fileInputEl.dom;
fileEl.setAttribute("accept","image/*");
},
change: function(field){
var form = field.ownerCt.ownerCt;
var myForm = field.ownerCt;
var fileEl = field.fileInputEl.dom;
var fd = new FormData();
fd.append('file', fileEl.files[0]);
form.setLoading(true);
Ext.Ajax.request({
url: 'http://192.168.253.31:8560/api/file/upload',//这里是填写需要跨域访问的URL
cors: true,
useDefaultXhrHeader: false,
method: 'post',
rawData: fd,
headers: {
'Access-Control-Allow-Origin': '*',
'Authorization': saas.util.State.get('session').token,
//"Content-Type": 'multipart/form-data' //文件上传的格式,
"Content-Type":null
},
success: function (response, opts) {
form.setLoading(false);
showToast('上传成功');
var res = Ext.decode(response.responseText);
if(res.success){
var data = res.data;
var name = data.name + " (" + Ext.util.Format.fileSize(data.size) + ")";
myForm.down('[name=signet]').setValue(data.id);
field.setRawValue(name);
}else{
showToast('上传失败: ' + res.message);
}
},
failure: function (response, opts) {
form.setLoading(false);
var res = Ext.decode(response.responseText);
showToast('上传失败: ' + res.message);
}
});
}
}
},{
hidden:true,
name:'showSignetPhoto',
xtype:'button',
iconCls: 'x-fa fa-picture-o'
}]
},{
xtype: 'form',
width:600,
frame: false,
border: false,
minHeight: 22,
bodyStyle: 'padding:2px;',
layout: 'hbox',
items:[{
bind:'{logoUrl}',
name : "logoUrl",
allowBlank : true,
hidden:true,
xtype:'numberfield'
},{
allowBlank : true,
width:500,
fieldLabel:'Logo上传',
xtype: 'filefield',
emptyText: '请选择图片',
buttonText: '',
buttonConfig: {
iconCls: 'x-fa fa-picture-o',
},
createFileInput : function() {
var me = this;
me.fileInputEl = me.button.el.createChild({
name: me.getName(),
cls: Ext.baseCSSPrefix + 'form-file-input',
tag: 'input',
type: 'file',
size: 1,
accept:"image/*"
}).on('change', me.onFileChange, me);
},
listeners: {
afterrender:function(field,ops){
var fileEl = field.fileInputEl.dom;
fileEl.setAttribute("accept","image/*");
},
change: function(field){
var form = field.ownerCt.ownerCt;
var myForm = field.ownerCt;
var fileEl = field.fileInputEl.dom;
var fd = new FormData();
fd.append('file', fileEl.files[0]);
form.setLoading(true);
Ext.Ajax.request({
url: 'http://192.168.253.31:8560/api/file/upload',//这里是填写需要跨域访问的URL
cors: true,
useDefaultXhrHeader: false,
method: 'post',
rawData: fd,
headers: {
'Access-Control-Allow-Origin': '*',
'Authorization': saas.util.State.get('session').token,
//"Content-Type": 'multipart/form-data' //文件上传的格式,
"Content-Type":null
},
success: function (response, opts) {
form.setLoading(false);
showToast('上传成功');
var res = Ext.decode(response.responseText);
if(res.success){
var data = res.data;
var name = data.name + " (" + Ext.util.Format.fileSize(data.size) + ")";
myForm.down('[name=logoUrl]').setValue(data.id);
field.setRawValue(name);
}else{
showToast('上传失败: ' + res.message);
}
},
failure: function (response, opts) {
form.setLoading(false);
var res = Ext.decode(response.responseText);
showToast('上传失败: ' + res.message);
}
});
}
}
},{
hidden:true,
name:'showLogoPhoto',
xtype:'button',
iconCls: 'x-fa fa-picture-o'
}]
}],
initComponent: function () {
var me = this,
viewModel = me.getViewModel();
var url = me._readUrl;
me.BaseUtil.request({url })
.then(function(res) {
if(res.success) {
var d = res.data;
viewModel.setData(d)
}
})
.catch(function(response) {
console.error(response);
});
me.callParent(arguments);
},
refresh:function(){
this.ownerCt.setTitle('参数设置')
}
});