InfoCard.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. var companyId = saas.util.BaseUtil.getCurrentUser().companyId;
  31. Ext.apply(me, {
  32. cards: {
  33. unship: {
  34. title: '待出货销售',
  35. color: 'yellow',
  36. viewType: 'home-infocardlist-saleout',
  37. },
  38. unstorage: {
  39. title: '待入库采购',
  40. color: 'purple',
  41. viewType: 'home-infocardlist-purchasein',
  42. },
  43. unpay: {
  44. title: '待付款',
  45. color: 'red',
  46. viewType: 'home-infocardlist-payment',
  47. },
  48. unreceive: {
  49. title: '待收款',
  50. color: 'pink',
  51. viewType: 'home-infocardlist-recment',
  52. },
  53. unauditcheck: {
  54. title: '未审核验收',
  55. color: 'blue',
  56. viewType: 'home-infocardlist-unauditcheckin',
  57. },
  58. unauditship: {
  59. title: '未审核出货',
  60. color: 'default',
  61. viewType: 'home-infocardlist-unauditsaleout',
  62. }
  63. },
  64. userCls: 'x-info-card ' + me.userCls,
  65. lbar: [{
  66. itemId: 'card-prev',
  67. hidden: true,
  68. cls: 'x-scroller-button x-scroller-button-left',
  69. handler: function() {
  70. me. showPrevious();
  71. },
  72. disabled: true
  73. }],
  74. rbar: [{
  75. itemId: 'card-next',
  76. hidden: true,
  77. cls: 'x-scroller-button x-scroller-button-right',
  78. handler: function() {
  79. me.showNext();
  80. }
  81. }],
  82. items: [],
  83. });
  84. me.callParent(arguments);
  85. },
  86. listeners: {
  87. boxready: function(m) {
  88. m.initCardItems();
  89. }
  90. },
  91. initCardItems: function() {
  92. this.addCardItems({});
  93. },
  94. addCardItems: function(infoData) {
  95. infoData = infoData || {};
  96. var me = this,
  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. me.updateLayout(true);
  141. },
  142. showPageTrigger: function() {
  143. var me = this;
  144. me.down('#card-prev').show();
  145. me.down('#card-next').show();
  146. },
  147. showNext: function () {
  148. this.doCardNavigation(1);
  149. },
  150. showPrevious: function (btn) {
  151. this.doCardNavigation(-1);
  152. },
  153. doCardNavigation: function (incr) {
  154. var me = this;
  155. var l = me.getLayout();
  156. var i = l.activeItem.id.split('card-')[1];
  157. var c = me.items.items.length;
  158. var next = parseInt(i, 10) + incr;
  159. l.setActiveItem(next);
  160. me.down('#card-prev').setDisabled(next === 0);
  161. me.down('#card-next').setDisabled(next === (c-1));
  162. }
  163. });