Ver Fonte

formpanel定义items方式变更

zhuth há 7 anos atrás
pai
commit
8b3c356115

+ 2 - 1
frontend/saas-web/app/util/BaseUtil.js

@@ -20,7 +20,8 @@ Ext.define('saas.util.BaseUtil', {
                 method: method,
                 timeout: timeout,
                 header: {
-                    'Access-Control-Allow-Origin': '*'
+                    'Access-Control-Allow-Origin': '*',
+                    "Content-Type": 'application/json;charset=UTF-8' 
                 },
                 success: function (response, opts) {
                     resolve(response);

+ 33 - 7
frontend/saas-web/app/util/FormUtil.js

@@ -3,9 +3,9 @@ Ext.define('saas.util.FormUtil', {
     BaseUtil: Ext.create('saas.util.BaseUtil'),
 
     // 请求页面组件接口模板
-    baseUrl: 'http://192.168.0.181:8560/api/ui/co_view/config?name={xtype}',
+    baseUrl: 'http://192.168.0.181:8560/api/ui/co_view/config?name={viewName}',
     // 模板替换正则
-    urlRe: /(.*){xtype}(.*)/g,
+    urlRe: /(.*){viewName}(.*)/g,
     
     /**
      * 获得form的字段配置
@@ -14,17 +14,43 @@ Ext.define('saas.util.FormUtil', {
      */
     setItems: function(form) {
         var me = this,
-            xtype = form.xtype,
-            url = me.baseUrl.replace(me.urlRe, '$1' + xtype);
+        viewName = form.viewName,
+        defaultItems = form.defaultItems,
+        formModel = form.getViewModel(),
+        url = me.baseUrl.replace(me.urlRe, '$1' + viewName);
         
         this.BaseUtil.request({url, })
         .then(function(response) {
             var res = Ext.decode(response.responseText);
             if(res.success) {
-
-                var config = res.data, items = [];
+                
+                var config = res.data || true, items = defaultItems || [];
                 if(config) {
-                    items = config.items,
+                    var cusItems = config.items || [];
+                    Ext.Array.each(cusItems, function(cusItem) {
+                        var item = items.find(function(item) {
+                            return item.name == cusItem.name;
+                        });
+                        Ext.apply(item, cusItem);
+                    });
+                    Ext.Array.each(items, function(item) {
+                        if(item.xtype == 'detailGridField') {
+                            var storeName = item.name || item.xtype + Ext.id();
+                            item.bind = {
+                                store: '{' + storeName + '}'
+                            };
+                            
+                            formModel.set(storeName, Ext.create('Ext.data.Store', {
+                                fields: item.columns ? item.columns.filter(function(c) {
+                                    return !!c.dataIndex;
+                                }).map(function(c) {
+                                    return c.dataIndex;
+                                }) : [],
+                                data: []
+                            }));
+                        }
+                    });
+
                     form.addItems(items);
                 }
 

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

@@ -31,13 +31,12 @@ Ext.define('saas.view.core.form.FormPanel', {
     items: [],
 
     remoteConfig: true, // 是否需要从远端读取form配置
-    bindFields: [], // 已绑定字段(需要保存到数据库)
     toolBtns: [], // 自定义按钮
 
     initComponent: function() {
 
         var me = this;
-
+        me.FormUtil.setItems(me);
         //判断是否加载数据
         if(me.initId&&me.initId!=0){
             var url = 'http://192.168.253.58:8800/purchase/form?id={id}',async=false;
@@ -54,6 +53,7 @@ Ext.define('saas.view.core.form.FormPanel', {
                 }
             })
             .catch(function(response) {
+                console.error(response);
             });
         }else if(me.initId==0){
             me.getViewModel().setData({detailGridField:[{},{},{},{},{},{},{},{},{},{}]})
@@ -91,7 +91,6 @@ Ext.define('saas.view.core.form.FormPanel', {
             }]
         });
         
-        me.remoteConfig && me.FormUtil.setItems(me);
         me.callParent(arguments);
     },
 

+ 35 - 14
frontend/saas-web/app/view/core/form/FormPanelController.js

@@ -2,6 +2,7 @@ Ext.define('saas.view.core.form.FormPanelController', {
     extend: 'Ext.app.ViewController',
     alias: 'controller.core-form-formpanel',
 
+    BaseUtil: Ext.create('saas.util.BaseUtil'),
     FormUtil: Ext.create('saas.util.FormUtil'),
 
     add: function(btn){
@@ -20,10 +21,13 @@ Ext.define('saas.view.core.form.FormPanelController', {
                 xtype:form.xtype
             };
             mainTab.setActiveTab(mainTab.add(form));
+        }else {
+            mainTab.setActiveTab(existingItem);
         }
     },
     delete: Ext.emptyFn,
     save:function(btn){
+        var me = this;
         var form = btn.ownerCt.ownerCt;
         if(form.getForm().wasDirty==false){
             Ext.Msg.alert('提示','未修改数据,请修改后保存');
@@ -59,23 +63,34 @@ Ext.define('saas.view.core.form.FormPanelController', {
             main:formData,
             items:newGridData
         }
-        Ext.Ajax.request({
-            url: 'http://192.168.253.58:8800/purchase/form',
+        me.BaseUtil.request({
+            url: me.saveUrl,
             params: JSON.stringify(params),
             method: 'POST',
-            headers: {
-                'Access-Control-Allow-Origin': '*',
-                "Content-Type": 'application/json;charset=UTF-8' 
-            },
-            success: function (response, opts) {
-                //解析参数
-                Ext.Msg.alert('提示','保存成功');
-            },
-            failure: function (response, opts) {
-                //失败
-                Ext.Msg.alert('提示','保存失败');
-            }
+        })
+        .then(function() {
+            Ext.Msg.alert('提示','保存成功');
+        })
+        .catch(function() {
+            Ext.Msg.alert('提示','保存失败');
         });
+        // Ext.Ajax.request({
+        //     url: 'http://192.168.253.58:8800/purchase/form',
+        //     params: JSON.stringify(params),
+        //     method: 'POST',
+        //     headers: {
+        //         'Access-Control-Allow-Origin': '*',
+        //         "Content-Type": 'application/json;charset=UTF-8' 
+        //     },
+        //     success: function (response, opts) {
+        //         //解析参数
+        //         Ext.Msg.alert('提示','保存成功');
+        //     },
+        //     failure: function (response, opts) {
+        //         //失败
+        //         Ext.Msg.alert('提示','保存失败');
+        //     }
+        // });
     },
     audit: function(btn){
         var form = btn.ownerCt.ownerCt;
@@ -126,5 +141,11 @@ Ext.define('saas.view.core.form.FormPanelController', {
                 Ext.Msg.alert('提示','审核失败');
             }
         });
+    },
+    /**
+     * 获取form数据
+     */
+    getFormData: function() {
+        
     }
 });

+ 8 - 6
frontend/saas-web/app/view/core/form/field/DetailGridField.js

@@ -7,6 +7,7 @@ Ext.define('saas.view.core.form.field.DetailGridField', {
     border: 1,
     margin: '0 5 5 0', // formpanel的fieldDefaults未生效
     height: 300,
+    columnWidth : 1.0, 
 
     requires: [
         'Ext.selection.CellModel'
@@ -17,15 +18,10 @@ Ext.define('saas.view.core.form.field.DetailGridField', {
     },
     plugins: {
         cellediting: {
-            clicksToEdit: 1
+            clicksToEdit: 2
         }
     },
 
-
-    store: {
-        data: []
-    },
-
     showIndex: true,
     configUrl: '',
 
@@ -55,6 +51,12 @@ Ext.define('saas.view.core.form.field.DetailGridField', {
                     handler: function() {
                         me.swapDown();
                     }
+                }, {
+                    text: 'Debugger',
+                    handler: function() {
+                        var detailGrid = me;
+                        debugger;
+                    }
                 }]
             }]
         });

+ 175 - 0
frontend/saas-web/app/view/test/order/FormPanel.js

@@ -12,11 +12,186 @@ Ext.define('saas.view.test.order.FormPanel', {
     _detnoColumn:  'pdDetno',
     initId:0,
 
+    saveUrl: 'http://192.168.253.58:8800/purchase/form',
+
     toolBtns: [{
         xtype: 'button',
         text: '转单按钮',
         handler: function() {
             console.log('11');
         }
+    }],
+
+    defaultItems: [{
+        xtype: 'hidden',
+        name: 'id',
+        bind: '{id}',
+        fieldLabel: 'id',
+        allowBlank: true,
+        columnWidth: 0
+    }, {
+        xtype : "textfield", 
+        name : "puCode", 
+        bind : "{puCode}", 
+        fieldLabel : "采购单号", 
+        allowBlank : true, 
+        columnWidth : 0.25
+    }, {
+        xtype : "datefield", 
+        name : "puDate", 
+        bind : "{puDate}", 
+        fieldLabel : "采购日期", 
+        allowBlank : true, 
+        columnWidth : 0.25
+    }, {
+        xtype : "hidden", 
+        name : "puVendid", 
+        bind : "{puVendid}", 
+        fieldLabel : "供应商ID", 
+        allowBlank : true, 
+        columnWidth : 0.0
+    }, {
+        xtype : "dbfindtrigger", 
+        name : "puVendcode", 
+        bind : "{puVendcode}", 
+        fieldLabel : "供应商编号", 
+        allowBlank : true, 
+        columnWidth : 0.25, 
+        configUrl : "resources/json/purchase/vendorColumnsDbfind.json", 
+        dataUrl : "resources/json/purchase/vendorDataDbfind.json"
+    }, {
+        xtype : "textfield", 
+        name : "puVendname", 
+        bind : "{puVendname}", 
+        fieldLabel : "供应商名称", 
+        allowBlank : true, 
+        columnWidth : 0.25
+    }, {
+        xtype : "hidden", 
+        name : "puBuyerid", 
+        bind : "{puBuyerid}", 
+        fieldLabel : "采购员ID", 
+        allowBlank : true, 
+        columnWidth : 0.0
+    }, {
+        xtype : "dbfindtrigger", 
+        name : "puBuyercode", 
+        bind : "{puBuyercode}", 
+        fieldLabel : "采购员编号", 
+        allowBlank : true, 
+        columnWidth : 0.25
+    }, {
+        xtype : "textfield", 
+        name : "puBuyername", 
+        bind : "{puBuyername}", 
+        fieldLabel : "采购员名称", 
+        allowBlank : true, 
+        columnWidth : 0.25
+    }, {
+        name : "detailGridField", 
+        xtype : "detailGridField", 
+        columns : [
+            {
+                text : "序号", 
+                dataIndex : "pdDetno", 
+                width : 80.0, 
+                xtype : "rownumberer"
+            }, 
+            {
+                editor : {
+                    displayField : "display", 
+                    editable : true, 
+                    format : "", 
+                    hideTrigger : false, 
+                    maxLength : 100.0, 
+                    minValue : null, 
+                    positiveNum : false, 
+                    queryMode : "local", 
+                    store : null, 
+                    valueField : "value", 
+                    xtype : "dbfindtrigger"
+                }, 
+                text : "物料编号", 
+                width : 200.0, 
+                dataIndex : "pdProdcode", 
+                xtype : "", 
+                items : null
+            }, 
+            {
+                text : "单位", 
+                editor : {
+                    xtype : "textfield"
+                }, 
+                dataIndex : "pdUnit", 
+                width : 120.0, 
+                xtype : "", 
+                items : null
+            }, 
+            {
+                text : "数量", 
+                dataIndex : "pdQty", 
+                width : 120.0, 
+                xtype : "", 
+                items : null
+            }, 
+            {
+                text : "单价", 
+                dataIndex : "pdPrice", 
+                width : 120.0, 
+                xtype : "numbercolumn", 
+                items : null
+            }, 
+            {
+                text : "总额", 
+                dataIndex : "pdTotal", 
+                width : 120.0, 
+                xtype : "numbercolumn"
+            }, 
+            {
+                text : "税额", 
+                dataIndex : "pdTaxtotal", 
+                flex : 1.0, 
+                xtype : "numbercolumn"
+            }, 
+            {
+                text : "id", 
+                dataIndex : "id", 
+                flex : 1.0, 
+                xtype : "numbercolumn"
+            }
+        ]
+    }, {
+        format : "Y-m-d", 
+        xtype : "datetimefield", 
+        name : "createTime", 
+        bind : "{createTime}", 
+        fieldLabel : "创建时间", 
+        allowBlank : true, 
+        columnWidth : 0.25
+    }, {
+        xtype : "datefield", 
+        name : "updateTime", 
+        bind : "{updateTime}", 
+        fieldLabel : "更新时间", 
+        allowBlank : true, 
+        columnWidth : 0.25
+    }, {
+        xtype : "textfield", 
+        readOnly : true, 
+        editable : false, 
+        name : "puStatus", 
+        bind : "{puStatus}", 
+        fieldLabel : "单据状态", 
+        allowBlank : true, 
+        columnWidth : 0.25
+    }, {
+        xtype : "hidden", 
+        readOnly : true, 
+        editable : false, 
+        name : "puStatuscode", 
+        bind : "{puStatuscode}", 
+        fieldLabel : "单据状态码", 
+        allowBlank : true, 
+        columnWidth : 0.0
     }]
 });