FormPanelController.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. Ext.define('saas.view.purchase.purchaseIn.FormPanelController', {
  2. extend: 'saas.view.core.form.FormPanelController',
  3. alias: 'controller.purchase-purchasein-formpanel',
  4. init: function (form) {
  5. var me = this;
  6. this.control({
  7. /**放大镜新增demo*/
  8. "field[name=combo]":{
  9. beforerender:function(f){
  10. f.addHandler=me.addCombo;
  11. }
  12. },
  13. //放大镜赋值关系 以及 tpl模板
  14. 'dbfindtrigger[name=pi_vendname]':{
  15. beforerender:function(f){
  16. Ext.apply(f,{
  17. dbfinds:[{
  18. from:'id',to:'pi_vendid',ignore:true
  19. },{
  20. from:'ve_code',to:'pi_vendcode'
  21. },{
  22. from:'ve_name',to:'pi_vendname'
  23. },{
  24. from:'ve_buyerid',to:'pi_buyerid'
  25. },{
  26. from:'ve_buyercode',to:'pi_buyercode'
  27. },{
  28. from:'ve_buyername',to:'pi_buyername'
  29. }],
  30. }) ;
  31. }
  32. },
  33. //放大镜赋值关系 以及 tpl模板
  34. 'multidbfindtrigger[name=pd_prodcode]':{
  35. beforerender:function(f){
  36. Ext.apply(f,{
  37. dbfinds:[{
  38. from:'id',to:'pd_prodid',ignore:true
  39. },{
  40. from:'pr_code',to:'pd_prodcode'
  41. },{
  42. from:'pr_detail',to:'pr_detail'
  43. },{
  44. from:'pr_spec',to:'pr_spec'
  45. },{
  46. from: 'pr_brand', to: 'pr_brand'
  47. },{
  48. from: 'pr_orispeccode', to: 'pr_orispeccode'
  49. },{
  50. from: 'pr_unit', to: 'pr_unit'
  51. }, {
  52. from:'pr_whid',to:'pd_whid'
  53. },{
  54. from:'pr_whcode',to:'pd_whcode'
  55. },{
  56. from:'pr_whname',to:'pd_whname'
  57. },{
  58. from:'pr_purcprice',to:'pd_orderprice'
  59. }],
  60. });
  61. }
  62. },
  63. //放大镜赋值关系 以及 tpl模板
  64. 'dbfindtrigger[name=pd_whname]':{
  65. beforerender:function(f){
  66. Ext.apply(f,{
  67. dbfinds:[{
  68. from:'id',to:'pd_whid',ignore:true
  69. },{
  70. from:'wh_code',to:'pd_whcode'
  71. },{
  72. from:'wh_description',to:'pd_whname'
  73. }],
  74. }) ;
  75. }
  76. } , // 主表-采购员名称
  77. 'dbfindtrigger[name=pi_buyername]':{
  78. beforerender:function(f){
  79. Ext.apply(f,{
  80. //赋值
  81. dbfinds:[{
  82. from:'id',to:'pi_buyerid',ignore:true
  83. },{
  84. from:'em_code',to:'pi_buyercode'
  85. },{
  86. from:'em_name',to:'pi_buyername'
  87. }]
  88. }) ;
  89. }
  90. },
  91. });
  92. },
  93. addCombo:function(){
  94. var combo=this.ownerCmp;
  95. Ext.create('Ext.window.Window',{
  96. layout:'vbox',
  97. bodyPadding: 15,
  98. width:500,
  99. items:[{
  100. fieldLabel:'实际值',
  101. xtype:'textfield'
  102. },{
  103. fieldLabel:'显示值',
  104. xtype:'textfield'
  105. }],
  106. buttons:[{
  107. text:'确认',
  108. handler:function(b){
  109. combo.setValue('ok');
  110. b.up('window').close();
  111. }
  112. }],
  113. renderTo:this.ownerCmp.ownerCt.getEl()
  114. }).show();
  115. },
  116. initCopyData: function(formData) {
  117. var me = this;
  118. var form = this.getView();
  119. var detailCount = form.detailCount;
  120. var main = formData.main;
  121. var auditTexts = form.auditTexts;
  122. // 单号、id清空
  123. main[form._idField] = 0;
  124. main[form._codeField] = '';
  125. //采购单id,采购单号清空
  126. main['pi_puid'] = 0;
  127. main['pi_pucode'] = '';
  128. // 单据状态为录入状态(未审核)
  129. main[form._statusCodeField] = auditTexts.unAuditCode;
  130. main[form._statusField] = auditTexts.unAuditText;
  131. //重设录入人,录入日期,审核人,审核日期
  132. main['creatorId'] = saas.util.BaseUtil.getCurrentUser().id;
  133. main['creatorName'] = saas.util.BaseUtil.getCurrentUser().realname;
  134. main['createTime'] = Ext.Date.format(new Date(), 'Y-m-d H:i:s');
  135. main['updaterId'] = saas.util.BaseUtil.getCurrentUser().id;
  136. main['updaterName'] = saas.util.BaseUtil.getCurrentUser().realname;
  137. main['updateTime'] = Ext.Date.format(new Date(), 'Y-m-d H:i:s');
  138. main[form._auditmanField] = undefined;
  139. main[form._auditdateField] = undefined;
  140. for(var k in main) {
  141. // 主表日期改为当前日期
  142. if(saas.util.BaseUtil.isDateString(main[k])) {
  143. main[k] = Ext.Date.format(new Date, 'Y-m-d H:i:s');
  144. }
  145. }
  146. for(var j = 0; j < detailCount; j++) {
  147. var detail = formData['detail' + j];
  148. for(var x = 0; x < detail.length; x ++) {
  149. var d = detail[x];
  150. for(var k in d) {
  151. // 从表id清空
  152. delete d['id'];
  153. //采购单号清空
  154. delete d['pd_orderid'];
  155. delete d['pd_ordercode'];
  156. delete d['pd_orderdetno'];
  157. // 从表日期清空
  158. if(saas.util.BaseUtil.isDateString(d[k])) {
  159. d[k] = '';
  160. }
  161. }
  162. }
  163. }
  164. return me.myInitCopyData(formData);;
  165. },
  166. turnOut: function() {
  167. var me = this,
  168. form = me.getView(),
  169. id = form.getForm().findField(form._idField);
  170. form.setLoading(true);
  171. saas.util.BaseUtil.request({
  172. url: form._turnOutUrl+'/'+id.value,
  173. method: 'POST',
  174. })
  175. .then(function(localJson) {
  176. form.setLoading(false);
  177. if(localJson.success){
  178. var intValue = localJson.data.id,
  179. codeValue= localJson.data.code,
  180. name = localJson.data.name;
  181. saas.util.BaseUtil.openTab('purchase-purchaseout-formpanel',name+"("+codeValue+")",codeValue+intValue, {
  182. initId: intValue
  183. });
  184. saas.util.BaseUtil.showSuccessToast('转单成功');
  185. }
  186. })
  187. .catch(function(res) {
  188. form.setLoading(false);
  189. console.error(res);
  190. saas.util.BaseUtil.showErrorToast('转单失败: ' + res.message);
  191. });
  192. }
  193. });