preview.ui.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. window.pivotID = pivotID;
  2. window.waitDom('#export-data-button', function()
  3. {
  4. $(document).off('click', '#export-data-button').on('click', '#export-data-button', () => exportData());
  5. });
  6. /**
  7. * 查询条件改变时重新加载 Bug 创建表。
  8. * Reload bug create table when query conditions changed.
  9. *
  10. * @access public
  11. * @return void
  12. */
  13. function loadBugCreate()
  14. {
  15. const begin = $('#conditions').find('[name="begin"]').val().replaceAll('-', '');
  16. const end = $('#conditions').find('[name="end"]').val().replaceAll('-', '');
  17. const product = $('#conditions').find('[name=product]').val() || 0;
  18. const execution = $('#conditions').find('[name=execution]').val() || 0;
  19. const params = window.btoa('begin=' + begin + '&end=' + end + '&product=' + +product + '&execution=' + +execution);
  20. const link = $.createLink('pivot', 'preview', 'dimensionID=' + dimensionID + '&groupID=' + groupID + '&method=bugCreate&params=' + params);
  21. loadPage(link, '#pivotPanel');
  22. }
  23. /**
  24. * 查询条件改变时重新加载产品汇总表。
  25. * Reload product summary table when query conditions changed.
  26. *
  27. * @access public
  28. * @return void
  29. */
  30. function loadProductSummary()
  31. {
  32. let conditions = '';
  33. $('#conditions input[type=checkbox]').each(function(i)
  34. {
  35. if($(this).prop('checked')) conditions += $(this).val() + ',';
  36. })
  37. conditions = conditions.substring(0, conditions.length - 1);
  38. const productID = $('#product').find('.pick-value').val();
  39. const productStatus = $('#productStatus').find('.pick-value').val();
  40. const productType = $('#productType').find('.pick-value').val();
  41. const params = window.btoa('conditions=' + conditions + '&productID=' + productID + '&productStatus=' + productStatus + '&productType=' + productType);
  42. const link = $.createLink('pivot', 'preview', 'dimensionID=' + dimensionID + '&groupID=' + groupID + '&method=productSummary&params=' + params);
  43. loadPage(link, '#pivotPanel');
  44. }
  45. /**
  46. * 查询条件改变时重新加载执行偏差表。
  47. * Reload execution deviation table when query conditions changed.
  48. *
  49. * @access public
  50. * @return void
  51. */
  52. function loadProjectDeviation()
  53. {
  54. const begin = $('#conditions').find('[name="begin"]').val().replaceAll('-', '');
  55. const end = $('#conditions').find('[name="end"]').val().replaceAll('-', '');
  56. const params = window.btoa('begin=' + begin + '&end=' + end);
  57. const link = $.createLink('pivot', 'preview', 'dimensionID=' + dimensionID + '&groupID=' + groupID + '&method=projectdeviation&params=' + params);
  58. loadPage(link, '#pivotPanel,#pivotChart');
  59. }
  60. /**
  61. * 查询条件改变时重新加载工作负载表。
  62. * Reload workload table when query conditions changed.
  63. *
  64. * @access public
  65. * @return void
  66. */
  67. function loadWorkload()
  68. {
  69. const begin = $('#conditions').find('[name="begin"]').val();
  70. const end = $('#conditions').find('[name="end"]').val();
  71. const workhour = $('#conditions').find('#workhour').val();
  72. const dept = $('#conditions').find('[name=dept]').val();
  73. const assign = $('#conditions').find('[name=assign]').val();
  74. const days = diffDate(begin, end);
  75. $('#days').val(days);
  76. const params = window.btoa('begin=' + begin.replaceAll('-', '') + '&end=' + end.replaceAll('-', '') + '&days=' + days + '&workhour=' + +workhour + '&dept=' + dept + '&assign=' + assign);
  77. const link = $.createLink('pivot', 'preview', 'dimensionID=' + dimensionID + '&groupID=' + groupID + '&method=workload&params=' + params);
  78. loadPage(link, '#pivotPanel');
  79. }
  80. function toggleShowMode(showMode = 'group')
  81. {
  82. if(showMode == 'group')
  83. {
  84. $('#origin-query').removeClass('hidden');
  85. $('#pivot-query').addClass('hidden');
  86. }
  87. else
  88. {
  89. $('#origin-query').addClass('hidden');
  90. $('#pivot-query').removeClass('hidden');
  91. }
  92. loadCustomPivot(showMode);
  93. }
  94. /**
  95. * 查询条件改变时重新加载自定义透视表。
  96. * Reload custom pivot table when query conditions changed.
  97. *
  98. * @access public
  99. * @param showMode group|origin
  100. * @return void
  101. */
  102. function loadCustomPivot(showMode = 'group')
  103. {
  104. const filterValues = getFilterValues();
  105. const form = zui.createFormData();
  106. if(showMode == 'origin') form.append('summary', 'notuse');
  107. filterValues.forEach((val, index) => {
  108. if (typeof val === 'object') {
  109. for(var i in val) form.append(`filterValues[${index}][${i}]`, val[i]);
  110. } else {
  111. form.append(`filterValues[${index}]`, val)
  112. }
  113. });
  114. const params = window.btoa('groupID=' + currentGroup + '&pivotID=' + pivotID);
  115. const link = $.createLink('pivot', 'preview', 'dimensionID=' + dimensionID + '&groupID=' + groupID + '&method=show&params=' + params);
  116. postAndLoadPage(link, form, 'dtable/#table-pivot-preview:component,#conditions,pageJS/.zin-page-js,#exportData');
  117. }
  118. /**
  119. * 导出透视表数据。
  120. * Export pivot table data.
  121. *
  122. * @access public
  123. * @return void
  124. */
  125. function exportData()
  126. {
  127. const $domObj = $(".table-condensed")[0];
  128. exportFile($domObj);
  129. }
  130. /**
  131. * 把日期字符串转换成日期对象。
  132. * Convert date string to date object.
  133. *
  134. * @param string $dateString
  135. * @access public
  136. * @return date
  137. */
  138. function convertStringToDate(dateString)
  139. {
  140. dateString = dateString.split('-');
  141. return new Date(dateString[0], dateString[1] - 1, dateString[2]);
  142. }
  143. /**
  144. * 计算两个日期之间的天数。
  145. * Compute the days between two date.
  146. *
  147. * @param string $date1
  148. * @param string $date1
  149. * @access public
  150. * @return int
  151. */
  152. function diffDate(date1, date2)
  153. {
  154. date1 = convertStringToDate(date1);
  155. date2 = convertStringToDate(date2);
  156. delta = (date2 - date1) / (1000 * 60 * 60 * 24) + 1;
  157. weekEnds = 0;
  158. for(i = 0; i < delta; i++)
  159. {
  160. if((weekend == 2 && date1.getDay() == 6) || date1.getDay() == 0) weekEnds ++;
  161. date1 = date1.valueOf();
  162. date1 += 1000 * 60 * 60 * 24;
  163. date1 = new Date(date1);
  164. }
  165. return delta - weekEnds;
  166. }
  167. /**
  168. * 合并单元格。
  169. * Merge cell.
  170. *
  171. * @param object cell
  172. * @access public
  173. * @return object|void
  174. */
  175. getCellSpan = function(cell)
  176. {
  177. const options = this.options.cellSpanOptions[cell.col.name];
  178. if(options)
  179. {
  180. const rowSpan = cell.row.data[options.rowspan ?? 'rowspan'] ?? 1;
  181. const colSpan = cell.row.data[options.colspan ?? 'colspan'] ?? 1;
  182. return {rowSpan, colSpan};
  183. }
  184. }