change_detail.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 width="25"><input type="checkbox" class="check-file" file-id=${fileInfo.id}></td>` +
  77. '<td>' + index + '</td> ' +
  78. `<td><a href="javascript: void(0);" class="file-atn" f-id="${fileInfo.id}">${fileInfo.filename}${fileInfo.fileext}</a></td>`+
  79. '<td>' + fileInfo.filesize + '</td> ' +
  80. '<td>' + fileInfo.in_time + '</td> ' +
  81. `<td>
  82. <a href="/change/download/file/${fileInfo.id}" class="btn btn-light btn-sm" title="下载"><span class="fa fa-download text-primary"></span></a>
  83. <a class="btn btn-light btn-sm delete-file" data-attid="${fileInfo.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>
  84. </td>`+
  85. // '<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> ' +
  86. '</tr>';
  87. ++index;
  88. }
  89. $('#attList').append(html);
  90. }, function () {
  91. });
  92. $('#upload-file').val('');
  93. });
  94. // 删除附件
  95. $('body').on('click', '.delete-file', function () {
  96. let attid = $(this).data('attid');
  97. let self = $(this);
  98. const data = {id: attid};
  99. postData('/change/delete/file', data, function (result) {
  100. self.parents('tr').remove();
  101. // 重新排序
  102. let newsort = 1;
  103. $('#attList tr').each(function(){
  104. $(this).children('td').eq(1).text(newsort);
  105. newsort++;
  106. });
  107. });
  108. });
  109. // /change/download/file/
  110. $('#attList').on('click', '.file-atn', function() {
  111. const id = $(this).attr('f-id')
  112. postData(`/change/download/file/${id}`, {}, (data) => {
  113. const { filepath } = data
  114. $('#file-upload').attr('href', filepath)
  115. $('#file-upload')[0].click()
  116. })
  117. })
  118. $('#attList').on('click', '.check-file', function() {
  119. const checkedList = $('#attList').find('input:checked')
  120. const childs = $('#attList').children().length
  121. const checkBox = $('#check-all-file')
  122. if (checkedList.length === childs) {
  123. checkBox.prop("checked", true)
  124. } else {
  125. checkBox.prop("checked", false)
  126. }
  127. })
  128. $('#check-all-file').click(function() {
  129. const isCheck = $(this).is(':checked')
  130. $('#attList').children().each(function() {
  131. $(this).find('input:checkbox').prop("checked", isCheck)
  132. })
  133. });
  134. $('#bach-download').click(function() {
  135. const fileIds = []
  136. $( '#attList .check-file:checked').each(function() {
  137. const fileId = $(this).attr('file-id')
  138. fileId && fileIds.push(fileId)
  139. })
  140. if (fileIds.length) {
  141. const tid = $('#tenderId').val()
  142. const cid = $('#changeId').val()
  143. $('#downloadZip').attr('href', `/tender/${tid}/change/${cid}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`);
  144. $('#downloadZip')[0].click();
  145. }
  146. });
  147. //
  148. const cca = getLocalCache('change-checkbox-account-' + accountId);
  149. if (cca !== null && cca !== undefined) {
  150. $('#customCheck1').prop('checked', cca !== 'false');
  151. }
  152. // 变更详情展示和隐藏
  153. $('.change-detail-checkbox').on('click', function (e) {
  154. if($(e.target).is('label')){
  155. return;
  156. }
  157. let column = table.column(3);
  158. // 设置用户项目本地记录展示和隐藏情况
  159. setLocalCache('change-checkbox-account-'+ accountId, $(this).is(':checked'));
  160. column.visible(!column.visible());
  161. })
  162. // 重新审批获取手机验证码
  163. // 获取验证码
  164. let isPosting = false;
  165. $("#get-code").click(function() {
  166. if (isPosting) {
  167. return false;
  168. }
  169. const btn = $(this);
  170. $.ajax({
  171. url: '/profile/code?_csrf=' + csrf,
  172. type: 'post',
  173. data: { mobile: authMobile, type: 'shenpi' },
  174. dataTye: 'json',
  175. error: function() {
  176. isPosting = false;
  177. },
  178. beforeSend: function() {
  179. isPosting = true;
  180. },
  181. success: function(response) {
  182. isPosting = false;
  183. if (response.err === 0) {
  184. codeSuccess(btn);
  185. $("input[name='code']").removeAttr('readonly');
  186. $("#re-shenpi-btn").removeAttr('disabled');
  187. } else {
  188. toast(response.msg, 'error');
  189. }
  190. }
  191. });
  192. });
  193. });
  194. /**
  195. * 获取成功后的操作
  196. *
  197. * @param {Object} btn - 点击的按钮
  198. * @return {void}
  199. */
  200. function codeSuccess(btn) {
  201. let counter = 60;
  202. btn.addClass('disabled').text('重新获取 ' + counter + 'S');
  203. btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');
  204. const bindBtn = $("#bind-btn");
  205. bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');
  206. const countDown = setInterval(function() {
  207. const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S';
  208. // 倒数结束后
  209. if (countString === '') {
  210. clearInterval(countDown);
  211. btn.removeClass('disabled');
  212. }
  213. const text = '重新获取' + countString;
  214. btn.text(text);
  215. counter -= 1;
  216. }, 1000);
  217. }