payment_detail.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. function iniPage() {
  2. dynamicLoadJs('/public/jspdf/Arial Narrow-normal.js');
  3. dynamicLoadJs('/public/jspdf/Arial Narrow-bold.js');
  4. dynamicLoadJs('/public/jspdf/Arial Narrow-italic.js');
  5. dynamicLoadJs('/public/jspdf/Arial Narrow-bolditalic.js');
  6. rptTplObj.isLoading = true;
  7. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal2.js', 'normal', getPdfFontCallbackLight);
  8. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', 'bold', getPdfFontCallbackLight);
  9. }
  10. function getPdfFontCallbackLight(fontProperty) {
  11. rptTplObj.pdfFont['SmartSimsun'].push(fontProperty);
  12. if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
  13. rptTplObj.isLoading = false;
  14. }
  15. }
  16. function getPdfFontCallback(fontProperty) {
  17. if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
  18. downloadPDFReport([tesRpttData], 'A4', ['测试审核表'], [], [], [-1], []);
  19. }
  20. }
  21. $(function () {
  22. autoFlashHeight();
  23. auditRptPrintHelper.showPage();
  24. iniPage();
  25. //初始化所有附件列表
  26. getAllList();
  27. $('#rpt-form input').on('change', function () {
  28. const newVal = $(this).val();
  29. const index = parseInt($(this).data('index'));
  30. checkAndUpdate(index, newVal, $(this));
  31. });
  32. $('#rpt-form textarea').on('change', function () {
  33. const newVal = $(this).val();
  34. const index = parseInt($(this).data('index'));
  35. checkAndUpdate(index, newVal, $(this));
  36. });
  37. $('#chose-private-stamp-path .stamp-img').on('click', function () {
  38. if (!$(this).hasClass('card-gk-active')) {
  39. $('#chose-private-stamp-path .stamp-img').removeClass('card-gk-active');
  40. $('#chose-private-stamp-path .stamp-img').find('.sel-width').removeClass('sel-blue');
  41. $(this).addClass('card-gk-active');
  42. $(this).find('.sel-width').addClass('sel-blue');
  43. }
  44. });
  45. $('#chose-private-stamp-path').on('show.bs.modal', function () {
  46. $('#chose-private-stamp-path .stamp-img').removeClass('card-gk-active');
  47. $('#chose-private-stamp-path .stamp-img').find('.sel-width').removeClass('sel-blue');
  48. $('#chose-private-stamp-path .stamp-img').each(function () {
  49. const src = $(this).find('img').attr('data-src');
  50. if (src === currentStamp) {
  51. $(this).addClass('card-gk-active');
  52. $(this).find('.sel-width').addClass('sel-blue');
  53. return;
  54. }
  55. });
  56. });
  57. $('#select_stamp_path_btn').click(function () {
  58. const src = $('#chose-private-stamp-path .card-gk-active').find('img').attr('data-src');
  59. currentStamp = src;
  60. $('#stamp_path').val(src);
  61. $('#chose-private-stamp-path').modal('hide');
  62. });
  63. let signatureDate = null;
  64. $('#sub-sp5').on('show.bs.modal', function () {
  65. $('#sign_path').prop('checked', rptAudit.signature_msg.sign_path !== null);
  66. $('#company_stamp').prop('checked', rptAudit.signature_msg.company_stamp !== null);
  67. $('#stamp_path').prop('checked', rptAudit.signature_msg.stamp_path !== null);
  68. $('#signature_date').val(rptAudit.signature_msg.date ? rptAudit.signature_msg.date : new Date());
  69. signatureDate = !signatureDate ? $('#signature_date').datepicker().data('datepicker') : signatureDate;
  70. if (signatureDate && rptAudit.signature_msg.date) {
  71. signatureDate.selectDate(new Date(rptAudit.signature_msg.date));
  72. } else if (signatureDate) {
  73. signatureDate.selectDate(new Date());
  74. // signatureDate.clear();
  75. }
  76. $('#signature_content').val(rptAudit.signature_msg.content ? rptAudit.signature_msg.content : '');
  77. });
  78. $('#sp-done').on('show.bs.modal', function () {
  79. $('#sp-done').find('textarea').val(rptAudit.signature_msg.content ? rptAudit.signature_msg.content : '同意');
  80. });
  81. $('#commit_sign').click(function () {
  82. rptAudit.signature_msg.sign_path = $('#sign_path').is(':checked') ? $('#sign_path').val() : null;
  83. rptAudit.signature_msg.company_stamp = $('#company_stamp').is(':checked') ? $('#company_stamp').val() : null;
  84. rptAudit.signature_msg.stamp_path = $('#stamp_path').is(':checked') ? $('#stamp_path').val() : null;
  85. rptAudit.signature_msg.date = $('#signature_date').val() ? $('#signature_date').val() : null;
  86. rptAudit.signature_msg.content = $('#signature_content').val() ? $('#signature_content').val() : null;
  87. console.log(rptAudit.signature_msg);
  88. // 签章
  89. if (rptAudit.signature_msg.sign_path !== null || rptAudit.signature_msg.company_stamp !== null || rptAudit.signature_msg.stamp_path !== null) {
  90. const signArray = [];
  91. rptAudit.signature_msg.sign_path ? signArray.push('/public/upload/sign/' + rptAudit.signature_msg.sign_path) : signArray.push('');
  92. rptAudit.signature_msg.company_stamp ? signArray.push(rptAudit.signature_msg.company_stamp) : signArray.push('');
  93. rptAudit.signature_msg.stamp_path ? signArray.push(rptAudit.signature_msg.stamp_path) : signArray.push('');
  94. tesRpttData.items[0].signature_cells[rptAudit.signature_index].path = signArray.length > 0 ? signArray.join('!;!') : null;
  95. const date_index = _.findIndex(tesRpttData.items[0].signature_date_cells, { signature_name: rptAudit.signature_name + '_签字日期' });
  96. if (date_index !== -1) {
  97. tesRpttData.items[0].signature_date_cells[date_index].Value = rptAudit.signature_msg.date ? rptAudit.signature_msg.date : '';
  98. }
  99. const content_index = _.findIndex(tesRpttData.items[0].signature_audit_cells, { signature_name: rptAudit.signature_name + '_审核意见' });
  100. if (content_index !== -1) {
  101. tesRpttData.items[0].signature_audit_cells[content_index].Value = rptAudit.signature_msg.content ? rptAudit.signature_msg.content : '';
  102. }
  103. postData('/payment/' + tenderId + '/detail/' + detailId + '/save', { type: 'update_sign', signature_msg: rptAudit.signature_msg }, function (result) {
  104. auditRptPrintHelper.showPage();
  105. // 更新签署进度图表展示
  106. $('#rpt_audit_sign td').eq(3).html(rptAudit.signature_msg.sign_path !== null ? '<i class="fa fa-check text-success"></i>' : '');
  107. $('#rpt_audit_sign td').eq(4).html(rptAudit.signature_msg.company_stamp !== null || rptAudit.signature_msg.stamp_path !== null ? '<i class="fa fa-check text-success"></i>' : '');
  108. });
  109. $('#sub-sp5').modal('hide');
  110. } else {
  111. toastr.error('至少选择一个签字/签章');
  112. }
  113. });
  114. let timer = null
  115. function checkAndUpdate(index, newVal, _self) {
  116. if (tesRpttData.items[0].interact_cells[index].DataType === 'intact_type_number' && _.indexOf(tesRpttData.items[0].interact_cells[index].Value, '元') !== -1) {
  117. newVal = newVal + '元';
  118. }
  119. console.log(index, newVal);
  120. clearTimeout(timer);
  121. timer = setTimeout(() => {
  122. tesRpttData.items[0].interact_cells[index].Value = tesRpttData.items[0].interact_cells[index].Prefix ? tesRpttData.items[0].interact_cells[index].Prefix + newVal : newVal;
  123. postData('/payment/' + tenderId + '/detail/' + detailId + '/save', { type: 'update_rpt', report_json: tesRpttData }, function (result) {
  124. auditRptPrintHelper.showPage();
  125. });
  126. clearTimeout(timer);
  127. }, 500);
  128. }
  129. //tab change
  130. $('a[data-toggle="tab"]').on('shown.bs.tab', function () {
  131. const tab = $(this).data('tab');
  132. if (tab === 'fujian') {
  133. $('#fujian_btn').show();
  134. } else {
  135. $('#fujian_btn').hide();
  136. }
  137. });
  138. // 切换页数
  139. $('.page-select').on('click', function () {
  140. const totalPageNum = parseInt($('#totalPage').text());
  141. const lastPageNum = parseInt($('#currentPage').text());
  142. const status = $(this).attr('content');
  143. if (status === 'pre' && lastPageNum > 1) {
  144. getAllList(lastPageNum-1);
  145. $('#annex .check-all-file').prop('checked', false)
  146. } else if (status === 'next' && lastPageNum < totalPageNum) {
  147. getAllList(lastPageNum+1);
  148. $('#annex .check-all-file').prop('checked', false)
  149. }
  150. });
  151. // 上传附件
  152. $('#upload-file-btn').click(function () {
  153. const files = $('#upload-file')[0].files;
  154. const formData = new FormData();
  155. for (const file of files) {
  156. if (file === undefined) {
  157. toastr.error('未选择上传文件!');
  158. return false;
  159. }
  160. const filesize = file.size;
  161. if (filesize > 30 * 1024 * 1024) {
  162. toastr.error('文件大小过大!');
  163. return false;
  164. }
  165. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  166. if (whiteList.indexOf(fileext) === -1) {
  167. toastr.error('只能上传指定格式的附件!');
  168. return false;
  169. }
  170. formData.append('size', filesize);
  171. formData.append('file[]', file);
  172. }
  173. if (uidList.indexOf(accountId) === -1) {
  174. return toastr.error('暂无权限上传!');
  175. }
  176. postDataWithFile(window.location.pathname + '/file/upload', formData, function (data) {
  177. attData = data.concat(attData);
  178. // 重新生成List
  179. getAllList();
  180. $('#addfujian').modal('hide');
  181. }, function () {
  182. });
  183. $('#upload-file').val('');
  184. });
  185. // 删除附件
  186. $('body').on('click', '.delete-file', function () {
  187. let attid = $(this).data('attid');
  188. let self = $(this);
  189. const data = {id: attid};
  190. postData(window.location.pathname + '/file/delete', data, function (result) {
  191. // 删除到attData中
  192. const att_index = attData.findIndex(function (item) {
  193. return item.id === parseInt(attid);
  194. });
  195. attData.splice(att_index, 1);
  196. // 重新生成List
  197. if ($('#attList tr').length === 1) {
  198. getAllList(parseInt($('#currentPage').text()) - 1);
  199. } else {
  200. getAllList(parseInt($('#currentPage').text()));
  201. }
  202. });
  203. });
  204. $('#attList').on('click', '.file-atn', function() {
  205. const id = $(this).attr('f-id');
  206. postData(`/payment/${tenderId}/detail/${detailId}/file/${id}/download`, {}, (data) => {
  207. const { filepath } = data;
  208. $('#file-upload').attr('href', filepath);
  209. $('#file-upload')[0].click();
  210. })
  211. });
  212. $('#attList').on('click', '.check-file', function() {
  213. const checkedList = $('#attList').find('input:checked');
  214. const childs = $('#attList').children().length;
  215. const checkBox = $('#check-all-file');
  216. if (checkedList.length === childs) {
  217. checkBox.prop("checked", true);
  218. } else {
  219. checkBox.prop("checked", false);
  220. }
  221. });
  222. $('#check-all-file').click(function() {
  223. const isCheck = $(this).is(':checked');
  224. $('#attList').children().each(function() {
  225. $(this).find('input:checkbox').prop("checked", isCheck);
  226. })
  227. });
  228. $('#bach-download').click(function() {
  229. const fileIds = [];
  230. $( '#attList .check-file:checked').each(function() {
  231. const fileId = $(this).attr('file-id');
  232. fileId && fileIds.push(fileId);
  233. });
  234. if (fileIds.length) {
  235. if (fileIds.length > 20) {
  236. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`);
  237. }
  238. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0});
  239. $(this).attr('disabled', "true");
  240. const btn = $(this);
  241. const fileArr = [];
  242. for (const id of fileIds) {
  243. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  244. fileArr.push({
  245. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  246. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  247. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  248. });
  249. }
  250. const packageName = `${trName}-${detailName}-附件.zip`;
  251. try {
  252. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  253. } catch (e) {
  254. btn.removeAttr('disabled');
  255. toastr.clear();
  256. toastr.error('批量下载失败');
  257. }
  258. }
  259. });
  260. });
  261. // 生成附件列表
  262. function getAllList(currPageNum = 1) {
  263. // 每页最多几个附件
  264. const pageCount = 20;
  265. // 附件总数
  266. const total = attData.length;
  267. // 总页数
  268. const pageNum = Math.ceil(total/pageCount);
  269. $('#totalPage').text(pageNum);
  270. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  271. // 当前页附件内容
  272. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  273. currPageFileData = currPageAttData;
  274. let html = '';
  275. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  276. for(const [index,att] of currPageAttData.entries()) {
  277. html += `<tr>
  278. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  279. <td>${((currPageNum-1)*pageCount)+index+1}</td>
  280. <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>
  281. <td>${moment(att.upload_time).format("YYYY-MM-DD HH:mm:ss")}<br>${bytesToSize(att.filesize)}</td>
  282. <td>
  283. <a href="/payment/${tenderId}/detail/${detailId}/file/${att.id}/download" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`
  284. html += (att.uid === accountId && (detailStatus === auditConst.status.checked ? Boolean(att.extra_upload) : true)) ?
  285. `<a href="javascript:void(0)" class="mr-2 delete-file" data-attid="${att.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : '';
  286. html += `</td>`;
  287. }
  288. $('#attList').html(html);
  289. $('#attList').on('click', 'tr', function() {
  290. $('#attList tr').removeClass('bg-light');
  291. $(this).addClass('bg-light');
  292. });
  293. }
  294. function bytesToSize(bytes) {
  295. if (parseInt(bytes) === 0) return '0 B';
  296. const k = 1024;
  297. const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  298. const i = Math.floor(Math.log(bytes) / Math.log(k));
  299. // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
  300. return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
  301. }