InfoCard.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. 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. unship: {
  32. title: '待出货销售',
  33. color: 'yellow',
  34. viewType: 'home-infocardlist-saleout',
  35. },
  36. unstorage: {
  37. title: '待入库采购',
  38. color: 'purple',
  39. viewType: 'home-infocardlist-purchasein',
  40. },
  41. unpay: {
  42. title: '待付款',
  43. color: 'red',
  44. viewType: 'home-infocardlist-payment',
  45. },
  46. unreceive: {
  47. title: '待收款',
  48. color: 'pink',
  49. viewType: 'home-infocardlist-recment',
  50. },
  51. unauditcheck: {
  52. title: '未审核验收',
  53. color: 'blue',
  54. viewType: 'home-infocardlist-unauditcheckin',
  55. },
  56. unauditship: {
  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. },
  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 / 230);
  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. });