|
@@ -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');
|