Category.js 8.9 KB

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