'use strict'; /** * * * @author lanjianrong * @date 2020/8/7 * @version */ $(document).ready(function () { autoFlashHeight(); $.subMenu({ menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list', toMenu: '#to-menu', toMiniMenu: '#to-mini-menu', key: 'menu.1.0.0', miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1', callback: function (info) { if (info.mini) { $('.panel-title').addClass('fluid'); $('#sub-menu').removeClass('panel-sidebar'); } else { $('.panel-title').removeClass('fluid'); $('#sub-menu').addClass('panel-sidebar'); } autoFlashHeight(); } }); // 展开历史审核记录 $('td #fold-btn').click(function () { const type = $(this).data('target') const auditCard = $(this).parent().parent() if (type === 'show') { $(this).data('target', 'hide') auditCard.find('.fold-card').slideDown('swing', () => { auditCard.find('#fold-btn').text('收起历史审核记录') }) } else { $(this).data('target', 'show') auditCard.find('.fold-card').slideUp('swing', () => { auditCard.find('#fold-btn').text('展开历史审核记录') }) } }); // 添加审批流程按钮逻辑 $('.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 }) 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 && inspection.uid !== item.id && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => { html += `

${item.name}${item.mobile || ''}

${item.role || ''}
` }) $('.book-list').empty() $('.book-list').append(html) } else { if (!$('.acc-btn').length) { accountGroup.forEach((group, idx) => { if (!group) return html += `
${group.groupName}
` group.groupList.forEach(item => { if (item.id !== inspection.uid) { html += `

${item.name}${item.mobile || ''}

${item.role || ''}
` } }); html += '
' }) $('.book-list').empty() $('.book-list').append(html) } } }, 400); }) if (!inspection.readOnly) { const checkDate = $('#check_date').datepicker({ autoClose: true, onSelect: function (formattedDate, date, inst) { if (!date && inspection.check_date) { toastr.error('检查日期不能为空'); checkDate.selectDate(inspection.check_date ? new Date(inspection.check_date) : new Date()); return; } // 判断日期格式 const check_date = moment(date).format('YYYY-MM-DD'); const reg = /^\d{4}-\d{2}-\d{2}$/; if (!reg.test(check_date)) { toastr.error('检查日期格式错误,应为YYYY-MM-DD。'); return; } if (check_date !== moment(inspection.check_date).format('YYYY-MM-DD')) { updateInspection('check_date', check_date); } } }).data('datepicker'); checkDate.selectDate(inspection.check_date ? new Date(inspection.check_date) : new Date()); $('#check_table textarea').on('change', function (e) { const value = $(this).val().trim(); const key = $(this).data('key'); if (value !== inspection[key]) { updateInspection(key, value); } }); $("#check_table input").on('change', function (e) { const value = $(this).val().trim(); const key = $(this).data('key'); if (key === 'check_date') { if (!value && inspection.check_date) { toastr.error('检查日期不能为空'); checkDate.selectDate(inspection.check_date ? new Date(inspection.check_date) : new Date()); return; } // 判断日期格式 const reg = /^\d{4}-\d{2}-\d{2}$/; if (!reg.test(value)) { toastr.error('检查日期格式错误,应为YYYY-MM-DD。'); checkDate.selectDate(inspection.check_date ? new Date(inspection.check_date) : new Date()); return; } } if (value !== inspection[key]) { updateInspection(key, value); } }); $('#check_table dl').on('click', 'dd', function () { const id = parseInt($(this).data('id')) if (id !== 0) { const user = _.find(accountList, { id }); $('#inspector-set').html(` ${user.name} `); $('#inspector-set').siblings('.dropdown').attr('style', 'display:none!important;'); updateInspection('inspector', user.name); } }); $('body').on('click', '#check_table .remove-btn', function () { updateInspection('inspector', ''); $('#inspector-set').html(''); $('#inspector-set').siblings('.dropdown').show(); }); function updateInspection(field, value) { const data = { id: inspection.id, }; data[field] = value; postData(`${preUrl}/save`, {type: 'update-field', update: data}, function (result) { inspection[field] = value; if (field === 'check_date') { checkDate.selectDate(inspection.check_date ? new Date(inspection.check_date) : new Date()); } }, function () { if (field === 'check_date') { checkDate.selectDate(inspection.check_date ? new Date(inspection.check_date) : new Date()); } else { $(`#check_table textarea[data-key=${field}]`).val(inspection[field] || ''); } }); } // 添加到审批流程中 $('#shenpi_select dl').on('click', 'dd', function () { const id = parseInt($(this).data('id')) if (id !== 0) { postData(preUrl + '/save', {type: 'add-audit', auditorId: id}, (datas) => { //

中交第一公路工程局有限公司国道311线满别公路施工一分部

const html = []; // 如果是重新上报,添加到重新上报列表中 const auditorshtml = []; for (const [index, data] of datas.entries()) { if (index !== 0) { html.push('
  • '); html.push(`
    ${index}
    `); html.push('
    '); for (const auditor of data) { html.push(`
    ${auditor.name} ${auditor.role}
    `); } html.push('
    '); html.push('
    '); if (data[0].audit_type !== auditType.key.common) { html.push(`${auditType.info[data[0].audit_type].long}`); } if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index + 1 !== datas.length)) { html.push('移除'); } html.push('
    '); html.push('
  • '); } // 添加新审批人流程修改 auditorshtml.push('
  • '); auditorshtml.push(''); auditorshtml.push(''); for (const auditor of data) { auditorshtml.push(`${auditor.name}`); } auditorshtml.push(''); auditorshtml.push('
    '); 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 }) }