change_information.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. 'use strict';
  2. /**
  3. * 变更令详细页js
  4. *
  5. * @author EllisRan.
  6. * @date 2018/11/22
  7. * @version
  8. */
  9. const is_numeric = (value) => {
  10. if (typeof(value) === 'object') {
  11. return false;
  12. } else {
  13. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  14. }
  15. };
  16. $(document).ready(() => {
  17. //初始化所有附件列表
  18. getAllList();
  19. const cca = getLocalCache('change-checkbox-account-' + accountId);
  20. if (cca !== null && cca !== undefined) {
  21. $('#customCheck1').prop('checked', cca !== 'false');
  22. }
  23. changeSpreadSheet.setColumnVisible(3,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  24. // 变更详情展示和隐藏
  25. $('.change-detail-checkbox').on('click', function (e) {
  26. if($(e.target).is('label')){
  27. return;
  28. }
  29. // // 设置用户项目本地记录展示和隐藏情况
  30. setLocalCache('change-checkbox-account-'+ accountId, $(this).is(':checked'));
  31. changeSpreadSheet.setColumnVisible(3,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  32. });
  33. //tab change
  34. $('a[data-toggle="tab"]').on('shown.bs.tab', function () {
  35. const tab = $(this).data('tab');
  36. if (tab === 'bgfujian') {
  37. $('#fujian_btn').show();
  38. } else {
  39. $('#fujian_btn').hide();
  40. }
  41. });
  42. $('#add-bj').on('click', 'input[type="checkbox"]', function () {
  43. const isCheck = $(this).prop('checked');
  44. if (isCheck) {
  45. $('#add-bj input[type="checkbox"]').each(function () {
  46. $(this).prop('checked', false)
  47. });
  48. $(this).prop('checked', true)
  49. }
  50. });
  51. $('#bg-copy').click(function() {
  52. const cid = $('#add-bj input:checked').data('id');
  53. postData(window.location.pathname + '/copy', cid, function () {
  54. window.location.reload();
  55. })
  56. });
  57. // 上传附件
  58. $('#upload-file-btn').click(function () {
  59. const files = $('#upload-file')[0].files;
  60. const formData = new FormData();
  61. formData.append('cid', $('#changeId').val());
  62. formData.append('tid', $('#tenderId').val());
  63. for (const file of files) {
  64. if (file === undefined) {
  65. toastr.error('未选择上传文件!');
  66. return false;
  67. }
  68. const filesize = file.size;
  69. if (filesize > 30 * 1024 * 1024) {
  70. toastr.error('文件大小过大!');
  71. return false;
  72. }
  73. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  74. if (whiteList.indexOf(fileext) === -1) {
  75. toastr.error('只能上传指定格式的附件!');
  76. return false;
  77. }
  78. formData.append('size', filesize);
  79. formData.append('file[]', file);
  80. }
  81. if (auditList.findIndex(item => item.uid === parseInt(accountId)) === -1) {
  82. return toastr.error('暂无权限上传!');
  83. }
  84. postDataWithFile(window.location.pathname + '/file/upload', formData, function (data) {
  85. attData = data.concat(attData);
  86. // 重新生成List
  87. getAllList();
  88. $('#addfujian').modal('hide');
  89. // let html = '';
  90. // let index = $('#attList tr').length + 1;
  91. // for (const fileInfo of data) {
  92. // html += '<tr> ' +
  93. // `<td width="20"><input type="checkbox" class="check-file" file-id=${fileInfo.id}></td>` +
  94. // '<td>' + index + '</td> ' +
  95. // `<td><a href="javascript: void(0);" class="file-atn" f-id="${fileInfo.id}">${fileInfo.filename}${fileInfo.fileext}</a></td>`+
  96. // '<td>' + fileInfo.in_time + '<br>' + fileInfo.filesize + '</td> ' +
  97. // `<td><a href="/change/download/file/${fileInfo.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`+
  98. // ( auditStatus === 4 ?
  99. // fileInfo.extra_upload ? `<a class="mr-2 delete-file" data-attid="${fileInfo.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : ''
  100. // : ` <a href="javascript:void(0);" class="mr-2 delete-file" data-attid="${fileInfo.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>`)+
  101. // `</td>`+
  102. // // '<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> ' +
  103. // '</tr>';
  104. // ++index;
  105. // }
  106. // $('#attList').append(html);
  107. }, function () {
  108. });
  109. $('#upload-file').val('');
  110. });
  111. // 删除附件
  112. $('body').on('click', '.delete-file', function () {
  113. let attid = $(this).data('attid');
  114. let self = $(this);
  115. const data = {id: attid};
  116. postData(window.location.pathname + '/file/delete', data, function (result) {
  117. // self.parents('tr').remove();
  118. // // 重新排序
  119. // let newsort = 1;
  120. // $('#attList tr').each(function(){
  121. // $(this).children('td').eq(1).text(newsort);
  122. // newsort++;
  123. // });
  124. // 删除到attData中
  125. const att_index = attData.findIndex(function (item) {
  126. return item.id === parseInt(attid);
  127. });
  128. attData.splice(att_index, 1);
  129. // 重新生成List
  130. if ($('#attList tr').length === 1) {
  131. getAllList(parseInt($('#currentPage').text()) - 1);
  132. } else {
  133. getAllList(parseInt($('#currentPage').text()));
  134. }
  135. });
  136. });
  137. // /change/download/file/
  138. $('#attList').on('click', '.file-atn', function() {
  139. const id = $(this).attr('f-id');
  140. postData(`/change/download/file/${id}`, {}, (data) => {
  141. const { filepath } = data;
  142. $('#file-upload').attr('href', filepath);
  143. $('#file-upload')[0].click();
  144. })
  145. });
  146. $('#attList').on('click', '.check-file', function() {
  147. const checkedList = $('#attList').find('input:checked');
  148. const childs = $('#attList').children().length;
  149. const checkBox = $('#check-all-file');
  150. if (checkedList.length === childs) {
  151. checkBox.prop("checked", true);
  152. } else {
  153. checkBox.prop("checked", false);
  154. }
  155. });
  156. $('#check-all-file').click(function() {
  157. const isCheck = $(this).is(':checked');
  158. $('#attList').children().each(function() {
  159. $(this).find('input:checkbox').prop("checked", isCheck);
  160. })
  161. });
  162. $('#bach-download').click(function() {
  163. const fileIds = [];
  164. $( '#attList .check-file:checked').each(function() {
  165. const fileId = $(this).attr('file-id');
  166. fileId && fileIds.push(fileId);
  167. });
  168. if (fileIds.length) {
  169. const tid = $('#tenderId').val();
  170. const cid = $('#changeId').val();
  171. $('#downloadZip').attr('href', `/tender/${tid}/change/${cid}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`);
  172. $('#downloadZip')[0].click();
  173. }
  174. });
  175. $.subMenu({
  176. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  177. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  178. key: 'menu.1.0.0',
  179. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  180. callback: function (info) {
  181. if (info.mini) {
  182. $('.panel-title').addClass('fluid');
  183. $('#sub-menu').removeClass('panel-sidebar');
  184. } else {
  185. $('.panel-title').removeClass('fluid');
  186. $('#sub-menu').addClass('panel-sidebar');
  187. }
  188. autoFlashHeight();
  189. changeSpread.refresh();
  190. }
  191. });
  192. // 切换页数
  193. $('.page-select').on('click', function () {
  194. const totalPageNum = parseInt($('#totalPage').text());
  195. const lastPageNum = parseInt($('#currentPage').text());
  196. const status = $(this).attr('content');
  197. if (status === 'pre' && lastPageNum > 1) {
  198. getAllList(lastPageNum-1);
  199. $('#showAttachment').hide();
  200. $('#syfujian .check-all-file').prop('checked', false)
  201. } else if (status === 'next' && lastPageNum < totalPageNum) {
  202. getAllList(lastPageNum+1);
  203. $('#showAttachment').hide();
  204. $('#syfujian .check-all-file').prop('checked', false)
  205. }
  206. });
  207. });
  208. function findDecimal(unit) {
  209. let value = precision.other.value;
  210. const changeUnits = precision;
  211. for (const d in changeUnits) {
  212. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  213. value = changeUnits[d].value;
  214. break;
  215. }
  216. }
  217. return value;
  218. }
  219. // 生成附件列表
  220. function getAllList(currPageNum = 1) {
  221. // 每页最多几个附件
  222. const pageCount = 15;
  223. // 附件总数
  224. const total = attData.length;
  225. // 总页数
  226. const pageNum = Math.ceil(total/pageCount);
  227. $('#totalPage').text(pageNum);
  228. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  229. // 当前页附件内容
  230. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  231. let html = '';
  232. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  233. for(const [index,att] of currPageAttData.entries()) {
  234. console.log(att.uid, accountId, auditStatus, Boolean(att.extra_upload));
  235. html += `<tr>
  236. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  237. <td>${index+1}</td>
  238. <td><a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a></td>
  239. <td>${moment(att.in_time * 1000).format('YYYY-MM-DD')}<br>${bytesToSize(att.filesize)}</td>
  240. <td>
  241. <a href="/change/download/file/${att.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`
  242. html += (att.uid === accountId && (auditStatus === 4 ? Boolean(att.extra_upload) : true)) ?
  243. `<a href="javascript:void(0)" class="mr-2 delete-file" data-attid="${att.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : '';
  244. html += `</td>`;
  245. }
  246. $('#attList').html(html);
  247. $('#attList').on('click', 'tr', function() {
  248. $('#attList tr').removeClass('bg-light');
  249. $(this).addClass('bg-light');
  250. })
  251. }
  252. function bytesToSize(bytes) {
  253. if (parseInt(bytes) === 0) return '0 B';
  254. const k = 1024;
  255. const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  256. const i = Math.floor(Math.log(bytes) / Math.log(k));
  257. // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
  258. return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
  259. }