change_detail.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. if (fileIds.length > 10) {
  161. return toastr.warning(`最大允许10个文件(当前${fileIds.length}个)`);
  162. }
  163. const tid = $('#tenderId').val();
  164. const cid = $('#changeId').val();
  165. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0});
  166. $(this).attr('disabled', "true");
  167. const btn = $(this);
  168. postCompressFile(`/tender/${tid}/change/${cid}/download/compresse-file`, {fileIds}, function(result) {
  169. toastr.clear();
  170. toastr.success('压缩文件成功');
  171. btn.removeAttr('disabled');
  172. const href = window.URL.createObjectURL(result);
  173. $('#zipDown').attr('href', href);
  174. $('#zipDown').attr('download', `${tenderName}-工程变更-${changeName}-附件.zip`);
  175. $("#zipDown")[0].click();
  176. }, () => {
  177. btn.removeAttr('disabled');
  178. toastr.clear();
  179. toastr.error('批量下载失败');
  180. });
  181. // $('#downloadZip').attr('href', `/tender/${tid}/change/${cid}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`);
  182. // $('#downloadZip')[0].click();
  183. }
  184. });
  185. //
  186. const cca = getLocalCache('change-checkbox-account-' + accountId);
  187. if (cca !== null && cca !== undefined) {
  188. $('#customCheck1').prop('checked', cca !== 'false');
  189. }
  190. // 变更详情展示和隐藏
  191. $('.change-detail-checkbox').on('click', function (e) {
  192. if($(e.target).is('label')){
  193. return;
  194. }
  195. let column = table.column(3);
  196. // 设置用户项目本地记录展示和隐藏情况
  197. setLocalCache('change-checkbox-account-'+ accountId, $(this).is(':checked'));
  198. column.visible(!column.visible());
  199. })
  200. // 重新审批获取手机验证码
  201. // 获取验证码
  202. let isPosting = false;
  203. $("#get-code").click(function() {
  204. if (isPosting) {
  205. return false;
  206. }
  207. const btn = $(this);
  208. $.ajax({
  209. url: '/profile/code?_csrf_j=' + csrf,
  210. type: 'post',
  211. data: { mobile: authMobile, type: 'shenpi' },
  212. dataTye: 'json',
  213. error: function() {
  214. isPosting = false;
  215. },
  216. beforeSend: function() {
  217. isPosting = true;
  218. },
  219. success: function(response) {
  220. isPosting = false;
  221. if (response.err === 0) {
  222. codeSuccess(btn);
  223. $("input[name='code']").removeAttr('readonly');
  224. $("#re-shenpi-btn").removeAttr('disabled');
  225. } else {
  226. toast(response.msg, 'error');
  227. }
  228. }
  229. });
  230. });
  231. });
  232. /**
  233. * 获取成功后的操作
  234. *
  235. * @param {Object} btn - 点击的按钮
  236. * @return {void}
  237. */
  238. function codeSuccess(btn) {
  239. let counter = 60;
  240. btn.addClass('disabled').text('重新获取 ' + counter + 'S');
  241. btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');
  242. const bindBtn = $("#bind-btn");
  243. bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');
  244. const countDown = setInterval(function() {
  245. const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S';
  246. // 倒数结束后
  247. if (countString === '') {
  248. clearInterval(countDown);
  249. btn.removeClass('disabled');
  250. }
  251. const text = '重新获取' + countString;
  252. btn.text(text);
  253. counter -= 1;
  254. }, 1000);
  255. }