$(function () {
autoFlashHeight();
//编辑input及textarea
$('.edit-input').on('change', function () {
const newVal = _.trim($(this).val());
const id = $(this).data('id');
if (newVal.length > 1000) {
toastr.error('内容字符长度不能超过1000');
return false;
}
updateJsonData(newVal, id);
});
$('.edit-textarea').on('change', function () {
const newVal = $(this).val();
const id = $(this).data('id');
if (newVal.length > 10000) {
toastr.error('内容字符长度不能超过10000');
return false;
}
updateJsonData(newVal, id);
});
function updateJsonData(newVal, id) {
postData('/construction/' + tender_id + '/log/' + log_id + '/save', { type: 'update_json', updateData: { key: id, value: newVal } }, function (result) {
});
}
// 审签人选择
let timer = null
let oldSearchVal = null
$('#gr-search').bind('input propertychange', function(e) {
oldSearchVal = e.target.value
timer && clearTimeout(timer)
timer = setTimeout(() => {
const newVal = $('#gr-search').val()
let html = ''
if (newVal && newVal === oldSearchVal) {
accountList.filter(item => item && cur_uid !== item.id && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
html += `
`
group.groupList.forEach(item => {
if (item.id !== cur_uid) {
html += `
${item.name}${item.mobile || ''}
${item.role || ''}
`
}
});
html += '
'
})
$('.book-list').empty()
$('.book-list').append(html)
}
}
}, 400);
})
// 添加审批流程按钮逻辑
$('.book-list').on('click', 'dt', function () {
const idx = $(this).find('.acc-btn').attr('data-groupid')
const type = $(this).find('.acc-btn').attr('data-type')
if (type === 'hide') {
$(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
$(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
$(this).find('.acc-btn').attr('data-type', 'show')
})
} else {
$(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
$(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
$(this).find('.acc-btn').attr('data-type', 'hide')
})
}
return false
});
// 添加到审批流程中
$('dl').on('click', 'dd', function () {
const id = parseInt($(this).data('id'));
if (id) {
postData('/construction/' + tender_id + '/log/' + log_id + '/save', { type: 'set_shenpi', uid: id }, function (result) {
$('#show-shenpi-btn').hide();
$('#show-shenpi span').text(result.shenpi_username);
$('#show-shenpi').show();
});
}
});
$('.remove-shenpi-btn').on('click', function () {
postData('/construction/' + tender_id + '/log/' + log_id + '/save', { type: 'remove_shenpi' }, function (result) {
$('#show-shenpi-btn').show();
$('#show-shenpi span').text('');
$('#show-shenpi').hide();
});
});
$('#start-btn').click(function () {
// 判断是否已选择审签人,有则提交
const username = $('#show-shenpi span').text();
if (username == '') {
toastr.error('请选择审签人再提交');
return false;
}
postData('/construction/' + tender_id + '/log/' + log_id + '/save', { type: 'start' }, function (result) {
window.location.reload();
});
});
$('#edit-start').click(function () {
$('#edit-end').show();
$('#edit-start').hide();
$('.edit-input').removeAttr('readonly');
$('.edit-textarea').removeAttr('readonly');
});
$('#edit-end').click(function () {
$('#edit-start').show();
$('#edit-end').hide();
$('.edit-input').attr('readonly', true);
$('.edit-textarea').attr('readonly', true);
});
$('#check-btn').click(function () {
postData('/construction/' + tender_id + '/log/' + log_id + '/save', { type: 'checked' }, function (result) {
window.location.reload();
});
});
// 上传附件
$('#upload-file-btn').click(function () {
const files = $('#upload-file')[0].files;
const formData = new FormData();
for (const file of files) {
if (file === undefined) {
toastr.error('未选择上传文件!');
return false;
}
const filesize = file.size;
if (filesize > 30 * 1024 * 1024) {
toastr.error('文件大小过大!');
return false;
}
const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
if (whiteList.indexOf(fileext) === -1) {
toastr.error('只能上传指定格式的附件!');
return false;
}
formData.append('size', filesize);
formData.append('file[]', file);
}
if (!filePermission) {
toastr.error('无权限上传!');
return false;
}
postDataWithFile('/construction/' + tender_id + '/log/' + log_id + '/file/upload', formData, function (data) {
attData = data.concat(attData);
// 重新生成List
getAllList();
$('#upload').modal('hide');
}, function () {
});
$('#upload-file').val('');
});
// 删除附件
$('body').on('click', '.delete-file', function () {
let attid = $(this).data('attid');
const data = {id: attid};
postData('/construction/' + tender_id + '/log/' + log_id + '/file/delete', data, function (result) {
// 删除到attData中
const att_index = attData.findIndex(function (item) {
return item.id === parseInt(attid);
});
attData.splice(att_index, 1);
getAllList();
});
});
// $('#attList').on('click', '.file-atn', function() {
// const id = $(this).attr('f-id');
// postData(`/construction/${tender_id}/log/${log_id}/file/${id}/download`, {}, (data) => {
// const { filepath } = data;
// $('#file-upload').attr('href', filepath);
// $('#file-upload')[0].click();
// })
// });
// 生成附件列表
function getAllList() {
let html = '';
for(const [index,att] of attData.entries()) {
html += `
${index+1} |
${att.filename}${att.fileext} |
${moment(att.upload_time).format("YYYY-MM-DD HH:mm:ss")} |
`
html += (att.uid === accountId && (logStatus === constructionStatusConst.checked ? Boolean(att.extra_upload) : true)) ?
`` : '';
html += ` | `;
}
$('#attList').html(html);
$('#attList').on('click', 'tr', function() {
$('#attList tr').removeClass('bg-light');
$(this).addClass('bg-light');
});
}
});