AutoCodeTrigger.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /**
  2. * 自动获取编号的trigger
  3. */
  4. Ext.define('erp.view.core.trigger.AutoCodeTrigger', {
  5. extend : 'Ext.form.field.Trigger',
  6. alias : 'widget.autocodetrigger',
  7. triggerCls : 'x-form-autocode-trigger',
  8. afterrender : function() {
  9. this.addEvent({
  10. 'aftertrigger' : true
  11. });
  12. },
  13. onTriggerClick : function() {
  14. if ("PreProduct" == caller) {
  15. var k1 = Ext.getCmp('pre_kind'), k2 = Ext.getCmp('pre_kind2'), k3 = Ext
  16. .getCmp('pre_kind3');
  17. if (k1 && !Ext.isEmpty(k1.getValue()) && k2
  18. && !Ext.isEmpty(k2.getValue()) && k3
  19. && !Ext.isEmpty(k3.getValue())) {
  20. var k4 = Ext.getCmp('pre_xikind');
  21. this.askFor(k1.getValue(), k2.getValue(), k3.getValue(),
  22. (k4 && !Ext.isEmpty(k4.getValue()))
  23. ? k4.getValue()
  24. : null);
  25. return;
  26. }
  27. }
  28. if ("FeePlease!YZSYSQ" == caller && Ext.getCmp('fp_statuscode') && Ext.getCmp('fp_statuscode').value == 'COMMITED') {
  29. var k1 = Ext.getCmp('FP_V4');
  30. if (k1 && !Ext.isEmpty(k1.getValue())) {
  31. var k2 = Ext.getCmp('FP_V5'),k3 = Ext.getCmp('FP_V7'), k4 = Ext.getCmp('FP_V8');
  32. this.askFor(k1.getValue(),
  33. (k2 && !Ext.isEmpty(k2.getValue()))? k2.getValue(): null,
  34. (k3 && !Ext.isEmpty(k3.getValue()))? k3.getValue(): null,
  35. (k4 && !Ext.isEmpty(k4.getValue()))? k4.getValue(): null);
  36. return;
  37. }
  38. }
  39. this.showWin();
  40. },
  41. showWin : function() {
  42. var win = this.win;
  43. if (!win) {
  44. var type = this.type || this.getType();
  45. var status=Ext.getCmp('fp_statuscode')?Ext.getCmp('fp_statuscode').getValue():'';
  46. this.win = win = new Ext.window.Window({
  47. id : 'win',
  48. height : "100%",
  49. width : "80%",
  50. maximizable : true,
  51. closeAction : 'hide',
  52. buttonAlign : 'center',
  53. layout : 'anchor',
  54. title : '获取编号',
  55. items : [{
  56. tag : 'iframe',
  57. anchor : '100% 100%',
  58. layout : 'fit',
  59. html : '<iframe id="iframe" src="'
  60. + basePath
  61. + 'jsps/scm/product/autoGetNum.jsp?type='
  62. + type+'&status='+status
  63. + '" height="100%" width="100%" frameborder="0"></iframe>'
  64. }]
  65. });
  66. }
  67. win.show();
  68. },
  69. askFor : function(k1, k2, k3, k4) {
  70. var me = this, s = '大类:' + k1 + (k2 ? (';中类:' + k2) : '') + (k3 ? (';小类:' + k3) : '')
  71. + (k4 ? (';细类:' + k4) : '');
  72. var box = Ext.create('Ext.window.MessageBox', {
  73. buttonAlign : 'center',
  74. buttons : [{
  75. text : '生成编号',
  76. handler : function(b) {
  77. me.autoCode(k1, k2, k3, k4);
  78. b.ownerCt.ownerCt.close();
  79. }
  80. }, {
  81. text : '重新选择',
  82. handler : function(b) {
  83. me.showWin();
  84. b.ownerCt.ownerCt.close();
  85. }
  86. }, {
  87. text : '关闭',
  88. handler : function(b) {
  89. b.ownerCt.ownerCt.close();
  90. }
  91. }]
  92. });
  93. box.show({
  94. title : "提示",
  95. msg : "您已选择了【" + s + '】<br>现在立刻生成编号?',
  96. icon : Ext.MessageBox.QUESTION
  97. });
  98. },
  99. autoCode : function(k1, k2, k3, k4) {
  100. var me = this;
  101. Ext.Ajax.request({
  102. url : basePath + me.getUrl(),
  103. params : {
  104. k1 : k1,
  105. k2 : k2,
  106. k3 : k3,
  107. k4 : k4
  108. },
  109. method : 'post',
  110. callback : function(opt, s, res) {
  111. var r = new Ext.decode(res.responseText);
  112. if (r.exceptionInfo) {
  113. showError(r.exceptionInfo);
  114. } else if (r.success && r.number) {
  115. if ("FeePlease!YZSYSQ" == caller){
  116. var code=r.number.split(";")[0];
  117. var len=r.number.split(";")[1];
  118. Ext.getCmp('FP_V13').setValue(code);
  119. Ext.getCmp('FP_V12').setValue(code.substr(0,(code.length-len)));
  120. Ext.getCmp('FP_N2').setValue(len);
  121. Ext.getCmp('FP_N1').setValue(code.substr((code.length-len),code.length));
  122. }
  123. if ("PreProduct" == caller) {
  124. me.setValue(r.number);
  125. me.autoSave(r.number);
  126. }
  127. } else {
  128. alert('取号失败!');
  129. }
  130. }
  131. });
  132. },
  133. autoSave : function(num) {
  134. var id = this.up('form').down('#pre_id');
  135. if (id && id.value > 0) {
  136. Ext.Ajax.request({
  137. url : basePath + 'common/updateByCondition.action',
  138. params : {
  139. table : 'PreProduct',
  140. update : 'pre_code=\'' + num + '\'',
  141. condition : 'pre_id=' + id.value
  142. },
  143. method : 'post',
  144. callback : function(opt, s, res) {
  145. var r = new Ext.decode(res.responseText);
  146. if (r.exceptionInfo) {
  147. showError('编号保存失败.<br>' + r.exceptionInfo);
  148. }
  149. }
  150. });
  151. }
  152. },
  153. getType : function() {
  154. var type = 'Product';
  155. switch (caller) {
  156. case 'PreProduct' :
  157. type = 'Product';
  158. break;
  159. case 'Vendor' :
  160. type = 'Vendor';
  161. break;
  162. case 'PreVendor' :
  163. type = 'Vendor';
  164. break;
  165. case 'Customer' :
  166. type = 'Customer';
  167. break;
  168. case 'PreCustomer' :
  169. type = 'Customer';
  170. break;
  171. case 'FeePlease!YZSYSQ' :
  172. type = 'FeePlease!YZSYSQ';
  173. break;
  174. }
  175. return type;
  176. },
  177. getUrl : function() {
  178. var type = this.getType();
  179. var url = 'scm/product/getProductKindNum.action';
  180. switch (type) {
  181. case 'Vendor' :
  182. url = 'scm/purchase/getVendorKindNum.action';
  183. break;
  184. case 'Customer' :
  185. url = 'scm/sale/getCustomerKindNum.action';
  186. break;
  187. case 'FeePlease!YZSYSQ' :
  188. url = 'oa/fee/getContractTypeNum.action';
  189. break;
  190. }
  191. return url;
  192. }
  193. });