123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- function iniPage() {
- dynamicLoadJs('/public/jspdf/Arial Narrow-normal.js');
- dynamicLoadJs('/public/jspdf/Arial Narrow-bold.js');
- dynamicLoadJs('/public/jspdf/Arial Narrow-italic.js');
- dynamicLoadJs('/public/jspdf/Arial Narrow-bolditalic.js');
- rptTplObj.isLoading = true;
- dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal2.js', 'normal', getPdfFontCallbackLight);
- dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', 'bold', getPdfFontCallbackLight);
- }
- function getPdfFontCallbackLight(fontProperty) {
- rptTplObj.pdfFont['SmartSimsun'].push(fontProperty);
- if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
- rptTplObj.isLoading = false;
- }
- }
- function getPdfFontCallback(fontProperty) {
- if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
- downloadPDFReport([tesRpttData], 'A4', ['测试审核表'], [], [], [-1], []);
- }
- }
- $(function () {
- autoFlashHeight();
- auditRptPrintHelper.showPage();
- iniPage();
- //初始化所有附件列表
- getAllList();
- $('#rpt-form input[type!="radio"]').on('change', function () {
- let newVal = $(this).val();
- const index = parseInt($(this).data('index'));
- const type = $(this).attr('type');
- if (type === 'number' && newVal) {
- const val = _.toNumber(newVal);
- if (countDigits(val) > 11) {
- toastr.error('请输入11位整数内的数');
- return;
- }
- const reg = new RegExp("^\\d+(\\.\\d{1,"+ 6 +"})?$");
- if (!reg.test(val)) {
- toastr.warning('已保留6位小数');
- newVal = ZhCalc.round(val, 6);
- $(this).val(newVal);
- }
- // find link(大写转换)
- const linkList = _.filter(tesRpttData.items[0].interact_cells, { link: index });
- if (linkList.length > 0) {
- const chineseNum = numberToChinese(newVal);
- // 赋值到input框并展示在报表里
- for (const cell of linkList) {
- $('#rpt-form input[data-index="'+ cell.index +'"]').val(chineseNum);
- tesRpttData.items[0].interact_cells[cell.index].Value =
- tesRpttData.items[0].interact_cells[cell.index].Prefix ? tesRpttData.items[0].interact_cells[cell.index].Prefix + chineseNum : chineseNum;
- }
- }
- }
- checkAndUpdate(index, newVal, $(this));
- });
- $(".link-dropdown").on("click",function (e) {
- e.stopPropagation();
- });
- $('.change-link').on('click', function () {
- const link = $(this).parents('.link-dropdown').find('input:checked').val();
- const index = parseInt($(this).attr('item-index'));
- const old_link = $(this).attr('old-link');
- if (old_link !== link) {
- let showTips = '';
- if (link !== '') {
- const numberInfo = _.find(tesRpttData.items[0].interact_cells, { index: parseInt(link) });
- if (numberInfo) showTips = '关联数据:' + numberInfo.Label;
- }
- $(this).parents('.link-dropdown').siblings('.show-link').html(showTips);
- $(this).attr('old-link', link);
- const info = link !== '' ? tesRpttData.items[0].interact_cells[link] : null;
- const linkValue = info ? removePreFix((info.Prefix ? info.Prefix : null), info.Value) : '';
- const chineseNum = linkValue ? numberToChinese(linkValue) : '';
- tesRpttData.items[0].interact_cells[index].link = link !== '' ? parseInt(link) : '';
- tesRpttData.items[0].interact_cells[index].Value = tesRpttData.items[0].interact_cells[index].Prefix ? tesRpttData.items[0].interact_cells[index].Prefix + chineseNum : chineseNum;
- const _self = $(this);
- postData('/sp/' + spid + '/payment/' + tenderId + '/detail/' + detailId + '/save', { type: 'update_rpt', report_json: tesRpttData }, function (result) {
- $('#rpt-form input[data-index="'+ index +'"]').val(chineseNum);
- auditRptPrintHelper.showPage();
- _self.parents('.show-link-dropdown').dropdown('toggle');
- });
- } else {
- $(this).parents('.show-link-dropdown').dropdown('toggle');
- }
- });
- function removePreFix(prefix, value) {
- const result = prefix ? _.replace(value, prefix, '') : value;
- return result ? parseFloat(result) : '';
- }
- $('.show-link-dropdown').on('show.bs.dropdown', function () {
- const link = $(this).find('button').attr('old-link');
- const index = $(this).find('button').attr('item-index');
- $('input:radio[name="radio_'+ index +'"][value="'+ link + '"]').prop('checked', true);
- });
- $('#rpt-form textarea').on('change', function () {
- const newVal = $(this).val();
- const index = parseInt($(this).data('index'));
- checkAndUpdate(index, newVal, $(this));
- });
- $('#chose-private-stamp-path .stamp-img').on('click', function () {
- if (!$(this).hasClass('card-gk-active')) {
- $('#chose-private-stamp-path .stamp-img').removeClass('card-gk-active');
- $('#chose-private-stamp-path .stamp-img').find('.sel-width').removeClass('sel-blue');
- $(this).addClass('card-gk-active');
- $(this).find('.sel-width').addClass('sel-blue');
- }
- });
- $('#chose-private-stamp-path').on('show.bs.modal', function () {
- $('#chose-private-stamp-path .stamp-img').removeClass('card-gk-active');
- $('#chose-private-stamp-path .stamp-img').find('.sel-width').removeClass('sel-blue');
- $('#chose-private-stamp-path .stamp-img').each(function () {
- const src = $(this).find('img').attr('data-src');
- if (src === currentStamp) {
- $(this).addClass('card-gk-active');
- $(this).find('.sel-width').addClass('sel-blue');
- return;
- }
- });
- });
- $('#select_stamp_path_btn').click(function () {
- const src = $('#chose-private-stamp-path .card-gk-active').find('img').attr('data-src');
- currentStamp = src;
- $('#stamp_path').val(src);
- $('#chose-private-stamp-path').modal('hide');
- });
- let signatureDate = null;
- $('#sub-sp5').on('show.bs.modal', function () {
- $('#sign_path').prop('checked', rptAudit.signature_msg.sign_path !== null);
- $('#company_stamp').prop('checked', rptAudit.signature_msg.company_stamp !== null);
- $('#stamp_path').prop('checked', rptAudit.signature_msg.stamp_path !== null);
- $('#signature_date').val(rptAudit.signature_msg.date ? rptAudit.signature_msg.date : new Date());
- signatureDate = !signatureDate ? $('#signature_date').datepicker().data('datepicker') : signatureDate;
- if (signatureDate && rptAudit.signature_msg.date) {
- signatureDate.selectDate(new Date(rptAudit.signature_msg.date));
- } else if (signatureDate) {
- signatureDate.selectDate(new Date());
- // signatureDate.clear();
- }
- $('#signature_content').val(rptAudit.signature_msg.content ? rptAudit.signature_msg.content : '');
- });
- $('#sp-done').on('show.bs.modal', function () {
- $('#sp-done').find('textarea').val(rptAudit && rptAudit.signature_msg.content ? rptAudit.signature_msg.content : '同意');
- });
- $('#commit_sign').click(function () {
- rptAudit.signature_msg.sign_path = $('#sign_path').is(':checked') ? $('#sign_path').val() : null;
- rptAudit.signature_msg.company_stamp = $('#company_stamp').is(':checked') ? $('#company_stamp').val() : null;
- rptAudit.signature_msg.stamp_path = $('#stamp_path').is(':checked') ? $('#stamp_path').val() : null;
- rptAudit.signature_msg.date = $('#signature_date').val() ? $('#signature_date').val() : null;
- rptAudit.signature_msg.content = $('#signature_content').val() ? $('#signature_content').val() : null;
- console.log(rptAudit.signature_msg);
- // 签章
- if (rptAudit.signature_msg.sign_path !== null || rptAudit.signature_msg.company_stamp !== null || rptAudit.signature_msg.stamp_path !== null) {
- const signArray = [];
- rptAudit.signature_msg.sign_path ? signArray.push('/public/upload/sign/' + rptAudit.signature_msg.sign_path) : signArray.push('');
- rptAudit.signature_msg.company_stamp ? signArray.push(rptAudit.signature_msg.company_stamp) : signArray.push('');
- rptAudit.signature_msg.stamp_path ? signArray.push(rptAudit.signature_msg.stamp_path) : signArray.push('');
- tesRpttData.items[0].signature_cells[rptAudit.signature_index].path = signArray.length > 0 ? signArray.join('!;!') : null;
- const date_index = _.findIndex(tesRpttData.items[0].signature_date_cells, { signature_name: rptAudit.signature_name + '_签字日期' });
- if (date_index !== -1) {
- tesRpttData.items[0].signature_date_cells[date_index].Value = rptAudit.signature_msg.date ? dateTranChinese(rptAudit.signature_msg.date) : '';
- }
- const content_index = _.findIndex(tesRpttData.items[0].signature_audit_cells, { signature_name: rptAudit.signature_name + '_审核意见' });
- if (content_index !== -1) {
- tesRpttData.items[0].signature_audit_cells[content_index].Value = rptAudit.signature_msg.content ? rptAudit.signature_msg.content : '';
- }
- postData('/sp/' + spid + '/payment/' + tenderId + '/detail/' + detailId + '/save', { type: 'update_sign', signature_msg: rptAudit.signature_msg }, function (result) {
- auditRptPrintHelper.showPage();
- // 更新签署进度图表展示
- $('#rpt_audit_sign td').eq(3).html(rptAudit.signature_msg.sign_path !== null ? '<i class="fa fa-check text-success"></i>' : '');
- $('#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>' : '');
- });
- $('#sub-sp5').modal('hide');
- } else {
- toastr.error('至少选择一个签字/签章');
- }
- });
- let timer = null
- function checkAndUpdate(index, newVal, _self) {
- if (tesRpttData.items[0].interact_cells[index].DataType === 'intact_type_number' && _.indexOf(tesRpttData.items[0].interact_cells[index].Value, '元') !== -1) {
- newVal = newVal + '元';
- }
- clearTimeout(timer);
- timer = setTimeout(() => {
- tesRpttData.items[0].interact_cells[index].Value = tesRpttData.items[0].interact_cells[index].Prefix ? tesRpttData.items[0].interact_cells[index].Prefix + newVal : newVal;
- postData('/sp/' + spid + '/payment/' + tenderId + '/detail/' + detailId + '/save', { type: 'update_rpt', report_json: tesRpttData }, function (result) {
- auditRptPrintHelper.showPage();
- });
- clearTimeout(timer);
- }, 500);
- }
- //tab change
- $('a[data-toggle="tab"]').on('shown.bs.tab', function () {
- const tab = $(this).data('tab');
- if (tab === 'fujian') {
- $('#fujian_btn').show();
- } else {
- $('#fujian_btn').hide();
- }
- });
- // 切换页数
- $('.page-select').on('click', function () {
- const totalPageNum = parseInt($('#totalPage').text());
- const lastPageNum = parseInt($('#currentPage').text());
- const status = $(this).attr('content');
- if (status === 'pre' && lastPageNum > 1) {
- getAllList(lastPageNum-1);
- $('#annex .check-all-file').prop('checked', false)
- } else if (status === 'next' && lastPageNum < totalPageNum) {
- getAllList(lastPageNum+1);
- $('#annex .check-all-file').prop('checked', false)
- }
- });
- // 上传附件
- $('#upload-file-btn').click(function () {
- const files = $('#upload-file')[0].files;
- const formData = new FormData();
- for (const file of files) {
- if (file === undefined) {
- toastr.error('未选择上传文件!');
- return false;
- }
- const filesize = file.size;
- if (filesize > 30 * 1024 * 1024) {
- toastr.error('文件大小过大!');
- return false;
- }
- const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
- if (whiteList.indexOf(fileext) === -1) {
- toastr.error('只能上传指定格式的附件!');
- return false;
- }
- formData.append('size', filesize);
- formData.append('file[]', file);
- }
- if (uidList.indexOf(accountId) === -1) {
- return toastr.error('暂无权限上传!');
- }
- postDataWithFile(window.location.pathname + '/file/upload', formData, function (data) {
- attData = data.concat(attData);
- // 重新生成List
- getAllList();
- $('#addfujian').modal('hide');
- }, function () {
- });
- $('#upload-file').val('');
- });
- // 删除附件
- $('body').on('click', '.delete-file', function () {
- let attid = $(this).data('attid');
- let self = $(this);
- const data = {id: attid};
- postData(window.location.pathname + '/file/delete', data, function (result) {
- // 删除到attData中
- const att_index = attData.findIndex(function (item) {
- return item.id === parseInt(attid);
- });
- attData.splice(att_index, 1);
- // 重新生成List
- if ($('#attList tr').length === 1) {
- getAllList(parseInt($('#currentPage').text()) - 1);
- } else {
- getAllList(parseInt($('#currentPage').text()));
- }
- });
- });
- $('#attList').on('click', '.file-atn', function() {
- const id = $(this).attr('f-id');
- postData(`'/sp/${spid}/payment/${tenderId}/detail/${detailId}/file/${id}/download`, {}, (data) => {
- const { filepath } = data;
- $('#file-upload').attr('href', filepath);
- $('#file-upload')[0].click();
- })
- });
- $('#attList').on('click', '.check-file', function() {
- const checkedList = $('#attList').find('input:checked');
- const childs = $('#attList').children().length;
- const checkBox = $('#check-all-file');
- if (checkedList.length === childs) {
- checkBox.prop("checked", true);
- } else {
- checkBox.prop("checked", false);
- }
- });
- $('#check-all-file').click(function() {
- const isCheck = $(this).is(':checked');
- $('#attList').children().each(function() {
- $(this).find('input:checkbox').prop("checked", isCheck);
- })
- });
- $('#bach-download').click(function() {
- const fileIds = [];
- $( '#attList .check-file:checked').each(function() {
- const fileId = $(this).attr('file-id');
- fileId && fileIds.push(fileId);
- });
- if (fileIds.length) {
- if (fileIds.length > 20) {
- return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`);
- }
- toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0});
- $(this).attr('disabled', "true");
- const btn = $(this);
- const fileArr = [];
- for (const id of fileIds) {
- const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
- fileArr.push({
- url: fileInfo.orginpath, //文件的oss存储路径 (必填)
- name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
- foldPath: '' // (可选, 文件在压缩包中的存储路径)
- });
- }
- const packageName = `${trName}-${detailName}-附件.zip`;
- try {
- zipOss.downloadFromAliOss(fileArr, packageName, btn);
- } catch (e) {
- btn.removeAttr('disabled');
- toastr.clear();
- toastr.error('批量下载失败');
- }
- }
- });
- });
- // 生成附件列表
- function getAllList(currPageNum = 1) {
- // 每页最多几个附件
- const pageCount = 20;
- // 附件总数
- const total = attData.length;
- // 总页数
- const pageNum = Math.ceil(total/pageCount);
- $('#totalPage').text(pageNum);
- $('#currentPage').text(total === 0 ? 0 : currPageNum);
- // 当前页附件内容
- const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
- currPageFileData = currPageAttData;
- let html = '';
- // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
- for(const [index,att] of currPageAttData.entries()) {
- html += `<tr>
- <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
- <td>${((currPageNum-1)*pageCount)+index+1}</td>
- <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>
- <td>${moment(att.upload_time).format("YYYY-MM-DD HH:mm:ss")}<br>${bytesToSize(att.filesize)}</td>
- <td>
- <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>`
- html += (att.uid === accountId && (detailStatus === auditConst.status.checked ? Boolean(att.extra_upload) : true)) ?
- `<a href="javascript:void(0)" class="mr-2 delete-file" data-attid="${att.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : '';
- html += `</td>`;
- }
- $('#attList').html(html);
- $('#attList').on('click', 'tr', function() {
- $('#attList tr').removeClass('bg-light');
- $(this).addClass('bg-light');
- });
- }
- // 整数位数判断
- function countDigits(number) {
- var numberString = Math.abs(number).toString();
- var decimalIndex = numberString.indexOf('.'); // 查找小数点的索引
- var scientificIndex = numberString.toLowerCase().indexOf('e'); // 查找科学计数法中的'e'索引
- var integerPart;
- if (decimalIndex !== -1) {
- integerPart = numberString.slice(0, decimalIndex); // 提取小数点之前的部分作为整数部分
- } else if (scientificIndex !== -1) {
- integerPart = numberString.slice(0, scientificIndex); // 提取科学计数法中'e'之前的部分作为整数部分
- } else {
- integerPart = numberString; // 整个数字都是整数部分
- }
- return integerPart.length;
- }
- function bytesToSize(bytes) {
- if (parseInt(bytes) === 0) return '0 B';
- const k = 1024;
- const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
- const i = Math.floor(Math.log(bytes) / Math.log(k));
- // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
- return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
- }
- // 大写转换
- // 向右移位
- function shiftRight(number, digit) {
- digit = parseInt(digit, 10);
- var value = number.toString().split('e');
- return +(value[0] + 'e' + (value[1] ? +value[1] + digit : digit));
- }
- // 向左移位
- function shiftLeft(number, digit) {
- digit = parseInt(digit, 10);
- var value = number.toString().split('e');
- return +(value[0] + 'e' + (value[1] ? +value[1] - digit : -digit));
- }
- var numberToChinese = function (n) {
- var fraction = ['角', '分'];
- var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
- var unit = [
- ['元', '万', '亿'],
- ['', '拾', '佰', '仟'],
- ];
- var head = n < 0 ? '负' : '';
- n = Math.abs(n);
- var s = '';
- for (var i = 0; i < fraction.length; i++) {
- s += (digit[Math.floor(shiftRight(n, 1 + i)) % 10] + fraction[i]).replace(
- /零./,
- ''
- );
- }
- s = s || '';
- n = Math.floor(n);
- for (var i = 0; i < unit[0].length && n > 0; i++) {
- var p = '';
- for (var j = 0; j < unit[1].length && n > 0; j++) {
- p = digit[n % 10] + unit[1][j] + p;
- n = Math.floor(shiftLeft(n, 1));
- }
- s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
- }
- return (
- head +
- s
- .replace(/(零.)*零元/, '元')
- .replace(/(零.)+/g, '零')
- // .replace(/^整$/, '零元整')
- );
- };
- function dateTranChinese(day) {
- const dateParts = day.split('-');
- return dateParts[0] + '年' + dateParts[1] + '月' + dateParts[2] + '日';
- }
|