change_detail.js 9.0 KB

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