HopperDraw.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. Ext.define('erp.view.crm.chance.HopperDraw',{
  2. extend: 'Ext.draw.Component',
  3. alias: 'widget.hopperdraw',
  4. width: 400,
  5. height: 400,
  6. cls: 'cursor-dragme',
  7. viewBox: true,
  8. initComponent : function(){
  9. var me=this;
  10. Ext.applyIf(me,{
  11. items:me.getItems()
  12. });
  13. me.callParent(arguments);
  14. this.addEvents(
  15. 'mousedown',
  16. 'mouseup',
  17. 'mousemove',
  18. 'mouseenter',
  19. 'mouseleave',
  20. 'click'
  21. );
  22. },
  23. getItems:function(){
  24. var hoppers=this.getSaleHopper();
  25. return this.getPaths(hoppers);
  26. },
  27. getSaleHopper:function(con){
  28. var o,param=new Object();
  29. if(con)param.condition=con;
  30. Ext.Ajax.request({
  31. url : basePath + 'crm/business/getHopperByCondition.action',
  32. params: param,
  33. async: false,
  34. method : 'get',
  35. callback : function(options,success,response){
  36. var res=new Ext.decode(response.responseText);
  37. o=res.counts;
  38. }
  39. });
  40. return o;
  41. },
  42. getPaths:function(hoppers){
  43. var allcount=0,s=0.556,h=200,maxWidth=300,minWidth=100,tW=110,itemH=h/hoppers.length;
  44. var items=new Array();
  45. Ext.Array.each(hoppers,function(a){
  46. allcount+=a.count;
  47. });
  48. var items=new Array(),point1,point2,point3,point4,linepoint1,linepoint2,linepoint3,linepoint4,linepoint5;
  49. var start={
  50. x:12,
  51. y:0
  52. };
  53. Ext.Array.each(hoppers,function(item,index){
  54. var _LC=0,_LY=0,_LX=0,_CY=0,_CX=0,count=item.count;
  55. if(index>0){
  56. for(var k=0;k<index;k++){
  57. _LC+=hoppers[k].count;
  58. }
  59. }
  60. _LY=h*(_LC/allcount);
  61. _LX=0.5*_LY;
  62. _CY=h*((_LC+count)/allcount);
  63. _CX=0.5*_CY;
  64. point1={
  65. x:start.x+_LX,
  66. y:start.y+_LY
  67. };
  68. point2={
  69. x:start.x+maxWidth-_LX,
  70. y:start.y+_LY
  71. };
  72. point3={
  73. x:start.x+maxWidth-_CX,
  74. y:start.y+_CY
  75. };
  76. point4={
  77. x:start.x+_CX,
  78. y:start.y+_CY
  79. };
  80. linepoint1={
  81. x:start.x+maxWidth+20,
  82. y:start.y+itemH*index
  83. };
  84. linepoint2={
  85. x:start.x+maxWidth+15,
  86. y:start.y+itemH*index
  87. };
  88. linepoint3={
  89. x:start.x+maxWidth+5,
  90. y:start.y+_LY+h*count/(2*allcount)
  91. };
  92. linepoint4={
  93. x:start.x+maxWidth,
  94. y:start.y+_LY+h*count/(2*allcount)
  95. };
  96. linepoint5={
  97. x:start.x+maxWidth-(_LY+h*count/(2*allcount))*0.5,
  98. y:start.y+_LY+h*count/(2*allcount)
  99. };
  100. items.push({
  101. type:'path',
  102. path:"M "+point1.x+" "+point1.y+" L "+point2.x+" "+point2.y+" "+point3.x+" "+point3.y+" "+point4.x+" "+point4.y+" Z",
  103. fill:'#'+item.color,
  104. stroke:"#FFFFFF",
  105. "stroke-width":"1"
  106. });
  107. items.push({
  108. type: "text",
  109. text: item.name+"("+item.count+")",
  110. x:linepoint1.x,
  111. y:linepoint1.y,
  112. fill: "black",
  113. label:item.name,
  114. font: "12px Lucida Grande,Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif;",
  115. listeners :{
  116. mousedown:function(e){
  117. var grid=Ext.getCmp('chancegrid');
  118. grid.GridUtil.loadNewStore(grid,{
  119. caller:grid.caller,
  120. condition:"bc_currentprocess='"+e.label+"'"
  121. });
  122. }
  123. }
  124. });
  125. items.push({
  126. type: "path",
  127. path: "M "+linepoint1.x+" "+linepoint1.y+" C "+linepoint2.x+" "+linepoint2.y+" "+linepoint3.x+" "+linepoint3.y+" "+linepoint4.x+" "+linepoint4.y+" L "+" "+linepoint5.x+" "+linepoint5.y,
  128. "stroke-width":"1",
  129. visibility:"visible",
  130. stroke:"gray",
  131. fill:"none"
  132. });
  133. });
  134. return items;
  135. }
  136. });