InfoCard.js 5.3 KB

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