payment_detail.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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[type!="radio"]').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. // find link(大写转换)
  44. const linkList = _.filter(tesRpttData.items[0].interact_cells, { link: index });
  45. if (linkList.length > 0) {
  46. const chineseNum = numberToChinese(newVal);
  47. // 赋值到input框并展示在报表里
  48. for (const cell of linkList) {
  49. $('#rpt-form input[data-index="'+ cell.index +'"]').val(chineseNum);
  50. tesRpttData.items[0].interact_cells[cell.index].Value =
  51. tesRpttData.items[0].interact_cells[cell.index].Prefix ? tesRpttData.items[0].interact_cells[cell.index].Prefix + chineseNum : chineseNum;
  52. }
  53. }
  54. }
  55. checkAndUpdate(index, newVal, $(this));
  56. });
  57. $(".link-dropdown").on("click",function (e) {
  58. e.stopPropagation();
  59. });
  60. $('.change-link').on('click', function () {
  61. const link = $(this).parents('.link-dropdown').find('input:checked').val();
  62. const index = parseInt($(this).attr('item-index'));
  63. const old_link = $(this).attr('old-link');
  64. if (old_link !== link) {
  65. let showTips = '';
  66. if (link !== '') {
  67. const numberInfo = _.find(tesRpttData.items[0].interact_cells, { index: parseInt(link) });
  68. if (numberInfo) showTips = '关联数据:' + numberInfo.Label;
  69. }
  70. $(this).parents('.link-dropdown').siblings('.show-link').html(showTips);
  71. $(this).attr('old-link', link);
  72. const info = link !== '' ? tesRpttData.items[0].interact_cells[link] : null;
  73. const linkValue = removePreFix(info.Prefix, info.Value);
  74. const chineseNum = linkValue ? numberToChinese(linkValue) : '';
  75. tesRpttData.items[0].interact_cells[index].link = link !== '' ? parseInt(link) : '';
  76. tesRpttData.items[0].interact_cells[index].Value = tesRpttData.items[0].interact_cells[index].Prefix ? tesRpttData.items[0].interact_cells[index].Prefix + chineseNum : chineseNum;
  77. postData('/payment/' + tenderId + '/detail/' + detailId + '/save', { type: 'update_rpt', report_json: tesRpttData }, function (result) {
  78. $('#rpt-form input[data-index="'+ index +'"]').val(chineseNum);
  79. auditRptPrintHelper.showPage();
  80. });
  81. }
  82. });
  83. function removePreFix(prefix, value) {
  84. const result = prefix ? _.replace(value, prefix, '') : value;
  85. return result ? parseFloat(result) : '';
  86. }
  87. $('.show-link-dropdown').on('show.bs.dropdown', function () {
  88. const link = $(this).find('button').attr('old-link');
  89. const index = $(this).find('button').attr('item-index');
  90. $('input:radio[name="radio_'+ index +'"][value="'+ link + '"]').prop('checked', true);
  91. });
  92. $('#rpt-form textarea').on('change', function () {
  93. const newVal = $(this).val();
  94. const index = parseInt($(this).data('index'));
  95. checkAndUpdate(index, newVal, $(this));
  96. });
  97. $('#chose-private-stamp-path .stamp-img').on('click', function () {
  98. if (!$(this).hasClass('card-gk-active')) {
  99. $('#chose-private-stamp-path .stamp-img').removeClass('card-gk-active');
  100. $('#chose-private-stamp-path .stamp-img').find('.sel-width').removeClass('sel-blue');
  101. $(this).addClass('card-gk-active');
  102. $(this).find('.sel-width').addClass('sel-blue');
  103. }
  104. });
  105. $('#chose-private-stamp-path').on('show.bs.modal', function () {
  106. $('#chose-private-stamp-path .stamp-img').removeClass('card-gk-active');
  107. $('#chose-private-stamp-path .stamp-img').find('.sel-width').removeClass('sel-blue');
  108. $('#chose-private-stamp-path .stamp-img').each(function () {
  109. const src = $(this).find('img').attr('data-src');
  110. if (src === currentStamp) {
  111. $(this).addClass('card-gk-active');
  112. $(this).find('.sel-width').addClass('sel-blue');
  113. return;
  114. }
  115. });
  116. });
  117. $('#select_stamp_path_btn').click(function () {
  118. const src = $('#chose-private-stamp-path .card-gk-active').find('img').attr('data-src');
  119. currentStamp = src;
  120. $('#stamp_path').val(src);
  121. $('#chose-private-stamp-path').modal('hide');
  122. });
  123. let signatureDate = null;
  124. $('#sub-sp5').on('show.bs.modal', function () {
  125. $('#sign_path').prop('checked', rptAudit.signature_msg.sign_path !== null);
  126. $('#company_stamp').prop('checked', rptAudit.signature_msg.company_stamp !== null);
  127. $('#stamp_path').prop('checked', rptAudit.signature_msg.stamp_path !== null);
  128. $('#signature_date').val(rptAudit.signature_msg.date ? rptAudit.signature_msg.date : new Date());
  129. signatureDate = !signatureDate ? $('#signature_date').datepicker().data('datepicker') : signatureDate;
  130. if (signatureDate && rptAudit.signature_msg.date) {
  131. signatureDate.selectDate(new Date(rptAudit.signature_msg.date));
  132. } else if (signatureDate) {
  133. signatureDate.selectDate(new Date());
  134. // signatureDate.clear();
  135. }
  136. $('#signature_content').val(rptAudit.signature_msg.content ? rptAudit.signature_msg.content : '');
  137. });
  138. $('#sp-done').on('show.bs.modal', function () {
  139. $('#sp-done').find('textarea').val(rptAudit && rptAudit.signature_msg.content ? rptAudit.signature_msg.content : '同意');
  140. });
  141. $('#commit_sign').click(function () {
  142. rptAudit.signature_msg.sign_path = $('#sign_path').is(':checked') ? $('#sign_path').val() : null;
  143. rptAudit.signature_msg.company_stamp = $('#company_stamp').is(':checked') ? $('#company_stamp').val() : null;
  144. rptAudit.signature_msg.stamp_path = $('#stamp_path').is(':checked') ? $('#stamp_path').val() : null;
  145. rptAudit.signature_msg.date = $('#signature_date').val() ? $('#signature_date').val() : null;
  146. rptAudit.signature_msg.content = $('#signature_content').val() ? $('#signature_content').val() : null;
  147. console.log(rptAudit.signature_msg);
  148. // 签章
  149. if (rptAudit.signature_msg.sign_path !== null || rptAudit.signature_msg.company_stamp !== null || rptAudit.signature_msg.stamp_path !== null) {
  150. const signArray = [];
  151. rptAudit.signature_msg.sign_path ? signArray.push('/public/upload/sign/' + rptAudit.signature_msg.sign_path) : signArray.push('');
  152. rptAudit.signature_msg.company_stamp ? signArray.push(rptAudit.signature_msg.company_stamp) : signArray.push('');
  153. rptAudit.signature_msg.stamp_path ? signArray.push(rptAudit.signature_msg.stamp_path) : signArray.push('');
  154. tesRpttData.items[0].signature_cells[rptAudit.signature_index].path = signArray.length > 0 ? signArray.join('!;!') : null;
  155. const date_index = _.findIndex(tesRpttData.items[0].signature_date_cells, { signature_name: rptAudit.signature_name + '_签字日期' });
  156. if (date_index !== -1) {
  157. tesRpttData.items[0].signature_date_cells[date_index].Value = rptAudit.signature_msg.date ? dateTranChinese(rptAudit.signature_msg.date) : '';
  158. }
  159. const content_index = _.findIndex(tesRpttData.items[0].signature_audit_cells, { signature_name: rptAudit.signature_name + '_审核意见' });
  160. if (content_index !== -1) {
  161. tesRpttData.items[0].signature_audit_cells[content_index].Value = rptAudit.signature_msg.content ? rptAudit.signature_msg.content : '';
  162. }
  163. postData('/payment/' + tenderId + '/detail/' + detailId + '/save', { type: 'update_sign', signature_msg: rptAudit.signature_msg }, function (result) {
  164. auditRptPrintHelper.showPage();
  165. // 更新签署进度图表展示
  166. $('#rpt_audit_sign td').eq(3).html(rptAudit.signature_msg.sign_path !== null ? '<i class="fa fa-check text-success"></i>' : '');
  167. $('#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>' : '');
  168. });
  169. $('#sub-sp5').modal('hide');
  170. } else {
  171. toastr.error('至少选择一个签字/签章');
  172. }
  173. });
  174. let timer = null
  175. function checkAndUpdate(index, newVal, _self) {
  176. if (tesRpttData.items[0].interact_cells[index].DataType === 'intact_type_number' && _.indexOf(tesRpttData.items[0].interact_cells[index].Value, '元') !== -1) {
  177. newVal = newVal + '元';
  178. }
  179. clearTimeout(timer);
  180. timer = setTimeout(() => {
  181. tesRpttData.items[0].interact_cells[index].Value = tesRpttData.items[0].interact_cells[index].Prefix ? tesRpttData.items[0].interact_cells[index].Prefix + newVal : newVal;
  182. postData('/payment/' + tenderId + '/detail/' + detailId + '/save', { type: 'update_rpt', report_json: tesRpttData }, function (result) {
  183. auditRptPrintHelper.showPage();
  184. });
  185. clearTimeout(timer);
  186. }, 500);
  187. }
  188. //tab change
  189. $('a[data-toggle="tab"]').on('shown.bs.tab', function () {
  190. const tab = $(this).data('tab');
  191. if (tab === 'fujian') {
  192. $('#fujian_btn').show();
  193. } else {
  194. $('#fujian_btn').hide();
  195. }
  196. });
  197. // 切换页数
  198. $('.page-select').on('click', function () {
  199. const totalPageNum = parseInt($('#totalPage').text());
  200. const lastPageNum = parseInt($('#currentPage').text());
  201. const status = $(this).attr('content');
  202. if (status === 'pre' && lastPageNum > 1) {
  203. getAllList(lastPageNum-1);
  204. $('#annex .check-all-file').prop('checked', false)
  205. } else if (status === 'next' && lastPageNum < totalPageNum) {
  206. getAllList(lastPageNum+1);
  207. $('#annex .check-all-file').prop('checked', false)
  208. }
  209. });
  210. // 上传附件
  211. $('#upload-file-btn').click(function () {
  212. const files = $('#upload-file')[0].files;
  213. const formData = new FormData();
  214. for (const file of files) {
  215. if (file === undefined) {
  216. toastr.error('未选择上传文件!');
  217. return false;
  218. }
  219. const filesize = file.size;
  220. if (filesize > 30 * 1024 * 1024) {
  221. toastr.error('文件大小过大!');
  222. return false;
  223. }
  224. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  225. if (whiteList.indexOf(fileext) === -1) {
  226. toastr.error('只能上传指定格式的附件!');
  227. return false;
  228. }
  229. formData.append('size', filesize);
  230. formData.append('file[]', file);
  231. }
  232. if (uidList.indexOf(accountId) === -1) {
  233. return toastr.error('暂无权限上传!');
  234. }
  235. postDataWithFile(window.location.pathname + '/file/upload', formData, function (data) {
  236. attData = data.concat(attData);
  237. // 重新生成List
  238. getAllList();
  239. $('#addfujian').modal('hide');
  240. }, function () {
  241. });
  242. $('#upload-file').val('');
  243. });
  244. // 删除附件
  245. $('body').on('click', '.delete-file', function () {
  246. let attid = $(this).data('attid');
  247. let self = $(this);
  248. const data = {id: attid};
  249. postData(window.location.pathname + '/file/delete', data, function (result) {
  250. // 删除到attData中
  251. const att_index = attData.findIndex(function (item) {
  252. return item.id === parseInt(attid);
  253. });
  254. attData.splice(att_index, 1);
  255. // 重新生成List
  256. if ($('#attList tr').length === 1) {
  257. getAllList(parseInt($('#currentPage').text()) - 1);
  258. } else {
  259. getAllList(parseInt($('#currentPage').text()));
  260. }
  261. });
  262. });
  263. $('#attList').on('click', '.file-atn', function() {
  264. const id = $(this).attr('f-id');
  265. postData(`/payment/${tenderId}/detail/${detailId}/file/${id}/download`, {}, (data) => {
  266. const { filepath } = data;
  267. $('#file-upload').attr('href', filepath);
  268. $('#file-upload')[0].click();
  269. })
  270. });
  271. $('#attList').on('click', '.check-file', function() {
  272. const checkedList = $('#attList').find('input:checked');
  273. const childs = $('#attList').children().length;
  274. const checkBox = $('#check-all-file');
  275. if (checkedList.length === childs) {
  276. checkBox.prop("checked", true);
  277. } else {
  278. checkBox.prop("checked", false);
  279. }
  280. });
  281. $('#check-all-file').click(function() {
  282. const isCheck = $(this).is(':checked');
  283. $('#attList').children().each(function() {
  284. $(this).find('input:checkbox').prop("checked", isCheck);
  285. })
  286. });
  287. $('#bach-download').click(function() {
  288. const fileIds = [];
  289. $( '#attList .check-file:checked').each(function() {
  290. const fileId = $(this).attr('file-id');
  291. fileId && fileIds.push(fileId);
  292. });
  293. if (fileIds.length) {
  294. if (fileIds.length > 20) {
  295. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`);
  296. }
  297. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0});
  298. $(this).attr('disabled', "true");
  299. const btn = $(this);
  300. const fileArr = [];
  301. for (const id of fileIds) {
  302. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  303. fileArr.push({
  304. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  305. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  306. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  307. });
  308. }
  309. const packageName = `${trName}-${detailName}-附件.zip`;
  310. try {
  311. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  312. } catch (e) {
  313. btn.removeAttr('disabled');
  314. toastr.clear();
  315. toastr.error('批量下载失败');
  316. }
  317. }
  318. });
  319. });
  320. // 生成附件列表
  321. function getAllList(currPageNum = 1) {
  322. // 每页最多几个附件
  323. const pageCount = 20;
  324. // 附件总数
  325. const total = attData.length;
  326. // 总页数
  327. const pageNum = Math.ceil(total/pageCount);
  328. $('#totalPage').text(pageNum);
  329. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  330. // 当前页附件内容
  331. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  332. currPageFileData = currPageAttData;
  333. let html = '';
  334. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  335. for(const [index,att] of currPageAttData.entries()) {
  336. html += `<tr>
  337. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  338. <td>${((currPageNum-1)*pageCount)+index+1}</td>
  339. <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>
  340. <td>${moment(att.upload_time).format("YYYY-MM-DD HH:mm:ss")}<br>${bytesToSize(att.filesize)}</td>
  341. <td>
  342. <a href="/payment/${tenderId}/detail/${detailId}/file/${att.id}/download" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`
  343. html += (att.uid === accountId && (detailStatus === auditConst.status.checked ? Boolean(att.extra_upload) : true)) ?
  344. `<a href="javascript:void(0)" class="mr-2 delete-file" data-attid="${att.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : '';
  345. html += `</td>`;
  346. }
  347. $('#attList').html(html);
  348. $('#attList').on('click', 'tr', function() {
  349. $('#attList tr').removeClass('bg-light');
  350. $(this).addClass('bg-light');
  351. });
  352. }
  353. // 整数位数判断
  354. function countDigits(number) {
  355. var numberString = Math.abs(number).toString();
  356. var decimalIndex = numberString.indexOf('.'); // 查找小数点的索引
  357. var scientificIndex = numberString.toLowerCase().indexOf('e'); // 查找科学计数法中的'e'索引
  358. var integerPart;
  359. if (decimalIndex !== -1) {
  360. integerPart = numberString.slice(0, decimalIndex); // 提取小数点之前的部分作为整数部分
  361. } else if (scientificIndex !== -1) {
  362. integerPart = numberString.slice(0, scientificIndex); // 提取科学计数法中'e'之前的部分作为整数部分
  363. } else {
  364. integerPart = numberString; // 整个数字都是整数部分
  365. }
  366. return integerPart.length;
  367. }
  368. function bytesToSize(bytes) {
  369. if (parseInt(bytes) === 0) return '0 B';
  370. const k = 1024;
  371. const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  372. const i = Math.floor(Math.log(bytes) / Math.log(k));
  373. // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
  374. return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
  375. }
  376. // 大写转换
  377. // 向右移位
  378. function shiftRight(number, digit) {
  379. digit = parseInt(digit, 10);
  380. var value = number.toString().split('e');
  381. return +(value[0] + 'e' + (value[1] ? +value[1] + digit : digit));
  382. }
  383. // 向左移位
  384. function shiftLeft(number, digit) {
  385. digit = parseInt(digit, 10);
  386. var value = number.toString().split('e');
  387. return +(value[0] + 'e' + (value[1] ? +value[1] - digit : -digit));
  388. }
  389. var numberToChinese = function (n) {
  390. var fraction = ['角', '分'];
  391. var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
  392. var unit = [
  393. ['元', '万', '亿'],
  394. ['', '拾', '佰', '仟'],
  395. ];
  396. var head = n < 0 ? '负' : '';
  397. n = Math.abs(n);
  398. var s = '';
  399. for (var i = 0; i < fraction.length; i++) {
  400. s += (digit[Math.floor(shiftRight(n, 1 + i)) % 10] + fraction[i]).replace(
  401. /零./,
  402. ''
  403. );
  404. }
  405. s = s || '';
  406. n = Math.floor(n);
  407. for (var i = 0; i < unit[0].length && n > 0; i++) {
  408. var p = '';
  409. for (var j = 0; j < unit[1].length && n > 0; j++) {
  410. p = digit[n % 10] + unit[1][j] + p;
  411. n = Math.floor(shiftLeft(n, 1));
  412. }
  413. s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
  414. }
  415. return (
  416. head +
  417. s
  418. .replace(/(零.)*零元/, '元')
  419. .replace(/(零.)+/g, '零')
  420. // .replace(/^整$/, '零元整')
  421. );
  422. };
  423. function dateTranChinese(day) {
  424. const dateParts = day.split('-');
  425. return dateParts[0] + '年' + dateParts[1] + '月' + dateParts[2] + '日';
  426. }