plan.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. $(function()
  2. {
  3. $('#planList').datatable(
  4. {
  5. customizable : false,
  6. sortable : false,
  7. tableClass : 'tablesorter',
  8. storage : false,
  9. fixCellHeight : false,
  10. selectable : false,
  11. fixedHeader : true,
  12. ready:function()
  13. {
  14. setTimeout(function()
  15. {
  16. var rowspan = 1;
  17. var compareVal = '';
  18. var mergeIndex = 0;
  19. $('.datatable-rows .datatable-rows-span:first table tr').each(function()
  20. {
  21. var $firstTd = $(this).find('td:first');
  22. var dataIndex = $(this).data('index');
  23. if(dataIndex == 0)
  24. {
  25. compareVal = $firstTd.html();
  26. mergeIndex = dataIndex;
  27. }
  28. if(mergeIndex != dataIndex)
  29. {
  30. if(compareVal == $firstTd.html())
  31. {
  32. rowspan += 1;
  33. $(this).parent().find('tr').eq(mergeIndex).find('td:first').attr('rowspan', rowspan);
  34. $firstTd.remove();
  35. }
  36. else
  37. {
  38. rowspan = 1;
  39. compareVal = $firstTd.html();
  40. mergeIndex = dataIndex;
  41. }
  42. }
  43. })
  44. }, 100);
  45. }
  46. })
  47. setTimeout(function()
  48. {
  49. fixScroll();
  50. $('.datatable .iframe').initIframeModal()
  51. }, 500);
  52. $('.datatable-head .datatable-row-left').height($('.datatable-head .flexarea table thead')[0].getBoundingClientRect().height * 2);
  53. $('.datatable-head .datatable-row-right').height($('.datatable-head .flexarea table thead')[0].getBoundingClientRect().height * 2);
  54. $('.datatable-head table').addClass('text-center');
  55. $('.datatable-rows .fixed-right .process').html("<td></td>");
  56. $('.datatable-rows .flexarea .table tr').html('');
  57. $('.datatable-rows .flexarea .process').html("<td class='text-center' colspan=" + (insideColspan + outsideColspan) + "></td>");
  58. $('.datatable-rows .flexarea tbody tr').each(function(index){$(this).css('height', $('.fixed-left > .datatable-wrapper table tr[data-index=' + index + ']')[0].getBoundingClientRect().height);})
  59. $('.datatable-rows .fixed-right tbody tr').each(function(index){$(this).css('height', $('.fixed-left > .datatable-wrapper table tr[data-index=' + index + ']')[0].getBoundingClientRect().height);})
  60. $('.datatable-head-span.flexarea .datatable-wrapper > table tr:first th:first').attr('colspan', insideColspan);
  61. $('.datatable-head-span.flexarea .datatable-wrapper > table tr:first th:last').attr('colspan', outsideColspan);
  62. $('.datatable-head-span.flexarea .datatable-wrapper > table .datatable-row-flex').after('<tr>' + insideList + outsideList + '</tr>');
  63. $('.main-table .table-footer').css({'bottom': '40px', 'width': $('.main-table').width()})
  64. $('.fixed-left').css('width', '45%');
  65. $('.fixed-right').css('width', '100px');
  66. $('#planList tbody tr').each(function(index)
  67. {
  68. if($(this).hasClass('process')) return;
  69. var $inside = $(this).find('.inside').html().replace(/span/g, 'td');
  70. var $outside = $(this).find('.outside').html().replace(/span/g, 'td');
  71. if($inside.trim().length == '') $inside = '<td></td>';
  72. if($outside.trim().length == '') $outside = '<td></td>';
  73. var $html = $inside + $outside;
  74. $('.datatable-rows .flexarea tbody tr[data-index=' + index + ']').html($html);
  75. })
  76. $('.edit-btn').click(function()
  77. {
  78. var $index = $(this).closest('tr').attr('data-index');
  79. var activityID = $(this).attr('activity');
  80. var $leftTr = $('.fixed-left .table tr[data-index=' + $index + ']');
  81. var $rightTr = $('.fixed-right .table tr[data-index=' + $index + ']');
  82. var $centerTr = $('.flexarea .table tr[data-index=' + $index + ']');
  83. var link = createLink('stakeholder', 'ajaxGetControl', 'activityID=' + activityID);
  84. $.post(link, function(data)
  85. {
  86. $centerTr.html('');
  87. data = JSON.parse(data);
  88. Object.keys(data.partakeList).forEach(function(key)
  89. {
  90. $centerTr.append(data.partakeList[key]);
  91. });
  92. $leftTr.find('td[data-index=1]').html(data.begin);
  93. $leftTr.find('td[data-index=2]').html(data.realBegin);
  94. $leftTr.find('td[data-index=3]').html(data.status);
  95. $leftTr.find('td[data-index=4]').html(data.situation);
  96. $('.form-date').datepicker();
  97. })
  98. $(this).closest('td').html('<button type="submit" id="submit" class="btn btn-primary" style="background: #16a8f8; color: #fff; width: 50px">保存</button>');
  99. })
  100. })
  101. function fixScroll()
  102. {
  103. var $scrollwrapper = $('div.datatable').first().find('.scroll-wrapper:first');
  104. if($scrollwrapper.size() == 0)return;
  105. var $tfoot = $('div.datatable').first().find('table tfoot:last');
  106. var scrollOffset = $scrollwrapper.offset().top + $scrollwrapper.find('.scroll-slide').height();
  107. if($tfoot.size() > 0) scrollOffset += $tfoot.height();
  108. if($('div.datatable.head-fixed').size() == 0) scrollOffset -= '29';
  109. var windowH = $(window).height();
  110. var bottom = $tfoot.hasClass('fixedTfootAction') ? 80 + $tfoot.height() : 80;
  111. if(typeof(ssoRedirect) != "undefined") bottom = 80;
  112. if(scrollOffset > windowH + $(window).scrollTop()) $scrollwrapper.css({'position': 'fixed', 'bottom': bottom + 'px'});
  113. $(window).scroll(function()
  114. {
  115. newBottom = $tfoot.hasClass('fixedTfootAction') ? 80 + $tfoot.height() : 80;
  116. if(typeof(ssoRedirect) != "undefined") newBottom = 80;
  117. if(scrollOffset <= windowH + $(window).scrollTop())
  118. {
  119. $scrollwrapper.css({'position':'relative', 'bottom': '0px'});
  120. }
  121. else if($scrollwrapper.css('position') != 'fixed' || bottom != newBottom)
  122. {
  123. $scrollwrapper.css({'position': 'fixed', 'bottom': newBottom + 'px'});
  124. bottom = newBottom;
  125. }
  126. });
  127. }