FormPanelController.js 7.1 KB

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