change_information.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 && !touristPermission) {
  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. if (fileIds.length > 20) {
  174. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`);
  175. }
  176. const tid = $('#tenderId').val();
  177. const cid = $('#changeId').val();
  178. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0});
  179. $(this).attr('disabled', "true");
  180. const btn = $(this);
  181. const fileArr = [];
  182. for (const id of fileIds) {
  183. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  184. fileArr.push({
  185. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  186. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  187. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  188. });
  189. }
  190. const packageName = `${tenderName}-工程变更-${changeName}-附件.zip`;
  191. try {
  192. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  193. } catch (e) {
  194. btn.removeAttr('disabled');
  195. toastr.clear();
  196. toastr.error('批量下载失败');
  197. }
  198. // postCompressFile(`/tender/${tid}/change/${cid}/download/compresse-file`, {fileIds}, function(result) {
  199. // toastr.clear();
  200. // toastr.success('压缩文件成功');
  201. // btn.removeAttr('disabled');
  202. // const href = window.URL.createObjectURL(result);
  203. // $('#zipDown').attr('href', href);
  204. // $('#zipDown').attr('download', `${tenderName}-工程变更-${changeName}-附件.zip`);
  205. // $("#zipDown")[0].click();
  206. // }, () => {
  207. // btn.removeAttr('disabled');
  208. // toastr.clear();
  209. // toastr.error('批量下载失败');
  210. // });
  211. }
  212. });
  213. $.subMenu({
  214. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  215. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  216. key: 'menu.1.0.0',
  217. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  218. callback: function (info) {
  219. if (info.mini) {
  220. $('.panel-title').addClass('fluid');
  221. $('#sub-menu').removeClass('panel-sidebar');
  222. } else {
  223. $('.panel-title').removeClass('fluid');
  224. $('#sub-menu').addClass('panel-sidebar');
  225. }
  226. autoFlashHeight();
  227. changeSpread.refresh();
  228. }
  229. });
  230. // 切换页数
  231. $('.page-select').on('click', function () {
  232. const totalPageNum = parseInt($('#totalPage').text());
  233. const lastPageNum = parseInt($('#currentPage').text());
  234. const status = $(this).attr('content');
  235. if (status === 'pre' && lastPageNum > 1) {
  236. getAllList(lastPageNum-1);
  237. $('#showAttachment').hide();
  238. $('#syfujian .check-all-file').prop('checked', false)
  239. } else if (status === 'next' && lastPageNum < totalPageNum) {
  240. getAllList(lastPageNum+1);
  241. $('#showAttachment').hide();
  242. $('#syfujian .check-all-file').prop('checked', false)
  243. }
  244. });
  245. // 项目节信息获取
  246. const xmjSpreadSetting = {
  247. cols: [
  248. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'xmj_code', hAlign: 0, width: 80},
  249. // {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
  250. {title: '细目', colSpan: '1', rowSpan: '2', field: 'xmj_jldy', hAlign: 0, width: 100},
  251. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'xmj_dwgc', hAlign: 0, width: 100},
  252. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'xmj_fbgc', hAlign: 0, width: 100},
  253. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'xmj_fxgc', hAlign: 0, width: 100},
  254. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 100},
  255. {title: '数量', colSpan: '1', rowSpan: '2', field: 'oamount', hAlign: 2, width: 80},
  256. ],
  257. emptyRows: 0,
  258. headRows: 1,
  259. headRowHeight: [25, 25],
  260. defaultRowHeight: 21,
  261. headerFont: '12px 微软雅黑',
  262. font: '12px 微软雅黑',
  263. readOnly: true,
  264. localCache: {
  265. key: 'changes-xmj',
  266. colWidth: true,
  267. }
  268. };
  269. SpreadJsObj.initSheet(xmjSpread.getActiveSheet(), xmjSpreadSetting);
  270. });
  271. function findDecimal(unit) {
  272. let value = precision.other.value;
  273. const changeUnits = precision;
  274. for (const d in changeUnits) {
  275. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  276. value = changeUnits[d].value;
  277. break;
  278. }
  279. }
  280. return value;
  281. }
  282. // 生成附件列表
  283. function getAllList(currPageNum = 1) {
  284. // 每页最多几个附件
  285. const pageCount = 20;
  286. // 附件总数
  287. const total = attData.length;
  288. // 总页数
  289. const pageNum = Math.ceil(total/pageCount);
  290. $('#totalPage').text(pageNum);
  291. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  292. // 当前页附件内容
  293. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  294. currPageFileData = currPageAttData;
  295. let html = '';
  296. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  297. for(const [index,att] of currPageAttData.entries()) {
  298. html += `<tr>
  299. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  300. <td>${((currPageNum-1)*pageCount)+index+1}</td>
  301. <td><a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a></td>
  302. <td>${moment(att.in_time * 1000).format('YYYY-MM-DD')}<br>${bytesToSize(att.filesize)}</td>
  303. <td>
  304. <a href="/change/download/file/${att.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`
  305. html += (att.uid === accountId && (auditStatus === 4 ? Boolean(att.extra_upload) : true)) ?
  306. `<a href="javascript:void(0)" class="mr-2 delete-file" data-attid="${att.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : '';
  307. html += `</td>`;
  308. }
  309. $('#attList').html(html);
  310. $('#attList').on('click', 'tr', function() {
  311. $('#attList tr').removeClass('bg-light');
  312. $(this).addClass('bg-light');
  313. })
  314. }
  315. function bytesToSize(bytes) {
  316. if (parseInt(bytes) === 0) return '0 B';
  317. const k = 1024;
  318. const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  319. const i = Math.floor(Math.log(bytes) / Math.log(k));
  320. // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
  321. return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
  322. }