ChildForm.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. allowBlank:false
  119. },{
  120. xtype:'textfield',
  121. fieldLabel: '仓库名称',
  122. name: 'wh_description',
  123. allowBlank:false
  124. },{
  125. readOnly:true,
  126. xtype:'textfield',
  127. fieldLabel: '仓库状态',
  128. name: 'wh_status',
  129. value:'已开启'
  130. },{
  131. xtype:'hidden',
  132. fieldLabel: '仓库状态码',
  133. name: 'wh_statuscode',
  134. value:'OPEN'
  135. }]
  136. }
  137. },
  138. setFormItems:function() {
  139. var me = this, kind = me.dataKind;
  140. var conf = {
  141. xtype: 'form',
  142. bodyPadding: 10,
  143. border: false,
  144. autoScroll:true,
  145. modelValidation: true,
  146. layout: {
  147. type: 'vbox',
  148. align: 'stretch'
  149. },
  150. defaults: {
  151. xtype: 'textfield'
  152. },
  153. buttons: [{
  154. text: '保存',
  155. formBind:true,
  156. handler: me.onSave,
  157. scope:me
  158. }, {
  159. text: '取消',
  160. handler: me.onCancel,
  161. scope:me
  162. }]
  163. };
  164. return Ext.apply(conf, me.etc[kind]);
  165. },
  166. onSave:function(){
  167. var belong = this.belong;
  168. var form=this.down('form');
  169. var params = {};
  170. var names = belong.columns.map(column => column.dataIndex);
  171. Ext.Array.each(names,function(name) {
  172. if(name){
  173. var dataField = form.down('[name='+name+']');
  174. if(dataField&&dataField.value){
  175. params[name] = dataField.value;
  176. }
  177. }
  178. });
  179. var idField = form.down('[name='+belong.keyField+']');
  180. params[belong.keyField] = idField.value || 0;
  181. //保存接口
  182. this.BaseUtil.request({
  183. url: belong.reqUrl,
  184. params: JSON.stringify(params),
  185. method: 'POST',
  186. })
  187. .then(function(localJson) {
  188. if(localJson.success){
  189. showToast('保存成功');
  190. var grid = form.ownerCt._parent.lookup('document-kind-Grid');
  191. if(grid){
  192. grid.store.load();
  193. }
  194. form.ownerCt.close();
  195. }
  196. })
  197. .catch(function(res) {
  198. console.error(res);
  199. showToast('保存失败: ' + res.message);
  200. });
  201. },
  202. onCancel:function(){
  203. this.hide();
  204. }
  205. });