ChildForm.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. productunit:{
  100. items:[{
  101. xtype:'hidden',
  102. name:'id'
  103. },{
  104. xtype:'textfield',
  105. name:'pu_name',
  106. allowBlank:false,
  107. fieldLabel:'计量单位'
  108. }]
  109. },
  110. inoutkind:{
  111. items:[{
  112. xtype:'hidden',
  113. name:'id'
  114. },{
  115. xtype:'textfield',
  116. name:'ft_name',
  117. allowBlank:false,
  118. fieldLabel:'类型'
  119. }]
  120. },
  121. address:{
  122. items:[{
  123. xtype:'hidden',
  124. name:'id'
  125. },{
  126. xtype:'textfield',
  127. name:'ad_address',
  128. allowBlank:false,
  129. fieldLabel:'地址详情'
  130. }]
  131. },
  132. warehouse:{
  133. items:[{
  134. xtype:'hidden',
  135. name:'id'
  136. },{
  137. xtype:'textfield',
  138. fieldLabel: '仓库编号',
  139. name: 'wh_code',
  140. allowBlank:false
  141. },{
  142. xtype:'textfield',
  143. fieldLabel: '仓库名称',
  144. name: 'wh_description',
  145. allowBlank:false
  146. },{
  147. readOnly:true,
  148. xtype:'textfield',
  149. fieldLabel: '仓库状态',
  150. name: 'wh_status',
  151. value:'已开启'
  152. },{
  153. xtype:'hidden',
  154. fieldLabel: '仓库状态码',
  155. name: 'wh_statuscode',
  156. value:'OPEN'
  157. }]
  158. }
  159. },
  160. setFormItems:function() {
  161. var me = this, kind = me.dataKind;
  162. var conf = {
  163. xtype: 'form',
  164. bodyPadding: 10,
  165. border: false,
  166. autoScroll:true,
  167. modelValidation: true,
  168. layout: {
  169. type: 'vbox',
  170. align: 'stretch'
  171. },
  172. defaults: {
  173. xtype: 'textfield'
  174. },
  175. buttons: [{
  176. text: '保存',
  177. formBind:true,
  178. handler: me.onSave,
  179. scope:me
  180. }, {
  181. text: '取消',
  182. handler: me.onCancel,
  183. scope:me
  184. }]
  185. };
  186. return Ext.apply(conf, me.etc[kind]);
  187. },
  188. onSave:function(){
  189. var belong = this.belong;
  190. var form=this.down('form');
  191. var combo = this._combo;
  192. var params = {};
  193. var names = belong.columns.map(column => column.dataIndex);
  194. Ext.Array.each(names,function(name) {
  195. if(name){
  196. var dataField = form.down('[name='+name+']');
  197. if(dataField&&dataField.value){
  198. params[name] = dataField.value;
  199. }
  200. }
  201. });
  202. var idField = form.down('[name='+belong.keyField+']');
  203. params[belong.keyField] = idField.value || 0;
  204. //保存接口
  205. this.BaseUtil.request({
  206. url: belong.reqUrl,
  207. params: JSON.stringify(params),
  208. method: 'POST',
  209. })
  210. .then(function(localJson) {
  211. if(localJson.success){
  212. showToast('保存成功');
  213. var grid = form.ownerCt._parent.lookup('document-kind-Grid');
  214. if(grid){
  215. grid.store.load();
  216. }
  217. if(combo){
  218. combo.store.load();
  219. }
  220. form.ownerCt.close();
  221. }
  222. })
  223. .catch(function(res) {
  224. console.error(res);
  225. showToast('保存失败: ' + res.message);
  226. });
  227. },
  228. onCancel:function(){
  229. this.hide();
  230. }
  231. });