change_detail.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. /**
  3. * 变更令详细页js
  4. *
  5. * @author EllisRan.
  6. * @date 2018/11/22
  7. * @version
  8. */
  9. $(document).ready(() => {
  10. // tab切换
  11. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  12. const tab = $(this).attr('aria-controls');
  13. $('.show_title').hide();
  14. $('#'+ tab +'_title').show();
  15. });
  16. // 上传附件
  17. $('#upload-file-btn').click(function () {
  18. const file = $('#upload-file')[0];
  19. if (file.files[0] === undefined) {
  20. toastr.error('未选择上传文件!');
  21. return false;
  22. }
  23. const filesize = file.files[0].size;
  24. if (filesize > 30 * 1024 * 1024) {
  25. toastr.error('文件大小过大!');
  26. return false;
  27. }
  28. const fileext = '.' + file.files[0].name.toLowerCase().split('.').splice(-1)[0];
  29. if (whiteList.indexOf(fileext) === -1) {
  30. toastr.error('只能上传指定格式的附件!');
  31. return false;
  32. }
  33. const formData = new FormData();
  34. formData.append('cid', $('#changeId').val());
  35. formData.append('tid', $('#tenderId').val());
  36. formData.append('size', filesize);
  37. formData.append('file', file.files[0]);
  38. postDataWithFile('/change/upload/file', formData, function (data) {
  39. $('#addfujian').modal('hide');
  40. console.log(data);
  41. const fileInfo = data;
  42. let index = $('#attList tr').length;
  43. let html = '<tr> ' +
  44. '<td>' + (index+1) + '</td> ' +
  45. '<td><a href="/change/download/file/' + fileInfo.id + '">' + fileInfo.filename + fileInfo.fileext + '</a></td> ' +
  46. '<td>' + fileInfo.filesize + '</td> ' +
  47. '<td>' + fileInfo.in_time + '</td> ' +
  48. '<td> <a class="btn btn-light btn-sm delete-file" data-attid="' + fileInfo.id + '" title="删除附件"><span class="fa fa-trash text-danger"></span></a> </td> ' +
  49. '</tr>';
  50. $('#attList').append(html);
  51. }, function () {
  52. });
  53. $('#upload-file').val('');
  54. });
  55. $('body').on('click', '.delete-file', function () {
  56. let attid = $(this).data('attid');
  57. console.log(attid);
  58. let self = $(this);
  59. const data = {id: attid};
  60. postData('/change/delete/file', data, function (result) {
  61. self.parents('tr').remove();
  62. // 重新排序
  63. let newsort = 1;
  64. $('#attList tr').each(function(){
  65. $(this).children('td').eq(0).text(newsort);
  66. newsort++;
  67. });
  68. });
  69. })
  70. });