Ver código fonte

变更附件分页

laiguoran 4 anos atrás
pai
commit
722c396091

+ 4 - 3
app/controller/change_controller.js

@@ -537,7 +537,7 @@ module.exports = app => {
                 const auditStatus = await ctx.service.changeAudit.getStatusByChange(change);
 
                 // 获取附件列表
-                const attList = await ctx.service.changeAtt.getChangeAttachment(change.cid);
+                const attList = await ctx.service.changeAtt.getChangeAttachment(change.cid, 'desc');
 
                 // 获取其他变更令数据
                 const othersChange = await ctx.service.change.getOthersChange(ctx.tender.id, change.cid);
@@ -1033,8 +1033,9 @@ module.exports = app => {
                     if (!result) {
                         throw '导入数据库保存失败';
                     }
-                    fileData.in_time = moment(create_time * 1000).format('YYYY-MM-DD');
-                    fileData.filesize = await ctx.helper.bytesToSize(fileData.filesize);
+                    // fileData.in_time = moment(create_time * 1000).format('YYYY-MM-DD');
+                    // fileData.filesize = await ctx.helper.bytesToSize(fileData.filesize);
+                    fileData.uid = ctx.session.sessionUser.accountId;
                     fileData.id = result.insertId;
                     delete fileData.filepath;
                     files.push(fileData);

+ 101 - 25
app/public/js/change_information.js

@@ -15,6 +15,8 @@ const is_numeric = (value) => {
     }
 };
 $(document).ready(() => {
+    //初始化所有附件列表
+    getAllList();
     const cca = getLocalCache('change-checkbox-account-' + accountId);
     if (cca !== null && cca !== undefined) {
         $('#customCheck1').prop('checked', cca !== 'false');
@@ -80,28 +82,31 @@ $(document).ready(() => {
             formData.append('file[]', file);
         }
         if (auditList.findIndex(item => item.uid === parseInt(accountId)) === -1) {
-            return toastr.error('暂无权限上传!')
+            return toastr.error('暂无权限上传!');
         }
         postDataWithFile(window.location.pathname + '/file/upload', formData, function (data) {
+            attData = data.concat(attData);
+            // 重新生成List
+            getAllList();
             $('#addfujian').modal('hide');
-            let html = '';
-            let index = $('#attList tr').length + 1;
-            for (const fileInfo of data) {
-                html += '<tr> ' +
-                    `<td width="20"><input type="checkbox" class="check-file" file-id=${fileInfo.id}></td>` +
-                    '<td>' + index + '</td> ' +
-                    `<td><a href="javascript: void(0);" class="file-atn" f-id="${fileInfo.id}">${fileInfo.filename}${fileInfo.fileext}</a></td>`+
-                    '<td>' + fileInfo.in_time + '<br>' + fileInfo.filesize + '</td> ' +
-                    `<td><a href="/change/download/file/${fileInfo.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`+
-                    ( auditStatus === 4 ?
-                        fileInfo.extra_upload ? `<a class="mr-2 delete-file" data-attid="${fileInfo.id}"  title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : ''
-                        : ` <a href="javascript:void(0);" class="mr-2 delete-file" data-attid="${fileInfo.id}"  title="删除附件"><span class="fa fa-trash text-danger"></span></a>`)+
-                    `</td>`+
-                    // '<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>';
-                ++index;
-            }
-            $('#attList').append(html);
+            // let html = '';
+            // let index = $('#attList tr').length + 1;
+            // for (const fileInfo of data) {
+            //     html += '<tr> ' +
+            //         `<td width="20"><input type="checkbox" class="check-file" file-id=${fileInfo.id}></td>` +
+            //         '<td>' + index + '</td> ' +
+            //         `<td><a href="javascript: void(0);" class="file-atn" f-id="${fileInfo.id}">${fileInfo.filename}${fileInfo.fileext}</a></td>`+
+            //         '<td>' + fileInfo.in_time + '<br>' + fileInfo.filesize + '</td> ' +
+            //         `<td><a href="/change/download/file/${fileInfo.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`+
+            //         ( auditStatus === 4 ?
+            //             fileInfo.extra_upload ? `<a class="mr-2 delete-file" data-attid="${fileInfo.id}"  title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : ''
+            //             : ` <a href="javascript:void(0);" class="mr-2 delete-file" data-attid="${fileInfo.id}"  title="删除附件"><span class="fa fa-trash text-danger"></span></a>`)+
+            //         `</td>`+
+            //         // '<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>';
+            //     ++index;
+            // }
+            // $('#attList').append(html);
         }, function () {
         });
         $('#upload-file').val('');
@@ -114,13 +119,26 @@ $(document).ready(() => {
         let self = $(this);
         const data = {id: attid};
         postData(window.location.pathname + '/file/delete', data, function (result) {
-            self.parents('tr').remove();
-            // 重新排序
-            let newsort = 1;
-            $('#attList tr').each(function(){
-                $(this).children('td').eq(1).text(newsort);
-                newsort++;
+            // self.parents('tr').remove();
+            // // 重新排序
+            // let newsort = 1;
+            // $('#attList tr').each(function(){
+            //     $(this).children('td').eq(1).text(newsort);
+            //     newsort++;
+            // });
+            // 删除到attData中
+            const att_index = attData.findIndex(function (item) {
+                return item.id === parseInt(attid);
             });
+            attData.splice(att_index, 1);
+            // 重新生成List
+
+            if ($('#attList tr').length === 1) {
+                getAllList(parseInt($('#currentPage').text()) - 1);
+
+            } else {
+                getAllList(parseInt($('#currentPage').text()));
+            }
         });
     });
     // /change/download/file/
@@ -182,6 +200,22 @@ $(document).ready(() => {
             changeSpread.refresh();
         }
     });
+
+    // 切换页数
+    $('.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);
+            $('#showAttachment').hide();
+            $('#syfujian .check-all-file').prop('checked', false)
+        } else if (status === 'next' && lastPageNum < totalPageNum) {
+            getAllList(lastPageNum+1);
+            $('#showAttachment').hide();
+            $('#syfujian .check-all-file').prop('checked', false)
+        }
+    });
 });
 function findDecimal(unit) {
     let value = precision.other.value;
@@ -194,4 +228,46 @@ function findDecimal(unit) {
     }
     return value;
 }
+// 生成附件列表
+function getAllList(currPageNum = 1) {
+    // 每页最多几个附件
+    const pageCount = 15;
+    // 附件总数
+    const total = attData.length;
+    // 总页数
+    const pageNum = Math.ceil(total/pageCount);
+    $('#totalPage').text(pageNum);
+    $('#currentPage').text(total === 0 ? 0 : currPageNum);
+    // 当前页附件内容
+    const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
+    let html = '';
+    // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
+    for(const [index,att] of currPageAttData.entries()) {
+        console.log(att.uid, accountId, auditStatus, Boolean(att.extra_upload));
+        html += `<tr>
+        <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
+        <td>${index+1}</td>
+        <td><a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a></td>
+        <td>${moment(att.in_time * 1000).format('YYYY-MM-DD')}<br>${bytesToSize(att.filesize)}</td>
+        <td>
+            <a href="/change/download/file/${att.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`
+        html += (att.uid === accountId && (auditStatus === 4 ? Boolean(att.extra_upload) : true)) ?
+            `<a href="javascript:void(0)" class="mr-2 delete-file" data-attid="${att.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : '';
+        html += `</td>`;
+    }
+    $('#attList').html(html);
+    $('#attList').on('click', 'tr', function() {
+        $('#attList tr').removeClass('bg-light');
+        $(this).addClass('bg-light');
+    })
+}
+
+function bytesToSize(bytes) {
+    if (parseInt(bytes) === 0) return '0 B';
+    const k = 1024;
+    const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
+    const i = Math.floor(Math.log(bytes) / Math.log(k));
+    // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
+    return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
+}
 

+ 2 - 2
app/service/change_att.js

@@ -47,12 +47,12 @@ module.exports = app => {
          * @param {uuid} cid - 变更令id
          * @return {Promise<void>}
          */
-        async getChangeAttachment(cid) {
+        async getChangeAttachment(cid, sort = 'asc') {
             const sql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' +
                 '  FROM ?? As ca ' +
                 '  Left Join ?? As pa ' +
                 '  On ca.uid = pa.id ' +
-                '  Where ca.cid = ?';
+                '  Where ca.cid = ? order by id ' + sort;
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cid];
             return await this.db.query(sql, sqlParam);
         }

+ 8 - 7
app/view/change/information.ejs

@@ -86,7 +86,7 @@
                         <li class="nav-item ml-auto pt-1" id="fujian_btn" style="display:none;">
                             <!--所有附件 翻页-->
                             <a href="javascript: void(0);" data-toggle="modal" class="btn btn-sm btn-primary" id="bach-download"><i class="fa fa-download "></i> 批量下载</a>
-                            <!--<a href="#" class=" ml-3"><i class="fa fa-chevron-left"></i></a> 1/10 <a href="#" class="mr-3"><i class="fa fa-chevron-right"></i></a>-->
+                            <a href="javascript:void(0);" class="page-select ml-3" 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  ml-3" content="next"><i class="fa fa-chevron-right"></i></a>
                             <a href="#addfujian" data-toggle="modal" class="btn btn-sm btn-light text-primary" data-placement="bottom" title="" data-original-title="上传附件"><i class="fa fa-cloud-upload" aria-hidden="true"></i> 上传附件</a>
                             <a href="" id="downloadZip" style="display: none;" download></a>
                         </li>
@@ -316,10 +316,10 @@
                     <div class="tab-pane" id="bgfujian">
                         <div class="sjs-sh-1">
                             <div class="p-2">
-                                <table class="table table-bordered">
+                                <table class="table table-bordered" style="word-break:break-all; table-layout: fixed">
                                     <thead>
                                     <tr>
-                                        <td width="20" style="background-color: #e9ecef;"><input type="checkbox" id="check-all-file" ></td>
+                                        <td width="25" style="background-color: #e9ecef;"><input type="checkbox" id="check-all-file" ></td>
                                         <th width="40">序号</th>
                                         <th>名称</th>
                                         <th width="100">上传时间/大小</th>
@@ -330,7 +330,7 @@
                                     <% if (attList !== undefined && attList !== '') { %>
                                         <% for (const [index,att] of attList.entries()) { %>
                                             <tr>
-                                                <td width="20"><input type="checkbox" class="check-file" file-id=<%- att.id %>></td>
+                                                <td width="25"><input type="checkbox" class="check-file" file-id=<%- att.id %>></td>
                                                 <td><%- index+1 %></td>
                                                 <td><a href="javascript: void(0);" class="file-atn" f-id="<%- att.id %>"><%- att.filename %><%- att.fileext %></a></td>
                                                 <td><%- moment(att.in_time * 1000).format('YYYY-MM-DD') %><br><%- ctx.helper.bytesToSize(att.filesize) %></td>
@@ -362,17 +362,18 @@
     let table = '';
     const totalPriceUnit = '<%- tpUnit %>';
     const unitPriceUnit = '<%- upUnit %>';
-    const accountId = '<%- ctx.session.sessionUser.accountId %>';
+    const accountId = parseInt('<%- ctx.session.sessionUser.accountId %>');
     const ledgeStatus = '<%- tender.ledger_status %>';
     const ledgerConsts = JSON.parse('<%- JSON.stringify(ledgerConsts) %>');
-    const auditStatus = '<%- auditStatus %>'
+    const auditStatus = parseInt('<%- auditStatus %>');
     const auditList = JSON.parse('<%- JSON.stringify(auditList) %>');
     const precision = JSON.parse('<%- JSON.stringify(precision) %>');
+    let attData = JSON.parse('<%- JSON.stringify(attList) %>');
     autoFlashHeight();
     $('a[href="#sub-ap"').click(function() {
         if (parseInt(ledgeStatus) === ledgerConsts.uncheck) {
             $('#warning-ledger').modal('show');
-            return false
+            return false;
         }
     });
     const readOnly = <%- change.readOnly %>;

+ 1 - 0
config/web.js

@@ -690,6 +690,7 @@ const JsFiles = {
                     '/public/js/path_tree.js',
                     '/public/js/gcl_gather.js',
                     '/public/js/jquery/jquery.form.min.js',
+                    '/public/js/moment/moment.min.js',
                     // '/public/js/change_calculation.js',
                     '/public/js/change_information.js',
                 ],