laiguoran 4 gadi atpakaļ
vecāks
revīzija
7c3191037d

+ 3 - 3
app/controller/measure_controller.js

@@ -142,9 +142,9 @@ module.exports = app => {
                 if (!stage) {
                     throw '提交数据错误';
                 }
-                if (stage.status === auditConst.status.checked) {
-                    throw '该计量期当前不可编辑';
-                }
+                // if (stage.status === auditConst.status.checked) {
+                //     throw '该计量期当前不可编辑';
+                // }
                 if (ctx.session.sessionUser.accountId !== stage.user_id) {
                     throw '您无权修改该数据';
                 }

+ 3 - 3
app/view/measure/stage.ejs

@@ -38,12 +38,12 @@
                     </tr>
                     </thead>
                     <tbody>
-                    <% for (const s of stages) { %>
+                    <% for (const [i,s] of stages.entries()) { %>
                     <tr>
                         <td>
                             <a href="<%- '/tender/' + ctx.tender.id + '/measure/stage/' + s.order %>" target="_blank">第 <%- s.order %> 期</a>
-                            <% if (s.status !== auditConst.status.checked && s.user_id === ctx.session.sessionUser.accountId) { %>
-                            <a href="#edit" data-toggle="modal" data-target="#edit"><i class="fa fa-pencil-square-o "></i></a>
+                            <% if ((s.status !== auditConst.status.checked || (stages[i-1] && stages[i-1].status !== auditConst.status.checked)) && s.user_id === ctx.session.sessionUser.accountId) { %>
+                            <a href="#edit" class="edit-stage" data-index="<%- i %>" data-toggle="modal" data-target="#edit"><i class="fa fa-pencil-square-o "></i></a>
                             <% } %>
                         </td>
                         <td class="text-center"><%- s.s_time %></td>

+ 23 - 16
app/view/measure/stage_modal.ejs

@@ -83,7 +83,7 @@
             <div class="modal-body">
                 <div class="form-group">
                     <label>期</label>
-                    <input class="form-control form-control-sm" value="第 <%- stages[0].order %> 期" type="text" readonly="" name="name">
+                    <input class="form-control form-control-sm" id="edit-name" value="第 <%- stages[0].order %> 期" type="text" readonly="" name="name">
                 </div>
                 <div class="form-group">
                     <label>计量年月<b class="text-danger">*</b></label>
@@ -96,7 +96,7 @@
             </div>
             <div class="modal-footer">
                 <input type="hidden" name="_csrf" value="<%= ctx.csrf %>" />
-                <input type="hidden" name="order" value="<%- stages[0].order %>">
+                <input type="hidden" name="order" id="edit-order" value="<%- stages[0].order %>">
                 <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
                 <button type="submit" class="btn btn-primary btn-sm" id="edit-ok" >确定修改</button>
             </div>
@@ -108,20 +108,27 @@
 <script src="/public/js/datepicker/datepicker.zh.js"></script>
 <script>
     <% if (stages.length > 0 && stages[0].status !== auditConst.status.checked && stages[0].user_id === ctx.session.sessionUser.accountId) { %>
-    const editDate = $('#edit-date').datepicker().data('datepicker');
-    if ('<%- stages[0].s_time %>' && '<%- stages[0].s_time %>' !== '') {
-        editDate.selectDate(new Date('<%- stages[0].s_time %>'));
-    }
-    const period = [];
-    for (const p of'<%- stages[0].period %>'.split('~')) {
-        if (p && p !== '') {
-            period.push(new Date(p));
-        }
-    }
-    const editPeriod = $('#edit-period').datepicker().data('datepicker');
-    if (period.length > 0) {
-        editPeriod.selectDate(period);
-    }
+    $(function () {
+       $('.edit-stage').on('click', function () {
+           const index = parseInt($(this).data('index'));
+           const editDate = $('#edit-date').datepicker().data('datepicker');
+           $('#edit-name').val('第 ' + stages[index].order + ' 期');
+           $('#edit-order').val(stages[index].order);
+           if (stages[index].s_time && stages[index].s_time !== '') {
+               editDate.selectDate(new Date(stages[index].s_time));
+           }
+           const period = [];
+           for (const p of stages[index].period.split('~')) {
+               if (p && p !== '') {
+                   period.push(new Date(p));
+               }
+           }
+           const editPeriod = $('#edit-period').datepicker().data('datepicker');
+           if (period.length > 0) {
+               editPeriod.selectDate(period);
+           }
+       })
+    });
 
     function checkForm () {
         if ($('#edit-date').val() == '') {