123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- 'use strict';
- $(document).ready(() => {
- const auditFlow = {
- getAuditTypeText: function (type) {
- if (type === auditType.key.common) return '';
- return `<span class="text-${auditType.info[type].class}">${auditType.info[type].long}</span>`;
- },
- getSimpleAuditFlow: function(groups) {
- const html = [];
- for (const group of groups) {
- html.push(`<li class="list-group-item" data-auditorid="${group[0].audit_id}">`);
- html.push(`<i class="fa ${(group[0].is_final ? 'fa-stop-circle' : 'fa-chevron-circle-down')}"></i>`);
- html.push(`${group[0].name} <small class="text-muted">${group[0].role}</small>`);
- html.push('<span class="pull-right">${group[0].flow_name}</span>');
- html.push('</li>');
- }
- return html.join('');
- },
- getStartAuditFlow: function(groups) {
- const html = [];
- for (const group of groups) {
- if (group[0].audit_order === 0) continue;
- html.push('<li class="list-group-item d-flex" auditorId="'+ group[0].audit_id +'">');
- html.push(`<div class="col-auto">${group[0].audit_order}</div>`);
- html.push('<div class="col">');
- for (const auditor of group) {
- html.push(`<div class="d-inline-block mx-1"><i class="fa fa-user text-muted"></i> ${auditor.name} <small class="text-muted">${auditor.role}</small></div>`);
- }
- html.push('</div>');
- html.push('<div class="col-auto">');
- if (group[0].audit_type !== auditType.key.common) {
- html.push(`<span class="badge badge-pill badge-${auditType.info[group[0].audit_type].class} badge-bg-small"><small>${auditType.info[group[0].audit_type].long}</small></span>`);
- }
- if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
- html.push('<a href="javascript: void(0)" class="text-danger pull-right ml-1">移除</a>');
- }
- html.push('</div>');
- html.push('</li>');
- }
- return html.join('');
- },
- saveAudit: function(data, callback) {
- postData('audit/save', data, (result) => {
- callback(result);
- });
- }
- };
- // 搜索
- 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 && userID !== item.id && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
- html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
- <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
- class="ml-auto">${item.mobile || ''}</span></p>
- <span class="text-muted">${item.role || ''}</span>
- </dd>`
- });
- $('.book-list').empty();
- $('.book-list').append(html);
- } else {
- if (!$('.acc-btn').length) {
- accountGroup.forEach((group, idx) => {
- if (!group) return;
- html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
- </a> ${group.groupName}</dt>
- <div class="dd-content" data-toggleid="${idx}">`;
- group.groupList.forEach(item => {
- if (item.id !== userID) {
- html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
- <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
- class="ml-auto">${item.mobile || ''}</span></p>
- <span class="text-muted">${item.role || ''}</span>
- </dd>`
- }
- });
- html += '</div>';
- });
- $('.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) return;
- auditFlow.saveAudit({ operate: 'add', audit_id: id }, (result) => {
- $('#auditors').html(auditFlow.getStartAuditFlow(result));
- $('#auditors-list').html(auditFlow.getSimpleAuditFlow(result));
- });
- });
- // 移除审批人
- $('body').on('click', '#auditors li a', function () {
- const li = $(this).parents('li');
- const data = {
- operate: 'del',
- audit_id: parseInt(li.attr('auditorId')),
- };
- auditFlow.saveAudit(data, (result) => {
- $('#auditors').html(auditFlow.getStartAuditFlow(result));
- });
- });
- $('body').on('click', '.remove-audit', function () {
- const id = parseInt($(this).attr('data-id'));
- postData('audit/save', { operate: 'del', audit_id: id }, (datas) => {
- $('#admin-edit-shenpi-list').html(auditFlow.getStartAuditFlow(datas));
- auditFlow.getStartAuditFlow(datas);
- });
- });
- });
|