BatchDeal.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.co.cost.BatchDeal', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.FormUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil', 'erp.util.RenderUtil'],
  5. views:[
  6. 'common.batchDeal.Viewport','common.batchDeal.Form','common.batchDeal.GridPanel','core.trigger.AddDbfindTrigger',
  7. 'core.trigger.DbfindTrigger','core.form.FtField','core.form.FtFindField','core.form.ConDateField',
  8. 'core.trigger.TextAreaTrigger','core.form.YnField', 'core.form.MonthDateField'
  9. ],
  10. init:function(){
  11. var me = this;
  12. me.resized = false;
  13. this.control({
  14. 'erpBatchDealFormPanel': {
  15. alladded: function(form){
  16. var grid = Ext.getCmp('batchDealGridPanel');
  17. me.resize(form, grid);
  18. }
  19. },
  20. 'erpBatchDealGridPanel': {
  21. reconfigure: function(grid){
  22. var form = Ext.getCmp('dealform');
  23. me.resize(form, grid);
  24. }
  25. },
  26. 'erpVastDealButton': {
  27. click: function(btn){
  28. me.vastDeal(btn.ownerCt.ownerCt.dealUrl);
  29. }
  30. },
  31. 'erpVastAnalyseButton': {
  32. click: function(btn){
  33. me.vastDeal(btn.ownerCt.ownerCt.dealUrl);
  34. }
  35. },
  36. 'erpVastPrintButton': {
  37. click: function(btn){
  38. me.vastDeal(btn.ownerCt.ownerCt.dealUrl);
  39. }
  40. },
  41. /**
  42. * 取价
  43. */
  44. 'erpGetPriceButton':{
  45. click: function(btn){
  46. me.vastDeal("cost/getPrice.action", true, ['pi_type', 'pi_remark']);
  47. }
  48. },
  49. /**
  50. * 费用分摊
  51. */
  52. 'erpFeeShareButton':{
  53. click: function(btn){
  54. me.vastDeal("cost/shareFee.action");
  55. }
  56. },
  57. /**
  58. * 核算
  59. */
  60. 'erpBussAccountButton':{
  61. click: function(btn){
  62. me.vastDeal("cost/accountProdio.action", true, ['pi_type', 'pi_class']);
  63. }
  64. },
  65. /**
  66. * 重置单价
  67. */
  68. 'erpRePriceButton':{
  69. click: function(btn){
  70. me.vastDeal("cost/resPrice.action");
  71. }
  72. },
  73. /**
  74. * 保存
  75. */
  76. 'erpVastSaveButton':{
  77. click: function(btn){
  78. me.vastDeal("cost/batchUpdate.action");
  79. }
  80. },
  81. 'monthdatefield': {
  82. afterrender: function(f) {
  83. me.getCurrentYearmonth(f);
  84. },
  85. change: function(f) {
  86. var c = Ext.getCmp('pi_date');
  87. if(c) {
  88. c.setMonthValue(f.value);
  89. }
  90. }
  91. },
  92. 'combo[name=pi_fromcode]': {
  93. afterrender: function(m) {
  94. m.hide();
  95. m.value = '';
  96. }
  97. },
  98. 'combo[name=pi_class]': {
  99. change: function(m){
  100. var f = Ext.getCmp('pi_fromcode');
  101. if(!Ext.isEmpty(m.value)) {
  102. if(m.value == '其它入库单'){
  103. f.show();
  104. } else {
  105. f.hide();
  106. }
  107. }
  108. }
  109. },
  110. 'erpConsistencyButton':{
  111. click:function(btn){
  112. var f = Ext.getCmp('pi_class'), piclass = f.value, url = "";
  113. if(piclass == '拨入单' || piclass == '拨出单'){
  114. url = "cost/consistencyCheck.action";
  115. } else if(piclass == '销售拨入单' || piclass == '销售拨出单'){
  116. url = "cost/consistencySaleCheck.action";
  117. } else if(piclass == '$ALL') {
  118. var b = f.store.findRecord('value', '拨入单');
  119. if(b) {
  120. url = "cost/consistencyCheck.action";
  121. } else {
  122. url = "cost/consistencySaleCheck.action";
  123. }
  124. }
  125. Ext.Ajax.request({
  126. url : basePath + url,
  127. params:{
  128. date: Ext.getCmp('pi_type').value
  129. },
  130. method:'post',
  131. callback:function(options,success,response){
  132. var localJson = new Ext.decode(response.responseText);
  133. if(localJson.success){
  134. Ext.Msg.alert("提示","操作成功!");
  135. } else {
  136. if(localJson.exceptionInfo){
  137. var str = localJson.exceptionInfo;
  138. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  139. str = str.replace('AFTERSUCCESS', '');
  140. showError(str);
  141. Ext.Msg.alert("提示","操作成功!");
  142. } else {
  143. showError(str);return;
  144. }
  145. }
  146. }
  147. }
  148. });
  149. }
  150. },
  151. 'textfield[name=pi_class]': {
  152. afterrender: function(m) {
  153. var f = Ext.getCmp('pi_class');
  154. if(!Ext.isEmpty(m.value)) {
  155. switch (m.value) {
  156. case '其它入库单':
  157. me.getComboData(f.store, 'ProdInOut!OtherIn');
  158. break;
  159. case '其它出库单':
  160. me.getComboData(f.store, 'ProdInOut!OtherOut');
  161. break;
  162. }
  163. }
  164. },
  165. change: function(m){
  166. if(typeof (f = Ext.getCmp('pi_fromcode')) != 'undefined'){
  167. if(!Ext.isEmpty(m.value)) {
  168. switch (m.value) {
  169. case '其它入库单':
  170. me.getComboData(f.store, 'ProdInOut!OtherIn');
  171. break;
  172. case '其它出库单':
  173. me.getComboData(f.store, 'ProdInOut!OtherOut');
  174. break;
  175. }
  176. }
  177. }
  178. }
  179. }
  180. });
  181. },
  182. resize: function(form, grid){
  183. if(!this.resized && form && grid && form.items.items.length > 0){
  184. var height = window.innerHeight,
  185. fh = form.getEl().down('.x-panel-body>.x-column-inner').getHeight();
  186. if(Ext.isIE){
  187. height = screen.height*0.75;
  188. }
  189. form.setHeight(35 + fh);
  190. grid.setHeight(height - fh - 35);
  191. this.resized = true;
  192. }
  193. },
  194. countGrid: function(){
  195. //重新计算合计栏值
  196. var grid = Ext.getCmp('batchDealGridPanel');
  197. Ext.each(grid.columns, function(column){
  198. if(column.summary){
  199. var sum = 0;
  200. Ext.each(grid.store.data.items, function(item){
  201. if(item.value != null && item.value != ''){
  202. sum += Number(item.value);
  203. }
  204. });
  205. Ext.getCmp(column.dataIndex + '_sum').setText(column.text + '(sum):' + sum);
  206. } else if(column.average) {
  207. var average = 0;
  208. Ext.each(grid.store.data.items, function(item){
  209. if(item.value != null && item.value != ''){
  210. average += Number(item.value);
  211. }
  212. });
  213. average = average/grid.store.data.items.length;
  214. Ext.getCmp(column.dataIndex + '_average').setText(column.text + '(average):' + average);
  215. } else if(column.count) {
  216. var count = 0;
  217. Ext.each(grid.store.data.items, function(item){
  218. if(item.value != null && item.value != ''){
  219. count++;
  220. }
  221. });
  222. Ext.getCmp(column.dataIndex + '_count').setText(column.text + '(count):' + count);
  223. }
  224. });
  225. },
  226. /**
  227. * @param useCondition 允许按条件执行
  228. * @param condParams 按条件执行时,作为额外条件传回的字段
  229. */
  230. vastDeal: function(url, useCondition, condParams){
  231. var grid = Ext.getCmp('batchDealGridPanel');
  232. var items = grid.getMultiSelected();
  233. Ext.each(items, function(item, index){
  234. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  235. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  236. item.index = this.data[grid.keyField];
  237. grid.multiselected.push(item);
  238. }
  239. });
  240. var form = Ext.getCmp('dealform');
  241. var records = Ext.Array.unique(grid.multiselected);
  242. var bool = false, params = new Object(), data = new Array();
  243. params.caller = caller;
  244. if(records.length > 0){
  245. Ext.each(records, function(record, index){
  246. var f = form.fo_detailMainKeyField;
  247. if((grid.keyField && this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  248. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0)
  249. ||(f && this.data[f] != null && this.data[f] != ''
  250. && this.data[f] != '0' && this.data[f] != 0)){
  251. bool = true;
  252. var o = new Object();
  253. if(grid.keyField){
  254. o[grid.keyField] = record.data[grid.keyField];
  255. } else {
  256. params.id[index] = record.data[form.fo_detailMainKeyField];
  257. }
  258. if(grid.toField){
  259. Ext.each(grid.toField, function(f, index){
  260. var v = Ext.getCmp(f).value;
  261. if(v != null && v.toString().trim() != '' && v.toString().trim() != 'null'){
  262. o[f] = v;
  263. }
  264. });
  265. }
  266. if(grid.necessaryFields){
  267. Ext.each(grid.necessaryFields, function(f, index){
  268. var v = record.data[f];
  269. if(Ext.isDate(v)){
  270. v = Ext.Date.toString(v);
  271. }
  272. o[f] = v;
  273. });
  274. }
  275. data.push(o);
  276. }
  277. });
  278. } else if(useCondition) {
  279. params.condition = form.getCondition();
  280. bool = true;
  281. if(condParams) {
  282. var s = {};
  283. Ext.Array.each(condParams, function(p){
  284. s[p] = Ext.getCmp(p).getValue();
  285. });
  286. params.condParams = unescape(Ext.JSON.encode(s).replace(/\\/g,"%"));
  287. }
  288. }
  289. if(bool){
  290. params.data = unescape(Ext.JSON.encode(data).replace(/\\/g,"%"));
  291. var main = parent.Ext.getCmp("content-panel");
  292. main.getActiveTab().setLoading(true);//loading...
  293. Ext.Ajax.request({
  294. url : basePath + url,
  295. params: params,
  296. method : 'post',
  297. timeout: 1200000,
  298. callback : function(opt, s, r){
  299. main.getActiveTab().setLoading(false);
  300. var rs = new Ext.decode(r.responseText);
  301. if(rs.exceptionInfo){
  302. var str = rs.exceptionInfo;
  303. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){
  304. str = str.replace('AFTERSUCCESS', '');
  305. grid.multiselected = new Array();
  306. Ext.getCmp('dealform').onQuery();
  307. }
  308. showError(str);return;
  309. } else if(rs.success){
  310. if(rs.log){
  311. showMessage("提示", localJson.log);
  312. }
  313. Ext.Msg.alert("提示", "处理成功!", function(){
  314. grid.multiselected = new Array();
  315. Ext.getCmp('dealform').onQuery();
  316. });
  317. }
  318. }
  319. });
  320. } else {
  321. showError("没有需要处理的数据!");
  322. }
  323. },
  324. getCurrentYearmonth: function(f) {
  325. Ext.Ajax.request({
  326. url : basePath + "fa/getMonth.action",
  327. params:{type:'MONTH-P'},
  328. method : 'post',
  329. callback : function(options,success,response){
  330. var res = new Ext.decode(response.responseText);
  331. if(res.exceptionInfo != null){
  332. showError(res.exceptionInfo);return;
  333. }
  334. if(res.success){
  335. Ext.getCmp('pi_type').setValue(res.data.PD_DETNO);
  336. }
  337. }
  338. });
  339. },
  340. getComboData: function(store, cal) {
  341. if(this._combodata && this._combodata[cal]) {
  342. store.loadData(this._combodata[cal]);
  343. return;
  344. }
  345. var me = this;
  346. Ext.Ajax.request({
  347. url : basePath + 'common/getFieldsDatas.action',
  348. async: false,
  349. params: {
  350. caller: 'DataListCombo',
  351. fields: 'dlc_value,dlc_display',
  352. condition: 'dlc_caller=\'' + cal + '\' AND dlc_fieldname=\'pi_type\''
  353. },
  354. method : 'post',
  355. callback : function(options,success,response){
  356. var localJson = new Ext.decode(response.responseText);
  357. if(localJson.exceptionInfo){
  358. showError(localJson.exceptionInfo);return;
  359. }
  360. if(localJson.success){
  361. var data = Ext.decode(localJson.data), arr = new Array();
  362. for(var i in data) {
  363. arr.push({
  364. display: data[i].DLC_VALUE,
  365. value: data[i].DLC_DISPLAY
  366. });
  367. }
  368. store.loadData(arr);
  369. if(me._combodata == null) {
  370. me._combodata = {};
  371. }
  372. me._combodata[cal] = arr;
  373. }
  374. }
  375. });
  376. }
  377. });