| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- /**
- * Created by zhouy on 2018/10/18.
- */
- Ext.define('saas.view.document.kind.ChildForm', {
- extend: 'Ext.window.Window',
- xtype: 'document-kind-childwin',
- cls:'x-window-dbfind',
- layout: 'fit',
- modal: true,
- width: 500,
- //工具类
- height: 280,
- listeners:{
- show:function(w){
- //自动适应窗口
- var items = w.down('form').items.items;
- var count = 0;
- var codeField;
- Ext.Array.each(items,function(item) {
- if(item.xtype!='hidden'){
- count++;
- }
- if(item.autoCode){
- codeField = item.name
- }
- });
- if(count!=0&&count<6){
- w.setHeight(114+40*count)
- }
- if(w.record){
- w.down('form').loadRecord(w.record);
- }else{
- //判断是否有code字段
- if(codeField){
- w.setLoading(true);
- //取后台编号
- var caller = w.caller || w._parent.caller;
- saas.util.BaseUtil.request({
- url: '/api/commons/number/getMaxnumber',
- headers: {
- "Content-Type": 'application/x-www-form-urlencoded;charset=UTF-8'
- },
- params: {
- caller:caller
- },
- method: 'POST',
- }).then(function(res) {
- w.setLoading(false);
- if(res.success){
- w.down('[name='+codeField+']').setValue(res.data);
- }else {
- saas.util.BaseUtil.showErrorToast(res.message);
- }
- }).catch(function(res) {
- saas.util.BaseUtil.showErrorToast(res.message);
- w.setLoading(true);
- })
- }
- }
- }
- },
- initComponent:function(){
- var me=this;
- Ext.apply(me,{
- items:me.setFormItems()
- });
- me.callParent();
- },
- etc:{
- customerkind:{
- items:[{
- xtype:'hidden',
- name:'id'
- },{
- xtype:'textfield',
- name:'ck_name',
- allowBlank:false,
- fieldLabel:'客户类型',
- maxLength: 20
- }]
- },
- vendorkind:{
- items:[{
- xtype:'hidden',
- name:'id'
- },{
- xtype:'textfield',
- name:'vk_name',
- allowBlank:false,
- fieldLabel:'供应商类型',
- maxLength: 20
- }]
- },
- productkind:{
- items:[{
- xtype:'hidden',
- name:'id'
- },{
- xtype:'textfield',
- name:'pt_name',
- allowBlank:false,
- fieldLabel:'物料类型',
- maxLength: 20
- }]
- },
- inoutkind:{
- items:[{
- xtype:'hidden',
- name:'id'
- },{
- xtype:'textfield',
- name:'ft_name',
- allowBlank:false,
- relativeField:'ord_type',
- fieldLabel:'收支名称',
- maxLength: 20
- },{
- xtype:'combo',
- name:'ft_kind',
- allowBlank:false,
- fieldLabel:'收支类型',
- hideTrigger : false,
- maxLength : 100.0,
- minValue : null,
- positiveNum : false,
- queryMode : "local",
- valueField : "value",
- xtype : "combo",
- editable:false,
- displayField : "display",
- store:{
- fields: ['display', 'value'],
- data : [
- {"display":"收入", "value":'收入'},
- {"display":"支出", "value":'支出'}
- ]
- }
- }]
- }
- },
- setFormItems:function() {
- var me = this, kind = me.dataKind;
- var conf = {
- xtype: 'form',
- bodyPadding: '10 30 10 10',
- border: false,
- autoScroll:true,
- modelValidation: true,
- layout: 'column',
- defaults: {
- margin:'0 0 10 0',
- beforeLabelTextTpl: "<font color=\"red\" style=\"position:relative; top:2px;right:2px; font-weight: bolder;\">*</font>",
- xtype: 'textfield',
- columnWidth:1
- },
- buttonAlign:'center',
- buttons: [{
- text: '保存',
- formBind:true,
- handler: me.onSave,
- scope:me
- }, {
- text: '取消',
- handler: me.onCancel,
- scope:me
- }]
- };
- return Ext.apply(conf, me.etc[kind]);
- },
- onSave:function(){
- var me = this;
- var belong = this.belong;
- me.setLoading(true);
- var form=this.down('form');
- var combo = this._combo;
- var params = {};
- var relativeField,relativeValue;//要赋值的字段和值
- var names = belong.columns.map(column => column.dataIndex);
- Ext.Array.each(names,function(name) {
- if(name){
- var dataField = form.down('[name='+name+']');
- if(dataField){
- var value = dataField.getValue();
-
- if(Ext.isDate(value)) {
- value = Ext.Date.format(value, 'Y-m-d H:i:s');
- }
- params[name] = value;
- if(!relativeValue){
- relativeField = dataField.relativeField;
- relativeValue = value;
- }
- }
- }
- });
- var idField = form.down('[name='+belong.keyField+']');
- params[belong.keyField] = idField.value || 0;
- //保存接口
- saas.util.BaseUtil.request({
- url: belong.reqUrl,
- params: JSON.stringify(params),
- method: 'POST'
- })
- .then(function(localJson) {
- me.setLoading(false);
- if(localJson.success){
- var grid = form.ownerCt._parent;
- if(grid){
- if(form.ownerCt._parent.lookup('document-kind-Grid')!=null){
- form.ownerCt._parent.lookup('document-kind-Grid').store.load()
- }else if(grid.store){
- grid.store.load();
- }
- }
- if(relativeField&&relativeValue&&form.ownerCt._parent){
- var grid = form.ownerCt._parent.down('grid');
- var rec = grid.getSelectionModel().getLastSelected();
- rec.set(relativeField,relativeValue);
- }
- if(combo){
- combo.store.load(function() {
- typeof combo.setValue == 'function' && combo.setValue(relativeValue);
- });
- }
- saas.util.BaseUtil.showSuccessToast('保存成功');
- form.ownerCt.close();
- }
- })
- .catch(function(res) {
- me.setLoading(false);
- console.error(res);
- saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message);
- });
- },
- onCancel:function(){
- this.hide();
- }
- });
|