AutoCodeTrigger.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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'),
  16. k2 = Ext.getCmp('pre_kind2'),
  17. k3 = Ext.getCmp('pre_kind3');
  18. if(k1 && !Ext.isEmpty(k1.getValue()) && k2 && !Ext.isEmpty(k2.getValue())
  19. && k3 && !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())) ? k4.getValue() : null);
  23. return;
  24. }
  25. }
  26. this.showWin();
  27. },
  28. showWin : function() {
  29. var win = this.win;
  30. if (!win) {
  31. var type = this.type || this.getType();
  32. this.win = win = new Ext.window.Window({
  33. id: 'win',
  34. height: "100%",
  35. width: "80%",
  36. maximizable: true,
  37. closeAction: 'hide',
  38. buttonAlign: 'center',
  39. layout: 'anchor',
  40. title: '获取编号',
  41. items: [{
  42. tag: 'iframe',
  43. anchor: '100% 100%',
  44. layout: 'fit',
  45. html: '<iframe id="iframe" src="' + basePath + 'jsps/scm/product/autoGetNum.jsp?type=' + type + '" height="100%" width="100%" frameborder="0"></iframe>'
  46. }]
  47. });
  48. }
  49. win.show();
  50. },
  51. askFor : function(k1, k2, k3, k4) {
  52. var me = this, s = '大类:' + k1 + ';中类:' + k2 + ';小类:' + k3 + (k4 ? (';细类' + k4) : '');
  53. var box = Ext.create('Ext.window.MessageBox', {
  54. buttonAlign : 'center',
  55. buttons: [{
  56. text: '生成编号',
  57. handler: function(b) {
  58. me.autoCode(k1, k2, k3, k4);
  59. b.ownerCt.ownerCt.close();
  60. }
  61. },{
  62. text: '重新选择',
  63. handler: function(b) {
  64. me.showWin();
  65. b.ownerCt.ownerCt.close();
  66. }
  67. },{
  68. text: '关闭',
  69. handler : function(b) {
  70. b.ownerCt.ownerCt.close();
  71. }
  72. }]
  73. });
  74. box.show({
  75. title : "提示",
  76. msg : "您已选择了【" + s + '】<br>现在立刻生成编号?',
  77. icon : Ext.MessageBox.QUESTION
  78. });
  79. },
  80. autoCode : function(k1, k2, k3, k4) {
  81. var me = this;
  82. Ext.Ajax.request({
  83. url : basePath + me.getUrl(),
  84. params: {
  85. k1: k1,
  86. k2: k2,
  87. k3: k3,
  88. k4: k4
  89. },
  90. method : 'post',
  91. callback : function(opt, s, res){
  92. var r = new Ext.decode(res.responseText);
  93. if(r.exceptionInfo){
  94. showError(r.exceptionInfo);
  95. } else if(r.success && r.number){
  96. me.setValue(r.number);
  97. me.autoSave(r.number);
  98. } else {
  99. alert('取号失败!');
  100. }
  101. }
  102. });
  103. },
  104. autoSave: function(num) {
  105. var id = this.up('form').down('#pre_id');
  106. if(id && id.value > 0) {
  107. Ext.Ajax.request({
  108. url : basePath + 'common/updateByCondition.action',
  109. params: {
  110. table: 'PreProduct',
  111. update: 'pre_code=\'' + num + '\'',
  112. condition: 'pre_id=' + id.value
  113. },
  114. method : 'post',
  115. callback : function(opt, s, res){
  116. var r = new Ext.decode(res.responseText);
  117. if(r.exceptionInfo){
  118. showError('编号保存失败.<br>' + r.exceptionInfo);
  119. }
  120. }
  121. });
  122. }
  123. },
  124. getType: function() {
  125. var type = 'Product';
  126. switch (caller) {
  127. case 'PreProduct':
  128. type = 'Product';
  129. break;
  130. case 'Vendor':
  131. type = 'Vendor';
  132. break;
  133. case 'PreVendor':
  134. type = 'Vendor';
  135. break;
  136. case 'Customer':
  137. type = 'Customer';
  138. break;
  139. case 'PreCustomer':
  140. type = 'Customer';
  141. break;
  142. }
  143. return type;
  144. },
  145. getUrl: function(){
  146. var type = this.getType();
  147. var url = 'scm/product/getProductKindNum.action';
  148. switch (type) {
  149. case 'Vendor':
  150. url = 'scm/purchase/getVendorKindNum.action';break;
  151. case 'Customer':
  152. url = 'scm/sale/getCustomerKindNum.action';break;
  153. }
  154. return url;
  155. }
  156. });