InfoCard.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. initComponent: function () {
  29. var me = this;
  30. Ext.apply(me, {
  31. cards: {
  32. unship: {
  33. title: '待出货销售',
  34. color: 'yellow',
  35. viewType: 'home-infocardlist-saleout',
  36. },
  37. unstorage: {
  38. title: '待入库采购',
  39. color: 'purple',
  40. viewType: 'home-infocardlist-purchasein',
  41. },
  42. unpay: {
  43. title: '待付款',
  44. color: 'red',
  45. viewType: 'home-infocardlist-payment',
  46. },
  47. unreceive: {
  48. title: '待收款',
  49. color: 'pink',
  50. viewType: 'home-infocardlist-recment',
  51. },
  52. unauditcheck: {
  53. title: '未审核验收',
  54. color: 'blue',
  55. viewType: 'home-infocardlist-unauditcheckin',
  56. },
  57. unauditship: {
  58. title: '未审核出货',
  59. color: 'default',
  60. viewType: 'home-infocardlist-unauditsaleout',
  61. }
  62. },
  63. userCls: 'x-info-card ' + me.userCls,
  64. lbar: [{
  65. itemId: 'card-prev',
  66. hidden: true,
  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. },
  93. addCardItems: function(infoData) {
  94. infoData = infoData || {};
  95. var me = this,
  96. currentIndex = me.currentIndex,
  97. p = me.up('home'),
  98. cards = me.cards,
  99. datas = [],
  100. items = [];
  101. size = Math.ceil(me.body.el.getBox().width / 235);
  102. me.removeAll();
  103. var cl = Ext.Object.getAllKeys(cards);
  104. for(var x = 0; x < cl.length;) {
  105. var d = [];
  106. for(var y = 0; y < size && x < cl.length; y++) {
  107. var key = cl[x];
  108. d.push(Ext.merge(cards[key], {
  109. content: infoData[key] || 0
  110. }));
  111. x++;
  112. }
  113. datas.push(d);
  114. }
  115. Ext.Array.each(datas, function(d, i) {
  116. var store = Ext.create('Ext.data.Store', {
  117. fields: ['title', 'content', 'color'],
  118. data: d,
  119. });
  120. var view = Ext.create('Ext.view.View', {
  121. store: store,
  122. tpl: new Ext.XTemplate(me.cardTpl),
  123. itemSelector: 'div.x-box',
  124. listeners: {
  125. itemclick: function(th, record, item, index, e, eOpts) {
  126. saas.util.BaseUtil.openTab(record.get('viewType'), record.get('title'), record.get('id'));
  127. }
  128. }
  129. });
  130. var item = {
  131. xtype: 'panel',
  132. id: 'card-' + i,
  133. items: view
  134. };
  135. me.add(item);
  136. });
  137. if(datas.length > 1) {
  138. me.showPageTrigger();
  139. }
  140. if(Ext.isNumber(currentIndex)) {
  141. me.setActiveItem(me.items.items[currentIndex]);
  142. }else {
  143. me.currentIndex = 0;
  144. }
  145. me.updateLayout(true);
  146. },
  147. showPageTrigger: function() {
  148. var me = this;
  149. me.down('#card-prev').show();
  150. me.down('#card-next').show();
  151. },
  152. showNext: function () {
  153. this.doCardNavigation(1);
  154. },
  155. showPrevious: function (btn) {
  156. this.doCardNavigation(-1);
  157. },
  158. doCardNavigation: function (incr) {
  159. var me = this;
  160. var l = me.getLayout();
  161. var i = l.activeItem.id.split('card-')[1];
  162. var c = me.items.items.length;
  163. var next = parseInt(i, 10) + incr;
  164. l.setActiveItem(next);
  165. me.currentIndex = me.currentIndex + incr;
  166. me.down('#card-prev').setDisabled(next === 0);
  167. me.down('#card-next').setDisabled(next === (c-1));
  168. }
  169. });