laiguoran 2 vuotta sitten
vanhempi
commit
a5d6da6165
2 muutettua tiedostoa jossa 39 lisäystä ja 5 poistoa
  1. 38 4
      app/public/js/construction_list.js
  2. 1 1
      app/view/construction/list_modal.ejs

+ 38 - 4
app/public/js/construction_list.js

@@ -34,7 +34,7 @@ $(function () {
         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) : '';
+                const showCode = showDate ? showDate + getCodeByDate(showDate, getDatesFromStringAndConvert(formattedDate)) : '';
                 if (!showCode) {
                     $('#existMsg').hide();
                 }
@@ -42,7 +42,7 @@ $(function () {
             }
         }).data('datepicker');
         codeDate.selectDate(new Date());
-        $('#show-code').val(moment().format('YYYYMMDD') + getCodeByDate(moment().format('YYYYMMDD')));
+        $('#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());
@@ -55,7 +55,7 @@ $(function () {
                 codeDate.clear();
                 $('#code-date').val(moment().format('YYYY-MM-DD'));
                 codeDate.selectDate(new Date());
-                $('#show-code').val(moment().format('YYYYMMDD') + getCodeByDate(moment().format('YYYYMMDD')));
+                $('#show-code').val(moment().format('YYYYMMDD') + getCodeByDate(moment().format('YYYYMMDD'), getDatesFromStringAndConvert(moment().format('YYYY-MM-DD'))));
             }
         });
 
@@ -108,12 +108,14 @@ $(function () {
             })
         });
 
-        function getCodeByDate(date) {
+        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();
@@ -124,6 +126,38 @@ $(function () {
             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);

+ 1 - 1
app/view/construction/list_modal.ejs

@@ -30,7 +30,7 @@
                     <label>日志编号</label>
                     <input class="form-control form-control-sm" id="show-code" placeholder="" type="text" value="" readonly>
                     <div class="text-warning m-1" id="existMsg" style="display: none">
-                        日已存在日志文件,请注意核查哦。
+                        日期/周期内已存在日志文件,请注意核查哦。
                     </div>
                 </div>
             </div>