CustomerBaseFP.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.sale.CustomerBaseFP', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. BaseUtil: Ext.create('erp.util.BaseUtil'),
  7. views:[
  8. 'scm.sale.CustomerBaseFP','core.form.Panel','core.form.MultiField','core.grid.Panel2','core.button.HandleHang','core.form.FileField',
  9. 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.Upload','core.button.ResAudit',
  10. 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.ResSubmit',
  11. 'core.button.Banned','core.button.ResBanned','core.button.Sync',
  12. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField'
  13. ],
  14. init:function(){
  15. var me = this;
  16. this.control({
  17. 'erpGridPanel2': {
  18. itemclick: this.onGridItemClick
  19. },
  20. 'erpSaveButton': {
  21. click: function(btn){
  22. var form = me.getForm(btn), s = Ext.getCmp('cu_source'),
  23. codeField = Ext.getCmp(form.codeField), kind =Ext.getCmp('cu_kind').value;
  24. if(s) {
  25. var source = s.value;
  26. if(codeField.value == null || codeField.value == ''){
  27. me.getSetting(function(s){
  28. if(s) {
  29. if(source == '国内'){
  30. me.BaseUtil.getRandomNumber('Customer!G');//自动添加编号
  31. } else if(source == '海外'){
  32. me.BaseUtil.getRandomNumber('Customer!W');//自动添加编号
  33. } else {
  34. me.BaseUtil.getRandomNumber(null,10,null);
  35. var res = me.getLeadCode(kind);
  36. if(res != null && res != ''){
  37. codeField.setValue(res + codeField.getValue());
  38. }
  39. }
  40. } else {
  41. me.BaseUtil.getRandomNumber(null,10,null);
  42. var res = me.getLeadCode(kind);
  43. if(res != null && res != ''){
  44. codeField.setValue(res + codeField.getValue());
  45. }
  46. }
  47. });
  48. }
  49. } else {
  50. if(codeField.value == null || codeField.value == ''){
  51. me.BaseUtil.getRandomNumber(null,10,null);//自动添加编号
  52. var res = me.getLeadCode(kind);
  53. if(res != null && res != ''){
  54. codeField.setValue(res + codeField.getValue());
  55. }
  56. }
  57. }
  58. var cust = Ext.getCmp('cu_code').value, custname = Ext.getCmp('cu_name').value,
  59. shcustcode = Ext.getCmp('cu_shcustcode').value, arcode=Ext.getCmp('cu_arcode').value;
  60. cust = cust != null ? cust.toUpperCase() : null;
  61. if(shcustcode == null || shcustcode == ''){
  62. Ext.getCmp('cu_shcustcode').setValue(cust);
  63. Ext.getCmp('cu_shcustname').setValue(custname);
  64. }
  65. if(arcode == null || arcode == ''){
  66. Ext.getCmp('cu_arcode').setValue(cust);
  67. Ext.getCmp('cu_arname').setValue(custname);
  68. }
  69. var id = Ext.getCmp('cu_id').value;
  70. if(id == null || id == '' || id == '0' || id == 0){
  71. this.FormUtil.beforeSave(this);
  72. } else {
  73. this.FormUtil.onUpdate(this);
  74. }
  75. }
  76. },
  77. 'erpDeleteButton' : {
  78. click: function(btn){
  79. me.FormUtil.onDelete(Ext.getCmp('cu_id').value);
  80. }
  81. },
  82. 'erpUpdateButton': {
  83. /* afterrender: function(btn){
  84. var status = Ext.getCmp('cu_statuscode');
  85. if(status && status.value != 'ENTERING'){
  86. btn.hide();
  87. }
  88. },*/
  89. click: function(btn){
  90. me.beforeUpdate();
  91. }
  92. },
  93. 'erpAddButton': {
  94. click: function(){
  95. me.FormUtil.onAdd('addCustomerBaseFP', '新增客户基础资料', 'jsps/scm/sale/customerBaseFP.jsp');
  96. }
  97. },
  98. 'erpCloseButton': {
  99. click: function(btn){
  100. me.FormUtil.beforeClose(me);
  101. }
  102. },
  103. 'erpSubmitButton': {
  104. afterrender: function(btn){
  105. var status = Ext.getCmp('cu_auditstatuscode');
  106. if(status && status.value != 'ENTERING'){
  107. btn.hide();
  108. }
  109. },
  110. click: function(btn){
  111. me.beforeSubmit(btn);
  112. }
  113. },
  114. 'erpResSubmitButton': {
  115. afterrender: function(btn){
  116. var status = Ext.getCmp('cu_auditstatuscode');
  117. if(status && status.value != 'COMMITED'){
  118. btn.hide();
  119. }
  120. },
  121. click: function(btn){
  122. me.FormUtil.onResSubmit(Ext.getCmp('cu_id').value);
  123. }
  124. },
  125. 'erpAuditButton': {
  126. afterrender: function(btn){
  127. var status = Ext.getCmp('cu_auditstatuscode');
  128. if(status && status.value != 'COMMITED'){
  129. btn.hide();
  130. }
  131. },
  132. click: function(btn){
  133. me.FormUtil.onAudit(Ext.getCmp('cu_id').value);
  134. }
  135. },
  136. 'erpResAuditButton': {
  137. afterrender: function(btn){
  138. var status = Ext.getCmp('cu_auditstatuscode');
  139. if(status && status.value != 'AUDITED'){
  140. btn.hide();
  141. }
  142. },
  143. click: function(btn){
  144. me.FormUtil.onResAudit(Ext.getCmp('cu_id').value);
  145. }
  146. },
  147. 'erpPrintButton': {
  148. click: function(btn){
  149. me.FormUtil.onPrint(Ext.getCmp('cu_id').value);
  150. }
  151. },
  152. 'erpBannedButton': {
  153. afterrender: function(btn){
  154. var status = Ext.getCmp('cu_auditstatuscode');
  155. if(status && (status.value == 'BANNED' || status.value == 'DISABLE')){
  156. btn.hide();
  157. }
  158. },
  159. click: function(btn){
  160. this.FormUtil.onBanned(Ext.getCmp('cu_id').value);
  161. }
  162. },
  163. 'erpResBannedButton': {
  164. afterrender: function(btn){
  165. var status = Ext.getCmp('cu_auditstatuscode');
  166. if(status && status.value != 'BANNED' && status.value != 'DISABLE'){
  167. btn.hide();
  168. }
  169. },
  170. click: function(btn){
  171. this.FormUtil.onResBanned(Ext.getCmp('cu_id').value);
  172. }
  173. },
  174. 'erpHandleHangButton':{
  175. afterrender:function(btn){
  176. var status=Ext.getCmp('cu_statuscode');
  177. if(status && status.value !='HUNG'){
  178. btn.hidden();
  179. }
  180. },
  181. click:function (btn){
  182. Ext.Ajax.request({
  183. url : basePath +'scm/sale/submitHandleHangCustomerBaseFP.action',
  184. params: param,
  185. method : 'post',
  186. callback : function(options, success, response){
  187. var res = new Ext.decode(response.responseText);
  188. if(res.exceptionInfo != null){
  189. showError(res.exceptionInfo);return;
  190. }else {
  191. submitSuccess(function(){
  192. window.location.reload();
  193. });
  194. }
  195. }
  196. });
  197. }
  198. }
  199. });
  200. },
  201. getSetting : function(fn) {
  202. var me = this;
  203. Ext.Ajax.request({
  204. url : basePath + 'common/getFieldData.action',
  205. async: false,
  206. params: {
  207. caller: 'Setting',
  208. field: 'se_value',
  209. condition: 'se_what=\'CustCodeType\''
  210. },
  211. method : 'post',
  212. callback : function(opt, s, res){
  213. var r = new Ext.decode(res.responseText);
  214. var t = false;
  215. if(r.exceptionInfo){
  216. showError(r.exceptionInfo);return;
  217. }
  218. if(r.success && r.data){
  219. t = r.data == 'true';
  220. }
  221. fn.call(me, t);
  222. }
  223. });
  224. },
  225. beforeSubmit:function(btn){
  226. var me = this;
  227. var grid = Ext.getCmp('grid'),items=grid.store.data.items;
  228. me.FormUtil.onSubmit(Ext.getCmp('cu_id').value);
  229. },
  230. beforeUpdate: function(){
  231. var bool = true;
  232. if(bool)
  233. this.FormUtil.onUpdate(this);
  234. },
  235. onGridItemClick: function(selModel, record){//grid行选择
  236. this.GridUtil.onGridItemClick(selModel, record);
  237. },
  238. getForm: function(btn){
  239. return btn.ownerCt.ownerCt;
  240. },
  241. getLeadCode: function(type) {
  242. var result = null;
  243. Ext.Ajax.request({
  244. url : basePath + 'common/getFieldData.action',
  245. async: false,
  246. params: {
  247. caller: 'CustomerKind',
  248. field: 'ck_excode',
  249. condition: 'ck_kind=\'' + type + '\''
  250. },
  251. method : 'post',
  252. callback : function(opt, s, res){
  253. var r = new Ext.decode(res.responseText);
  254. if(r.exceptionInfo){
  255. showError(r.exceptionInfo);return;
  256. } else if(r.success){
  257. result = r.data;
  258. }
  259. }
  260. });
  261. return result;
  262. }
  263. });