123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- $(function () {
- autoFlashHeight();
- $('.to-log-link').on('click', function () {
- const status = parseInt($(this).data('status'));
- const uid = parseInt($('#curReportUid').data('uid'));
- const queryArr = [];
- if (status) {
- queryArr.push('status=' + status);
- }
- if (uid) {
- queryArr.push('uid=' + uid);
- }
- const queryStr = queryArr.length > 0 ? '?' + queryArr.join('&') : '';
- const link = `/sp/${spid}/construction/${tender_id }/list` + queryStr;
- window.location.href = link;
- });
- $('.to-log-link2').on('click', function () {
- const status = parseInt($('#curReportStatus').data('status'));
- const uid = parseInt($(this).data('uid'));
- const queryArr = [];
- if (status) {
- queryArr.push('status=' + status);
- }
- if (uid) {
- queryArr.push('uid=' + uid);
- }
- const queryStr = queryArr.length > 0 ? '?' + queryArr.join('&') : '';
- const link = `/sp/${spid}/construction/${tender_id }/list` + queryStr;
- window.location.href = link;
- });
- if (reportFlag) {
- const codeDate = $('#code-date').datepicker({
- onSelect: function (formattedDate, date, inst) {
- const showDate = date ? moment(date[date.length - 1]).format('YYYYMMDD') : '';
- const showCode = showDate ? showDate + getCodeByDate(showDate, getDatesFromStringAndConvert(formattedDate)) : '';
- if (!showCode) {
- $('#existMsg').hide();
- }
- $('#show-code').val(showCode);
- }
- }).data('datepicker');
- codeDate.selectDate(new Date());
- $('#show-code').val(moment().format('YYYYMMDD') + getCodeByDate(moment().format('YYYYMMDD'), getDatesFromStringAndConvert(moment().format('YYYY-MM-DD'))));
- $('#add-log input[name="log-type"]').on('click', function () {
- const type = parseInt($(this).val());
- if (type) {
- $('#code-date').val('');
- codeDate.clear();
- $('#show-code').val('');
- $('#existMsg').hide();
- } else {
- codeDate.clear();
- $('#code-date').val(moment().format('YYYY-MM-DD'));
- codeDate.selectDate(new Date());
- $('#show-code').val(moment().format('YYYYMMDD') + getCodeByDate(moment().format('YYYYMMDD'), getDatesFromStringAndConvert(moment().format('YYYY-MM-DD'))));
- }
- });
- $('#add-log-btn').click(function () {
- if (_.trim($('#code-date').val()) === '') {
- toastr.error('请选择日期/周期');
- return false;
- }
- const newData = {
- type: parseInt($('#add-log input[name="log-type"]:checked').val()),
- code: $('#show-code').val(),
- period: _.trim($('#code-date').val()),
- };
- postData(`/sp/${spid}/construction/${tender_id}/list/add`, newData, function (result) {
- console.log(result);
- window.location.href = `/sp/${spid}/construction/${tender_id}/log/` + result;
- })
- });
- // 批量提交
- $('#confirm-uncheck-btn').click(function () {
- // 获取选中值
- const checkedIds = [];
- $('#uncheck-list input[type="checkbox"]:checked').each(function () {
- checkedIds.push(parseInt($(this).data('id')));
- });
- if (checkedIds.length === 0) {
- toastr.error('请勾选日志再批量提交');
- return false;
- }
- postData(`/sp/${spid}/construction/${tender_id}/list/startmulti`, { ids: checkedIds }, function (result) {
- window.location.reload();
- });
- });
- $('.delete-log-a').on('click', function () {
- $('#delete-log-id').val($(this).data('id'));
- });
- // 删除
- $('#delete-log-btn').click(function () {
- const log_id = $('#delete-log-id').val();
- if (!log_id) {
- toastr.error('删除的日志id为空');
- return false;
- }
- postData(`/sp/${spid}/construction/${tender_id}/log/${log_id}/delete`, {}, function (result) {
- window.location.reload();
- })
- });
- function getCodeByDate(date, dates) {
- let num = '001';
- if (date) {
- const dateInfo = _.find(dateCodeList, { date_code: date });
- if (dateInfo) {
- num = convertToThreeDigits(dateInfo.num + 1);
- }
- if (_.intersection(_.map(dateCodeList, 'date_code'), dates).length !== 0) {
- $('#existMsg').show();
- } else {
- $('#existMsg').hide();
- }
- } else {
- $('#existMsg').hide();
- }
- return num;
- }
- function getDatesFromStringAndConvert(dateString) {
- const dates = [];
- const dateParts = dateString.split(' ~ ');
- dateParts.forEach(datePart => {
- const date = new Date(datePart);
- if (!isNaN(date.getTime())) {
- dates.push(date);
- } else {
- console.error('Invalid date format in the input string:', datePart);
- }
- });
- if (dates.length === 1) {
- return [dates[0].toISOString().slice(0, 10).replace(/-/g, '')];
- }
- const startDate = dates[0];
- const endDate = dates[1];
- const currentDate = new Date(startDate);
- const endDatePlusOneDay = new Date(endDate);
- endDatePlusOneDay.setDate(endDatePlusOneDay.getDate() + 1);
- while (currentDate < endDatePlusOneDay) {
- const formattedDate = currentDate.toISOString().slice(0, 10).replace(/-/g, '');
- dates.push(formattedDate);
- currentDate.setDate(currentDate.getDate() + 1);
- }
- return dates.slice(2);
- }
- function convertToThreeDigits(number) {
- // 将数字转换为字符串
- let numStr = String(number);
- // 检查数字是否不足3位
- if (numStr.length < 3) {
- // 在前面添加足够的零使其成为3位数
- numStr = numStr.padStart(3, '0');
- }
- return numStr;
- }
- }
- });
|