'use strict'; /** * * * @author Mai * @date 2019/2/27 * @version */ $(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 && cur_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 !== cur_uid) { 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 }) // 添加到审批流程中 $('.search-user-list').on('click', 'dd', function () { const id = parseInt($(this).data('id')); if (id) { postData(preUrl + '/audit/add', { auditorId: id }, (datas) => { makeSpHtml(datas); }); } }); // 删除审批人 $('body').on('click', '#auditors li a', function () { const li = $(this).parents('li'); const data = { auditorId: parseInt(li.attr('auditorId')), }; postData(preUrl + '/audit/delete', data, (result) => { li.remove(); let index = 1; $('#auditors li').each(function () { $(this).children('.col-auto').eq(0).text(index); index++; }); // 如果是重新上报 // 令最后一个图标转换 $('#auditors-list li[data-auditorId="' + data.auditorId + '"]').remove(); if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) { console.log($('#auditors-list li').length-1, $('#auditors-list li').eq($('#auditors-list li').length-1).find('i')); $('#auditors-list li').eq($('#auditors-list li').length-1).find('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('.badge-pill').children('small').text(i === 0 ? '原报' : (i+1 === $('#auditors-list li').length ? '终' : transFormToChinese(i)) + '审'); } }); }); // 切换审批组 $('#change-sp-group').change(function () { const data = { type: 'change_sp_group', sp_group: parseInt($(this).val()), } if (!data.sp_group) { toastr.error('请选择固定审批组'); return false; } console.log(data); postData(preUrl + '/audit/spgroup', data, (datas) => { makeSpHtml(datas); }); }); // 退回选择修改审批人流程 $('#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'); }); }); function makeSpHtml(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 添加会签或签时 if (data[0].audit_type !== auditType.key.common) { html.push(`${auditType.info[data[0].audit_type].long}`); } // 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(''); 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) +'审'); } auditorshtml.push('
    '); auditorshtml.push('
  • '); } $('#auditors').html(html.join('')); $('#auditors-list').html(auditorshtml.join('')); } // 检查上报情况 function checkAuditorFrom () { if ($('#auditors li').length === 0) { if(shenpi_status === shenpiConst.sp_status.gdspl) { toastr.error('请联系管理员添加审批人'); } else { toastr.error('请先选择审批人,再上报数据'); } return false; } let flag = false; if (change.code === '') { toastr.error('变更申请编号不能为空'); flag = true; } if (!change.name) { toastr.error('变更工程名称不能为空'); flag = true; } if (!change.reason) { toastr.error('变更原因不能为空'); flag = true; } // 判断变更清单是否有空值 const nullCodeList = _.filter(changeList, function(item) { return item.code === null || item.code === ''; }); if (nullCodeList.length > 0) { toastr.error('变更清单都需要设置清单编号才能上报'); flag = true; } if (flag) { return false; } $('#hide-all').show(); } // texterea换行 function auditCheck(i) { // const inlineRadio1 = $('#inlineRadio1:checked').val() // const inlineRadio2 = $('#inlineRadio2:checked').val() const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '
    ').replace(/\n/g, '
    ').replace(/\s/g, ' '); $('textarea[name="opinion"]').eq(i).val(opinion); console.log($('input[name="notice_code"]').val()); if ($('input[name="notice_code"]').val() !== undefined) { if (_.trim($('input[name="notice_code"]').val()) === '') { toastr.error('请输入变更通知书'); return false; } } // if (i === 1) { // if (!inlineRadio1 && !inlineRadio2) { // if (!$('#warning-text').length) { // $('#reject-process').prepend('

    请选择退回流程

    '); // } // return false; // } // if ($('#warning-text').length) $('#warning-text').remove() // } return true; }