quality_inspection_information.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author lanjianrong
  6. * @date 2020/8/7
  7. * @version
  8. */
  9. $(document).ready(function () {
  10. autoFlashHeight();
  11. $.subMenu({
  12. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  13. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  14. key: 'menu.1.0.0',
  15. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  16. callback: function (info) {
  17. if (info.mini) {
  18. $('.panel-title').addClass('fluid');
  19. $('#sub-menu').removeClass('panel-sidebar');
  20. } else {
  21. $('.panel-title').removeClass('fluid');
  22. $('#sub-menu').addClass('panel-sidebar');
  23. }
  24. autoFlashHeight();
  25. }
  26. });
  27. // 展开历史审核记录
  28. $('td #fold-btn').click(function () {
  29. const type = $(this).data('target')
  30. const auditCard = $(this).parent().parent()
  31. if (type === 'show') {
  32. $(this).data('target', 'hide')
  33. auditCard.find('.fold-card').slideDown('swing', () => {
  34. auditCard.find('#fold-btn').text('收起历史审核记录')
  35. })
  36. } else {
  37. $(this).data('target', 'show')
  38. auditCard.find('.fold-card').slideUp('swing', () => {
  39. auditCard.find('#fold-btn').text('展开历史审核记录')
  40. })
  41. }
  42. });
  43. // 添加审批流程按钮逻辑
  44. $('.book-list').on('click', 'dt', function () {
  45. const idx = $(this).find('.acc-btn').attr('data-groupid')
  46. const type = $(this).find('.acc-btn').attr('data-type')
  47. if (type === 'hide') {
  48. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  49. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  50. $(this).find('.acc-btn').attr('data-type', 'show')
  51. })
  52. } else {
  53. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  54. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  55. $(this).find('.acc-btn').attr('data-type', 'hide')
  56. })
  57. }
  58. return false
  59. })
  60. let timer = null
  61. let oldSearchVal = null
  62. $('.gr-search').bind('input propertychange', function (e) {
  63. oldSearchVal = e.target.value
  64. timer && clearTimeout(timer)
  65. timer = setTimeout(() => {
  66. const newVal = $('#gr-search').val()
  67. let html = ''
  68. if (newVal && newVal === oldSearchVal) {
  69. accountList.filter(item => item && inspection.uid !== item.id && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  70. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  71. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  72. class="ml-auto">${item.mobile || ''}</span></p>
  73. <span class="text-muted">${item.role || ''}</span>
  74. </dd>`
  75. })
  76. $('.book-list').empty()
  77. $('.book-list').append(html)
  78. } else {
  79. if (!$('.acc-btn').length) {
  80. accountGroup.forEach((group, idx) => {
  81. if (!group) return
  82. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  83. </a> ${group.groupName}</dt>
  84. <div class="dd-content" data-toggleid="${idx}">`
  85. group.groupList.forEach(item => {
  86. if (item.id !== inspection.uid) {
  87. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  88. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  89. class="ml-auto">${item.mobile || ''}</span></p>
  90. <span class="text-muted">${item.role || ''}</span>
  91. </dd>`
  92. }
  93. });
  94. html += '</div>'
  95. })
  96. $('.book-list').empty()
  97. $('.book-list').append(html)
  98. }
  99. }
  100. }, 400);
  101. })
  102. if (!inspection.readOnly) {
  103. const checkDate = $('#check_date').datepicker({
  104. autoClose: true,
  105. onSelect: function (formattedDate, date, inst) {
  106. if (!date && inspection.check_date) {
  107. toastr.error('检查日期不能为空');
  108. checkDate.selectDate(inspection.check_date ? new Date(inspection.check_date) : new Date());
  109. return;
  110. }
  111. // 判断日期格式
  112. const check_date = moment(date).format('YYYY-MM-DD');
  113. const reg = /^\d{4}-\d{2}-\d{2}$/;
  114. if (!reg.test(check_date)) {
  115. toastr.error('检查日期格式错误,应为YYYY-MM-DD。');
  116. return;
  117. }
  118. if (check_date !== moment(inspection.check_date).format('YYYY-MM-DD')) {
  119. updateInspection('check_date', check_date);
  120. }
  121. }
  122. }).data('datepicker');
  123. checkDate.selectDate(inspection.check_date ? new Date(inspection.check_date) : new Date());
  124. $('#check_table textarea').on('change', function (e) {
  125. const value = $(this).val().trim();
  126. const key = $(this).data('key');
  127. if (value !== inspection[key]) {
  128. updateInspection(key, value);
  129. }
  130. });
  131. $("#check_table input").on('change', function (e) {
  132. const value = $(this).val().trim();
  133. const key = $(this).data('key');
  134. if (key === 'check_date') {
  135. if (!value && inspection.check_date) {
  136. toastr.error('检查日期不能为空');
  137. checkDate.selectDate(inspection.check_date ? new Date(inspection.check_date) : new Date());
  138. return;
  139. }
  140. // 判断日期格式
  141. const reg = /^\d{4}-\d{2}-\d{2}$/;
  142. if (!reg.test(value)) {
  143. toastr.error('检查日期格式错误,应为YYYY-MM-DD。');
  144. checkDate.selectDate(inspection.check_date ? new Date(inspection.check_date) : new Date());
  145. return;
  146. }
  147. }
  148. if (value !== inspection[key]) {
  149. updateInspection(key, value);
  150. }
  151. });
  152. $('#check_table dl').on('click', 'dd', function () {
  153. const id = parseInt($(this).data('id'))
  154. if (id !== 0) {
  155. const user = _.find(accountList, { id });
  156. $('#inspector-set').html(`<span class="badge">
  157. ${user.name}
  158. <span class="dropdown">
  159. <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>
  160. <div class="dropdown-menu">
  161. <a class="dropdown-item" href="javascript:void(0);">确认移除检查人?</a>
  162. <div class="dropdown-divider"></div>
  163. <div class="px-2 py-1 text-center">
  164. <button class="btn btn-sm btn-danger remove-btn">移除</button>
  165. <button class="btn btn-sm btn-secondary">取消</button>
  166. </div>
  167. </div>
  168. </span>
  169. </span>`);
  170. $('#inspector-set').siblings('.dropdown').attr('style', 'display:none!important;');
  171. updateInspection('inspector', user.name);
  172. }
  173. });
  174. $('body').on('click', '#check_table .remove-btn', function () {
  175. updateInspection('inspector', '');
  176. $('#inspector-set').html('');
  177. $('#inspector-set').siblings('.dropdown').show();
  178. });
  179. function updateInspection(field, value) {
  180. const data = {
  181. id: inspection.id,
  182. };
  183. data[field] = value;
  184. postData(`${preUrl}/save`, {type: 'update-field', update: data}, function (result) {
  185. inspection[field] = value;
  186. if (field === 'check_date') {
  187. checkDate.selectDate(inspection.check_date ? new Date(inspection.check_date) : new Date());
  188. }
  189. }, function () {
  190. if (field === 'check_date') {
  191. checkDate.selectDate(inspection.check_date ? new Date(inspection.check_date) : new Date());
  192. } else {
  193. $(`#check_table textarea[data-key=${field}]`).val(inspection[field] || '');
  194. }
  195. });
  196. }
  197. // 添加到审批流程中
  198. $('#shenpi_select dl').on('click', 'dd', function () {
  199. const id = parseInt($(this).data('id'))
  200. if (id !== 0) {
  201. postData(preUrl + '/save', {type: 'add-audit', auditorId: id}, (datas) => {
  202. // <p class="m-0 ml-2"><small class="text-muted">中交第一公路工程局有限公司国道311线满别公路施工一分部</small></p>
  203. const html = [];
  204. // 如果是重新上报,添加到重新上报列表中
  205. const auditorshtml = [];
  206. for (const [index, data] of datas.entries()) {
  207. if (index !== 0) {
  208. html.push('<li class="list-group-item d-flex" auditorId="' + data[0].aid + '">');
  209. html.push(`<div class="col-auto">${index}</div>`);
  210. html.push('<div class="col">');
  211. for (const auditor of data) {
  212. 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>`);
  213. }
  214. html.push('</div>');
  215. html.push('<div class="col-auto">');
  216. if (data[0].audit_type !== auditType.key.common) {
  217. 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>`);
  218. }
  219. if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index + 1 !== datas.length)) {
  220. html.push('<a href="javascript: void(0)" class="text-danger pull-right ml-1">移除</a>');
  221. }
  222. html.push('</div>');
  223. html.push('</li>');
  224. }
  225. // 添加新审批人流程修改
  226. auditorshtml.push('<li class="list-group-item d-flex justify-content-between align-items-center" data-auditorid="' + data[0].aid + '">');
  227. 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>');
  228. auditorshtml.push('<span class="text-muted">');
  229. for (const auditor of data) {
  230. auditorshtml.push(`<small class="d-inline-block text-dark mx-1" title="${auditor.role}" data-auditorId="${auditor.uid}">${auditor.name}</small>`);
  231. }
  232. auditorshtml.push('</span>');
  233. auditorshtml.push('<div class="d-flex ml-auto">');
  234. if (data[0].audit_type !== auditType.key.common) {
  235. 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>`);
  236. }
  237. if (index === 0) {
  238. auditorshtml.push('<span class="badge badge-light badge-pill ml-auto"><small>原报</small></span>');
  239. } else if (index + 1 === datas.length) {
  240. auditorshtml.push('<span class="badge badge-light badge-pill"><small>终审</small></span>');
  241. } else {
  242. auditorshtml.push('<span class="badge badge-light badge-pill"><small>' + transFormToChinese(index) + '审</small></span>');
  243. }
  244. }
  245. $('#auditors').html(html.join(''));
  246. $('#auditors2').html(auditorshtml.join(''));
  247. });
  248. }
  249. });
  250. // 删除审批人
  251. $('body').on('click', '#auditors li a', function () {
  252. const li = $(this).parents('li');
  253. const data = {
  254. type: 'del-audit',
  255. auditorId: parseInt(li.attr('auditorId')),
  256. };
  257. postData(preUrl + '/save', data, (result) => {
  258. li.remove();
  259. for (const rst of result) {
  260. const aLi = $('li[auditorid=' + rst.aid + ']');
  261. $('div:first', aLi).text(rst.order);
  262. }
  263. // 删除左边审核人
  264. $(`#auditors2 li[data-auditorid='${data.auditorId}']`).remove();
  265. if ($('#auditors2 li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  266. console.log($('#auditors2 li').length - 1, $('#auditors2 li').eq($('#auditors2 li').length - 1).find('i'));
  267. $('#auditors2 li').eq($('#auditors2 li').length - 1).find('i')
  268. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  269. }
  270. for (let i = 0; i < $('#auditors2 li').length; i++) {
  271. $('#auditors2 li').eq(i).find('.badge-pill').children('small').text(i === 0 ? '原报' : (i + 1 === $('#auditors2 li').length ? '终' : transFormToChinese(i)) + '审');
  272. }
  273. })
  274. });
  275. $('#del-inspection-btn').click(function() {
  276. const text = $('#del-inspection-text').val().trim();
  277. if (text.length === 0 || text !== '确认删除本次巡检') {
  278. toastr.error('请正确输入“确认删除本次巡检”');
  279. return;
  280. }
  281. postData(preUrl + '/save', {type: 'del-inspection' }, function (result) {
  282. let link = `/sp/${spid}/quality/tender/${tender_id}/inspection`;
  283. let orderSetting = getLocalCache('quality-inspection-'+ tender_id +'-list-order');
  284. if (!orderSetting) orderSetting = 'time|desc';
  285. const orders = orderSetting.split('|');
  286. const filterData = [];
  287. filterData.push('sort='+ orders[0]);
  288. filterData.push('order=' + orders[1]);
  289. if (getLocalCache('account-pageSize')) {
  290. filterData.push('pageSize=' + getLocalCache('account-pageSize'));
  291. }
  292. if (filterData.length > 0) {
  293. link += '?' + filterData.join('&');
  294. }
  295. window.location.href = link;
  296. });
  297. });
  298. $('#judge-start-btn').click(function () {
  299. const flag = !(inspection.code && inspection.check_item && inspection.check_date);
  300. if (flag) {
  301. toastr.warning('请完善巡检信息再提交');
  302. return;
  303. }
  304. if ($('#auditors li').length === 0) {
  305. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  306. toastr.error('请联系管理员添加审批人');
  307. } else {
  308. toastr.error('请先选择审批人,再上报数据');
  309. }
  310. return false;
  311. }
  312. $('#sp-done').modal('show');
  313. });
  314. $('#start-btn').click(function () {
  315. $('#start-btn').prop('disabled', true);
  316. postData(preUrl + '/save', { type: 'start-inspection' }, function (result) {
  317. window.location.reload();
  318. });
  319. });
  320. } else if (inspection.shenpiPower) {
  321. // 添加到审批流程中
  322. $('dl').on('click', 'dd', function () {
  323. const id = parseInt($(this).data('id'))
  324. if (id !== 0) {
  325. const user = _.find(accountList, { id });
  326. $('#rectification-user-set').html(`<span class="badge">
  327. ${user.name}
  328. <span class="dropdown">
  329. <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>
  330. <div class="dropdown-menu">
  331. <a class="dropdown-item" href="javascript:void(0);">确认移除整改人?</a>
  332. <div class="dropdown-divider"></div>
  333. <div class="px-2 py-1 text-center">
  334. <button class="btn btn-sm btn-danger remove-btn">移除</button>
  335. <button class="btn btn-sm btn-secondary">取消</button>
  336. </div>
  337. </div>
  338. </span>
  339. </span>`);
  340. $('#rectification-uid').val(user.id);
  341. $('#rectification-user-set').siblings('.dropdown').attr('style', 'display:none!important;');
  342. }
  343. });
  344. // 删除审批人
  345. $('body').on('click', '#rectification-user-set .remove-btn', function () {
  346. $('#rectification-user-set').html('');
  347. $('#rectification-uid').val('');
  348. $('#rectification-user-set').siblings('.dropdown').show();
  349. });
  350. $('#approval-success-btn').click(function () {
  351. if (inspection.finalAuditorIds.indexOf(cur_uid) !== -1 && $('#rectification-uid').val() === '') {
  352. toastr.warning('请选择整改人');
  353. return;
  354. }
  355. const opinion = $('#sp-done').find('textarea[name="opinion"]').eq(0).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  356. if (opinion.length === 0) {
  357. toastr.warning('请填写审核意见');
  358. return;
  359. }
  360. const data = {
  361. type: 'check',
  362. checkType: auditConst.status.checked,
  363. opinion,
  364. rectification_uid: $('#rectification-uid').val(),
  365. }
  366. postData(preUrl + '/save', data, function (result) {
  367. window.location.reload();
  368. });
  369. });
  370. $('#approval-back-btn').click(function () {
  371. console.log($('#sp-back').find('textarea[name="opinion"]').eq(0).val());
  372. const opinion = $('#sp-back').find('textarea[name="opinion"]').eq(0).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  373. if (opinion.length === 0) {
  374. toastr.warning('请填写审核意见');
  375. return;
  376. }
  377. const inlineRadio1 = $('#inlineRadio1:checked').val();
  378. const inlineRadio2 = $('#inlineRadio2:checked').val();
  379. if (!inlineRadio1 && !inlineRadio2) {
  380. if (!$('#warning-text').length) {
  381. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  382. }
  383. return;
  384. }
  385. if ($('#warning-text').length) $('#warning-text').remove()
  386. const data = {
  387. type: 'check',
  388. checkType: parseInt(inlineRadio1 ? inlineRadio1 : inlineRadio2),
  389. opinion,
  390. }
  391. postData(preUrl + '/save', data, function (result) {
  392. window.location.reload();
  393. });
  394. });
  395. $('#approval-stop-btn').click(function () {
  396. const opinion = $('#sp-close').find('textarea[name="opinion"]').eq(0).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  397. if (opinion.length === 0) {
  398. toastr.warning('请填写关闭原因');
  399. return;
  400. }
  401. const data = {
  402. type: 'check',
  403. checkType: auditConst.status.checkStop,
  404. opinion,
  405. }
  406. postData(preUrl + '/save', data, function (result) {
  407. window.location.reload();
  408. });
  409. });
  410. } else if (inspection.rectificationPower) {
  411. $('#judge-success-btn').click(function () {
  412. const flag = !(inspection.rectification_item && inspection.rectification_date);
  413. if (flag) {
  414. toastr.warning('请完善整改单再提交');
  415. return;
  416. }
  417. $('#sp-done').modal('show');
  418. });
  419. // 整改完成
  420. $('#rectification-success-btn').click(function () {
  421. const opinion = $('#sp-done').find('textarea[name="opinion"]').eq(0).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  422. if (opinion.length === 0) {
  423. toastr.warning('请填写审核意见');
  424. return;
  425. }
  426. const data = {
  427. type: 'rectification',
  428. checkType: auditConst.status.checked,
  429. opinion,
  430. }
  431. postData(preUrl + '/save', data, function (result) {
  432. window.location.reload();
  433. });
  434. });
  435. $('#rectification-back-btn').click(function () {
  436. const opinion = $('#sp-back').find('textarea[name="opinion"]').eq(0).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  437. if (opinion.length === 0) {
  438. toastr.warning('请填写审核意见');
  439. return;
  440. }
  441. const data = {
  442. type: 'rectification',
  443. checkType: auditConst.status.checkNoPre,
  444. opinion,
  445. }
  446. postData(preUrl + '/save', data, function (result) {
  447. window.location.reload();
  448. });
  449. });
  450. const rectificationDate = $('#rectification_date').datepicker({
  451. autoClose: true,
  452. onSelect: function (formattedDate, date, inst) {
  453. if (!date && inspection.rectification_date) {
  454. toastr.error('检查日期不能为空');
  455. rectificationDate.selectDate(inspection.rectification_date ? new Date(inspection.rectification_date) : '');
  456. return;
  457. }
  458. // 判断日期格式
  459. const rectification_date = moment(date).format('YYYY-MM-DD');
  460. const reg = /^\d{4}-\d{2}-\d{2}$/;
  461. if (!reg.test(rectification_date)) {
  462. toastr.error('整改日期格式错误,应为YYYY-MM-DD。');
  463. return;
  464. }
  465. if (rectification_date !== moment(inspection.rectification_date).format('YYYY-MM-DD')) {
  466. updateInspection('rectification_date', rectification_date);
  467. }
  468. }
  469. }).data('datepicker');
  470. rectificationDate.selectDate(inspection.rectification_date ? new Date(inspection.rectification_date) : '');
  471. $('#rectification_table textarea').on('change', function (e) {
  472. const value = $(this).val().trim();
  473. const key = $(this).data('key');
  474. if (value !== inspection[key]) {
  475. updateInspection(key, value);
  476. }
  477. });
  478. $("#rectification_table input").on('change', function (e) {
  479. const value = $(this).val().trim();
  480. const key = $(this).data('key');
  481. if (key === 'check_date') {
  482. if (!value && inspection.rectification_date) {
  483. toastr.error('检查日期不能为空');
  484. rectificationDate.selectDate(inspection.rectification_date ? new Date(inspection.rectification_date) : '');
  485. return;
  486. }
  487. // 判断日期格式
  488. const reg = /^\d{4}-\d{2}-\d{2}$/;
  489. if (!reg.test(value)) {
  490. toastr.error('检查日期格式错误,应为YYYY-MM-DD。');
  491. rectificationDate.selectDate(inspection.rectification_date ? new Date(inspection.rectification_date) : '');
  492. return;
  493. }
  494. }
  495. if (value !== inspection[key]) {
  496. updateInspection(key, value);
  497. }
  498. });
  499. function updateInspection(field, value) {
  500. const data = {
  501. id: inspection.id,
  502. };
  503. data[field] = value;
  504. console.log(data);
  505. postData(`${preUrl}/save`, {type: 'update-field', update: data}, function (result) {
  506. inspection[field] = value;
  507. if (field === 'rectification_date') {
  508. rectificationDate.selectDate(inspection.rectification_date ? new Date(inspection.rectification_date) : '');
  509. }
  510. }, function () {
  511. if (field === 'rectification_date') {
  512. rectificationDate.selectDate(inspection.rectification_date ? new Date(inspection.rectification_date) : '');
  513. } else {
  514. $(`#rectification_table textarea[data-key=${field}]`).val(inspection[field] || '');
  515. }
  516. });
  517. }
  518. }
  519. handleFileList(fileList);
  520. $('#file-ok').click(function () {
  521. const files = Array.from($('#file-modal')[0].files)
  522. const valiData = files.map(v => {
  523. const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
  524. return {
  525. size: v.size,
  526. ext
  527. }
  528. });
  529. if (validateFiles(valiData)) {
  530. if (files.length) {
  531. const formData = new FormData();
  532. files.forEach(file => {
  533. formData.append('name', file.name);
  534. formData.append('size', file.size);
  535. formData.append('file', file);
  536. })
  537. postDataWithFile(`${preUrl}/file/upload`, formData, function (result) {
  538. handleFileList(result);
  539. $('#file-modal').val('');
  540. $('#file-cancel').click();
  541. });
  542. }
  543. }
  544. })
  545. function handleFileList(files = []) {
  546. $('#file-content').empty();
  547. const newFiles = files.map(file => {
  548. let showDel = false;
  549. if (file.uid === cur_uid) {
  550. if (inspection.status === auditConst.status.checked) {
  551. showDel = Boolean(file.extra_upload ) || deleteFilePermission
  552. } else {
  553. showDel = true
  554. }
  555. }
  556. return {...file, showDel}
  557. })
  558. 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>` : '';
  559. newFiles.forEach((file, idx) => {
  560. if (file.showDel) {
  561. 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>`
  562. } else {
  563. 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>`
  564. }
  565. })
  566. $('#file-content').append(html);
  567. }
  568. $('#file-content').on('click', 'a', function () {
  569. if ($(this).hasClass('file-del')) {
  570. const id = $(this).data('id');
  571. postData(`${preUrl}/file/delete`, {id}, (result) => {
  572. handleFileList(result);
  573. })
  574. }
  575. });
  576. })
  577. /**
  578. * 校验文件大小、格式
  579. * @param {Array} files 文件数组
  580. */
  581. function validateFiles(files) {
  582. if (files.length > 10) {
  583. toastr.error('至多同时上传10个文件');
  584. return false
  585. }
  586. return files.every(file => {
  587. if (file.size > 1024 * 1024 * 50) {
  588. toastr.error('文件大小限制为50MB');
  589. return false
  590. }
  591. if (whiteList.indexOf('.' + file.ext) === -1) {
  592. toastr.error('请上传正确的格式文件');
  593. return false
  594. }
  595. return true
  596. })
  597. }