InfoCard.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. Ext.define('school.view.home.InfoCard', {
  2. extend: 'Ext.panel.Panel',
  3. xtype: 'infocard',
  4. id: 'infocard',
  5. requires: [
  6. 'Ext.layout.container.Card'
  7. ],
  8. layout: 'card',
  9. height: 110,
  10. cardTpl: [
  11. '<div class="x-row">',
  12. '<tpl for=".">',
  13. '<div class="x-col">',
  14. '<div>',
  15. '<div class="x-box ',
  16. '<tpl if="color"> x-bg-{color}</tpl>',
  17. '<tpl else"> x-bg-default</tpl>',
  18. '">',
  19. '<div class="title">{title}</div>',
  20. '<div class="value">{content}</div>',
  21. '</div>',
  22. '</div>',
  23. '</div>',
  24. '</tpl>',
  25. '</div>'
  26. ],
  27. initComponent: function () {
  28. var me = this;
  29. Ext.apply(me, {
  30. cards: {
  31. student: {
  32. title: '学生人数',
  33. color: 'blue',
  34. viewType: 'home-infocardlist-unauditcheckin',
  35. },
  36. teacher: {
  37. title: '教职工人数',
  38. color: 'yellow',
  39. viewType: 'home-infocardlist-saleout',
  40. },
  41. parent: {
  42. title: '家长人数',
  43. color: 'default',
  44. viewType: 'home-infocardlist-unauditsaleout',
  45. },
  46. grade: {
  47. title: '年级',
  48. color: 'red',
  49. viewType: 'home-infocardlist-payment',
  50. },
  51. class: {
  52. title: '班级',
  53. color: 'pink',
  54. viewType: 'home-infocardlist-recment',
  55. }
  56. },
  57. userCls: 'x-info-card ' + me.userCls,
  58. lbar: [{
  59. itemId: 'card-prev',
  60. hidden: true,
  61. margin: '0 8 0 0',
  62. cls: 'x-scroller-button x-scroller-button-left',
  63. handler: function() {
  64. me.showPrevious();
  65. },
  66. disabled: true
  67. }],
  68. rbar: [{
  69. itemId: 'card-next',
  70. hidden: true,
  71. cls: 'x-scroller-button x-scroller-button-right',
  72. handler: function() {
  73. me.showNext();
  74. }
  75. }],
  76. items: [],
  77. });
  78. me.callParent(arguments);
  79. },
  80. listeners: {
  81. boxready: function(m) {
  82. m.initCardItems();
  83. }
  84. },
  85. initCardItems: function() {
  86. this.addCardItems({});
  87. },
  88. addCardItems: function(infoData) {
  89. infoData = infoData || {};
  90. var me = this,
  91. currentIndex = me.currentIndex,
  92. p = me.up('home'),
  93. cards = me.cards,
  94. datas = [],
  95. size = Math.ceil(me.body.el.getBox().width / 230);
  96. me.removeAll();
  97. var cl = Ext.Object.getAllKeys(cards);
  98. for(var x = 0; x < cl.length;) {
  99. var d = [];
  100. for(var y = 0; y < size && x < cl.length; y++) {
  101. var key = cl[x];
  102. d.push(Ext.merge(cards[key], {
  103. content: infoData[key] || 0
  104. }));
  105. x++;
  106. }
  107. datas.push(d);
  108. }
  109. Ext.Array.each(datas, function(d, i) {
  110. var store = Ext.create('Ext.data.Store', {
  111. fields: ['title', 'content', 'color'],
  112. data: d,
  113. });
  114. var view = Ext.create('Ext.view.View', {
  115. store: store,
  116. tpl: new Ext.XTemplate(me.cardTpl),
  117. itemSelector: 'div.x-box',
  118. listeners: {
  119. itemclick: function(th, record, item, index, e, eOpts) {
  120. // school.util.BaseUtil.openTab(record.get('viewType'), record.get('title'), record.get('id'));
  121. }
  122. }
  123. });
  124. var item = {
  125. xtype: 'panel',
  126. id: 'card-' + i,
  127. items: view
  128. };
  129. me.add(item);
  130. });
  131. if(datas.length > 1) {
  132. me.showPageTrigger();
  133. }
  134. if(Ext.isNumber(currentIndex)) {
  135. me.setActiveItem(me.items.items[currentIndex]);
  136. }else {
  137. me.currentIndex = 0;
  138. }
  139. me.updateLayout(true);
  140. },
  141. showPageTrigger: function() {
  142. var me = this;
  143. me.down('#card-prev').show();
  144. me.down('#card-next').show();
  145. },
  146. showNext: function () {
  147. this.doCardNavigation(1);
  148. },
  149. showPrevious: function (btn) {
  150. this.doCardNavigation(-1);
  151. },
  152. doCardNavigation: function (incr) {
  153. var me = this;
  154. var l = me.getLayout();
  155. var i = l.activeItem.id.split('card-')[1];
  156. var c = me.items.items.length;
  157. var next = parseInt(i, 10) + incr;
  158. l.setActiveItem(next);
  159. me.currentIndex = me.currentIndex + incr;
  160. me.down('#card-prev').setDisabled(next === 0);
  161. me.down('#card-next').setDisabled(next === (c-1));
  162. }
  163. });