change_detail.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. 'use strict';
  2. /**
  3. * 变更令详细页js
  4. *
  5. * @author EllisRan.
  6. * @date 2018/11/22
  7. * @version
  8. */
  9. $.event.special.valuechange = {
  10. teardown: function (namespaces) {
  11. $(this).unbind('.valuechange');
  12. },
  13. handler: function (e) {
  14. $.event.special.valuechange.triggerChanged($(this));
  15. },
  16. add: function (obj) {
  17. $(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange', obj.selector, $.event.special.valuechange.handler)
  18. },
  19. triggerChanged: function (element) {
  20. var current = element[0].contentEditable === 'true' ? element.html() : element.val()
  21. , previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous');
  22. if (current !== previous) {
  23. element.trigger('valuechange', [element.data('previous')]);
  24. element.data('previous', current);
  25. }
  26. }
  27. };
  28. $(document).ready(() => {
  29. // tab切换
  30. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  31. const tab = $(this).attr('aria-controls');
  32. $('.show_title').hide();
  33. $('#'+ tab +'_title').show();
  34. if (tab === 'bills' && $('#bills').hasClass('first-bill-pane')) {
  35. if (table) {
  36. table.destroy();
  37. }
  38. table = $('.table-list').removeAttr('width').DataTable(billsTable);
  39. $('#bills').removeClass('first-bill-pane');
  40. }
  41. });
  42. // 上传附件
  43. $('#upload-file-btn').click(function () {
  44. const files = $('#upload-file')[0].files;
  45. const formData = new FormData();
  46. formData.append('cid', $('#changeId').val());
  47. formData.append('tid', $('#tenderId').val());
  48. for (const file of files) {
  49. if (file === undefined) {
  50. toastr.error('未选择上传文件!');
  51. return false;
  52. }
  53. const filesize = file.size;
  54. if (filesize > 30 * 1024 * 1024) {
  55. toastr.error('文件大小过大!');
  56. return false;
  57. }
  58. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  59. if (whiteList.indexOf(fileext) === -1) {
  60. toastr.error('只能上传指定格式的附件!');
  61. return false;
  62. }
  63. formData.append('size', filesize);
  64. formData.append('file[]', file);
  65. }
  66. postDataWithFile('/change/upload/file', formData, function (data) {
  67. $('#addfujian').modal('hide');
  68. let html = '';
  69. let index = $('#attList tr').length + 1;
  70. for (const fileInfo of data) {
  71. html += '<tr> ' +
  72. '<td>' + index + '</td> ' +
  73. '<td><a href="/change/download/file/' + fileInfo.id + '">' + fileInfo.filename + fileInfo.fileext + '</a></td> ' +
  74. '<td>' + fileInfo.filesize + '</td> ' +
  75. '<td>' + fileInfo.in_time + '</td> ' +
  76. '<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> ' +
  77. '</tr>';
  78. ++index;
  79. }
  80. $('#attList').append(html);
  81. }, function () {
  82. });
  83. $('#upload-file').val('');
  84. });
  85. // 删除附件
  86. $('body').on('click', '.delete-file', function () {
  87. let attid = $(this).data('attid');
  88. console.log(attid);
  89. let self = $(this);
  90. const data = {id: attid};
  91. postData('/change/delete/file', data, function (result) {
  92. self.parents('tr').remove();
  93. // 重新排序
  94. let newsort = 1;
  95. $('#attList tr').each(function(){
  96. $(this).children('td').eq(0).text(newsort);
  97. newsort++;
  98. });
  99. });
  100. });
  101. // 变更详情展示和隐藏
  102. $('.change-detail-checkbox').on('click', function (e) {
  103. if($(e.target).is('label')){
  104. return;
  105. }
  106. let column = table.column(3);
  107. column.visible(!column.visible());
  108. })
  109. });