change_detail.js 4.4 KB

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