ChildForm.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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: 500,
  10. //工具类
  11. FormUtil: Ext.create('saas.util.FormUtil'),
  12. BaseUtil: Ext.create('saas.util.BaseUtil'),
  13. height: 260,
  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:'id'
  33. },{
  34. xtype:'textfield',
  35. name:'ck_name',
  36. allowBlank:false,
  37. fieldLabel:'类型'
  38. }]
  39. },
  40. vendorkind:{
  41. items:[{
  42. xtype:'hidden',
  43. name:'id'
  44. },{
  45. xtype:'textfield',
  46. name:'vk_name',
  47. allowBlank:false,
  48. fieldLabel:'类型'
  49. }]
  50. },
  51. productkind:{
  52. items:[{
  53. xtype:'hidden',
  54. name:'id'
  55. },{
  56. xtype:'textfield',
  57. name:'pt_name',
  58. allowBlank:false,
  59. fieldLabel:'类型'
  60. }]
  61. },
  62. bankinformation:{
  63. items:[{
  64. xtype:'hidden',
  65. name:'id'
  66. },{
  67. xtype:'textfield',
  68. name:'bk_bankname',
  69. allowBlank:false,
  70. fieldLabel:'账户名称'
  71. },{
  72. xtype:'textfield',
  73. name:'bk_bankcode',
  74. allowBlank:false,
  75. fieldLabel:'账户编号'
  76. },{
  77. xtype:'numberfield',
  78. name:'bk_beginamount',
  79. allowBlank:false,
  80. fieldLabel:'期初金额'
  81. },{
  82. xtype:'numberfield',
  83. name:'bk_thisamount',
  84. allowBlank:false,
  85. fieldLabel:'当前金额'
  86. }]
  87. },
  88. productbrand:{
  89. items:[{
  90. xtype:'hidden',
  91. name:'id'
  92. },{
  93. xtype:'textfield',
  94. name:'pb_name',
  95. allowBlank:false,
  96. fieldLabel:'类型'
  97. }]
  98. },
  99. inoutkind:{
  100. items:[{
  101. xtype:'hidden',
  102. name:'id'
  103. },{
  104. xtype:'textfield',
  105. name:'ft_name',
  106. allowBlank:false,
  107. fieldLabel:'类型'
  108. }]
  109. },
  110. storeinformation:{
  111. items:[{
  112. xtype:'hidden',
  113. name:'id'
  114. },{
  115. xtype:'textfield',
  116. fieldLabel: '仓库编号',
  117. name: 'wh_code'
  118. },{
  119. xtype:'textfield',
  120. fieldLabel: '仓库名称',
  121. name: 'wh_description'
  122. },{
  123. readOnly:true,
  124. xtype:'textfield',
  125. fieldLabel: '仓库状态',
  126. name: 'wh_status',
  127. value:'已开启'
  128. },{
  129. xtype:'hidden',
  130. fieldLabel: '仓库状态码',
  131. name: 'wh_statuscode',
  132. value:'OPEN'
  133. }]
  134. }
  135. },
  136. setFormItems:function() {
  137. var me = this, kind = me.dataKind;
  138. var conf = {
  139. xtype: 'form',
  140. bodyPadding: 10,
  141. border: false,
  142. autoScroll:true,
  143. modelValidation: true,
  144. layout: {
  145. type: 'vbox',
  146. align: 'stretch'
  147. },
  148. defaults: {
  149. xtype: 'textfield'
  150. },
  151. buttons: [{
  152. text: '保存',
  153. formBind:true,
  154. handler: me.onSave,
  155. scope:me
  156. }, {
  157. text: '取消',
  158. handler: me.onCancel,
  159. scope:me
  160. }]
  161. };
  162. return Ext.apply(conf, me.etc[kind]);
  163. },
  164. onSave:function(){
  165. var belong = this.belong;
  166. var form=this.down('form');
  167. var params = {};
  168. var names = belong.columns.map(column => column.dataIndex);
  169. Ext.Array.each(names,function(name) {
  170. if(name){
  171. var dataField = form.down('[name='+name+']');
  172. if(dataField&&dataField.value){
  173. params[name] = dataField.value;
  174. }
  175. }
  176. });
  177. var idField = form.down('[name='+belong.keyField+']');
  178. params[belong.keyField] = idField.value || 0;
  179. //保存接口
  180. this.BaseUtil.request({
  181. url: belong.reqUrl,
  182. params: JSON.stringify(params),
  183. method: 'POST',
  184. })
  185. .then(function(localJson) {
  186. if(localJson.success){
  187. showToast('保存成功');
  188. var grid = form.ownerCt._parent.lookup('document-kind-Grid');
  189. if(grid){
  190. grid.store.load();
  191. }
  192. form.ownerCt.close();
  193. }
  194. })
  195. .catch(function(res) {
  196. console.error(res);
  197. showToast('保存失败: ' + res.message);
  198. });
  199. },
  200. onCancel:function(){
  201. this.hide();
  202. }
  203. });