ChildForm.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * Created by zhouy on 2018/10/18.
  3. */
  4. Ext.define('KitchenSink.view.binding.ChildForm', {
  5. extend: 'Ext.window.Window',
  6. xtype: 'document-kind-childwin',
  7. layout: 'fit',
  8. modal: true,
  9. width: 400,
  10. //工具类
  11. FormUtil: Ext.create('saas.util.FormUtil'),
  12. BaseUtil: Ext.create('saas.util.BaseUtil'),
  13. height: 220,
  14. listeners:{
  15. show:function(w){
  16. if(w.record){
  17. w.down('form').loadRecord(w.record);
  18. }
  19. }
  20. },
  21. initComponent:function(){
  22. var me=this;
  23. Ext.apply(me,{
  24. items:me.setFormItems()
  25. });
  26. me.callParent();
  27. },
  28. etc:{
  29. customerkind:{
  30. items:[{
  31. xtype:'hidden',
  32. name:'ck_id'
  33. },{
  34. xtype:'textfield',
  35. name:'ck_kind',
  36. allowBlank:false,
  37. fieldLabel:'类型'
  38. }],
  39. keyField:'ck_id',
  40. saveUrl:''
  41. },
  42. vendorkind:{
  43. items:[{
  44. xtype:'hidden',
  45. name:'id'
  46. },{
  47. xtype:'textfield',
  48. name:'vk_name',
  49. allowBlank:false,
  50. fieldLabel:'类型'
  51. }],
  52. },
  53. productkind:{
  54. items:[{
  55. xtype:'hidden',
  56. name:'pk_id'
  57. },{
  58. xtype:'textfield',
  59. name:'pk_kind',
  60. allowBlank:false,
  61. fieldLabel:'类型'
  62. }],
  63. },
  64. inoutkind:{
  65. }
  66. },
  67. setFormItems:function() {
  68. var me = this, kind = me.dataKind;
  69. var conf = {
  70. xtype: 'form',
  71. bodyPadding: 10,
  72. border: false,
  73. modelValidation: true,
  74. layout: {
  75. type: 'vbox',
  76. align: 'stretch'
  77. },
  78. defaults: {
  79. xtype: 'textfield'
  80. },
  81. buttons: [{
  82. text: '保存',
  83. formBind:true,
  84. handler: me.onSave,
  85. scope:me
  86. }, {
  87. text: '取消',
  88. handler: me.onCancel,
  89. scope:me
  90. }]
  91. };
  92. return Ext.apply(conf, me.etc[kind]);
  93. },
  94. onSave:function(){
  95. var belong = this.belong;
  96. var form=this.down('form');
  97. var dataField = form.down('[name='+belong.dataField+']');
  98. if(!dataField.value){
  99. Ext.Msg.alert('提示','数据有误');
  100. return false;
  101. }
  102. var keyField = form.down('[name='+belong.keyField+']');
  103. //保存接口
  104. var params = {};
  105. params[belong.dataField] = dataField.value;
  106. params[belong.keyField] = keyField.value || 0;
  107. this.BaseUtil.request({
  108. url: belong.reqUrl,
  109. params: JSON.stringify(params),
  110. method: 'POST',
  111. })
  112. .then(function(res) {
  113. var localJson = new Ext.decode(res.responseText);
  114. if(localJson.success){
  115. Ext.Msg.alert('提示','保存成功');
  116. var grid = form.ownerCt._parent.lookup('document-kind-Grid');
  117. if(grid){
  118. grid.store.load();
  119. }
  120. form.ownerCt.close();
  121. }
  122. })
  123. .catch(function() {
  124. Ext.Msg.alert('提示','保存失败');
  125. });
  126. },
  127. onCancel:function(){
  128. this.hide();
  129. }
  130. });