Browse Source

fix: 材料调差-附件所有期逻辑bug修复

lanjianrong 5 years ago
parent
commit
8986ef2c14

+ 1 - 0
app/controller/stage_controller.js

@@ -180,6 +180,7 @@ module.exports = app => {
                 renderData.imType = tenderConst.imType;
                 renderData.imType = tenderConst.imType;
                 // 获取附件列表
                 // 获取附件列表
                 const attData = await ctx.service.stageAtt.getDataByTenderIdAndStageId(ctx.tender.id, ctx.params.order);
                 const attData = await ctx.service.stageAtt.getDataByTenderIdAndStageId(ctx.tender.id, ctx.params.order);
+                console.log(attData);
                 for (const index in attData) {
                 for (const index in attData) {
                     attData[index].in_time = moment(attData[index].in_time * 1000).format('YYYY-MM-DD');
                     attData[index].in_time = moment(attData[index].in_time * 1000).format('YYYY-MM-DD');
                 }
                 }

+ 23 - 8
app/public/js/material_file.js

@@ -34,7 +34,7 @@ $(document).ready(function () {
                         <td><a href="/${fileInfo.filepath}">${fileInfo.file_name}</a></td>
                         <td><a href="/${fileInfo.filepath}">${fileInfo.file_name}</a></td>
                         <td>${fileInfo.file_size}</td>
                         <td>${fileInfo.file_size}</td>
                         <td>${fileInfo.upload_time}</td>`
                         <td>${fileInfo.upload_time}</td>`
-                    if (user_id == fileInfo.user_id && !checked) {
+                    if (user_id == fileInfo.user_id && checked) {
                         html += `<td>
                         html += `<td>
                         <a class="btn btn-light btn-sm delete-file" data-attid="${fileInfo.id}" title="删除附件">
                         <a class="btn btn-light btn-sm delete-file" data-attid="${fileInfo.id}" title="删除附件">
                         <span class="fa fa-trash text-danger"></span>
                         <span class="fa fa-trash text-danger"></span>
@@ -64,15 +64,30 @@ $(document).ready(function () {
                 <td><a href="/${fileInfo.filepath}">${fileInfo.file_name}</a></td>
                 <td><a href="/${fileInfo.filepath}">${fileInfo.file_name}</a></td>
                 <td>${fileInfo.file_size}</td>
                 <td>${fileInfo.file_size}</td>
                 <td>${fileInfo.upload_time}</td>`
                 <td>${fileInfo.upload_time}</td>`
-                if (user_id == fileInfo.user_id && !checked) {
-                    html += `<td>
-                    <a class="btn btn-light btn-sm delete-file" data-attid="${fileInfo.id}" title="删除附件">
-                    <span class="fa fa-trash text-danger"></span>
-                    </a>
-                    </td></tr>`
+                if (isCheck) {
+                    // 所有期
+                    if (fileInfo.pre_delete && user_id == fileInfo.user_id) {
+                        html += `<td>
+                        <a class="btn btn-light btn-sm delete-file" data-attid="${fileInfo.id}" title="删除附件">
+                        <span class="fa fa-trash text-danger"></span>
+                        </a>
+                        </td></tr>`
+                    } else {
+                        html += `<td></td></tr>`
+                    }
                 } else {
                 } else {
-                    html += `<td></td></tr>`
+                    // 当前期
+                    if (user_id == fileInfo.user_id && checked) {
+                        html += `<td>
+                        <a class="btn btn-light btn-sm delete-file" data-attid="${fileInfo.id}" title="删除附件">
+                        <span class="fa fa-trash text-danger"></span>
+                        </a>
+                        </td></tr>`
+                    } else {
+                        html += `<td></td></tr>`
+                    }
                 }
                 }
+
             })
             })
             $('#file-list').empty();
             $('#file-list').empty();
             $('#file-list').append(html);
             $('#file-list').append(html);

+ 24 - 9
app/service/material_file.js

@@ -1,7 +1,5 @@
 'use strict';
 'use strict';
-const fs = require('fs');
-const path = require('path');
-
+const auditConst = require('../const/audit');
 /**
 /**
  * 附件表 数据模型
  * 附件表 数据模型
  * @author LanJianRong
  * @author LanJianRong
@@ -23,20 +21,37 @@ module.exports = app => {
         }
         }
 
 
         /**
         /**
-         * 获取当前标段所有上传的附件
-         * @param {Number?} tenderId 标段id
+         * 获取当前标段(期)所有上传的附件
+         * @param {Number} tid 标段id
          * @param {Number?} mid 期id
          * @param {Number?} mid 期id
          * @return {Promise<void>} 数据库查询实例
          * @return {Promise<void>} 数据库查询实例
          */
          */
-        async getAllMaterialFiles(tenderId, mid) {
-            const where = {};
-            if (tenderId) where.tenderId = tenderId;
+        async getAllMaterialFiles(tid, mid) {
+            const where = { tid };
             if (mid) where.mid = mid;
             if (mid) where.mid = mid;
-            return await this.db.select(this.tableName, {
+            const materialList = await this.db.select(this.ctx.service.material.tableName, {
+                where: { tid },
+            });
+            // 当用户点击所有期时,不能通过当前的material.status !== auditConst.status.checked来判断是否有删除权限
+            // 需要获取当前标段所有期与fileList一一对比,可删除的加上pre_delete标记true
+            const fileList = await this.db.select(this.tableName, {
                 where,
                 where,
             });
             });
+            return fileList.map(file => {
+                const material = materialList.find(i => i.id === file.mid && i.tid === file.tid);
+                if (material) {
+                    const { status } = material;
+                    if ( status !== auditConst.stage.status.checked) {
+                        return { ...file, pre_delete: true }
+                    }
+                }
+                return file
+            })
+
         }
         }
 
 
+
+
         /**
         /**
          * 存储上传的文件信息至数据库
          * 存储上传的文件信息至数据库
          * @param {Array} payload 载荷
          * @param {Array} payload 载荷

+ 3 - 4
app/view/material/file.ejs

@@ -45,8 +45,7 @@
   </div>
   </div>
 </div>
 </div>
 <script>
 <script>
-  const curMaterialStatus = <%- material.status %>;
-  // const auditConstCheck =  <%- auditConst.status.checked %>;
-  const fileList = <%- fileList %>;
-  const auditors = <%- auditors %>;
+  const curMaterialStatus = '<%- material.status %>';
+  const fileList = '<%- JSON.stringify(fileList) %>';
+  const auditors = JSON.parse('<%- JSON.stringify(auditors) %>');
 </script>
 </script>

+ 1 - 1
app/view/material/file_modal.ejs

@@ -50,5 +50,5 @@
   <% include ./audit_modal.ejs %>
   <% include ./audit_modal.ejs %>
 <script>
 <script>
   const user_id = '<%- ctx.session.sessionUser.accountId %>';
   const user_id = '<%- ctx.session.sessionUser.accountId %>';
-  const checked = '<%- material.status === auditConst.status.checked %>';
+  const checked = '<%- material.status !== auditConst.status.checked %>';
 </script>
 </script>