Browse Source

主从表bind配置调整

zhuth 7 years ago
parent
commit
9ec748dc26

+ 3 - 3
frontend/saas-web/app/util/FormUtil.js

@@ -66,11 +66,11 @@ Ext.define('saas.util.FormUtil', {
                             }).map(function(c) {
                                 return c.dataIndex
                             });
-                            formModel.set('_detailBindFields', cnames);
+                            formModel.set('detailBindFields', cnames);
                             item.bind = {
-                                store: '{_detailStore}'
+                                store: '{detailStore}'
                             };     
-                            formModel.set('_detailStore', Ext.create('Ext.data.Store', {
+                            formModel.set('detailStore', Ext.create('Ext.data.Store', {
                                 model:item.storeModel,
                                 data: []
                             }));

+ 31 - 37
frontend/saas-web/app/view/core/form/FormPanel.js

@@ -116,37 +116,19 @@ Ext.define('saas.view.core.form.FormPanel', {
 
     /**
      * 获取form数据
-     * @param all: true:取全部数据,false:排除忽视字段
      */
-    getFormData: function(all) {
+    getFormData: function() {
         var me = this,
         viewModel = me.getViewModel(),
         allData = viewModel.getData(),
-        bindFields = allData._bindFields,
-        formData = {
-            main: {},
-            detail: []
+        formData = allData['form'],
+        detailStore = allData['detailStore'],
+        data = {
+            main: formData,
+            detail: detailStore.getData().items
         };
 
-        for(k in allData) {
-            var d = allData[k];
-            // 主表数据
-            if(all) {
-                formData.main[k] = d;
-            }else {
-                if(bindFields.indexOf(k) != -1) {
-                    formData.main[k] = d;
-                }
-            }
-
-            // 从表数据
-            if(k == '_detailStore') {
-                storeData = d.getData().items;
-                formData.detail = storeData;
-            }
-        }
-        
-        return formData;
+        return data;
     },
 
     setFormData: function(formData) {
@@ -165,25 +147,37 @@ Ext.define('saas.view.core.form.FormPanel', {
      */
     setBindFields: function(items) {
         var me = this,
-        viewModel = me.getViewModel(),
-        bindFields = [];
+        viewModel = me.getViewModel();
 
         Ext.Array.each(items, function(item) {
-            var ignore = item.ignore,
-            bind = item.bind;
+            var bind = item.bind,
+            name = item.name,
+            ignore = item.ignore,
+            defaultValue = item.defaultValue;
 
-            if(!ignore && bind) {
-                if(!Ext.isString(bind)) {
-                    // 这里默认所有的fields都绑定的value,如果是其他属性则需要在加载成组件之后去获取他的defaultBind
-                    bind = bind.value;
-                }
+            // 设置model绑定
+            if(!ignore) {
                 if(bind) {
-                    bind = bind.replace(/[{|}]/g, '');
-                    bindFields.push(bind);
+                    if(!Ext.isString(bind)) {
+                        bind = name;
+                        Ext.apply(bind, {
+                            value: '{form.' + bind + '}'
+                        });
+                    }else {
+                        bind = bind.replace(/[{|}]/g, '');
+                        item.bind = '{form.' + bind + '}';
+                    }
+                }else {
+                    bind = name;
+                    item.bind = '{form.' + bind + '}';
+                }
+                // 设置默认值
+                if(defaultValue) {
+                    viewModel.set('form.' + bind, defaultValue);
                 }
             }
+
         });
-        viewModel.set('_bindFields', bindFields);
     },
 
     initFormData: function(formData) {

+ 2 - 5
frontend/saas-web/app/view/core/form/FormPanelController.js

@@ -62,10 +62,7 @@ Ext.define('saas.view.core.form.FormPanelController', {
 
     onSave: function() {
         var me = this,
-        form = this.getView(),
-        viewModel = me.getViewModel(),
-        modelData = viewModel.getData(),
-        detailBindFields = modelData._detailBindFields;
+        form = this.getView();
 
         if(form.getForm().wasDirty==false){
             Ext.Msg.alert('提示','未修改数据,请修改后保存');
@@ -86,7 +83,7 @@ Ext.define('saas.view.core.form.FormPanelController', {
         form = this.getView(),
         viewModel = me.getViewModel(),
         modelData = viewModel.getData(),
-        detailBindFields = modelData._detailBindFields;
+        detailBindFields = modelData.detailBindFields;
 
         var gridData = formData.detail?formData.detail:[];
         var dirtyGridData = [];

+ 2 - 3
frontend/saas-web/app/view/core/form/FormPanelModel.js

@@ -4,9 +4,8 @@ Ext.define('saas.view.core.form.FormPanelModel', {
 
     data: {
         id:0,
-        _bindFields: [], // 主表绑定字段,绑定到formfield并且未设置ignore为true
-        _detailBindeFields: [], // 从表绑定列
-        _detailStore: null, // 从表store
+        detailBindeFields: [], // 从表绑定列
+        detailStore: null, // 从表store
     },
 
     formulas:{

+ 2 - 7
frontend/saas-web/app/view/core/query/QueryFormPanel.js

@@ -7,17 +7,12 @@ Ext.define('saas.view.core.query.QueryFormPanel', {
     bodyPadding: 5,
     labelSeparator : ':',
     defaults:{
-		xtype:'textfield',
-		columnWidth:0.33,
-		margin:'5 5 5 5'
-	},
-    fieldDefaults: {
-        margin: '0 5 5 0',
+		margin: '0 5 5 0',
         labelAlign: 'right',
         labelWidth: 90,
         columnWidth: 0.25,
         blankText: '该字段不能为空'
-    },
+	},
 
     dockedItems: [{
         xtype: 'toolbar',

+ 1 - 1
frontend/saas-web/app/view/purchase/purchase/FormPanel.js

@@ -3,7 +3,7 @@ Ext.define('saas.view.purchase.purchase.FormPanel', {
     xtype: 'purchase-purchase-formpanel',
 
     controller: 'purchase-purchase-formpanel',
-    viewModel: 'purchase-purchase-formmodel',
+    viewModel: 'purchase-purchase-formpanel',
 
     viewName: 'purchase-purchase-formpanel',