PreCustomer.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. kind =Ext.getCmp('cu_kind').value,shcustcode = Ext.getCmp('cu_shcustcode').value,
  52. arcode=Ext.getCmp('cu_arcode').value;
  53. //cust = cust != null ? cust.toUpperCase() : null;
  54. if(cust==null||cust==''){
  55. var res = me.getCode(kind);
  56. if(res != null && res != ''){
  57. Ext.getCmp('cu_code').setValue(res);
  58. } else {
  59. me.BaseUtil.getRandomNumber('Customer',10,null);//自动添加编号
  60. }
  61. }
  62. if(shcustcode == null || shcustcode == ''){
  63. Ext.getCmp('cu_shcustcode').setValue(cust);
  64. Ext.getCmp('cu_shcustname').setValue(custname);
  65. }
  66. if(arcode == null || arcode == ''){
  67. Ext.getCmp('cu_arcode').setValue(cust);
  68. Ext.getCmp('cu_arname').setValue(custname);
  69. }
  70. this.FormUtil.onUpdate(this);
  71. }
  72. },
  73. 'erpAddButton': {
  74. click: function(){
  75. me.FormUtil.onAdd('addPreCustomer', '新增客户资料', 'jsps/scm/sale/preCustomer.jsp');
  76. }
  77. },
  78. 'erpCloseButton': {
  79. click: function(btn){
  80. me.FormUtil.beforeClose(me);
  81. }
  82. },
  83. 'erpSubmitButton': {
  84. afterrender: function(btn){
  85. var status = Ext.getCmp('cu_auditstatuscode');
  86. if(status && status.value != 'ENTERING'){
  87. btn.hide();
  88. }
  89. },
  90. click: function(btn){
  91. me.FormUtil.onSubmit(Ext.getCmp('cu_id').value);
  92. }
  93. },
  94. 'erpResSubmitButton': {
  95. afterrender: function(btn){
  96. var status = Ext.getCmp('cu_auditstatuscode');
  97. if(status && status.value != 'COMMITED'){
  98. btn.hide();
  99. }
  100. },
  101. click: function(btn){
  102. me.FormUtil.onResSubmit(Ext.getCmp('cu_id').value);
  103. }
  104. },
  105. 'erpAuditButton': {
  106. afterrender: function(btn){
  107. var status = Ext.getCmp('cu_auditstatuscode');
  108. if(status && status.value != 'COMMITED'){
  109. btn.hide();
  110. }
  111. },
  112. click: function(btn){
  113. me.FormUtil.onAudit(Ext.getCmp('cu_id').value);
  114. }
  115. },
  116. 'erpResAuditButton': {
  117. afterrender: function(btn){
  118. var status = Ext.getCmp('cu_auditstatuscode');
  119. if(status && status.value != 'AUDITED'){
  120. btn.hide();
  121. }
  122. },
  123. click: function(btn){
  124. me.FormUtil.onResAudit(Ext.getCmp('cu_id').value);
  125. }
  126. },
  127. 'erpPrintButton': {
  128. click: function(btn){
  129. me.FormUtil.onPrint(Ext.getCmp('cu_id').value);
  130. }
  131. },
  132. 'erpTurnFKCustomerButton':{
  133. afterrender: function(btn){
  134. var status = Ext.getCmp('cu_auditstatuscode');
  135. if(status && status.value != 'TURNED'){
  136. btn.hide();
  137. }
  138. },
  139. click:function(){
  140. var cu_code=Ext.getCmp('cu_code').value;
  141. var formCondition="cu_code='"+cu_code+"'";
  142. var gridCondition="shi_cucode='"+cu_code+"'";
  143. var linkCaller='Customer!BaseFP';
  144. me.FormUtil.onAdd('Customer!BaseFP', '风控客户资料', 'jsps/fa/fp/customerBaseFP.jsp?_noc=1&whoami='+linkCaller+'&formCondition='+formCondition+'&gridCondition='+gridCondition);
  145. }
  146. },
  147. 'erpTurnCustomerButton': {
  148. afterrender: function(btn){
  149. var status = Ext.getCmp('cu_auditstatuscode');
  150. if(status && status.value != 'AUDITED'){
  151. btn.hide();
  152. }
  153. },
  154. click: function(btn){
  155. warnMsg("确定要转入客户吗?", function(btn){
  156. if(btn == 'yes'){
  157. me.FormUtil.getActiveTab().setLoading(true);//loading...
  158. Ext.Ajax.request({
  159. url : basePath + 'scm/sale/turnCustomer.action',
  160. params: {
  161. id: Ext.getCmp('cu_id').value
  162. },
  163. method : 'post',
  164. callback : function(options,success,response){
  165. me.FormUtil.getActiveTab().setLoading(false);
  166. var localJson = new Ext.decode(response.responseText);
  167. console.log(localJson);
  168. if(localJson.exceptionInfo){
  169. showError(localJson.exceptionInfo);
  170. }
  171. if(localJson.success){
  172. turnSuccess(function(){
  173. var id = localJson.id;
  174. var url = "jsps/scm/sale/customerBase.jsp?formCondition=cu_id=" + id;
  175. me.FormUtil.onAdd('Customer' + id, '客户' + id, url);
  176. window.loaction.href = window.loaction.href;
  177. });
  178. }
  179. }
  180. });
  181. }
  182. });
  183. }
  184. }
  185. });
  186. },
  187. getForm: function(btn){
  188. return btn.ownerCt.ownerCt;
  189. },
  190. getSetting : function(fn) {
  191. var me = this;
  192. Ext.Ajax.request({
  193. url : basePath + 'common/getFieldData.action',
  194. async: false,
  195. params: {
  196. caller: 'Setting',
  197. field: 'se_value',
  198. condition: 'se_what=\'CustCodeType\''
  199. },
  200. method : 'post',
  201. callback : function(opt, s, res){
  202. var r = new Ext.decode(res.responseText);
  203. var t = false;
  204. if(r.exceptionInfo){
  205. showError(r.exceptionInfo);return;
  206. }
  207. if(r.success && r.data){
  208. t = r.data == 'true';
  209. }
  210. fn.call(me, t);
  211. }
  212. });
  213. },
  214. getLeadCode: function(type) {
  215. var result = null;
  216. Ext.Ajax.request({
  217. url : basePath + 'common/getFieldData.action',
  218. async: false,
  219. params: {
  220. caller: 'CustomerKind',
  221. field: 'ck_excode',
  222. condition: 'ck_kind=\'' + type + '\''
  223. },
  224. method : 'post',
  225. callback : function(opt, s, res){
  226. var r = new Ext.decode(res.responseText);
  227. if(r.exceptionInfo){
  228. showError(r.exceptionInfo);return;
  229. } else if(r.success){
  230. result = r.data;
  231. }
  232. }
  233. });
  234. return result;
  235. },
  236. getCode: function(type) {
  237. var result = null;
  238. Ext.Ajax.request({
  239. url : basePath + 'scm/sale/getCustomerCodeNum.action',
  240. async: false,
  241. params: {
  242. cu_kind: type
  243. },
  244. method : 'post',
  245. callback : function(opt, s, res){
  246. var r = new Ext.decode(res.responseText);
  247. if(r.exceptionInfo){
  248. showError(r.exceptionInfo);return;
  249. } else if(r.success){
  250. result = r.number;
  251. }
  252. }
  253. });
  254. return result;
  255. }
  256. });