Sfoglia il codice sorgente

feat: 材料调差-附件增加分页功能

lanjianrong 4 anni fa
parent
commit
aa20b6ad22

+ 4 - 9
app/controller/material_controller.js

@@ -323,7 +323,7 @@ module.exports = app => {
                 const whiteList = this.ctx.app.config.multipart.whitelist;
                 // 获取当前标段所有附件
                 // const searchsql = { tid: ctx.tender.id };
-                renderData.fileList = await ctx.service.materialFile.getAllMaterialFiles(ctx.tender.id, ctx.material.id);
+                renderData.fileList = await ctx.service.materialFile.getAllMaterialFiles(ctx.tender.id);
                 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;
@@ -661,7 +661,7 @@ module.exports = app => {
                 // 执行文件信息写入数据库
                 await ctx.service.materialFile.saveFileMsgToDb(payload);
                 // 将最新的当前标段的所有文件信息返回
-                const data = await ctx.service.materialFile.getAllMaterialFiles(ctx.tender.id, ctx.material.id);
+                const data = await ctx.service.materialFile.getAllMaterialFiles(ctx.tender.id);
                 ctx.body = { err: 0, msg: '', data };
             } catch (err) {
                 stream && (await sendToWormhole(stream));
@@ -675,13 +675,8 @@ module.exports = app => {
          */
         async getCurMatericalFiles(ctx) {
             try {
-                const { isCheck } = JSON.parse(ctx.request.body.data);
-                let data;
-                if (isCheck) {
-                    data = await ctx.service.materialFile.getAllMaterialFiles(ctx.tender.id);
-                } else {
-                    data = await ctx.service.materialFile.getAllMaterialFiles(ctx.tender.id, ctx.material.id);
-                }
+                // const { isCheck } = JSON.parse(ctx.request.body.data);
+                const data = await ctx.service.materialFile.getAllMaterialFiles(ctx.tender.id);
                 ctx.body = { err: 0, msg: '', data };
             } catch (err) {
                 this.log(err);

+ 9 - 2
app/controller/stage_controller.js

@@ -990,7 +990,8 @@ module.exports = app => {
                 }
 
                 await ctx.service.stageAudit.start(ctx.stage.id, ctx.stage.times);
-
+                const auditor = await ctx.service.stageAudit.getCurAuditor(ctx.stage.id, ctx.stage.times);
+                console.log('stage-auditor:', auditor);
                 ctx.body = { err: 0, msg: '', data: [] };
             } catch (err) {
                 this.log(err);
@@ -1027,7 +1028,13 @@ module.exports = app => {
                 }
 
                 await ctx.service.stageAudit.check(ctx.stage.id, data, ctx.stage.times);
-
+                const stageOrder = parseInt(ctx.params.order);
+                const stage = await ctx.service.stage.getDataByCondition({
+                    tid: ctx.tender.id,
+                    order: stageOrder,
+                });
+                const auditor = await ctx.service.stageAudit.getCurAuditor(ctx.stage.id, ctx.stage.times);
+                console.log('stage-auditor:', auditor, 'status:', stage.status);
                 ctx.body = { err: 0, msg: '', data: [] };
                 // ctx.redirect(ctx.request.header.referer);
             } catch (err) {

+ 103 - 83
app/public/js/material_file.js

@@ -6,8 +6,11 @@
  * @date 2020/06/30
  * @version
  */
-
 $(document).ready(function () {
+    // 全局fileData初始化
+    let fileData = fileList || []
+    handleFileList(fileData)
+    getAllList()
     $('#upload-file-ok').click(function () {
         const files = Array.from($('#upload-fujian-file')[0].files)
         const valiData = files.map(v => {
@@ -26,101 +29,114 @@ $(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
-                    })
+                    handleFileList(result)
                     $('#addfujian').modal('hide');
-                    let html = '';
-                    files.forEach((fileInfo, idx) => {
-                        html += `<tr>
-                        <td>${idx + 1}</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 (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);
+                    if (!$('#file-list tr').length) {
+                        getAllList();
+                    } else {
+                        getAllList(parseInt($('#currentPage').text()));
+                    }
                 });
             }
         }
     })
+    // 选择/未选所有期列表
     $('#file-checkbox').click(function() {
-        let isCheck = false
-        if($(this).is(':checked')) {
-            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 = '';
-            files.forEach((fileInfo, idx) => {
-                html += `<tr>
-                <td>${idx + 1 }</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 (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);
-        })
+        getAllList()
     })
+
     // 删除附件
     $('body').on('click', '.delete-file', function () {
         let attid = $(this).data('attid');
-        let self = $(this);
         const data = {id: attid};
-        postData('/tender/measure/material/file/delete', data, function (result) {
-            self.parents('tr').remove();
-            // 重新排序
-            let newsort = 1;
-            $('#file-list tr').each(function(){
-                $(this).children('td').eq(0).text(newsort);
-                newsort++;
-            });
+        postData('/tender/measure/material/file/delete', data, function () {
+            const idx = fileData.findIndex(file => file.id === parseInt(attid))
+            idx !== -1 && fileData.splice(idx, 1)
+            if ($('#file-list tr').length === 1) {
+                getAllList(parseInt($('#currentPage').text()) - 1);
+            } else {
+                getAllList(parseInt($('#currentPage').text()));
+            }
+            // self.parents('tr').remove();
+            // // 重新排序
+            // let newsort = 1;
+            // $('#file-list tr').each(function(){
+            //     $(this).children('td').eq(0).text(newsort);
+            //     newsort++;
+            // });
         });
     });
+    // 切换页数
+    $('.page-select').on('click', function () {
+        const totalPageNum = parseInt($('#totalPage').text());
+        const lastPageNum = parseInt($('#currentPage').text());
+        const status = $(this).attr('content');
+        if (status === 'pre' && lastPageNum > 1) {
+            getAllList(lastPageNum-1);
+        } else if (status === 'next' && lastPageNum < totalPageNum) {
+            getAllList(lastPageNum+1);
+        }
+    });
+    // 生成所有附件列表
+    function getAllList(currPageNum = 1) {
+        // 每页最多几个附件
+        const pageCount = 15;
+        // 附件总数
+        let total = fileData && fileData.length;
+        // 未选中checkbox,需要过滤出来当前期的数据
+        const filterFileData = fileData && fileData.filter(file => file.mid === parseInt(mid) && file.tid === parseInt(tid))
+        if(!$('#file-checkbox').is(':checked')) {
+            total = filterFileData.length
+        }
+        // 总页数
+        const pageNum = Math.ceil(total/pageCount);
+        $('#totalPage').text(pageNum);
+        // total为0,当前还没上传过附件
+        $('#currentPage').text(total ? currPageNum : 0);
+        // 当前页附件内容
+        const currPageAttData = fileData && $('#file-checkbox').is(':checked') ? fileData.slice((currPageNum-1)*pageCount, currPageNum*pageCount) : filterFileData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
+        renderHtml(currPageAttData)
+    }
+
+
+    function renderHtml(list) {
+        let html = '';
+        list.forEach((fileInfo, idx) => {
+            html += `<tr style="height: 31px;">
+            <td>${idx + 1}</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 (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);
+    }
+
+    function handleFileList(fileList) {
+        fileData = fileList.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
+        })
+    }
 });
 
 /**
@@ -128,6 +144,10 @@ $(document).ready(function () {
  * @param {Array} files 文件数组
  */
 function validateFiles(files) {
+    if (files.length > 10) {
+        toastr.error('至多同时上传10个文件');
+        return false
+    }
     return files.every(file => {
         if (file.size > 1024 * 1024 * 30) {
             toastr.error('文件大小限制为30MB');

+ 1 - 0
app/service/material_file.js

@@ -31,6 +31,7 @@ module.exports = app => {
             if (mid) where.mid = mid;
             return await this.db.select(this.tableName, {
                 where,
+                orders: [['upload_time', 'desc']],
             });
         }
 

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

@@ -7,6 +7,10 @@
           <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>
+            <div style="margin-left: 20px;">
+              <!--所有附件 翻页-->
+              <span id="showPage"><a href="javascript:void(0);" class="page-select" content="pre"><i class="fa fa-chevron-left"></i></a> <span id="currentPage">1</span>/<span id="totalPage">10</span> <a href="javascript:void(0);" class="page-select" content="next"><i class="fa fa-chevron-right"></i></a></span>
+            </div>
           </span>
         </div>
     </div>
@@ -16,10 +20,17 @@
       <div class="sjs-height-0">
         <table class="table table-bordered">
           <thead>
-            <tr><th width="50">序号</th><th>名称</th><th width="90">大小</th><th width="90">调差期</th><th width="150">上传时间</th><th width="100">操作</th></tr>
+            <tr>
+              <th width="50">序号</th>
+              <th>名称</th>
+              <th width="90">大小</th>
+              <th width="90">调差期</th>
+              <th width="150">上传时间</th>
+              <th width="100">操作</th>
+            </tr>
           </thead>
           <tbody id="file-list">
-            <% fileList.forEach(function(file, idx){ %>
+            <!-- <% fileList.filter(file => file.mid === ctx.material.id).forEach(function(file, idx){ %>
               <tr>
                 <td><%=idx + 1%></td>
                 <td><a href="/<%- file.filepath %>" target="_blank"><%=file.file_name%></a></td>
@@ -49,7 +60,7 @@
                   <% } %>
                 </td>
               </tr>
-            <% }) %>
+            <% }) %> -->
           </tbody>
         </table>
       </div>