change_detail.js 9.5 KB

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