|
@@ -0,0 +1,631 @@
|
|
|
+'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 += `<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 !== inspection.uid) {
|
|
|
+ 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);
|
|
|
+ })
|
|
|
+ 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(`<span class="badge">
|
|
|
+ ${user.name}
|
|
|
+ <span class="dropdown">
|
|
|
+ <a href="javascript:void(0)" class="btn-sm text-danger px-1" title="移除" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-remove"></i></a>
|
|
|
+ <div class="dropdown-menu">
|
|
|
+ <a class="dropdown-item" href="javascript:void(0);">确认移除检查人?</a>
|
|
|
+ <div class="dropdown-divider"></div>
|
|
|
+ <div class="px-2 py-1 text-center">
|
|
|
+ <button class="btn btn-sm btn-danger remove-btn">移除</button>
|
|
|
+ <button class="btn btn-sm btn-secondary">取消</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </span>
|
|
|
+ </span>`);
|
|
|
+ $('#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) => {
|
|
|
+ // <p class="m-0 ml-2"><small class="text-muted">中交第一公路工程局有限公司国道311线满别公路施工一分部</small></p>
|
|
|
+ const html = [];
|
|
|
+ // 如果是重新上报,添加到重新上报列表中
|
|
|
+ const auditorshtml = [];
|
|
|
+ for (const [index, data] of datas.entries()) {
|
|
|
+ if (index !== 0) {
|
|
|
+ html.push('<li class="list-group-item d-flex" auditorId="' + data[0].aid + '">');
|
|
|
+ html.push(`<div class="col-auto">${index}</div>`);
|
|
|
+ html.push('<div class="col">');
|
|
|
+ for (const auditor of data) {
|
|
|
+ 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 (data[0].audit_type !== auditType.key.common) {
|
|
|
+ html.push(`<span class="badge badge-pill badge-${auditType.info[data[0].audit_type].class} badge-bg-small"><small>${auditType.info[data[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>');
|
|
|
+ }
|
|
|
+ // 添加新审批人流程修改
|
|
|
+ auditorshtml.push('<li class="list-group-item d-flex justify-content-between align-items-center" data-auditorid="' + data[0].aid + '">');
|
|
|
+ auditorshtml.push('<span class="mr-1"><i class="fa ' + (index === 0 ? 'fa-play-circle fa-rotate-90' : index + 1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i></span>');
|
|
|
+ auditorshtml.push('<span class="text-muted">');
|
|
|
+ for (const auditor of data) {
|
|
|
+ auditorshtml.push(`<small class="d-inline-block text-dark mx-1" title="${auditor.role}" data-auditorId="${auditor.uid}">${auditor.name}</small>`);
|
|
|
+ }
|
|
|
+ auditorshtml.push('</span>');
|
|
|
+ auditorshtml.push('<div class="d-flex ml-auto">');
|
|
|
+ if (data[0].audit_type !== auditType.key.common) {
|
|
|
+ auditorshtml.push(`<span class="badge badge-pill badge-${auditType.info[data[0].audit_type].class} p-1"><small>${auditType.info[data[0].audit_type].short}</small></span>`);
|
|
|
+ }
|
|
|
+ if (index === 0) {
|
|
|
+ auditorshtml.push('<span class="badge badge-light badge-pill ml-auto"><small>原报</small></span>');
|
|
|
+ } else if (index + 1 === datas.length) {
|
|
|
+ auditorshtml.push('<span class="badge badge-light badge-pill"><small>终审</small></span>');
|
|
|
+ } else {
|
|
|
+ auditorshtml.push('<span class="badge badge-light badge-pill"><small>' + transFormToChinese(index) + '审</small></span>');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $('#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(`<span class="badge">
|
|
|
+ ${user.name}
|
|
|
+ <span class="dropdown">
|
|
|
+ <a href="javascript:void(0)" class="btn-sm text-danger px-1" title="移除" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-remove"></i></a>
|
|
|
+ <div class="dropdown-menu">
|
|
|
+ <a class="dropdown-item" href="javascript:void(0);">确认移除整改人?</a>
|
|
|
+ <div class="dropdown-divider"></div>
|
|
|
+ <div class="px-2 py-1 text-center">
|
|
|
+ <button class="btn btn-sm btn-danger remove-btn">移除</button>
|
|
|
+ <button class="btn btn-sm btn-secondary">取消</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </span>
|
|
|
+ </span>`);
|
|
|
+ $('#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, '<br/>').replace(/\n/g, '<br/>').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, '<br/>').replace(/\n/g, '<br/>').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('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
|
|
|
+ }
|
|
|
+ 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, '<br/>').replace(/\n/g, '<br/>').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, '<br/>').replace(/\n/g, '<br/>').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, '<br/>').replace(/\n/g, '<br/>').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 ? `<tr><td colspan="5"><a href="#addfujian" data-toggle="modal" class="btn btn-sm btn-light text-primary" data-placement="bottom" title="" data-original-title="上传附件"><i class="fa fa-cloud-upload" aria-hidden="true"></i> 上传附件</a></td></tr>` : '';
|
|
|
+ newFiles.forEach((file, idx) => {
|
|
|
+ if (file.showDel) {
|
|
|
+ html += `<tr><td>${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="${preUrl}/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a><a href="javascript: void(0);" class="text-danger file-del" data-id="${file.id}"><i class="fa fa-remove"></i></a></td></tr>`
|
|
|
+ } else {
|
|
|
+ html += `<tr><td width="70">${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="${preUrl}/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a></td></tr>`
|
|
|
+ }
|
|
|
+ })
|
|
|
+ $('#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
|
|
|
+ })
|
|
|
+}
|
|
|
+
|