ProdOnhand.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * grid,tip显示物料分仓库存
  3. */
  4. Ext.define('erp.view.core.plugin.ProdOnhand', {
  5. ptype : 'prodonhand',
  6. constructor : function(cfg) {
  7. if (cfg) {
  8. Ext.apply(this, cfg);
  9. }
  10. },
  11. prodKey: 'pr_code',
  12. init : function(grid) {
  13. this.grid = grid;
  14. var me = this, view = grid.view.normalView || grid.view;
  15. if (view) {
  16. view.on({
  17. scope: me,
  18. render: me.renderTip
  19. })
  20. var views = grid.view.lockedView;
  21. if(views){
  22. views.on({
  23. scope: me,
  24. render: me.renderTip
  25. })
  26. }
  27. grid.store.on({
  28. scope: me,
  29. load: me.getProductWh
  30. });
  31. }
  32. },
  33. renderTip: function(view) {
  34. if (!view.tip) {
  35. var me = this;
  36. view.tip = me.createTip(view);
  37. view.tip.on({
  38. beforeshow : function() {
  39. me.updateTipBody(view, view.tip);
  40. }
  41. });
  42. }
  43. },
  44. createTip : function(view) {
  45. return Ext.create('Ext.tip.ToolTip', {
  46. target : view.el,
  47. delegate : view.itemSelector,
  48. trackMouse : true,
  49. renderTo : Ext.getBody(),
  50. maxWidth :500,
  51. items : [{
  52. xtype : 'grid',
  53. width : 382,
  54. columns : [ {
  55. text : '仓库编号',
  56. cls : 'x-grid-header-1',
  57. dataIndex : 'PW_WHCODE',
  58. width : 140
  59. },{
  60. text : '仓库名称',
  61. cls : 'x-grid-header-1',
  62. dataIndex : 'WH_DESCRIPTION',
  63. width : 150
  64. }, {
  65. text : '库存',
  66. cls : 'x-grid-header-1',
  67. xtype : 'numbercolumn',
  68. dataIndex : 'PW_ONHAND',
  69. width : 100
  70. }/*, {
  71. text : '可用库存',
  72. cls : 'x-grid-header-1',
  73. xtype : 'numbercolumn',
  74. dataIndex : 'FREEONHAND',
  75. width : 90
  76. }*/ ],
  77. columnLines : true,
  78. title : '物料分仓库存',
  79. store : new Ext.data.Store({
  80. fields : [ 'PW_WHCODE', 'WH_DESCRIPTION', 'PW_ONHAND'/*, 'FREEONHAND'*/ ],
  81. data : [ {} ]
  82. })
  83. } ]
  84. });
  85. },
  86. updateTipBody : function(view, tip) {
  87. var me = this, record = view.getRecord(tip.triggerElement);
  88. if (record && me.grid.productwh) {
  89. var c = record.get(me.prodKey), pws = new Array();
  90. Ext.each(me.grid.productwh, function(d) {
  91. if (d.PW_PRODCODE == c) {
  92. pws.push(d);
  93. }
  94. });
  95. tip.down('grid').setTitle(c);
  96. tip.down('grid').store.loadData(pws);
  97. }
  98. },
  99. getProductWh : function() {
  100. var me = this, codes = [];
  101. me.grid.store.each(function(d) {
  102. var p = d.get(me.prodKey);
  103. if(!Ext.isEmpty(p))
  104. codes.push("'" + p + "'");
  105. });
  106. if(codes.length > 0) {
  107. Ext.Ajax.request({
  108. url : basePath + 'scm/product/getProductwh.action',
  109. params : {
  110. codes : codes.join(','),
  111. useFactory:me.grid.ifOnlyShowUserFactoryWh||false //根据登录用户所属工厂获取对应仓库分仓库存
  112. },
  113. callback : function(opt, s, r) {
  114. if (s) {
  115. var rs = Ext.decode(r.responseText);
  116. if (rs.data) {
  117. me.productWh = rs.data;
  118. }
  119. }
  120. }
  121. });
  122. } else {
  123. me.productWh = [];
  124. }
  125. }
  126. });