PreCustomer.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.sale.PreCustomer', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. BaseUtil: Ext.create('erp.util.BaseUtil'),
  6. views:[
  7. 'scm.sale.PreCustomer','core.form.Panel','core.form.FileField','core.form.MultiField',
  8. 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.Upload','core.button.ResAudit',
  9. 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.ResSubmit',
  10. 'core.button.TurnCustomer','core.button.TurnFKCustomer','core.button.Flow','core.button.DownLoad','core.button.Scan',
  11. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.trigger.AutoCodeTrigger','core.form.CascadingCityField'
  12. ],
  13. init:function(){
  14. var me = this;
  15. this.control({
  16. 'erpSaveButton': {
  17. click: function(btn){
  18. var form = me.getForm(btn),
  19. codeField = Ext.getCmp(form.codeField), kind =Ext.getCmp('cu_kind').value;
  20. if(codeField.value == null || codeField.value == ''){
  21. //var res = me.getLeadCode(kind);
  22. var res = me.getCode(kind);
  23. if(res != null && res != ''){
  24. //codeField.setValue(res + codeField.getValue());
  25. codeField.setValue(res);
  26. } else
  27. me.BaseUtil.getRandomNumber('Customer',10,null);//自动添加编号
  28. }
  29. var cust = Ext.getCmp('cu_code').value, custname = Ext.getCmp('cu_name').value,
  30. shcustcode = Ext.getCmp('cu_shcustcode').value, arcode=Ext.getCmp('cu_arcode').value;
  31. cust = cust != null ? cust.toUpperCase() : null;
  32. if(shcustcode == null || shcustcode == ''){
  33. Ext.getCmp('cu_shcustcode').setValue(cust);
  34. Ext.getCmp('cu_shcustname').setValue(custname);
  35. }
  36. if(arcode == null || arcode == ''){
  37. Ext.getCmp('cu_arcode').setValue(cust);
  38. Ext.getCmp('cu_arname').setValue(custname);
  39. }
  40. this.FormUtil.beforeSave(this);
  41. }
  42. },
  43. 'erpDeleteButton' : {
  44. click: function(btn){
  45. me.FormUtil.onDelete(Ext.getCmp('cu_id').value);
  46. }
  47. },
  48. 'erpUpdateButton': {
  49. click: function(btn){
  50. var cust = Ext.getCmp('cu_code').value, custname = Ext.getCmp('cu_name').value,
  51. shcustcode = Ext.getCmp('cu_shcustcode').value, arcode=Ext.getCmp('cu_arcode').value;
  52. cust = cust != null ? cust.toUpperCase() : null;
  53. if(shcustcode == null || shcustcode == ''){
  54. Ext.getCmp('cu_shcustcode').setValue(cust);
  55. Ext.getCmp('cu_shcustname').setValue(custname);
  56. }
  57. if(arcode == null || arcode == ''){
  58. Ext.getCmp('cu_arcode').setValue(cust);
  59. Ext.getCmp('cu_arname').setValue(custname);
  60. }
  61. this.FormUtil.onUpdate(this);
  62. }
  63. },
  64. 'erpAddButton': {
  65. click: function(){
  66. me.FormUtil.onAdd('addPreCustomer', '新增客户资料', 'jsps/scm/sale/preCustomer.jsp');
  67. }
  68. },
  69. 'erpCloseButton': {
  70. click: function(btn){
  71. me.FormUtil.beforeClose(me);
  72. }
  73. },
  74. 'erpSubmitButton': {
  75. afterrender: function(btn){
  76. var status = Ext.getCmp('cu_auditstatuscode');
  77. if(status && status.value != 'ENTERING'){
  78. btn.hide();
  79. }
  80. },
  81. click: function(btn){
  82. me.FormUtil.onSubmit(Ext.getCmp('cu_id').value);
  83. }
  84. },
  85. 'erpResSubmitButton': {
  86. afterrender: function(btn){
  87. var status = Ext.getCmp('cu_auditstatuscode');
  88. if(status && status.value != 'COMMITED'){
  89. btn.hide();
  90. }
  91. },
  92. click: function(btn){
  93. me.FormUtil.onResSubmit(Ext.getCmp('cu_id').value);
  94. }
  95. },
  96. 'erpAuditButton': {
  97. afterrender: function(btn){
  98. var status = Ext.getCmp('cu_auditstatuscode');
  99. if(status && status.value != 'COMMITED'){
  100. btn.hide();
  101. }
  102. },
  103. click: function(btn){
  104. me.FormUtil.onAudit(Ext.getCmp('cu_id').value);
  105. }
  106. },
  107. 'erpResAuditButton': {
  108. afterrender: function(btn){
  109. var status = Ext.getCmp('cu_auditstatuscode');
  110. if(status && status.value != 'AUDITED'){
  111. btn.hide();
  112. }
  113. },
  114. click: function(btn){
  115. me.FormUtil.onResAudit(Ext.getCmp('cu_id').value);
  116. }
  117. },
  118. 'erpPrintButton': {
  119. click: function(btn){
  120. me.FormUtil.onPrint(Ext.getCmp('cu_id').value);
  121. }
  122. },
  123. 'erpTurnFKCustomerButton':{
  124. afterrender: function(btn){
  125. var status = Ext.getCmp('cu_auditstatuscode');
  126. if(status && status.value != 'TURNED'){
  127. btn.hide();
  128. }
  129. },
  130. click:function(){
  131. var cu_code=Ext.getCmp('cu_code').value;
  132. var formCondition="cu_code='"+cu_code+"'";
  133. var gridCondition="shi_cucode='"+cu_code+"'";
  134. var linkCaller='Customer!BaseFP';
  135. me.FormUtil.onAdd('Customer!BaseFP', '风控客户资料', 'jsps/fa/fp/customerBaseFP.jsp?_noc=1&whoami='+linkCaller+'&formCondition='+formCondition+'&gridCondition='+gridCondition);
  136. }
  137. },
  138. 'erpTurnCustomerButton': {
  139. afterrender: function(btn){
  140. var status = Ext.getCmp('cu_auditstatuscode');
  141. if(status && status.value != 'AUDITED'){
  142. btn.hide();
  143. }
  144. },
  145. click: function(btn){
  146. warnMsg("确定要转入客户吗?", function(btn){
  147. if(btn == 'yes'){
  148. me.FormUtil.getActiveTab().setLoading(true);//loading...
  149. Ext.Ajax.request({
  150. url : basePath + 'scm/sale/turnCustomer.action',
  151. params: {
  152. id: Ext.getCmp('cu_id').value
  153. },
  154. method : 'post',
  155. callback : function(options,success,response){
  156. me.FormUtil.getActiveTab().setLoading(false);
  157. var localJson = new Ext.decode(response.responseText);
  158. if(localJson.exceptionInfo){
  159. showError(localJson.exceptionInfo);
  160. }
  161. if(localJson.success){
  162. turnSuccess(function(){
  163. var id = localJson.id;
  164. var url = "jsps/scm/sale/customerBase.jsp?formCondition=cu_id=" + id;
  165. me.FormUtil.onAdd('Customer' + id, '客户' + id, url);
  166. window.loaction.href = window.loaction.href;
  167. });
  168. }
  169. }
  170. });
  171. }
  172. });
  173. }
  174. }
  175. });
  176. },
  177. getForm: function(btn){
  178. return btn.ownerCt.ownerCt;
  179. },
  180. getSetting : function(fn) {
  181. var me = this;
  182. Ext.Ajax.request({
  183. url : basePath + 'common/getFieldData.action',
  184. async: false,
  185. params: {
  186. caller: 'Setting',
  187. field: 'se_value',
  188. condition: 'se_what=\'CustCodeType\''
  189. },
  190. method : 'post',
  191. callback : function(opt, s, res){
  192. var r = new Ext.decode(res.responseText);
  193. var t = false;
  194. if(r.exceptionInfo){
  195. showError(r.exceptionInfo);return;
  196. }
  197. if(r.success && r.data){
  198. t = r.data == 'true';
  199. }
  200. fn.call(me, t);
  201. }
  202. });
  203. },
  204. getLeadCode: function(type) {
  205. var result = null;
  206. Ext.Ajax.request({
  207. url : basePath + 'common/getFieldData.action',
  208. async: false,
  209. params: {
  210. caller: 'CustomerKind',
  211. field: 'ck_excode',
  212. condition: 'ck_kind=\'' + type + '\''
  213. },
  214. method : 'post',
  215. callback : function(opt, s, res){
  216. var r = new Ext.decode(res.responseText);
  217. if(r.exceptionInfo){
  218. showError(r.exceptionInfo);return;
  219. } else if(r.success){
  220. result = r.data;
  221. }
  222. }
  223. });
  224. return result;
  225. },
  226. getCode: function(type) {
  227. var result = null;
  228. Ext.Ajax.request({
  229. url : basePath + 'scm/sale/getCustomerCodeNum.action',
  230. async: false,
  231. params: {
  232. cu_kind: type
  233. },
  234. method : 'post',
  235. callback : function(opt, s, res){
  236. var r = new Ext.decode(res.responseText);
  237. if(r.exceptionInfo){
  238. showError(r.exceptionInfo);return;
  239. } else if(r.success){
  240. result = r.number;
  241. }
  242. }
  243. });
  244. return result;
  245. }
  246. });