');
if (data[0].audit_type !== auditType.key.common) {
auditorshtml.push(`
${auditType.info[data[0].audit_type].short}`);
}
if (index === 0) {
auditorshtml.push('
原报');
} else if (index + 1 === datas.length) {
auditorshtml.push('
终审');
} else {
auditorshtml.push('
' + transFormToChinese(index) + '审');
}
}
$('#auditors').html(html.join(''));
$('#auditors2').html(auditorshtml.join(''));
});
}
});
// 删除审批人
$('body').on('click', '#auditors li a', function () {
const li = $(this).parents('li');
const data = {
type: 'del-audit',
auditorId: parseInt(li.attr('auditorId')),
};
postData(preUrl + '/save', data, (result) => {
li.remove();
for (const rst of result) {
const aLi = $('li[auditorid=' + rst.aid + ']');
$('div:first', aLi).text(rst.order);
}
// 删除左边审核人
$(`#auditors2 li[data-auditorid='${data.auditorId}']`).remove();
if ($('#auditors2 li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
console.log($('#auditors2 li').length - 1, $('#auditors2 li').eq($('#auditors2 li').length - 1).find('i'));
$('#auditors2 li').eq($('#auditors2 li').length - 1).find('i')
.removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
}
for (let i = 0; i < $('#auditors2 li').length; i++) {
$('#auditors2 li').eq(i).find('.badge-pill').children('small').text(i === 0 ? '原报' : (i + 1 === $('#auditors2 li').length ? '终' : transFormToChinese(i)) + '审');
}
})
});
$('#del-inspection-btn').click(function() {
const text = $('#del-inspection-text').val().trim();
if (text.length === 0 || text !== '确认删除本次巡检') {
toastr.error('请正确输入“确认删除本次巡检”');
return;
}
postData(preUrl + '/save', {type: 'del-inspection' }, function (result) {
let link = `/sp/${spid}/quality/tender/${tender_id}/inspection`;
let orderSetting = getLocalCache('quality-inspection-'+ tender_id +'-list-order');
if (!orderSetting) orderSetting = 'time|desc';
const orders = orderSetting.split('|');
const filterData = [];
filterData.push('sort='+ orders[0]);
filterData.push('order=' + orders[1]);
if (getLocalCache('account-pageSize')) {
filterData.push('pageSize=' + getLocalCache('account-pageSize'));
}
if (filterData.length > 0) {
link += '?' + filterData.join('&');
}
window.location.href = link;
});
});
$('#judge-start-btn').click(function () {
const flag = !(inspection.code && inspection.check_item && inspection.check_date);
if (flag) {
toastr.warning('请完善巡检信息再提交');
return;
}
if ($('#auditors li').length === 0) {
if(shenpi_status === shenpiConst.sp_status.gdspl) {
toastr.error('请联系管理员添加审批人');
} else {
toastr.error('请先选择审批人,再上报数据');
}
return false;
}
$('#sp-done').modal('show');
});
$('#start-btn').click(function () {
$('#start-btn').prop('disabled', true);
postData(preUrl + '/save', { type: 'start-inspection' }, function (result) {
window.location.reload();
});
});
} else if (inspection.shenpiPower) {
// 添加到审批流程中
$('dl').on('click', 'dd', function () {
const id = parseInt($(this).data('id'))
if (id !== 0) {
const user = _.find(accountList, { id });
$('#rectification-user-set').html(`
${user.name}
`);
$('#rectification-uid').val(user.id);
$('#rectification-user-set').siblings('.dropdown').attr('style', 'display:none!important;');
}
});
// 删除审批人
$('body').on('click', '#rectification-user-set .remove-btn', function () {
$('#rectification-user-set').html('');
$('#rectification-uid').val('');
$('#rectification-user-set').siblings('.dropdown').show();
});
$('#approval-success-btn').click(function () {
if (inspection.finalAuditorIds.indexOf(cur_uid) !== -1 && $('#rectification-uid').val() === '') {
toastr.warning('请选择整改人');
return;
}
const opinion = $('#sp-done').find('textarea[name="opinion"]').eq(0).val().replace(/\r\n/g, '
').replace(/\n/g, '
').replace(/\s/g, ' ');
if (opinion.length === 0) {
toastr.warning('请填写审核意见');
return;
}
const data = {
type: 'check',
checkType: auditConst.status.checked,
opinion,
rectification_uid: $('#rectification-uid').val(),
}
postData(preUrl + '/save', data, function (result) {
window.location.reload();
});
});
$('#approval-back-btn').click(function () {
console.log($('#sp-back').find('textarea[name="opinion"]').eq(0).val());
const opinion = $('#sp-back').find('textarea[name="opinion"]').eq(0).val().replace(/\r\n/g, '
').replace(/\n/g, '
').replace(/\s/g, ' ');
if (opinion.length === 0) {
toastr.warning('请填写审核意见');
return;
}
const inlineRadio1 = $('#inlineRadio1:checked').val();
const inlineRadio2 = $('#inlineRadio2:checked').val();
if (!inlineRadio1 && !inlineRadio2) {
if (!$('#warning-text').length) {
$('#reject-process').prepend('
请选择退回流程
');
}
return;
}
if ($('#warning-text').length) $('#warning-text').remove()
const data = {
type: 'check',
checkType: parseInt(inlineRadio1 ? inlineRadio1 : inlineRadio2),
opinion,
}
postData(preUrl + '/save', data, function (result) {
window.location.reload();
});
});
$('#approval-stop-btn').click(function () {
const opinion = $('#sp-close').find('textarea[name="opinion"]').eq(0).val().replace(/\r\n/g, '
').replace(/\n/g, '
').replace(/\s/g, ' ');
if (opinion.length === 0) {
toastr.warning('请填写关闭原因');
return;
}
const data = {
type: 'check',
checkType: auditConst.status.checkStop,
opinion,
}
postData(preUrl + '/save', data, function (result) {
window.location.reload();
});
});
} else if (inspection.rectificationPower) {
$('#judge-success-btn').click(function () {
const flag = !(inspection.rectification_item && inspection.rectification_date);
if (flag) {
toastr.warning('请完善整改单再提交');
return;
}
$('#sp-done').modal('show');
});
// 整改完成
$('#rectification-success-btn').click(function () {
const opinion = $('#sp-done').find('textarea[name="opinion"]').eq(0).val().replace(/\r\n/g, '
').replace(/\n/g, '
').replace(/\s/g, ' ');
if (opinion.length === 0) {
toastr.warning('请填写审核意见');
return;
}
const data = {
type: 'rectification',
checkType: auditConst.status.checked,
opinion,
}
postData(preUrl + '/save', data, function (result) {
window.location.reload();
});
});
$('#rectification-back-btn').click(function () {
const opinion = $('#sp-back').find('textarea[name="opinion"]').eq(0).val().replace(/\r\n/g, '
').replace(/\n/g, '
').replace(/\s/g, ' ');
if (opinion.length === 0) {
toastr.warning('请填写审核意见');
return;
}
const data = {
type: 'rectification',
checkType: auditConst.status.checkNoPre,
opinion,
}
postData(preUrl + '/save', data, function (result) {
window.location.reload();
});
});
const rectificationDate = $('#rectification_date').datepicker({
autoClose: true,
onSelect: function (formattedDate, date, inst) {
if (!date && inspection.rectification_date) {
toastr.error('检查日期不能为空');
rectificationDate.selectDate(inspection.rectification_date ? new Date(inspection.rectification_date) : '');
return;
}
// 判断日期格式
const rectification_date = moment(date).format('YYYY-MM-DD');
const reg = /^\d{4}-\d{2}-\d{2}$/;
if (!reg.test(rectification_date)) {
toastr.error('整改日期格式错误,应为YYYY-MM-DD。');
return;
}
if (rectification_date !== moment(inspection.rectification_date).format('YYYY-MM-DD')) {
updateInspection('rectification_date', rectification_date);
}
}
}).data('datepicker');
rectificationDate.selectDate(inspection.rectification_date ? new Date(inspection.rectification_date) : '');
$('#rectification_table textarea').on('change', function (e) {
const value = $(this).val().trim();
const key = $(this).data('key');
if (value !== inspection[key]) {
updateInspection(key, value);
}
});
$("#rectification_table input").on('change', function (e) {
const value = $(this).val().trim();
const key = $(this).data('key');
if (key === 'check_date') {
if (!value && inspection.rectification_date) {
toastr.error('检查日期不能为空');
rectificationDate.selectDate(inspection.rectification_date ? new Date(inspection.rectification_date) : '');
return;
}
// 判断日期格式
const reg = /^\d{4}-\d{2}-\d{2}$/;
if (!reg.test(value)) {
toastr.error('检查日期格式错误,应为YYYY-MM-DD。');
rectificationDate.selectDate(inspection.rectification_date ? new Date(inspection.rectification_date) : '');
return;
}
}
if (value !== inspection[key]) {
updateInspection(key, value);
}
});
function updateInspection(field, value) {
const data = {
id: inspection.id,
};
data[field] = value;
console.log(data);
postData(`${preUrl}/save`, {type: 'update-field', update: data}, function (result) {
inspection[field] = value;
if (field === 'rectification_date') {
rectificationDate.selectDate(inspection.rectification_date ? new Date(inspection.rectification_date) : '');
}
}, function () {
if (field === 'rectification_date') {
rectificationDate.selectDate(inspection.rectification_date ? new Date(inspection.rectification_date) : '');
} else {
$(`#rectification_table textarea[data-key=${field}]`).val(inspection[field] || '');
}
});
}
}
handleFileList(fileList);
$('#file-ok').click(function () {
const files = Array.from($('#file-modal')[0].files)
const valiData = files.map(v => {
const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
return {
size: v.size,
ext
}
});
if (validateFiles(valiData)) {
if (files.length) {
const formData = new FormData();
files.forEach(file => {
formData.append('name', file.name);
formData.append('size', file.size);
formData.append('file', file);
})
postDataWithFile(`${preUrl}/file/upload`, formData, function (result) {
handleFileList(result);
$('#file-modal').val('');
$('#file-cancel').click();
});
}
}
})
function handleFileList(files = []) {
$('#file-content').empty();
const newFiles = files.map(file => {
let showDel = false;
if (file.uid === cur_uid) {
if (inspection.status === auditConst.status.checked) {
showDel = Boolean(file.extra_upload ) || deleteFilePermission
} else {
showDel = true
}
}
return {...file, showDel}
})
let html = inspection.filePermission ? `
上传附件 |
` : '';
newFiles.forEach((file, idx) => {
if (file.showDel) {
html += `
${idx + 1} | ${file.filename} | ${file.username} | ${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')} | |
`
} else {
html += `
${idx + 1} | ${file.filename} | ${file.username} | ${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')} | |
`
}
})
$('#file-content').append(html);
}
$('#file-content').on('click', 'a', function () {
if ($(this).hasClass('file-del')) {
const id = $(this).data('id');
postData(`${preUrl}/file/delete`, {id}, (result) => {
handleFileList(result);
})
}
});
})
/**
* 校验文件大小、格式
* @param {Array} files 文件数组
*/
function validateFiles(files) {
if (files.length > 10) {
toastr.error('至多同时上传10个文件');
return false
}
return files.every(file => {
if (file.size > 1024 * 1024 * 50) {
toastr.error('文件大小限制为50MB');
return false
}
if (whiteList.indexOf('.' + file.ext) === -1) {
toastr.error('请上传正确的格式文件');
return false
}
return true
})
}