InfoCard.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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: 'sale-sale-querypanel',
  37. condition: 'sale.companyid=' + companyId + ' and sa_statuscode=\'AUDITED\' and exists (select 1 from saledetail detail where sd_id=saledetail.sd_id and IFNULL(sd_sendqty,0)<ifnull(sd_qty,0) and TO_DAYS(sd_delivery)-TO_DAYS(now())<= 7)'
  38. },
  39. unstorage: {
  40. title: '未入库采购订单',
  41. color: 'purple',
  42. viewType: 'purchase-purchase-querypanel',
  43. condition: 'purchase.companyId=' + companyId + ' and pu_statuscode=\'AUDITED\' and exists (select 1 from purchasedetail detail where pd_id=purchasedetail.pd_id and IFNULL(pd_acceptqty,0) < ifnull(pd_qty,0) and TO_DAYS(PD_DELIVERY)-TO_DAYS(now()) <= 7)'
  44. },
  45. unpay: {
  46. title: '未收款出货',
  47. color: 'red',
  48. viewType: 'purchase-purchasein-querypanel',
  49. condition: 'pi_class in(\'采购验收单\',\'采购验退单\') and prodinout.companyId=' + companyId + ' and TO_DAYS(pi_date+ifnull(ve_promisedays,0))-TO_DAYS(now()) <= 7 and exists (select 1 from subledger where sl_code=pi_inoutno and sl_kind=pi_class and subledger.companyId=' + companyId + ' and ifnull(sl_namount,0)<>0)'
  50. },
  51. unreceive: {
  52. title: '未审核出货单',
  53. color: 'pink',
  54. viewType: 'sale-saleout-querypanel',
  55. condition: 'pi_class in(\'出货单\',\'销售退货单\') and prodinout.companyId=' + companyId + ' and TO_DAYS(pi_date+ifnull(cu_promisedays,0))-TO_DAYS(now()) <= 7 and exists (select 1 from subledger where sl_code=pi_inoutno and sl_kind=pi_class and subledger.companyId=' + companyId + ' and ifnull(sl_namount,0)<>0)'
  56. },
  57. unauditcheck: {
  58. title: '未审核验收单',
  59. color: 'blue',
  60. viewType: 'purchase-purchasein-querypanel',
  61. condition: 'pi_statuscode<>\'AUDITED\' and pi_class=\'采购验收单\' and prodinout.companyId=' + companyId
  62. },
  63. unauditship: {
  64. title: '未审核出货',
  65. color: 'default',
  66. viewType: 'purchase-purchasein-querypanel',
  67. condition: 'pi_statuscode<>\'AUDITED\' and pi_class=\'出货单\' and prodinout.companyId=' + companyId
  68. }
  69. },
  70. userCls: 'x-info-card ' + me.userCls,
  71. lbar: [{
  72. itemId: 'card-prev',
  73. hidden: true,
  74. cls: 'x-scroller-button x-scroller-button-left',
  75. handler: function() {
  76. me. showPrevious();
  77. },
  78. disabled: true
  79. }],
  80. rbar: [{
  81. itemId: 'card-next',
  82. hidden: true,
  83. cls: 'x-scroller-button x-scroller-button-right',
  84. handler: function() {
  85. me.showNext();
  86. }
  87. }],
  88. items: [],
  89. });
  90. me.callParent(arguments);
  91. },
  92. listeners: {
  93. boxready: function(m) {
  94. m.initCardItems();
  95. }
  96. },
  97. initCardItems: function() {
  98. this.addCardItems({});
  99. },
  100. addCardItems: function(infoData) {
  101. infoData = infoData || {};
  102. var me = this,
  103. p = me.up('home'),
  104. cards = me.cards,
  105. datas = [],
  106. items = [];
  107. size = Math.ceil(me.body.el.getBox().width / 235);
  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. saas.util.BaseUtil.openTab(record.get('viewType'), record.get('title'), record.get('id'), {
  133. simpleMode: true,
  134. defaultCondition: record.get('condition')
  135. });
  136. }
  137. }
  138. });
  139. var item = {
  140. xtype: 'panel',
  141. id: 'card-' + i,
  142. items: view
  143. };
  144. me.add(item);
  145. });
  146. if(datas.length > 1) {
  147. me.showPageTrigger();
  148. }
  149. me.updateLayout(true);
  150. },
  151. showPageTrigger: function() {
  152. var me = this;
  153. me.down('#card-prev').show();
  154. me.down('#card-next').show();
  155. },
  156. showNext: function () {
  157. this.doCardNavigation(1);
  158. },
  159. showPrevious: function (btn) {
  160. this.doCardNavigation(-1);
  161. },
  162. doCardNavigation: function (incr) {
  163. var me = this;
  164. var l = me.getLayout();
  165. var i = l.activeItem.id.split('card-')[1];
  166. var c = me.items.items.length;
  167. var next = parseInt(i, 10) + incr;
  168. l.setActiveItem(next);
  169. me.down('#card-prev').setDisabled(next === 0);
  170. me.down('#card-next').setDisabled(next === (c-1));
  171. }
  172. });