BatchDeal.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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', 'core.form.SeparNumber'
  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. f.setValue('$ALL');
  105. } else {
  106. f.hide();
  107. f.setValue(null);
  108. }
  109. }
  110. }
  111. },
  112. 'erpConsistencyButton':{
  113. click:function(btn){
  114. var f = Ext.getCmp('pi_class'), piclass = f.value, url = "";
  115. if(piclass == '拨入单' || piclass == '拨出单'){
  116. url = "cost/consistencyCheck.action";
  117. } else if(piclass == '销售拨入单' || piclass == '销售拨出单'){
  118. url = "cost/consistencySaleCheck.action";
  119. } else if(piclass == '$ALL') {
  120. var b = f.store.findRecord('value', '拨入单');
  121. if(b) {
  122. url = "cost/consistencyCheck.action";
  123. } else {
  124. url = "cost/consistencySaleCheck.action";
  125. }
  126. }
  127. Ext.Ajax.request({
  128. url : basePath + url,
  129. params:{
  130. date: Ext.getCmp('pi_type').value
  131. },
  132. method:'post',
  133. callback:function(options,success,response){
  134. var localJson = new Ext.decode(response.responseText);
  135. if(localJson.success){
  136. Ext.Msg.alert("提示","操作成功!");
  137. } else {
  138. if(localJson.exceptionInfo){
  139. var str = localJson.exceptionInfo;
  140. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  141. str = str.replace('AFTERSUCCESS', '');
  142. showError(str);
  143. Ext.Msg.alert("提示","操作成功!");
  144. } else {
  145. showError(str);return;
  146. }
  147. }
  148. }
  149. }
  150. });
  151. }
  152. },
  153. 'textfield[name=pi_class]': {
  154. afterrender: function(m) {
  155. var f = Ext.getCmp('pi_class');
  156. if(!Ext.isEmpty(m.value)) {
  157. switch (m.value) {
  158. case '其它入库单':
  159. me.getComboData(f.store, 'ProdInOut!OtherIn');
  160. break;
  161. case '其它出库单':
  162. me.getComboData(f.store, 'ProdInOut!OtherOut');
  163. break;
  164. }
  165. }
  166. },
  167. change: function(m){
  168. if(typeof (f = Ext.getCmp('pi_fromcode')) != 'undefined'){
  169. if(!Ext.isEmpty(m.value)) {
  170. switch (m.value) {
  171. case '其它入库单':
  172. me.getComboData(f.store, 'ProdInOut!OtherIn');
  173. break;
  174. case '其它出库单':
  175. me.getComboData(f.store, 'ProdInOut!OtherOut');
  176. break;
  177. }
  178. }
  179. }
  180. }
  181. }
  182. });
  183. },
  184. resize: function(form, grid){
  185. if(!this.resized && form && grid && form.items.items.length > 0){
  186. var height = window.innerHeight,
  187. fh = form.getEl().down('.x-panel-body>.x-column-inner').getHeight();
  188. if(Ext.isIE){
  189. height = screen.height*0.75;
  190. }
  191. form.setHeight(35 + fh);
  192. grid.setHeight(height - fh - 35);
  193. this.resized = true;
  194. }
  195. },
  196. countGrid: function(){
  197. //重新计算合计栏值
  198. var grid = Ext.getCmp('batchDealGridPanel');
  199. Ext.each(grid.columns, function(column){
  200. if(column.summary){
  201. var sum = 0;
  202. Ext.each(grid.store.data.items, function(item){
  203. if(item.value != null && item.value != ''){
  204. sum += Number(item.value);
  205. }
  206. });
  207. Ext.getCmp(column.dataIndex + '_sum').setText(column.text + '(sum):' + sum);
  208. } else if(column.average) {
  209. var average = 0;
  210. Ext.each(grid.store.data.items, function(item){
  211. if(item.value != null && item.value != ''){
  212. average += Number(item.value);
  213. }
  214. });
  215. average = average/grid.store.data.items.length;
  216. Ext.getCmp(column.dataIndex + '_average').setText(column.text + '(average):' + average);
  217. } else if(column.count) {
  218. var count = 0;
  219. Ext.each(grid.store.data.items, function(item){
  220. if(item.value != null && item.value != ''){
  221. count++;
  222. }
  223. });
  224. Ext.getCmp(column.dataIndex + '_count').setText(column.text + '(count):' + count);
  225. }
  226. });
  227. },
  228. /**
  229. * @param useCondition 允许按条件执行
  230. * @param condParams 按条件执行时,作为额外条件传回的字段
  231. */
  232. vastDeal: function(url, useCondition, condParams){
  233. var grid = Ext.getCmp('batchDealGridPanel');
  234. var items = grid.getMultiSelected();
  235. Ext.each(items, function(item, index){
  236. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  237. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  238. item.index = this.data[grid.keyField];
  239. grid.multiselected.push(item);
  240. }
  241. });
  242. var form = Ext.getCmp('dealform');
  243. var records = Ext.Array.unique(grid.multiselected);
  244. var bool = false, params = new Object(), data = new Array();
  245. params.caller = caller;
  246. if(records.length > 0){
  247. Ext.each(records, function(record, index){
  248. var f = form.fo_detailMainKeyField;
  249. if((grid.keyField && this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  250. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0)
  251. ||(f && this.data[f] != null && this.data[f] != ''
  252. && this.data[f] != '0' && this.data[f] != 0)){
  253. bool = true;
  254. var o = new Object();
  255. if(grid.keyField){
  256. o[grid.keyField] = record.data[grid.keyField];
  257. } else {
  258. params.id[index] = record.data[form.fo_detailMainKeyField];
  259. }
  260. if(grid.toField){
  261. Ext.each(grid.toField, function(f, index){
  262. var v = Ext.getCmp(f).value;
  263. if(v != null && v.toString().trim() != '' && v.toString().trim() != 'null'){
  264. o[f] = v;
  265. }
  266. });
  267. }
  268. if(grid.necessaryFields){
  269. Ext.each(grid.necessaryFields, function(f, index){
  270. var v = record.data[f];
  271. if(Ext.isDate(v)){
  272. v = Ext.Date.toString(v);
  273. }
  274. o[f] = v;
  275. });
  276. }
  277. data.push(o);
  278. }
  279. });
  280. } else if(useCondition) {
  281. params.condition = form.getCondition();
  282. bool = true;
  283. if(condParams) {
  284. var s = {};
  285. Ext.Array.each(condParams, function(p){
  286. s[p] = Ext.getCmp(p).getValue();
  287. });
  288. params.condParams = unescape(Ext.JSON.encode(s).replace(/\\/g,"%"));
  289. }
  290. }
  291. if(bool){
  292. params.data = unescape(Ext.JSON.encode(data).replace(/\\/g,"%"));
  293. var main = parent.Ext.getCmp("content-panel");
  294. main.getActiveTab().setLoading(true);//loading...
  295. Ext.Ajax.request({
  296. url : basePath + url,
  297. params: params,
  298. method : 'post',
  299. timeout: 1200000,
  300. callback : function(opt, s, r){
  301. main.getActiveTab().setLoading(false);
  302. var rs = new Ext.decode(r.responseText);
  303. if(rs.exceptionInfo){
  304. var str = rs.exceptionInfo;
  305. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){
  306. str = str.replace('AFTERSUCCESS', '');
  307. grid.multiselected = new Array();
  308. Ext.getCmp('dealform').onQuery();
  309. }
  310. showError(str);return;
  311. } else if(rs.success){
  312. if(rs.log){
  313. showMessage("提示", localJson.log);
  314. }
  315. Ext.Msg.alert("提示", "处理成功!", function(){
  316. grid.multiselected = new Array();
  317. Ext.getCmp('dealform').onQuery();
  318. });
  319. }
  320. }
  321. });
  322. } else {
  323. showError("没有需要处理的数据!");
  324. }
  325. },
  326. getCurrentYearmonth: function(f) {
  327. Ext.Ajax.request({
  328. url : basePath + "fa/getMonth.action",
  329. params:{type:'MONTH-P'},
  330. method : 'post',
  331. callback : function(options,success,response){
  332. var res = new Ext.decode(response.responseText);
  333. if(res.exceptionInfo != null){
  334. showError(res.exceptionInfo);return;
  335. }
  336. if(res.success){
  337. Ext.getCmp('pi_type').setValue(res.data.PD_DETNO);
  338. }
  339. }
  340. });
  341. },
  342. getComboData: function(store, cal) {
  343. if(this._combodata && this._combodata[cal]) {
  344. store.loadData(this._combodata[cal]);
  345. return;
  346. }
  347. var me = this;
  348. Ext.Ajax.request({
  349. url : basePath + 'common/getFieldsDatas.action',
  350. async: false,
  351. params: {
  352. caller: 'DataListCombo',
  353. fields: 'dlc_value,dlc_display',
  354. condition: 'dlc_caller=\'' + cal + '\' AND dlc_fieldname=\'pi_type\''
  355. },
  356. method : 'post',
  357. callback : function(options,success,response){
  358. var localJson = new Ext.decode(response.responseText);
  359. if(localJson.exceptionInfo){
  360. showError(localJson.exceptionInfo);return;
  361. }
  362. if(localJson.success){
  363. var data = Ext.decode(localJson.data), arr = new Array();
  364. if(cal == 'ProdInOut!OtherIn' || cal == 'ProdInOut!OtherOut') {
  365. arr.push({
  366. display: '全部',
  367. value: '$ALL'
  368. });
  369. }
  370. for(var i in data) {
  371. arr.push({
  372. display: data[i].DLC_VALUE,
  373. value: data[i].DLC_DISPLAY
  374. });
  375. }
  376. store.loadData(arr);
  377. if(me._combodata == null) {
  378. me._combodata = {};
  379. }
  380. me._combodata[cal] = arr;
  381. }
  382. }
  383. });
  384. }
  385. });