DeleteDetail.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * 明细行删除按钮
  3. */
  4. Ext.define('erp.view.core.button.DeleteDetail',{
  5. extend: 'Ext.Button',
  6. alias: 'widget.erpDeleteDetailButton',
  7. iconCls: 'x-button-icon-close',
  8. cls: 'x-btn-tb',
  9. tooltip: $I18N.common.button.erpDeleteDetailButton,
  10. disabled: true,
  11. //width: 90,
  12. initComponent : function(){
  13. this.callParent(arguments);
  14. this.addEvents({//添加[删除明细后]事件
  15. afterdelete: true
  16. });
  17. },
  18. handler: function(btn){
  19. var me = this;
  20. var grid = btn.ownerCt.ownerCt;
  21. console.log(btn.ownerCt);
  22. console.log(grid);
  23. var callerConfig = (grid.caller&&grid.caller!='')?grid.caller:caller;
  24. var records = grid.selModel.getSelection();
  25. console.log(records);
  26. if(records.length > 0){
  27. if(grid.keyField){
  28. if(records[0].data[grid.keyField] != null && records[0].data[grid.keyField] > 0){
  29. warnMsg($I18N.common.msg.ask_del, function(btn){
  30. if(btn == 'yes'){
  31. var url = "common/deleteDetail.action?_noc=" + (grid._noc || 0);
  32. grid.BaseUtil.getActiveTab().setLoading(true);//loading...
  33. Ext.Ajax.request({
  34. url : basePath + url,
  35. params: {
  36. caller: callerConfig,
  37. condition: grid.keyField + "=" + records[0].data[grid.keyField]
  38. },
  39. method : 'post',
  40. callback : function(options,success,response){
  41. grid.BaseUtil.getActiveTab().setLoading(false);
  42. var localJson = new Ext.decode(response.responseText);
  43. if(localJson.exceptionInfo){
  44. showError(localJson.exceptionInfo);return;
  45. }
  46. if(localJson.success){
  47. me.fireEvent('afterdelete', records[0].data, records[0], me);//触发删除后事件
  48. grid.store.remove(records[0]);
  49. delSuccess(function(){
  50. });//@i18n/i18n.js
  51. } else {
  52. delFailure();
  53. }
  54. }
  55. });
  56. }
  57. });
  58. } else {
  59. me.fireEvent('afterdelete', records[0].data, records[0], me);
  60. grid.store.remove(records[0]);
  61. }
  62. } else {
  63. if(records[0].data[grid.keyField] != null && records[0].data[grid.keyField] > 0){
  64. showError("grid未配置keyField,无法删除该行数据!");
  65. } else {
  66. grid.store.remove(records[0]);
  67. }
  68. }
  69. }
  70. },
  71. autoSetSequence: false,//删除明细行后,自动调整detno排序字段
  72. listeners: {
  73. afterdelete: function(d, r, btn){
  74. var grid = btn.ownerCt.ownerCt;
  75. if(btn.autoSetSequence || grid.autoSetSequence) {
  76. btn.setSequence(grid, r);
  77. }
  78. }
  79. },
  80. setSequence: function(grid, record){
  81. if(grid.detno) {
  82. if(grid.keyField && record.data[grid.keyField] != null && record.data[grid.keyField] > 0){
  83. if(grid.mainField) {
  84. Ext.Ajax.request({
  85. url: basePath + 'common/setDetailDetno.action',
  86. params: {
  87. caller: caller,
  88. dfield: grid.detno,
  89. mfield: grid.mainField,
  90. id: record.data[grid.mainField],
  91. detno: record.data[grid.detno]
  92. },
  93. callback: function(opt, s, r){
  94. var res = Ext.decode(r.responseText);
  95. if(res.exceptionInfo) {
  96. showError(res.exceptionInfo);
  97. }
  98. }
  99. });
  100. }
  101. }
  102. var items = grid.store.data.items;
  103. Ext.each(items, function(item){
  104. if(item.index != record.index && item.data[grid.detno] > record.data[grid.detno]) {
  105. item.set(grid.detno, item.data[grid.detno] - 1);
  106. }
  107. });
  108. }
  109. }
  110. });