'use strict';
/**
*
*
* @author Mai
* @date 2019/2/27
* @version
*/
$(document).ready(function () {
let timer = null;
let oldSearchVal = null;
// 获取审核相关url
function getUrlPre () {
const path = window.location.pathname.split('/');
return _.take(path, 6).join('/');
}
$('#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 && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
html += `
`;
group.groupList.forEach(item => {
// if (item.id !== changesUid) {
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
});
$('#hideSp').click(function () {
$('#sub-sp2').modal('hide');
});
// 添加到审批流程中
$('dl').on('click', 'dd', function () {
const id = parseInt($(this).data('id'));
if (id !== 0) {
postData(getUrlPre() + '/audit/add', { auditorId: id }, (datas) => {
makeSpList(datas);
});
}
});
// 移除审批流程的审批人
$('body').on('click', '#auditList li a', function () {
const uid = $(this).parents('li').attr('data-auditid');
const li = $(this).parents('li');
const data = {
auditorId: uid,
};
postData(getUrlPre() + '/audit/delete', data, (result) => {
li.remove();
let index = 1;
$('#auditList li').each(function () {
$(this).children('.col-auto').eq(0).text(index);
index++;
});
// if (index === 1) {
// $('#account_list').val(0);
// }
// 重新上报时。移除审批流程
// 令最后一个图标转换
$('#auditors-list li[data-auditid="' + uid + '"]').remove();
if ($('#auditors-list li').length !== 0 && !$('#auditors-list li').find('i').hasClass('fa-stop-circle')) {
$('#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)) + '审');
}
// $('#auditors-list li').eq(0).find('i').removeClass('fa-chevron-circle-down').addClass('fa-play-circle fa-rotate-90');
});
});
// 切换审批组
$('#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(getUrlPre() + '/audit/spgroup', data, (datas) => {
makeSpList(datas)
});
});
$('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 makeSpList(datas) {
const html = [];
// 如果是重新上报,添加到重新上报列表中
const auditorshtml = [];
for (const [index,data] of datas.entries()) {
if (index !== 0) {
html.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('');
}
$('#auditList').html(html.join(''));
$('#auditors-list').html(auditorshtml.join(''));
}
});
// 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, '