InfoCard.js 5.0 KB

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