change_detail.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. if (!$('.change-detail-checkbox').is(':checked')) {
  40. const column = table.column(3);
  41. column.visible(!column.visible());
  42. }
  43. $('#bills').removeClass('first-bill-pane');
  44. }
  45. });
  46. // 上传附件
  47. $('#upload-file-btn').click(function () {
  48. const files = $('#upload-file')[0].files;
  49. const formData = new FormData();
  50. formData.append('cid', $('#changeId').val());
  51. formData.append('tid', $('#tenderId').val());
  52. for (const file of files) {
  53. if (file === undefined) {
  54. toastr.error('未选择上传文件!');
  55. return false;
  56. }
  57. const filesize = file.size;
  58. if (filesize > 30 * 1024 * 1024) {
  59. toastr.error('文件大小过大!');
  60. return false;
  61. }
  62. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  63. if (whiteList.indexOf(fileext) === -1) {
  64. toastr.error('只能上传指定格式的附件!');
  65. return false;
  66. }
  67. formData.append('size', filesize);
  68. formData.append('file[]', file);
  69. }
  70. postDataWithFile('/change/upload/file', formData, function (data) {
  71. $('#addfujian').modal('hide');
  72. let html = '';
  73. let index = $('#attList tr').length + 1;
  74. for (const fileInfo of data) {
  75. html += '<tr> ' +
  76. '<td>' + index + '</td> ' +
  77. '<td><a href="/change/download/file/' + fileInfo.id + '">' + fileInfo.filename + fileInfo.fileext + '</a></td> ' +
  78. '<td>' + fileInfo.filesize + '</td> ' +
  79. '<td>' + fileInfo.in_time + '</td> ' +
  80. '<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> ' +
  81. '</tr>';
  82. ++index;
  83. }
  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. const cca = getLocalCache('change-checkbox-account-' + accountId);
  107. if (cca !== null && cca !== undefined) {
  108. $('#customCheck1').prop('checked', cca !== 'false');
  109. }
  110. // 变更详情展示和隐藏
  111. $('.change-detail-checkbox').on('click', function (e) {
  112. if($(e.target).is('label')){
  113. return;
  114. }
  115. let column = table.column(3);
  116. // 设置用户项目本地记录展示和隐藏情况
  117. setLocalCache('change-checkbox-account-'+ accountId, $(this).is(':checked'));
  118. column.visible(!column.visible());
  119. })
  120. // 重新审批获取手机验证码
  121. // 获取验证码
  122. let isPosting = false;
  123. $("#get-code").click(function() {
  124. if (isPosting) {
  125. return false;
  126. }
  127. const btn = $(this);
  128. $.ajax({
  129. url: '/profile/code?_csrf=' + csrf,
  130. type: 'post',
  131. data: { mobile: authMobile, type: 'shenpi' },
  132. dataTye: 'json',
  133. error: function() {
  134. isPosting = false;
  135. },
  136. beforeSend: function() {
  137. isPosting = true;
  138. },
  139. success: function(response) {
  140. isPosting = false;
  141. if (response.err === 0) {
  142. codeSuccess(btn);
  143. $("input[name='code']").removeAttr('readonly');
  144. $("#re-shenpi-btn").removeAttr('disabled');
  145. } else {
  146. toast(response.msg, 'error');
  147. }
  148. }
  149. });
  150. });
  151. });
  152. /**
  153. * 获取成功后的操作
  154. *
  155. * @param {Object} btn - 点击的按钮
  156. * @return {void}
  157. */
  158. function codeSuccess(btn) {
  159. let counter = 60;
  160. btn.addClass('disabled').text('重新获取 ' + counter + 'S');
  161. btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');
  162. const bindBtn = $("#bind-btn");
  163. bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');
  164. const countDown = setInterval(function() {
  165. const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S';
  166. // 倒数结束后
  167. if (countString === '') {
  168. clearInterval(countDown);
  169. btn.removeClass('disabled');
  170. }
  171. const text = '重新获取' + countString;
  172. btn.text(text);
  173. counter -= 1;
  174. }, 1000);
  175. }