change_detail.js 8.8 KB

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