|
@@ -6,7 +6,10 @@
|
|
|
* @date 2020/06/30
|
|
|
* @version
|
|
|
*/
|
|
|
+
|
|
|
$(document).ready(function () {
|
|
|
+ // 每页最多几个附件
|
|
|
+ const pageCount = 15;
|
|
|
// 全局fileData初始化
|
|
|
let fileData = fileList || []
|
|
|
handleFileList(fileData)
|
|
@@ -34,7 +37,8 @@ $(document).ready(function () {
|
|
|
if (!$('#file-list tr').length) {
|
|
|
getAllList();
|
|
|
} else {
|
|
|
- getAllList(parseInt($('#currentPage').text()));
|
|
|
+ const curPageNo = $('#file-pagination > li[class="page-item active"] > a').text() || 1
|
|
|
+ getAllList(parseInt(curPageNo));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -52,10 +56,12 @@ $(document).ready(function () {
|
|
|
postData('/tender/measure/material/file/delete', data, function () {
|
|
|
const idx = fileData.findIndex(file => file.id === parseInt(attid))
|
|
|
idx !== -1 && fileData.splice(idx, 1)
|
|
|
+ const curPageNo = parseInt($('#file-pagination > li[class="page-item active"] > a').text()) || 1
|
|
|
if ($('#file-list tr').length === 1) {
|
|
|
- getAllList(parseInt($('#currentPage').text()) - 1);
|
|
|
+ getAllList(curPageNo - 1);
|
|
|
} else {
|
|
|
- getAllList(parseInt($('#currentPage').text()));
|
|
|
+
|
|
|
+ getAllList(curPageNo);
|
|
|
}
|
|
|
// self.parents('tr').remove();
|
|
|
// // 重新排序
|
|
@@ -67,43 +73,124 @@ $(document).ready(function () {
|
|
|
});
|
|
|
});
|
|
|
// 切换页数
|
|
|
- $('.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);
|
|
|
+ $('#file-pagination').on('click', '.page-item a', function () {
|
|
|
+ // 找到当前的pageNo
|
|
|
+ const curPageNo = $('#file-pagination > li[class="page-item active"] > a').text() || 1
|
|
|
+ const btnType = $(this).attr('aria-label')
|
|
|
+ const total = calcCount();
|
|
|
+ // btnType存在,说明点击的是前一个/后一个
|
|
|
+ // btnType不存在,点击的是页数
|
|
|
+ if (btnType) {
|
|
|
+ if (btnType === 'Previous') {
|
|
|
+ // 只有大于1时才处理
|
|
|
+ if (parseInt(curPageNo) !== 1) {
|
|
|
+ getAllList(curPageNo - 1)
|
|
|
+ }
|
|
|
+ } else if(btnType === 'Next') {
|
|
|
+ if (parseInt(curPageNo) !== Math.ceil(total/pageCount)) {
|
|
|
+ getAllList(parseInt(curPageNo) + 1)
|
|
|
+ }
|
|
|
+ } else if(btnType === 'Start') {
|
|
|
+ getAllList(1)
|
|
|
+ } else {
|
|
|
+ getAllList(Math.ceil(total/pageCount))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ curPageNo !== $(this).text() && getAllList(parseInt($(this).text()))
|
|
|
}
|
|
|
- });
|
|
|
+ })
|
|
|
// 生成所有附件列表
|
|
|
function getAllList(currPageNum = 1) {
|
|
|
- // 每页最多几个附件
|
|
|
- const pageCount = 15;
|
|
|
- // 附件总数
|
|
|
- let total = fileData && fileData.length;
|
|
|
- // 未选中checkbox,需要过滤出来当前期的数据
|
|
|
+ // 未选中checkbox,需要过滤出来当前期的数据
|
|
|
const filterFileData = fileData && fileData.filter(file => file.mid === parseInt(mid) && file.tid === parseInt(tid))
|
|
|
- if(!$('#file-checkbox').is(':checked')) {
|
|
|
- total = filterFileData.length
|
|
|
- }
|
|
|
+ const total = calcCount(filterFileData);
|
|
|
// 总页数
|
|
|
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);
|
|
|
+ const currPageAttData = fileData && $('#file-checkbox').is(':checked') ? fileData.slice((currPageNum-1)*pageCount, currPageNum*pageCount) : filterFileData.map((v, index) => {
|
|
|
+ return {...v, index }
|
|
|
+ }).slice((currPageNum-1)*pageCount, currPageNum*pageCount);
|
|
|
+
|
|
|
renderHtml(currPageAttData)
|
|
|
+ // 渲染分页器
|
|
|
+ renderPagination(currPageNum, pageNum)
|
|
|
}
|
|
|
|
|
|
|
|
|
+ function renderPagination(pageNo, pageSize) {
|
|
|
+ $('#file-pagination').empty()
|
|
|
+ if (pageSize < 2) return
|
|
|
+ const btnHtml = `
|
|
|
+ <li class="page-item page-begin">
|
|
|
+ <a class="page-link" href="#" aria-label="Start">
|
|
|
+ <span aria-hidden="true">«</span>
|
|
|
+ </a>
|
|
|
+ </li>
|
|
|
+ <li class="page-item page-back">
|
|
|
+ <a class="page-link" href="#" aria-label="Previous">
|
|
|
+ <span aria-hidden="true">‹</span>
|
|
|
+ </a>
|
|
|
+ </li>
|
|
|
+ <li class="page-item page-next">
|
|
|
+ <a class="page-link" href="#" aria-label="Next">
|
|
|
+ <span aria-hidden="true">›</span>
|
|
|
+ </a>
|
|
|
+ </li>
|
|
|
+ <li class="page-item page-end">
|
|
|
+ <a class="page-link" href="#" aria-label="End">
|
|
|
+ <span aria-hidden="true">»</span>
|
|
|
+ </a>
|
|
|
+ </li>`
|
|
|
+ $('#file-pagination').append(btnHtml)
|
|
|
+ let html = ''
|
|
|
+ // 考虑极端情况
|
|
|
+ if (pageNo - 2 <= 0 || pageNo + 2 >= pageSize) {
|
|
|
+ if (pageNo < 3) {
|
|
|
+ const max = pageSize > 5 ? 5 : pageSize
|
|
|
+ for (let i = 0; i < max; i++) {
|
|
|
+ html += pageNo === i + 1 ?
|
|
|
+ `<li class="page-item active"><a class="page-link" href="#">${i+1}</a></li>` :
|
|
|
+ `<li class="page-item"><a class="page-link" href="#">${i+1}</a></li>`
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (let i = (pageSize-4 > 0 ? pageSize-4 : 1 ); i <= pageSize; i++) {
|
|
|
+ html += pageNo === i ?
|
|
|
+ `<li class="page-item active"><a class="page-link" href="#">${i}</a></li>` :
|
|
|
+ `<li class="page-item"><a class="page-link" href="#">${i}</a></li>`
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ for (let i = 0; i < pageSize; i++) {
|
|
|
+ if (i + 1 === pageNo) {
|
|
|
+ // 当前
|
|
|
+ html+=`<li class="page-item active"><a class="page-link" href="#">${i + 1}</a></li>`
|
|
|
+ } else if(i + 2 === pageNo && i + 2 <= pageSize) {
|
|
|
+ // 后一页
|
|
|
+ html+=`<li class="page-item"><a class="page-link" href="#">${i + 1}</a></li>`
|
|
|
+ } else if (i + 3 === pageNo && i + 3 <= pageSize) {
|
|
|
+ // 后两页
|
|
|
+ html+=`<li class="page-item"><a class="page-link" href="#">${i + 1}</a></li>`
|
|
|
+ } else if(i === pageNo) {
|
|
|
+ // 前一页
|
|
|
+ html+=`<li class="page-item"><a class="page-link" href="#">${i + 1}</a></li>`
|
|
|
+ } else if (i -1 === pageNo && i -1 >= 0) {
|
|
|
+ // 前两页
|
|
|
+ html+=`<li class="page-item"><a class="page-link" href="#">${i + 1}</a></li>`
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $('.page-next').before(html)
|
|
|
+ }
|
|
|
+
|
|
|
function renderHtml(list) {
|
|
|
let html = '';
|
|
|
- list.forEach((fileInfo, idx) => {
|
|
|
+ list.forEach(fileInfo => {
|
|
|
html += `<tr style="height: 31px;">
|
|
|
- <td>${idx + 1}</td>
|
|
|
+ <td>${fileInfo.index + 1}</td>
|
|
|
<td><a href="/${fileInfo.filepath}" target="_blank">${fileInfo.file_name}</a></td>
|
|
|
<td>${fileInfo.file_size}</td>
|
|
|
<td>第${fileInfo.s_order}期</td>
|
|
@@ -123,7 +210,7 @@ $(document).ready(function () {
|
|
|
}
|
|
|
|
|
|
function handleFileList(fileList) {
|
|
|
- fileData = fileList.map(file => {
|
|
|
+ fileData = fileList.map((file, index) => {
|
|
|
let showDel = false
|
|
|
// 只判断当前期,因为以往期都是只读的
|
|
|
if (file.mid === parseInt(mid) && file.tid === parseInt(tid) && file.user_id === parseInt(cur_uid)) {
|
|
@@ -134,9 +221,18 @@ $(document).ready(function () {
|
|
|
curAuditor.aid === parseInt(cur_uid) && (showDel = true)
|
|
|
}
|
|
|
}
|
|
|
- return showDel ? {...file, canDel: true} : file
|
|
|
+ return showDel ? {...file, canDel: true, index} : {...file, index}
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ function calcCount() {
|
|
|
+ // 附件总数
|
|
|
+ let total = fileData && fileData.length;
|
|
|
+ if(!$('#file-checkbox').is(':checked')) {
|
|
|
+ total = fileData && fileData.filter(file => file.mid === parseInt(mid) && file.tid === parseInt(tid)).length
|
|
|
+ }
|
|
|
+ return total
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
/**
|