ChildForm.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /**
  2. * Created by zhouy on 2018/10/18.
  3. */
  4. Ext.define('saas.view.document.kind.ChildForm', {
  5. extend: 'Ext.window.Window',
  6. xtype: 'document-kind-childwin',
  7. cls:'x-window-dbfind',
  8. layout: 'fit',
  9. modal: true,
  10. width: 500,
  11. //工具类
  12. height: 280,
  13. listeners:{
  14. show:function(w){
  15. //自动适应窗口
  16. var items = w.down('form').items.items;
  17. var count = 0;
  18. var codeField;
  19. Ext.Array.each(items,function(item) {
  20. if(item.xtype!='hidden'){
  21. count++;
  22. }
  23. if(item.autoCode){
  24. codeField = item.name
  25. }
  26. });
  27. if(count!=0&&count<6){
  28. w.setHeight(114+40*count)
  29. }
  30. if(w.record){
  31. w.down('form').loadRecord(w.record);
  32. }else{
  33. //判断是否有code字段
  34. if(codeField){
  35. w.setLoading(true);
  36. //取后台编号
  37. var caller = w.caller || w._parent.caller;
  38. saas.util.BaseUtil.request({
  39. url: '/api/commons/number/getMaxnumber',
  40. headers: {
  41. "Content-Type": 'application/x-www-form-urlencoded;charset=UTF-8'
  42. },
  43. params: {
  44. caller:caller
  45. },
  46. method: 'POST',
  47. }).then(function(res) {
  48. w.setLoading(false);
  49. if(res.success){
  50. w.down('[name='+codeField+']').setValue(res.data);
  51. }else {
  52. saas.util.BaseUtil.showErrorToast(res.message);
  53. }
  54. }).catch(function(res) {
  55. saas.util.BaseUtil.showErrorToast(res.message);
  56. w.setLoading(true);
  57. })
  58. }
  59. }
  60. }
  61. },
  62. initComponent:function(){
  63. var me=this;
  64. Ext.apply(me,{
  65. items:me.setFormItems()
  66. });
  67. me.callParent();
  68. },
  69. etc:{
  70. customerkind:{
  71. items:[{
  72. xtype:'hidden',
  73. name:'id'
  74. },{
  75. xtype:'textfield',
  76. name:'ck_name',
  77. allowBlank:false,
  78. fieldLabel:'客户类型',
  79. maxLength: 20
  80. }]
  81. },
  82. vendorkind:{
  83. items:[{
  84. xtype:'hidden',
  85. name:'id'
  86. },{
  87. xtype:'textfield',
  88. name:'vk_name',
  89. allowBlank:false,
  90. fieldLabel:'供应商类型',
  91. maxLength: 20
  92. }]
  93. },
  94. productkind:{
  95. items:[{
  96. xtype:'hidden',
  97. name:'id'
  98. },{
  99. xtype:'textfield',
  100. name:'pt_name',
  101. allowBlank:false,
  102. fieldLabel:'物料类型',
  103. maxLength: 20
  104. }]
  105. },
  106. inoutkind:{
  107. items:[{
  108. xtype:'hidden',
  109. name:'id'
  110. },{
  111. xtype:'textfield',
  112. name:'ft_name',
  113. allowBlank:false,
  114. relativeField:'ord_type',
  115. fieldLabel:'收支名称',
  116. maxLength: 20
  117. },{
  118. xtype:'combo',
  119. name:'ft_kind',
  120. allowBlank:false,
  121. fieldLabel:'收支类型',
  122. hideTrigger : false,
  123. maxLength : 100.0,
  124. minValue : null,
  125. positiveNum : false,
  126. queryMode : "local",
  127. valueField : "value",
  128. xtype : "combo",
  129. editable:false,
  130. displayField : "display",
  131. store:{
  132. fields: ['display', 'value'],
  133. data : [
  134. {"display":"收入", "value":'收入'},
  135. {"display":"支出", "value":'支出'}
  136. ]
  137. }
  138. }]
  139. }
  140. },
  141. setFormItems:function() {
  142. var me = this, kind = me.dataKind;
  143. var conf = {
  144. xtype: 'form',
  145. bodyPadding: '10 30 10 10',
  146. border: false,
  147. autoScroll:true,
  148. modelValidation: true,
  149. layout: 'column',
  150. defaults: {
  151. margin:'0 0 10 0',
  152. beforeLabelTextTpl: "<font color=\"red\" style=\"position:relative; top:2px;right:2px; font-weight: bolder;\">*</font>",
  153. xtype: 'textfield',
  154. columnWidth:1
  155. },
  156. buttonAlign:'center',
  157. buttons: [{
  158. text: '保存',
  159. formBind:true,
  160. handler: me.onSave,
  161. scope:me
  162. }, {
  163. text: '取消',
  164. handler: me.onCancel,
  165. scope:me
  166. }]
  167. };
  168. return Ext.apply(conf, me.etc[kind]);
  169. },
  170. onSave:function(){
  171. var me = this;
  172. var belong = this.belong;
  173. me.setLoading(true);
  174. var form=this.down('form');
  175. var combo = this._combo;
  176. var params = {};
  177. var relativeField,relativeValue;//要赋值的字段和值
  178. var names = belong.columns.map(column => column.dataIndex);
  179. Ext.Array.each(names,function(name) {
  180. if(name){
  181. var dataField = form.down('[name='+name+']');
  182. if(dataField){
  183. var value = dataField.getValue();
  184. if(Ext.isDate(value)) {
  185. value = Ext.Date.format(value, 'Y-m-d H:i:s');
  186. }
  187. params[name] = value;
  188. if(!relativeValue){
  189. relativeField = dataField.relativeField;
  190. relativeValue = value;
  191. }
  192. }
  193. }
  194. });
  195. var idField = form.down('[name='+belong.keyField+']');
  196. params[belong.keyField] = idField.value || 0;
  197. //保存接口
  198. saas.util.BaseUtil.request({
  199. url: belong.reqUrl,
  200. params: JSON.stringify(params),
  201. method: 'POST'
  202. })
  203. .then(function(localJson) {
  204. me.setLoading(false);
  205. if(localJson.success){
  206. var grid = form.ownerCt._parent;
  207. if(grid){
  208. if(form.ownerCt._parent.lookup('document-kind-Grid')!=null){
  209. form.ownerCt._parent.lookup('document-kind-Grid').store.load()
  210. }else if(grid.store){
  211. grid.store.load();
  212. }
  213. }
  214. if(relativeField&&relativeValue&&form.ownerCt._parent){
  215. var grid = form.ownerCt._parent.down('grid');
  216. var rec = grid.getSelectionModel().getLastSelected();
  217. rec.set(relativeField,relativeValue);
  218. }
  219. if(combo){
  220. combo.store.load(function() {
  221. typeof combo.setValue == 'function' && combo.setValue(relativeValue);
  222. });
  223. }
  224. saas.util.BaseUtil.showSuccessToast('保存成功');
  225. form.ownerCt.close();
  226. }
  227. })
  228. .catch(function(res) {
  229. me.setLoading(false);
  230. console.error(res);
  231. saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message);
  232. });
  233. },
  234. onCancel:function(){
  235. this.hide();
  236. }
  237. });