construction_list.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. $(function () {
  2. autoFlashHeight();
  3. $('.to-log-link').on('click', function () {
  4. const status = parseInt($(this).data('status'));
  5. const uid = parseInt($('#curReportUid').data('uid'));
  6. const queryArr = [];
  7. if (status) {
  8. queryArr.push('status=' + status);
  9. }
  10. if (uid) {
  11. queryArr.push('uid=' + uid);
  12. }
  13. const queryStr = queryArr.length > 0 ? '?' + queryArr.join('&') : '';
  14. const link = `/sp/${spid}/construction/${tender_id }/list` + queryStr;
  15. window.location.href = link;
  16. });
  17. $('.to-log-link2').on('click', function () {
  18. const status = parseInt($('#curReportStatus').data('status'));
  19. const uid = parseInt($(this).data('uid'));
  20. const queryArr = [];
  21. if (status) {
  22. queryArr.push('status=' + status);
  23. }
  24. if (uid) {
  25. queryArr.push('uid=' + uid);
  26. }
  27. const queryStr = queryArr.length > 0 ? '?' + queryArr.join('&') : '';
  28. const link = `/sp/${spid}/construction/${tender_id }/list` + queryStr;
  29. window.location.href = link;
  30. });
  31. if (reportFlag) {
  32. const codeDate = $('#code-date').datepicker({
  33. onSelect: function (formattedDate, date, inst) {
  34. const showDate = date ? moment(date[date.length - 1]).format('YYYYMMDD') : '';
  35. const showCode = showDate ? showDate + getCodeByDate(showDate, getDatesFromStringAndConvert(formattedDate)) : '';
  36. if (!showCode) {
  37. $('#existMsg').hide();
  38. }
  39. $('#show-code').val(showCode);
  40. }
  41. }).data('datepicker');
  42. codeDate.selectDate(new Date());
  43. $('#show-code').val(moment().format('YYYYMMDD') + getCodeByDate(moment().format('YYYYMMDD'), getDatesFromStringAndConvert(moment().format('YYYY-MM-DD'))));
  44. $('#add-log input[name="log-type"]').on('click', function () {
  45. const type = parseInt($(this).val());
  46. if (type) {
  47. $('#code-date').val('');
  48. codeDate.clear();
  49. $('#show-code').val('');
  50. $('#existMsg').hide();
  51. } else {
  52. codeDate.clear();
  53. $('#code-date').val(moment().format('YYYY-MM-DD'));
  54. codeDate.selectDate(new Date());
  55. $('#show-code').val(moment().format('YYYYMMDD') + getCodeByDate(moment().format('YYYYMMDD'), getDatesFromStringAndConvert(moment().format('YYYY-MM-DD'))));
  56. }
  57. });
  58. $('#add-log-btn').click(function () {
  59. if (_.trim($('#code-date').val()) === '') {
  60. toastr.error('请选择日期/周期');
  61. return false;
  62. }
  63. const newData = {
  64. type: parseInt($('#add-log input[name="log-type"]:checked').val()),
  65. code: $('#show-code').val(),
  66. period: _.trim($('#code-date').val()),
  67. };
  68. postData(`/sp/${spid}/construction/${tender_id}/list/add`, newData, function (result) {
  69. console.log(result);
  70. window.location.href = `/sp/${spid}/construction/${tender_id}/log/` + result;
  71. })
  72. });
  73. // 批量提交
  74. $('#confirm-uncheck-btn').click(function () {
  75. // 获取选中值
  76. const checkedIds = [];
  77. $('#uncheck-list input[type="checkbox"]:checked').each(function () {
  78. checkedIds.push(parseInt($(this).data('id')));
  79. });
  80. if (checkedIds.length === 0) {
  81. toastr.error('请勾选日志再批量提交');
  82. return false;
  83. }
  84. postData(`/sp/${spid}/construction/${tender_id}/list/startmulti`, { ids: checkedIds }, function (result) {
  85. window.location.reload();
  86. });
  87. });
  88. $('.delete-log-a').on('click', function () {
  89. $('#delete-log-id').val($(this).data('id'));
  90. });
  91. // 删除
  92. $('#delete-log-btn').click(function () {
  93. const log_id = $('#delete-log-id').val();
  94. if (!log_id) {
  95. toastr.error('删除的日志id为空');
  96. return false;
  97. }
  98. postData(`/sp/${spid}/construction/${tender_id}/log/${log_id}/delete`, {}, function (result) {
  99. window.location.reload();
  100. })
  101. });
  102. function getCodeByDate(date, dates) {
  103. let num = '001';
  104. if (date) {
  105. const dateInfo = _.find(dateCodeList, { date_code: date });
  106. if (dateInfo) {
  107. num = convertToThreeDigits(dateInfo.num + 1);
  108. }
  109. if (_.intersection(_.map(dateCodeList, 'date_code'), dates).length !== 0) {
  110. $('#existMsg').show();
  111. } else {
  112. $('#existMsg').hide();
  113. }
  114. } else {
  115. $('#existMsg').hide();
  116. }
  117. return num;
  118. }
  119. function getDatesFromStringAndConvert(dateString) {
  120. const dates = [];
  121. const dateParts = dateString.split(' ~ ');
  122. dateParts.forEach(datePart => {
  123. const date = new Date(datePart);
  124. if (!isNaN(date.getTime())) {
  125. dates.push(date);
  126. } else {
  127. console.error('Invalid date format in the input string:', datePart);
  128. }
  129. });
  130. if (dates.length === 1) {
  131. return [dates[0].toISOString().slice(0, 10).replace(/-/g, '')];
  132. }
  133. const startDate = dates[0];
  134. const endDate = dates[1];
  135. const currentDate = new Date(startDate);
  136. const endDatePlusOneDay = new Date(endDate);
  137. endDatePlusOneDay.setDate(endDatePlusOneDay.getDate() + 1);
  138. while (currentDate < endDatePlusOneDay) {
  139. const formattedDate = currentDate.toISOString().slice(0, 10).replace(/-/g, '');
  140. dates.push(formattedDate);
  141. currentDate.setDate(currentDate.getDate() + 1);
  142. }
  143. return dates.slice(2);
  144. }
  145. function convertToThreeDigits(number) {
  146. // 将数字转换为字符串
  147. let numStr = String(number);
  148. // 检查数字是否不足3位
  149. if (numStr.length < 3) {
  150. // 在前面添加足够的零使其成为3位数
  151. numStr = numStr.padStart(3, '0');
  152. }
  153. return numStr;
  154. }
  155. }
  156. });