change_information.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. // 计算最新的变更总额和change的total_price是否一致,不一致则更新
  34. if (changeStatus !== auditConst.status.checked) {
  35. let new_tp = 0;
  36. for (const c of changeList) {
  37. new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
  38. }
  39. console.log(changeTp, new_tp);
  40. if (changeTp !== new_tp) {
  41. postData(window.location.pathname + '/save', { type:'update_tp', updateData: new_tp }, function (result) {
  42. });
  43. }
  44. }
  45. //tab change
  46. $('a[data-toggle="tab"]').on('shown.bs.tab', function () {
  47. const tab = $(this).data('tab');
  48. if (tab === 'bgfujian') {
  49. $('#fujian_btn').show();
  50. } else {
  51. $('#fujian_btn').hide();
  52. }
  53. });
  54. $('#add-bj').on('click', 'input[type="checkbox"]', function () {
  55. const isCheck = $(this).prop('checked');
  56. if (isCheck) {
  57. $('#add-bj input[type="checkbox"]').each(function () {
  58. $(this).prop('checked', false)
  59. });
  60. $(this).prop('checked', true)
  61. }
  62. });
  63. $('#bg-copy').click(function() {
  64. const cid = $('#add-bj input:checked').data('id');
  65. postData(window.location.pathname + '/copy', cid, function () {
  66. window.location.reload();
  67. })
  68. });
  69. // 上传附件
  70. $('#upload-file-btn').click(function () {
  71. const files = $('#upload-file')[0].files;
  72. const formData = new FormData();
  73. formData.append('cid', $('#changeId').val());
  74. formData.append('tid', $('#tenderId').val());
  75. for (const file of files) {
  76. if (file === undefined) {
  77. toastr.error('未选择上传文件!');
  78. return false;
  79. }
  80. const filesize = file.size;
  81. if (filesize > 30 * 1024 * 1024) {
  82. toastr.error('文件大小过大!');
  83. return false;
  84. }
  85. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  86. if (whiteList.indexOf(fileext) === -1) {
  87. toastr.error('只能上传指定格式的附件!');
  88. return false;
  89. }
  90. formData.append('size', filesize);
  91. formData.append('file[]', file);
  92. }
  93. if (auditList.findIndex(item => item.uid === parseInt(accountId)) === -1 && !touristPermission) {
  94. return toastr.error('暂无权限上传!');
  95. }
  96. postDataWithFile(window.location.pathname + '/file/upload', formData, function (data) {
  97. attData = data.concat(attData);
  98. // 重新生成List
  99. getAllList();
  100. $('#addfujian').modal('hide');
  101. // let html = '';
  102. // let index = $('#attList tr').length + 1;
  103. // for (const fileInfo of data) {
  104. // html += '<tr> ' +
  105. // `<td width="20"><input type="checkbox" class="check-file" file-id=${fileInfo.id}></td>` +
  106. // '<td>' + index + '</td> ' +
  107. // `<td><a href="javascript: void(0);" class="file-atn" f-id="${fileInfo.id}">${fileInfo.filename}${fileInfo.fileext}</a></td>`+
  108. // '<td>' + fileInfo.in_time + '<br>' + fileInfo.filesize + '</td> ' +
  109. // `<td><a href="/change/download/file/${fileInfo.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`+
  110. // ( auditStatus === 4 ?
  111. // fileInfo.extra_upload ? `<a class="mr-2 delete-file" data-attid="${fileInfo.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : ''
  112. // : ` <a href="javascript:void(0);" class="mr-2 delete-file" data-attid="${fileInfo.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>`)+
  113. // `</td>`+
  114. // // '<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> ' +
  115. // '</tr>';
  116. // ++index;
  117. // }
  118. // $('#attList').append(html);
  119. }, function () {
  120. });
  121. $('#upload-file').val('');
  122. });
  123. // 删除附件
  124. $('body').on('click', '.delete-file', function () {
  125. let attid = $(this).data('attid');
  126. let self = $(this);
  127. const data = {id: attid};
  128. postData(window.location.pathname + '/file/delete', data, function (result) {
  129. // self.parents('tr').remove();
  130. // // 重新排序
  131. // let newsort = 1;
  132. // $('#attList tr').each(function(){
  133. // $(this).children('td').eq(1).text(newsort);
  134. // newsort++;
  135. // });
  136. // 删除到attData中
  137. const att_index = attData.findIndex(function (item) {
  138. return item.id === parseInt(attid);
  139. });
  140. attData.splice(att_index, 1);
  141. // 重新生成List
  142. if ($('#attList tr').length === 1) {
  143. getAllList(parseInt($('#currentPage').text()) - 1);
  144. } else {
  145. getAllList(parseInt($('#currentPage').text()));
  146. }
  147. });
  148. });
  149. // /change/download/file/
  150. $('#attList').on('click', '.file-atn', function() {
  151. const id = $(this).attr('f-id');
  152. postData(`/change/download/file/${id}`, {}, (data) => {
  153. const { filepath } = data;
  154. $('#file-upload').attr('href', filepath);
  155. $('#file-upload')[0].click();
  156. })
  157. });
  158. $('#attList').on('click', '.check-file', function() {
  159. const checkedList = $('#attList').find('input:checked');
  160. const childs = $('#attList').children().length;
  161. const checkBox = $('#check-all-file');
  162. if (checkedList.length === childs) {
  163. checkBox.prop("checked", true);
  164. } else {
  165. checkBox.prop("checked", false);
  166. }
  167. });
  168. $('#check-all-file').click(function() {
  169. const isCheck = $(this).is(':checked');
  170. $('#attList').children().each(function() {
  171. $(this).find('input:checkbox').prop("checked", isCheck);
  172. })
  173. });
  174. $('#bach-download').click(function() {
  175. const fileIds = [];
  176. $( '#attList .check-file:checked').each(function() {
  177. const fileId = $(this).attr('file-id');
  178. fileId && fileIds.push(fileId);
  179. });
  180. if (fileIds.length) {
  181. // const tid = $('#tenderId').val();
  182. // const cid = $('#changeId').val();
  183. // $('#downloadZip').attr('href', `/tender/${tid}/change/${cid}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`);
  184. // $('#downloadZip')[0].click();
  185. if (fileIds.length > 20) {
  186. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`);
  187. }
  188. const tid = $('#tenderId').val();
  189. const cid = $('#changeId').val();
  190. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0});
  191. $(this).attr('disabled', "true");
  192. const btn = $(this);
  193. const fileArr = [];
  194. for (const id of fileIds) {
  195. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  196. fileArr.push({
  197. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  198. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  199. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  200. });
  201. }
  202. const packageName = `${tenderName}-工程变更-${changeName}-附件.zip`;
  203. try {
  204. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  205. } catch (e) {
  206. btn.removeAttr('disabled');
  207. toastr.clear();
  208. toastr.error('批量下载失败');
  209. }
  210. // postCompressFile(`/tender/${tid}/change/${cid}/download/compresse-file`, {fileIds}, function(result) {
  211. // toastr.clear();
  212. // toastr.success('压缩文件成功');
  213. // btn.removeAttr('disabled');
  214. // const href = window.URL.createObjectURL(result);
  215. // $('#zipDown').attr('href', href);
  216. // $('#zipDown').attr('download', `${tenderName}-工程变更-${changeName}-附件.zip`);
  217. // $("#zipDown")[0].click();
  218. // }, () => {
  219. // btn.removeAttr('disabled');
  220. // toastr.clear();
  221. // toastr.error('批量下载失败');
  222. // });
  223. }
  224. });
  225. $.subMenu({
  226. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  227. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  228. key: 'menu.1.0.0',
  229. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  230. callback: function (info) {
  231. if (info.mini) {
  232. $('.panel-title').addClass('fluid');
  233. $('#sub-menu').removeClass('panel-sidebar');
  234. } else {
  235. $('.panel-title').removeClass('fluid');
  236. $('#sub-menu').addClass('panel-sidebar');
  237. }
  238. autoFlashHeight();
  239. changeSpread.refresh();
  240. }
  241. });
  242. // 切换页数
  243. $('.page-select').on('click', function () {
  244. const totalPageNum = parseInt($('#totalPage').text());
  245. const lastPageNum = parseInt($('#currentPage').text());
  246. const status = $(this).attr('content');
  247. if (status === 'pre' && lastPageNum > 1) {
  248. getAllList(lastPageNum-1);
  249. $('#showAttachment').hide();
  250. $('#syfujian .check-all-file').prop('checked', false)
  251. } else if (status === 'next' && lastPageNum < totalPageNum) {
  252. getAllList(lastPageNum+1);
  253. $('#showAttachment').hide();
  254. $('#syfujian .check-all-file').prop('checked', false)
  255. }
  256. });
  257. // 项目节信息获取
  258. const xmjSpreadSetting = {
  259. cols: [
  260. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'xmj_code', hAlign: 0, width: 80},
  261. // {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
  262. {title: '细目', colSpan: '1', rowSpan: '2', field: 'xmj_jldy', hAlign: 0, width: 100},
  263. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'xmj_dwgc', hAlign: 0, width: 100},
  264. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'xmj_fbgc', hAlign: 0, width: 100},
  265. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'xmj_fxgc', hAlign: 0, width: 100},
  266. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 100},
  267. {title: '数量', colSpan: '1', rowSpan: '2', field: 'oamount', hAlign: 2, width: 80},
  268. ],
  269. emptyRows: 0,
  270. headRows: 1,
  271. headRowHeight: [25, 25],
  272. defaultRowHeight: 21,
  273. headerFont: '12px 微软雅黑',
  274. font: '12px 微软雅黑',
  275. readOnly: true,
  276. localCache: {
  277. key: 'changes-xmj',
  278. colWidth: true,
  279. }
  280. };
  281. SpreadJsObj.initSheet(xmjSpread.getActiveSheet(), xmjSpreadSetting);
  282. });
  283. function findDecimal(unit) {
  284. let value = precision.other.value;
  285. const changeUnits = precision;
  286. for (const d in changeUnits) {
  287. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  288. value = changeUnits[d].value;
  289. break;
  290. }
  291. }
  292. return value;
  293. }
  294. // 生成附件列表
  295. function getAllList(currPageNum = 1) {
  296. // 每页最多几个附件
  297. const pageCount = 20;
  298. // 附件总数
  299. const total = attData.length;
  300. // 总页数
  301. const pageNum = Math.ceil(total/pageCount);
  302. $('#totalPage').text(pageNum);
  303. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  304. // 当前页附件内容
  305. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  306. currPageFileData = currPageAttData;
  307. let html = '';
  308. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  309. for(const [index,att] of currPageAttData.entries()) {
  310. html += `<tr>
  311. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  312. <td>${((currPageNum-1)*pageCount)+index+1}</td>
  313. <td><a href="${att.filepath}" target="_blank" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a></td>
  314. <td>${moment(att.in_time * 1000).format('YYYY-MM-DD')}<br>${bytesToSize(att.filesize)}</td>
  315. <td>
  316. <a href="/change/download/file/${att.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`
  317. html += (att.uid === accountId && (auditStatus === 4 ? Boolean(att.extra_upload) : true)) ?
  318. `<a href="javascript:void(0)" class="mr-2 delete-file" data-attid="${att.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : '';
  319. html += `</td>`;
  320. }
  321. $('#attList').html(html);
  322. $('#attList').on('click', 'tr', function() {
  323. $('#attList tr').removeClass('bg-light');
  324. $(this).addClass('bg-light');
  325. })
  326. }
  327. function bytesToSize(bytes) {
  328. if (parseInt(bytes) === 0) return '0 B';
  329. const k = 1024;
  330. const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  331. const i = Math.floor(Math.log(bytes) / Math.log(k));
  332. // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
  333. return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
  334. }