InfoCard.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. Ext.define('saas.view.home.InfoCard', {
  2. extend: 'Ext.panel.Panel',
  3. xtype: 'infocard',
  4. id: 'infocard',
  5. requires: [
  6. 'Ext.layout.container.Card'
  7. ],
  8. BaseUtil: Ext.create('saas.util.BaseUtil'),
  9. layout: 'card',
  10. height: 150,
  11. cardTpl: [
  12. '<div class="x-row">',
  13. '<tpl for=".">',
  14. '<div class="x-col">',
  15. '<div>',
  16. '<div class="x-box ',
  17. '<tpl if="color"> x-bg-{color}</tpl>',
  18. '<tpl else"> x-bg-default</tpl>',
  19. '">',
  20. '<h3>{title}</h3>',
  21. '<p>{content}</p>',
  22. '</div>',
  23. '</div>',
  24. '</div>',
  25. '</tpl>',
  26. '</div>'
  27. ],
  28. cards: {
  29. unship: {
  30. title: '七天内待出货销售',
  31. color: 'yellow'
  32. },
  33. unstorage: {
  34. title: '七天内待入库采购',
  35. color: 'purple'
  36. },
  37. unpay: {
  38. title: '七天内待付款',
  39. color: 'red'
  40. },
  41. unreceive: {
  42. title: '七天内待收款',
  43. color: 'pink'
  44. },
  45. unauditcheck: {
  46. title: '未审核验收',
  47. color: 'blue'
  48. },
  49. unauditship: {
  50. title: '未审核出货',
  51. color: ''
  52. }
  53. },
  54. initComponent: function () {
  55. var me = this;
  56. Ext.apply(me, {
  57. userCls: 'x-info-card ' + me.userCls,
  58. lbar: [{
  59. itemId: 'card-prev',
  60. hidden: true,
  61. cls: 'x-scroller-button x-scroller-button-left',
  62. handler: function() {
  63. me. showPrevious();
  64. },
  65. disabled: true
  66. }],
  67. rbar: [{
  68. itemId: 'card-next',
  69. hidden: true,
  70. cls: 'x-scroller-button x-scroller-button-right',
  71. handler: function() {
  72. me.showNext();
  73. }
  74. }],
  75. items: [],
  76. });
  77. me.callParent(arguments);
  78. },
  79. listeners: {
  80. boxready: function(m) {
  81. m.initCardItems();
  82. }
  83. },
  84. initCardItems: function() {
  85. this.addCardItems({});
  86. },
  87. addCardItems: function(infoData) {
  88. infoData = infoData || {};
  89. var me = this,
  90. p = me.up('home'),
  91. cards = me.cards,
  92. datas = [],
  93. items = [];
  94. size = Math.ceil(me.body.el.getBox().width / 235);
  95. me.removeAll();
  96. var cl = Ext.Object.getAllKeys(cards);
  97. for(var x = 0; x < cl.length;) {
  98. var d = [];
  99. for(var y = 0; y < size && x < cl.length; y++) {
  100. var key = cl[x];
  101. d.push(Ext.merge(cards[key], {
  102. content: infoData[key] || 0
  103. }));
  104. x++;
  105. }
  106. datas.push(d);
  107. }
  108. Ext.Array.each(datas, function(d, i) {
  109. var store = Ext.create('Ext.data.Store', {
  110. fields: ['title', 'content', 'color'],
  111. data: d,
  112. });
  113. var view = Ext.create('Ext.view.View', {
  114. store: store,
  115. tpl: new Ext.XTemplate(me.cardTpl),
  116. itemSelector: 'div.x-info-card-body',
  117. });
  118. var item = {
  119. xtype: 'panel',
  120. id: 'card-' + i,
  121. items: view
  122. };
  123. me.add(item);
  124. });
  125. if(datas.length > 1) {
  126. me.showPageTrigger();
  127. }
  128. me.updateLayout(true);
  129. },
  130. showPageTrigger: function() {
  131. var me = this;
  132. me.down('#card-prev').show();
  133. me.down('#card-next').show();
  134. },
  135. showNext: function () {
  136. this.doCardNavigation(1);
  137. },
  138. showPrevious: function (btn) {
  139. this.doCardNavigation(-1);
  140. },
  141. doCardNavigation: function (incr) {
  142. var me = this;
  143. var l = me.getLayout();
  144. var i = l.activeItem.id.split('card-')[1];
  145. var c = me.items.items.length;
  146. var next = parseInt(i, 10) + incr;
  147. l.setActiveItem(next);
  148. me.down('#card-prev').setDisabled(next === 0);
  149. me.down('#card-next').setDisabled(next === (c-1));
  150. }
  151. });