Prechádzať zdrojové kódy

fix: 调差-附件上传附件新增记录bug修复

lanjianrong 4 rokov pred
rodič
commit
4acbed8d80

+ 3 - 1
app/controller/material_controller.js

@@ -326,6 +326,7 @@ module.exports = app => {
                 renderData.auditors = ctx.material.auditors.map(audit => audit.aid);
                 // renderData.auditors = ctx.material.auditors2.map(audit => audit.aid);
                 renderData.report_id = ctx.material.user_id;
+                renderData.auditConst = auditConst;
                 renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.material.file);
                 await this.layout('material/file.ejs', renderData, 'material/file_modal.ejs');
             } catch (err) {
@@ -613,7 +614,8 @@ module.exports = app => {
                         return;
                     }
                     const fileInfo = path.parse(stream.filename);
-                    const filepath = path.join('public/upload', this.ctx.tender.id.toString(), 'tc', 'fujian_' + create_time + fileInfo.ext);
+                    // const filepath = path.join('public/upload', this.ctx.tender.id.toString(), 'tc', 'fujian_' + create_time + fileInfo.ext);
+                    const filepath = `public/upload/${this.ctx.tender.id.toString()}/tc/fujian_${create_time + fileInfo.ext}`;
                     await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, 'app', filepath));
                     files.push({ filepath, name: stream.filename });
                 }

+ 49 - 36
app/public/js/material_file.js

@@ -26,27 +26,40 @@ $(document).ready(function () {
                     formData.append('size', file.size)
                 })
                 postDataWithFile(window.location.pathname + '/upload', formData, function (result) {
+                    const files = result.map(file => {
+                        let showDel = false
+                        // 只判断当前期,因为以往期都是只读的
+                        if (file.mid === parseInt(mid) && file.tid === parseInt(tid) && file.user_id === parseInt(cur_uid)) {
+                            if (!curAuditor) {
+                                material.status === auditConst.status.uncheck && parseInt(cur_uid) === material.user_id && (showDel = true)
+                                material.status === auditConst.status.checkNo && parseInt(cur_uid) === material.user_id && (showDel = true)
+                            } else {
+                                curAuditor.aid === parseInt(cur_uid) && (showDel = true)
+                            }
+                        }
+                        return showDel ? {...file, canDel: true} : file
+                    })
                     $('#addfujian').modal('hide');
                     let html = '';
-                    result.forEach((fileInfo, idx) => {
+                    files.forEach((fileInfo, idx) => {
                         html += `<tr>
                         <td>${idx + 1}</td>
-                        <td><a href="/${fileInfo.filepath}">${fileInfo.file_name}</a></td>
+                        <td><a href="/${fileInfo.filepath}" target="_blank">${fileInfo.file_name}</a></td>
                         <td>${fileInfo.file_size}</td>
+                        <td>第${fileInfo.s_order}期</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>`
-                    } else {
-                        html += `<td></td></tr>`
-                    }
+                        if (fileInfo.canDel ) {
+                            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').append(html);
-                    console.log(result)
                 });
             }
         }
@@ -57,35 +70,35 @@ $(document).ready(function () {
             isCheck = true
         }
         postData(window.location.pathname + '/find', {isCheck}, function(result) {
+            const files = result.map(file => {
+                let showDel = false
+                // 只判断当前期,因为以往期都是只读的
+                if (file.mid === parseInt(mid) && file.tid === parseInt(tid) && file.user_id === parseInt(cur_uid)) {
+                    if (!curAuditor) {
+                        material.status === auditConst.status.uncheck && parseInt(cur_uid) === material.user_id && (showDel = true)
+                        material.status === auditConst.status.checkNo && parseInt(cur_uid) === material.user_id && (showDel = true)
+                    } else {
+                        curAuditor.aid === parseInt(cur_uid) && (showDel = true)
+                    }
+                }
+                return showDel ? {...file, canDel: true} : file
+            })
             let html = '';
-            result.forEach((fileInfo, idx) => {
+            files.forEach((fileInfo, idx) => {
                 html += `<tr>
                 <td>${idx + 1 }</td>
-                <td><a href="/${fileInfo.filepath}">${fileInfo.file_name}</a></td>
+                <td><a href="/${fileInfo.filepath}" target="_blank">${fileInfo.file_name}</a></td>
                 <td>${fileInfo.file_size}</td>
+                <td>第${fileInfo.s_order}期</td>
                 <td>${fileInfo.upload_time}</td>`
-                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>`
-                    }
+                if (fileInfo.canDel ) {
+                    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 {
-                    // 当前期
-                    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>`
-                    }
+                    html += `<td></td></tr>`
                 }
 
             })
@@ -115,7 +128,7 @@ $(document).ready(function () {
  * @param {Array} files 文件数组
  */
 function validateFiles(files) {
-    const reg = /(doc|docx|excel|pdf|xlsx|xls|txt|zip|jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
+    const reg = /(doc|docx|excel|pdf|xlsx|xls|txt|zip|jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG|gif)$/;
     return files.every(file => {
         if (file.size > 1024 * 1024 * 10) {
             toastr.error('文件大小限制为10MB');

+ 1 - 18
app/service/material_file.js

@@ -29,29 +29,12 @@ module.exports = app => {
         async getAllMaterialFiles(tid, mid) {
             const where = { tid };
             if (mid) where.mid = mid;
-            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, {
+            return await this.db.select(this.tableName, {
                 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 载荷

+ 26 - 10
app/view/material/file.ejs

@@ -3,9 +3,7 @@
   <div class="panel-title">
     <div class="title-main d-flex justify-content-between">
       <div class="d-flex justify-content-start align-items-center">
-        <% if(report_id === ctx.session.sessionUser.accountId || auditors.includes(ctx.session.sessionUser.accountId)) { %>
           <a href="#addfujian" data-toggle="modal" class="btn btn-sm btn-light text-primary" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="添加清单"><i class="fa fa-cloud-upload" aria-hidden="true"></i> 上传附件</a>
-        <% } %>
           <span class="d-flex align-items-center" style="margin-left: 5px;">
             <input type="checkbox" id="file-checkbox">
             <span class="text-primary" style="margin-left: 5px;">所有期</span>
@@ -29,11 +27,25 @@
                 <td>第<%= file.s_order %>期</td>
                 <td><%=file.upload_time%></td>
                 <td>
-                  <% if(material.status !== auditConst.status.checked &&
-                  ctx.session.sessionUser.accountId === file.user_id) { %>
-                    <a href="javascript: void;" class="btn btn-light btn-sm delete-file" title="删除附件" data-attid="<%- file.id %>">
-                      <span class="fa fa-trash text-danger"></span>
-                    </a>
+                  <% if(file.user_id === ctx.session.sessionUser.accountId) { %>
+                    <% if (!ctx.material.curAuditor) { %>
+                      <% if (ctx.material.status === auditConst.status.uncheck && ctx.session.sessionUser.accountId === ctx.material.user_id) { %>
+                        <a href="javascript: void;" class="btn btn-light btn-sm delete-file" title="删除附件" data-attid="<%- file.id %>">
+                          <span class="fa fa-trash text-danger"></span>
+                        </a>
+                      <% } %>
+                      <% if (ctx.material.status === auditConst.status.checkNo && ctx.session.sessionUser.accountId === ctx.material.user_id) { %>
+                        <a href="javascript: void;" class="btn btn-light btn-sm delete-file" title="删除附件" data-attid="<%- file.id %>">
+                          <span class="fa fa-trash text-danger"></span>
+                        </a>
+                      <% } %>
+                    <% } else {%>
+                      <% if(ctx.material.curAuditor.aid === ctx.session.sessionUser.accountId) { %>
+                        <a href="javascript: void;" class="btn btn-light btn-sm delete-file" title="删除附件" data-attid="<%- file.id %>">
+                          <span class="fa fa-trash text-danger"></span>
+                        </a>
+                      <% } %>
+                    <% } %>
                   <% } %>
                 </td>
               </tr>
@@ -45,8 +57,12 @@
   </div>
 </div>
 <script>
-  const curMaterialStatus = '<%- material.status %>';
-  const fileList = '<%- JSON.stringify(fileList) %>';
   const auditors = JSON.parse('<%- JSON.stringify(auditors) %>');
-  const report_id = '<%- JSON.stringify(report_id) %>'
+  const curAuditor = JSON.parse('<%- JSON.stringify(ctx.material.curAuditor) %>');
+  const material = JSON.parse('<%- JSON.stringify(ctx.material) %>');
+  const auditConst = JSON.parse('<%- JSON.stringify(auditConst) %>');
+  const cur_uid = '<%- ctx.session.sessionUser.accountId %>';
+  const tid = '<%- ctx.tender.id %>';
+  const mid = '<%- ctx.material.id %>';
+  const fileList = JSON.parse('<%- JSON.stringify(fileList) %>');
 </script>

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

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