payment_detail.js 20 KB

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