'use strict'; /** * * * @author Mai * @date 2019/2/27 * @version */ // 检查上报情况 function checkAuditorFrom () { if ($('#auditors li').length === 0) { if(shenpi_status === shenpiConst.sp_status.gdspl) { toastr.error('请联系管理员添加审批人'); } else { toastr.error('请先选择审批人,再上报数据'); } return false; } $('#hide-all').show(); return true; } // 点击验证码 function codeSuccess(btn) { let counter = 60; btn.addClass('disabled').text('重新获取 ' + counter + 'S'); btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码'); const bindBtn = $("#bind-btn"); bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary'); const countDown = setInterval(function() { const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S'; // 倒数结束后 if (countString === '') { clearInterval(countDown); btn.removeClass('disabled'); } const text = '重新获取' + countString; btn.text(text); counter -= 1; }, 1000); } $(document).ready(function () { 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 && settle !== 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 !== settle) { html += `

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

${item.role || ''}
`; } }); html += '
'; }); $('.book-list').empty(); $('.book-list').append(html); } } }, 400); }); // 添加审批流程按钮逻辑 $('body').on('click', '.book-list 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 }); // 添加到审批流程 $('#book-list').on('click', 'dd', function () { const id = parseInt($(this).data('id')); if (id !== 0) { postData('audit/add', { auditorId: id }, (datas) => { 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('
    '); // todo 添加会签或签时 // html.push(''); 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(data.name + ' ' + data.role + ''); if (index === 0) { auditorshtml.push('原报'); } else if (index+1 === datas.length) { auditorshtml.push('终审'); } else { auditorshtml.push(''+ transFormToChinese(index) +'审'); } auditorshtml.push('
  • '); } $('#auditors').html(html.join('')); $('#auditors-list').html(auditorshtml.join('')); }); } }); // 删除审批人 $('body').on('click', '#auditors li a', function () { const li = $(this).parents('li'); const data = { auditorId: parseInt(li.attr('auditorId')), }; postData('audit/delete', data, (result) => { li.remove(); for (const rst of result) { const aLi = $('li[auditorId=' + rst.audit_id + ']'); $('span', aLi).text(rst.order + ' ' + rst.name + ' '); } // 如果是重新上报 // 令最后一个图标转换 $('#auditors-list li[data-auditorid="' + data.auditorId + '"]').remove(); if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) { $('#auditors-list li').eq($('#auditors-list li').length-1).children('i') .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle'); } for (let i = 0; i < $('#auditors-list li').length; i++) { $('#auditors-list li').eq(i).find('.pull-right').text(i === 0 ? '原报' : (i+1 === $('#auditors-list li').length ? '终' : transFormToChinese(i)) + '审'); // $('#auditors-list2 li').eq(i).find('.pull-right').text((i+1 === $('#auditors-list2 li').length ? '终' : transFormToChinese(i+1)) + '审'); } }); }); // 退回选择修改审批人流程 $('#hideSp').click(function () { $('#sp-list').modal('hide'); }); $('a[f-target]').click(function () { $($(this).attr('f-target')).modal('show'); }); // 多层modal关闭后的滚动bug修复 $('#sp-list').on('hidden.bs.modal', function (e) { $(document.body).addClass('modal-open'); }); // 重新审批获取手机验证码 // 获取验证码 let isPosting = false; $("#get-code").click(function() { if (isPosting) return false; const btn = $(this); $.ajax({ url: '/profile/code', type: 'post', data: { mobile: authMobile, type: 'shenpi' }, dataTye: 'json', error: function() { isPosting = false; let csrfToken = Cookies.get('csrfToken_j'); xhr.setRequestHeader('x-csrf-token', csrfToken); }, beforeSend: function() { isPosting = true; }, success: function(response) { isPosting = false; if (response.err === 0) { codeSuccess(btn); $("input[name='code']").removeAttr('readonly'); $("#re-shenpi-btn").removeAttr('disabled'); } else { toast(response.msg, 'error'); } } }); }); // 管理员更改审批流程js部分 let timer2 = null; let oldSearchVal2 = null; $('body').on('input propertychange', '.gr-search', function(e) { oldSearchVal2 = e.target.value; timer2 && clearTimeout(timer2); timer2 = setTimeout(() => { const newVal = $(this).val(); const code = $(this).attr('data-code'); let html = ''; if (newVal && newVal === oldSearchVal2) { accountList.filter(item => item && item.id !== settle && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => { html += `

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

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

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

    ${item.role || ''}
    `; } }); html += '
    '; }); $('#' + code + '_dropdownMenu .book-list').empty(); $('#' + code + '_dropdownMenu .book-list').append(html); } } }, 400); }); const getAdminEditShenpiListHtml = function(auditGroup) { const html = []; for (const [i, group] of auditGroup.entries()) { if (i === 0) continue; for (const [j, auditor] of group.entries()) { html.push(''); if (j === 0) { const auditTypeHtml = auditor.type === auditType.key.common ? '' : `${auditType.info[auditor.audit_type].short}`; html.push(`${i + '审'}${auditTypeHtml}`); } else { html.push(``); } html.push(` ${auditor.name} ${auditor.role}`); html.push(`${ auditor.audit_status !== auditConst.status.uncheck ? auditConst.auditString[auditor.audit_status] : '待审批' }`); html.push(''); if (auditor.audit_status === auditConst.status.checking && j === group.length - 1) { html.push('', ``, makeSelectAudit(auditor.audit_id+'_add', auditor.audit_id, 'add'),'', ''); } if (auditor.audit_status === auditConst.status.uncheck) { if (j === group.length - 1) { html.push('', ``, makeSelectAudit(auditor.audit_id+'_add', auditor.audit_id, 'add'),'', ''); if (auditor.audit_type !== auditType.key.common) { html.push('', ``, makeSelectAudit(auditor.audit_id+'_add-sibling', auditor.audit_id, 'add-sibling'),'', ''); } } html.push('', ``, makeSelectAudit(auditor.audit_id+'_change', auditor.audit_id, 'change'),'', ''); html.push(` `); } html.push(''); html.push(''); } } return html.join(''); }; $('body').on('click', '#admin-edit-shenpi dl dd', function () { const id = parseInt($(this).attr('data-id')); if (!id) return; let this_aid = parseInt($(this).parents('.book-list').attr('data-aid')); let this_operate = $(this).parents('.book-list').attr('data-operate'); const user = _.find(accountList, function (item) { return item.id === id; }); const auditorIndex = _.findIndex(auditorList, { audit_id: id }); if (auditorIndex !== -1) { toastr.warning('该审核人已存在,请勿重复添加'); return; } const prop = { operate: this_operate, old_aid: this_aid, new_aid: user.id, }; postData('audit/save', prop, (datas) => { $('#admin-edit-shenpi-list').html(getAdminEditShenpiListHtml(datas)); changeLiucheng(datas); }); }); // 管理员移除审批人 $('body').on('click', '.remove-audit', function () { const id = parseInt($(this).attr('data-id')); const prop = { operate: 'del', old_aid: id, }; postData('audit/save', prop, (datas) => { $('#admin-edit-shenpi-list').html(getAdminEditShenpiListHtml(datas)); changeLiucheng(datas); }); }); const getAuditTypeText = function (type) { if (type === auditType.key.common) return ''; return `${auditType.info[type].long}`; }; function changeLiucheng(datas) { const auditorshtml = []; let lastAuditorHtml = []; for (const [index,data] of datas.entries()) { auditorshtml.push('
  • '); if (index === 0) { auditorshtml.push(''); } else if (index+1 === datas.length) { auditorshtml.push(''); } else { auditorshtml.push(''); } auditorshtml.push(''); for (const u of data) { auditorshtml.push(`${u.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) +'审'); } auditorshtml.push('
    '); auditorshtml.push('
  • '); if (data[0].audit_status === sam_auditConst.status.uncheck) { lastAuditorHtml.push('
  • '); if (index < datas.length - 1) { lastAuditorHtml.push('
    '); } lastAuditorHtml.push('
    '); lastAuditorHtml.push('
    '); lastAuditorHtml.push(`
    ${ !index === datas.length - 1 ? data[0].audit_order + '' : '终' }审 ${getAuditTypeText(data[0].audit_type)}
    `); lastAuditorHtml.push('
    '); for (const [i, auditor] of data.entries()) { lastAuditorHtml.push(`
    `); lastAuditorHtml.push(`
    ${auditor.name}${auditor.role}
    `); lastAuditorHtml.push('
    '); lastAuditorHtml.push('
    '); lastAuditorHtml.push('
    '); } lastAuditorHtml.push('
    '); lastAuditorHtml.push('
    '); lastAuditorHtml.push('
  • '); } } $('.last-auditor-list .is_uncheck').remove(); $('.last-auditor-list').append(lastAuditorHtml.join('')); $('.auditors-list').html(auditorshtml.join('')); } // 审批流程-选择审批人html 生成 function makeSelectAudit(code, aid, status) { let divhtml = ''; accountGroup.forEach((group, idx) => { let didivhtml = ''; if(group) { group.groupList.forEach(item => { didivhtml += item.id !== settle ? '
    \n' + '

    ' + item.name + '' + item.mobile + '

    \n' + ' ' + item.role + '\n' + '
    \n' : ''; }); divhtml += '
    ' + group.groupName + '
    \n' + '
    \n' + didivhtml + '
    \n'; } }); let html = '\n' + ' \n' + ' \n' + ' \n' + ' '; return html; } });