SecondCategory.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.ars.SecondCategory', {
  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. 'core.form.Panel','fa.ars.SecondCategory','core.grid.Panel2','core.toolbar.Toolbar',
  9. 'core.button.Save','core.button.Add','core.button.Close','core.button.Delete','core.button.Update',
  10. 'core.button.Submit','core.button.ResSubmit','core.button.Audit','core.trigger.CateTreeDbfindTrigger',
  11. 'core.button.DeleteDetail', 'core.trigger.MultiDbfindTrigger','core.trigger.DbfindTrigger',
  12. 'core.trigger.TextAreaTrigger','core.form.YnField'
  13. ],
  14. init:function(){
  15. var me = this;
  16. me.gridLastSelected = null;
  17. this.control({
  18. 'erpGridPanel2': {
  19. itemclick: this.onGridItemClick
  20. },
  21. 'erpSaveButton': {
  22. click: function(btn){
  23. var form = me.getForm(btn);
  24. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  25. me.BaseUtil.getRandomNumber();//自动添加编号
  26. }
  27. var code = Ext.getCmp('ca_code'),
  28. level = Ext.getCmp('ca_level'),
  29. err = null;
  30. if(level == 1) {
  31. if(code.length != 3 && code.length != 4) {
  32. err = "一级科目的编号一般为3~4位,当前科目号:" + code + ".是否仍然保存?";
  33. }
  34. } else {
  35. if(code.length <= 4) {
  36. err = "下级科目的编号一般大于4位,当前科目号:" + code + ".是否仍然保存?";
  37. }
  38. }
  39. if(err != null) {
  40. warnMsg(err, function(btn){
  41. if(btn == 'yes') {
  42. this.FormUtil.beforeSave(this);
  43. }
  44. });
  45. } else {
  46. this.FormUtil.beforeSave(this);
  47. }
  48. }
  49. },
  50. 'erpDeleteButton' : {
  51. click: function(btn){
  52. me.FormUtil.onDelete(Ext.getCmp('ca_id').value);
  53. }
  54. },
  55. 'erpUpdateButton': {
  56. afterrender: function(btn){
  57. var status = Ext.getCmp('ca_statuscode');
  58. if(status && status.value != 'ENTERING'){
  59. btn.hide();
  60. }
  61. },
  62. click: function(btn){
  63. var code = Ext.getCmp('ca_code'),
  64. level = Ext.getCmp('ca_level'),
  65. err = null;
  66. if(level == 1) {
  67. if(code.length != 3 && code.length != 4) {
  68. err = "一级科目的编号一般为3~4位,当前科目号:" + code + ".是否仍然保存?";
  69. }
  70. } else {
  71. if(code.length <= 4) {
  72. err = "下级科目的编号一般大于4位,当前科目号:" + code + ".是否仍然保存?";
  73. }
  74. }
  75. if(err != null) {
  76. warnMsg(err, function(btn){
  77. if(btn == 'yes') {
  78. this.FormUtil.onUpdate(this);
  79. }
  80. });
  81. } else {
  82. this.FormUtil.onUpdate(this);
  83. }
  84. }
  85. },
  86. 'erpAddButton': {
  87. click: function(){
  88. me.FormUtil.onAdd('addSecondCategory', '新增科目维护', 'jsps/fa/ars/SecondCategory.jsp');
  89. }
  90. },
  91. 'erpCloseButton': {
  92. click: function(btn){
  93. this.FormUtil.beforeClose(this);
  94. }
  95. },
  96. 'erpSubmitButton': {
  97. afterrender: function(btn){
  98. var status = Ext.getCmp('ca_statuscode');
  99. if(status && status.value != 'ENTERING'){
  100. btn.hide();
  101. }
  102. },
  103. click: function(btn){
  104. me.FormUtil.onSubmit(Ext.getCmp('ca_id').value);
  105. }
  106. },
  107. 'erpResSubmitButton': {
  108. afterrender: function(btn){
  109. var status = Ext.getCmp('ca_statuscode');
  110. if(status && status.value != 'COMMITED'){
  111. btn.hide();
  112. }
  113. },
  114. click: function(btn){
  115. me.FormUtil.onResSubmit(Ext.getCmp('ca_id').value);
  116. }
  117. },
  118. 'field[name=ca_assname]': {
  119. change: function(f) {
  120. if(Ext.isEmpty(f.value)) {
  121. var t = f.ownerCt.down('#ca_asstype');
  122. t && t.setValue(null);
  123. }
  124. }
  125. },
  126. 'erpAuditButton': {
  127. afterrender: function(btn){
  128. var status = Ext.getCmp('ca_statuscode');
  129. if(status && status.value != 'COMMITED'){
  130. btn.hide();
  131. }
  132. },
  133. click: function(btn){
  134. me.FormUtil.onAudit(Ext.getCmp('ca_id').value);
  135. }
  136. },
  137. 'erpResAuditButton': {
  138. afterrender: function(btn){
  139. var status = Ext.getCmp('ca_statuscode');
  140. if(status && status.value != 'AUDITED'){
  141. btn.hide();
  142. }
  143. },
  144. click: function(btn){
  145. me.FormUtil.onResAudit(Ext.getCmp('ca_id').value);
  146. }
  147. },
  148. 'combobox[name=ca_type]': {
  149. change: function(f){
  150. var n = Ext.getCmp('ca_typename');
  151. if(n){
  152. switch(f.value){
  153. case 0:
  154. n.setValue('借');
  155. break;
  156. case 1:
  157. n.setValue('贷');
  158. break;
  159. case 2:
  160. n.setValue('借或贷');
  161. break;
  162. }
  163. }
  164. }
  165. },
  166. 'dbfindtrigger[name=ca_pcode]': {
  167. change: function(f) {
  168. if(Ext.isEmpty(f.value)) {
  169. var n = Ext.getCmp('ca_level');
  170. if(n){
  171. n.setValue(1);
  172. }
  173. }
  174. },
  175. aftertrigger: function(f, r){
  176. var n = Ext.getCmp('ca_level');
  177. if(n){
  178. n.setValue(n.value + 1);
  179. }
  180. var sCode = f.value, cf = Ext.getCmp('ca_code');
  181. if(!Ext.isEmpty(cf.getValue())) {
  182. return;
  183. }
  184. Ext.Ajax.request({
  185. url : basePath + 'common/getFieldData.action',
  186. async: false,
  187. params: {
  188. caller: 'Category',
  189. field: 'count(*)',
  190. condition: 'ca_subof=(SELECT ca_id FROM Category WHERE ca_code=\'' + sCode + '\')'
  191. },
  192. method : 'post',
  193. callback : function(options,success,response){
  194. var localJson = new Ext.decode(response.responseText);
  195. if(localJson.exceptionInfo){
  196. showError(localJson.exceptionInfo);return null;
  197. }
  198. var str = '001';
  199. if(localJson.success && localJson.data != null){
  200. var count = localJson.data + 1;
  201. str = '' + count;
  202. if(count < 10) {
  203. str = '00' + count;
  204. } else if (count < 100) {
  205. str = '0' + count;
  206. }
  207. }
  208. cf.setValue(sCode + str);
  209. }
  210. });
  211. }
  212. },
  213. 'field[name=ca_iscash]': {
  214. change: function(f) {
  215. var s = Ext.getCmp('ca_isbank');
  216. if(f.value == '-1') {
  217. Ext.getCmp('ca_iscashbank').setValue('-1');
  218. if(s.value == '-1')
  219. Ext.getCmp('ca_isbank').setValue('0');
  220. }
  221. }
  222. },
  223. 'field[name=ca_isbank]': {
  224. change: function(f) {
  225. var s = Ext.getCmp('ca_iscash');
  226. if(f.value == '-1') {
  227. Ext.getCmp('ca_iscashbank').setValue('-1');
  228. if(s.value == '-1')
  229. Ext.getCmp('ca_iscash').setValue('0');
  230. }
  231. }
  232. },
  233. 'field[name=ca_iscashbank]': {
  234. change: function(f) {
  235. if(f.value == '0') {
  236. Ext.getCmp('ca_iscash').setValue('0');
  237. Ext.getCmp('ca_isbank').setValue('0');
  238. }
  239. }
  240. },
  241. 'cateTreeDbfindTrigger[name=ca_pcode]': {
  242. change: function(f) {
  243. if(Ext.isEmpty(f.value)) {
  244. var n = Ext.getCmp('ca_level');
  245. if(n){
  246. n.setValue(1);
  247. }
  248. }
  249. },
  250. aftertrigger: function(tri, data){
  251. // var newlevel = Number(Ext.getCmp('ca_level').getValue()) + 1;
  252. // Ext.getCmp('ca_level').setValue(newlevel);
  253. var depth = data[0].data.depth;
  254. var n = Ext.getCmp('ca_level');
  255. if(depth != null){
  256. if(n){
  257. n.setValue(Number(depth) + 1);
  258. }
  259. } else {
  260. n.setValue(1);
  261. }
  262. }
  263. }
  264. });
  265. },
  266. getForm: function(btn){
  267. return btn.ownerCt.ownerCt;
  268. }
  269. });