payment_detail.js 16 KB

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