change_detail.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. table = $('.table-list').removeAttr('width').DataTable(billsTable);
  36. $('#bills').removeClass('first-bill-pane');
  37. }
  38. });
  39. // 上传附件
  40. $('#upload-file-btn').click(function () {
  41. const files = $('#upload-file')[0].files;
  42. const formData = new FormData();
  43. formData.append('cid', $('#changeId').val());
  44. formData.append('tid', $('#tenderId').val());
  45. for (const file of files) {
  46. if (file === undefined) {
  47. toastr.error('未选择上传文件!');
  48. return false;
  49. }
  50. const filesize = file.size;
  51. if (filesize > 30 * 1024 * 1024) {
  52. toastr.error('文件大小过大!');
  53. return false;
  54. }
  55. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  56. if (whiteList.indexOf(fileext) === -1) {
  57. toastr.error('只能上传指定格式的附件!');
  58. return false;
  59. }
  60. formData.append('size', filesize);
  61. formData.append('file[]', file);
  62. }
  63. postDataWithFile('/change/upload/file', formData, function (data) {
  64. $('#addfujian').modal('hide');
  65. let html = '';
  66. let index = $('#attList tr').length + 1;
  67. for (const fileInfo of data) {
  68. html += '<tr> ' +
  69. '<td>' + index + '</td> ' +
  70. '<td><a href="/change/download/file/' + fileInfo.id + '">' + fileInfo.filename + fileInfo.fileext + '</a></td> ' +
  71. '<td>' + fileInfo.filesize + '</td> ' +
  72. '<td>' + fileInfo.in_time + '</td> ' +
  73. '<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> ' +
  74. '</tr>';
  75. ++index;
  76. }
  77. $('#attList').append(html);
  78. }, function () {
  79. });
  80. $('#upload-file').val('');
  81. });
  82. // 删除附件
  83. $('body').on('click', '.delete-file', function () {
  84. let attid = $(this).data('attid');
  85. console.log(attid);
  86. let self = $(this);
  87. const data = {id: attid};
  88. postData('/change/delete/file', data, function (result) {
  89. self.parents('tr').remove();
  90. // 重新排序
  91. let newsort = 1;
  92. $('#attList tr').each(function(){
  93. $(this).children('td').eq(0).text(newsort);
  94. newsort++;
  95. });
  96. });
  97. });
  98. // 变更详情展示和隐藏
  99. $('.change-detail-checkbox').on('click', function (e) {
  100. if($(e.target).is('label')){
  101. return;
  102. }
  103. let column = table.column(3);
  104. column.visible(!column.visible());
  105. })
  106. });