ChildForm.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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<4){
  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: {
  150. type: 'vbox',
  151. align: 'stretch'
  152. },
  153. defaults: {
  154. beforeLabelTextTpl: "<font color=\"red\" style=\"position:relative; top:2px;right:2px; font-weight: bolder;\">*</font>",
  155. xtype: 'textfield'
  156. },
  157. buttonAlign:'center',
  158. buttons: [{
  159. text: '保存',
  160. formBind:true,
  161. handler: me.onSave,
  162. scope:me
  163. }, {
  164. text: '取消',
  165. handler: me.onCancel,
  166. scope:me
  167. }]
  168. };
  169. return Ext.apply(conf, me.etc[kind]);
  170. },
  171. onSave:function(){
  172. var me = this;
  173. var belong = this.belong;
  174. me.setLoading(true);
  175. var form=this.down('form');
  176. var combo = this._combo;
  177. var params = {};
  178. var relativeField,relativeValue;//要赋值的字段和值
  179. var names = belong.columns.map(column => column.dataIndex);
  180. Ext.Array.each(names,function(name) {
  181. if(name){
  182. var dataField = form.down('[name='+name+']');
  183. if(dataField){
  184. var value = dataField.getValue();
  185. if(Ext.isDate(value)) {
  186. value = Ext.Date.format(value, 'Y-m-d H:i:s');
  187. }
  188. params[name] = value;
  189. if(!relativeValue){
  190. relativeField = dataField.relativeField;
  191. relativeValue = value;
  192. }
  193. }
  194. }
  195. });
  196. var idField = form.down('[name='+belong.keyField+']');
  197. params[belong.keyField] = idField.value || 0;
  198. //保存接口
  199. saas.util.BaseUtil.request({
  200. url: belong.reqUrl,
  201. params: JSON.stringify(params),
  202. method: 'POST'
  203. })
  204. .then(function(localJson) {
  205. me.setLoading(false);
  206. if(localJson.success){
  207. var grid = form.ownerCt._parent ? form.ownerCt._parent.lookup('document-kind-Grid') : null;
  208. if(grid){
  209. grid.store.load();
  210. }
  211. if(relativeField&&relativeValue&&form.ownerCt._parent){
  212. var grid = form.ownerCt._parent.down('grid');
  213. var rec = grid.getSelectionModel().getLastSelected();
  214. rec.set(relativeField,relativeValue);
  215. }
  216. if(combo){
  217. combo.store.load(function() {
  218. typeof combo.setValue == 'function' && combo.setValue(relativeValue);
  219. });
  220. }
  221. saas.util.BaseUtil.showSuccessToast('保存成功');
  222. form.ownerCt.close();
  223. }
  224. })
  225. .catch(function(res) {
  226. me.setLoading(false);
  227. console.error(res);
  228. saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message);
  229. });
  230. },
  231. onCancel:function(){
  232. this.hide();
  233. }
  234. });