'use strict'; /** * 变更令详细页js * * @author EllisRan. * @date 2018/11/22 * @version */ function getPasteHint (str, row = '') { let returnObj = str; if (row) { returnObj.msg = '清单第' + (row+1) + '行' + str.msg; } return returnObj; } $(document).ready(() => { const changeSpreadSetting = { cols: [ {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true}, {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: true}, {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true}, {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price', readOnly: true}, {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: true}, {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: true}, {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.oamount', readOnly: true}, {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.oa_tp', readOnly: true}, {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount', readOnly: true}, {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.ca_tp', readOnly: true}, {title: '变更后|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'}, {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.changed_tp'}, ], emptyRows: 0, headRows: 2, headRowHeight: [25, 25], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', // readOnly: true, rowHeader:[ { rowHeaderType: 'circle', setting: { size: 5, indent: 16, getColor: function (index, data) { if (!data) return; if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) { return '#dc3545'; } if(data.lid != 0) return; return '#007bff'; } }, }, ], localCache: { key: 'changes-spread', colWidth: true, } }; for (const aid of aidList) { const userinfo = _.find(auditList2, { 'uid': aid }); const newColcount = { title: userinfo.name + ' 审批|数量', colSpan: '2|1', rowSpan: '1|1', field: 'audit_amount_' + aid, hAlign: 2, width: 60, type: 'Number', readOnly: aid !== parseInt(accountId) }; const newColTp = { title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp_' + aid, hAlign: 2, width: 80, type: 'Number', readOnly: true }; changeSpreadSetting.cols.push(newColcount); changeSpreadSetting.cols.push(newColTp); } const changeCol = { getValue: { unit_price: function(data) { return ZhCalc.round(data.unit_price, unitPriceUnit); }, oa_tp: function (data) { return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount, findDecimal(data.unit))), totalPriceUnit); }, ca_tp: function (data) { return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit); }, oamount: function (data) { return ZhCalc.round(data.oamount, findDecimal(data.unit)); }, camount: function (data) { return ZhCalc.round(data.camount, findDecimal(data.unit)); }, changed_amount: function (data) { return ZhCalc.round(ZhCalc.add(data.oamount, data.spamount), findDecimal(data.unit)); }, changed_tp: function (data) { return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(ZhCalc.add(data.oamount, data.spamount), findDecimal(data.unit))), totalPriceUnit); }, }, }; const changeSpreadObj = { makeSjsFooter: function () { // 增加汇总行并设为锁定禁止编辑状态 changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1); changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计'); changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1); changeSpreadObj.countSum(); }, setAuditValue: function () { for (const c of changeList) { for (const j of aidList) { c['audit_amount_' + j] = ZhCalc.round(c['audit_amount_' + j], findDecimal(c.unit)); c['sa_tp_' + j] = ZhCalc.round(ZhCalc.mul(c['audit_amount_' + j], ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit); } } // const rowCount = changeSpreadSheet.getRowCount(); // // 用户的数据合计 // for (const j in aidList) { // for(let i = 0; i <= rowCount - 1; i++){ // const data = { // unit_price: changeSpreadSheet.getValue(i, 5), // amount: parseFloat(changeSpreadSheet.getValue(i, 10 + parseInt(j)*2)), // }; // const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.amount), totalPriceUnit); // changeSpreadSheet.setValue(i, 11 + j*2, sum !== 0 ? sum : null); // } // } }, resetXmjSpread: function(data = null) { const xmj = []; if (data && data.lid != 0 && data.xmj_code !== '' && data.xmj_code !== null) { if (data.bwmx === data.xmj_jldy) { data.bwmx = ''; } xmj.push(data); } SpreadJsObj.loadSheetData(xmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, xmj); }, selectionChanged: function (e, info) { const data = SpreadJsObj.getSelectObject(info.sheet); changeSpreadObj.resetXmjSpread(data); }, setRowValueAndSum: function (data, row, col) { for (const j in aidList) { const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, parseFloat(changeSpreadSheet.getValue(row, 12 + parseInt(j)*2))), totalPriceUnit); changeSpreadSheet.setValue(row, 13 + j*2, sum !== 0 ? sum : null); } // const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.spamount), totalPriceUnit); // changeSpreadSheet.setValue(row, col+1, sum !== 0 ? sum : null); const rowCount = changeSpreadSheet.getRowCount(); // 用户的数据合计 // 变更后数据合计 let audit_sum = 0; let changed_sum = 0; for(let i = 0; i < rowCount - 1; i++){ audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, col+1)); changed_sum = ZhCalc.add(changed_sum, changeSpreadSheet.getValue(i, 11)); } changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, col+1, audit_sum !== 0 ? audit_sum : null); changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 11, changed_sum !== 0 ? changed_sum : null); }, countSum: function() { const rowCount = changeSpreadSheet.getRowCount(); let oSum = 0, cSum = 0, cdSum = 0; for(let i = 0; i < rowCount - 1; i++){ oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 7)); cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9)); cdSum = ZhCalc.add(cdSum, changeSpreadSheet.getValue(i, 11)); } changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null); changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null); changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 11, cdSum !== 0 ? cdSum : null); // 用户的数据合计 for (const j in aidList) { let audit_sum = 0; for(let i = 0; i < rowCount - 1; i++){ audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, 13 + j*2)); } changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 13 + j*2, audit_sum !== 0 ? audit_sum : null); } }, deletePress: function (sheet) { return; }, editEnded: function (e, info) { if (info.sheet.zh_setting) { const select = SpreadJsObj.getSelectObject(info.sheet); const col = info.sheet.zh_setting.cols[info.col]; // 未改变值则不提交 let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : ''); const orgValue = select[col.field]; if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) { SpreadJsObj.reLoadRowData(info.sheet, info.row); changeSpreadObj.setRowValueAndSum(select, info.row, info.col); return; } // 判断部分值是否输入的是数字判断和数据计算 if (col.type === 'Number') { if (isNaN(validText)) { toastr.error('不能输入其它非数字类型字符'); SpreadJsObj.reLoadRowData(info.sheet, info.row); changeSpreadObj.setRowValueAndSum(select, info.row, info.col); return; } validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0; // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改 const usedInfo = _.find(changeUsedData, { cbid: select.id }); if (usedInfo && validText >= 0 && validText < usedInfo.qty) { toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty); SpreadJsObj.reLoadRowData(info.sheet, info.row); changeSpreadObj.setRowValueAndSum(select, info.row, info.col); return; } else if (usedInfo && validText < 0 && validText > usedInfo.qty) { toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty); SpreadJsObj.reLoadRowData(info.sheet, info.row); changeSpreadObj.setRowValueAndSum(select, info.row, info.col); return; } } select[col.field] = validText; select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0; const data = { id: select.id, spamount: select.spamount, }; console.log(data); // 更新至服务器 postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) { changeList.splice(info.row, 1, select); SpreadJsObj.reLoadRowData(info.sheet, info.row); changeSpreadObj.setRowValueAndSum(select, info.row, info.col); }, function () { select[col.field] = orgValue; select.spamount = orgValue; SpreadJsObj.reLoadRowData(info.sheet, info.row); changeSpreadObj.setRowValueAndSum(select, info.row, info.col); }); } }, clipboardPasted(e, info) { const hint = { cellError: {type: 'error', msg: '粘贴内容超出了表格范围'}, numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'}, qtyError: {type: 'error', msg: '变更数值必须大于等于已调用值'}, }; const range = info.cellRange; const sortData = info.sheet.zh_data || []; // console.log(info, range); // if (info.cellRange.row + info.cellRange.rowCount > sortData.length) { // toastMessageUniq(hint.cellError); // // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData); // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet); // SpreadJsObj.reLoadSheetData(changeSpreadSheet); // changeSpreadObj.setAuditValue(); // changeSpreadObj.makeSjsFooter(); // return; // } // if (sortData.length > 0 && range.col + range.colCount > 10) { // toastMessageUniq(hint.cellError); // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet); // SpreadJsObj.reLoadSheetData(changeSpreadSheet); // changeSpreadObj.setAuditValue(); // changeSpreadObj.makeSjsFooter(); // return; // } const data = []; // const rowData = []; for (let iRow = 0; iRow < range.rowCount; iRow++) { let bPaste = true; const curRow = range.row + iRow; // const materialData = JSON.parse(JSON.stringify(sortData[curRow])); const cLData = { id: sortData[curRow].id }; const hintRow = range.rowCount > 1 ? curRow : ''; let sameCol = 0; for (let iCol = 0; iCol < range.colCount; iCol++) { const curCol = range.col + iCol; const colSetting = info.sheet.zh_setting.cols[curCol]; if (!colSetting) continue; let validText = info.sheet.getText(curRow, curCol); validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null); const orgValue = sortData[curRow][colSetting.field]; if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) { sameCol++; if (range.colCount === sameCol) { bPaste = false; } continue; } if (colSetting.type === 'Number') { if (isNaN(validText)) { toastMessageUniq(getPasteHint(hint.numberExpr, hintRow)); bPaste = false; continue; } validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0; // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改 const usedInfo = _.find(changeUsedData, { id: sortData[curRow].id }); if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) { toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty); SpreadJsObj.reLoadRowData(info.sheet, curRow); changeSpreadObj.setRowValueAndSum(sortData[curRow], curRow, curCol); bPaste = false; continue; } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) { toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty); SpreadJsObj.reLoadRowData(info.sheet, curRow); changeSpreadObj.setRowValueAndSum(sortData[curRow], curRow, curCol); bPaste = false; continue; } } // cLData[colSetting.field] = validText; sortData[curRow][colSetting.field] = validText; cLData.spamount = validText; } if (bPaste) { data.push(cLData); // rowData.push(curRow); } else { // SpreadJsObj.reLoadRowData(info.sheet, curRow); } } if (data.length === 0) { // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount); return; } console.log(data); // 更新至服务器 postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) { changeList = result; changeSpreadObj.setAuditValue(); SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList); changeSpreadObj.makeSjsFooter(); changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet)); }, function () { changeSpreadObj.setAuditValue(); SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount); return; }); }, }; SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol); SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting); changeSpreadObj.setAuditValue(); SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList); console.log(changeList); changeSpreadObj.makeSjsFooter(); changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet)); const userIndex = aidList.indexOf(parseInt(accountId)); changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded); changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted); changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged); SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress); // 审批提交与判断 $('.approval-btn').on('click', function () { // 判断审批状态 let returnflag = true; if ($(this).hasClass('btn-success')) { const sdesc = $('#success-approval').find('textarea').val(); if (sdesc === '') { toastr.error('审批意见不能为空!'); returnflag = false; } if ($('input[name="p_code"]').val() === '') { toastr.error('变更令号(批复编号)不能为空!'); returnflag = false; } else if ($('input[name="p_code"]').val() !== undefined) { $('input[name="p_code"]').val($.trim($('input[name="p_code"]').val())); const postData = { p_code: $('input[name="p_code"]').val(), }; postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData, function (result) { }, function (data) { returnflag = false; }); } // 判断并提交变更清单表格数据到表单中 const clist = []; for(const [i,cl] of changeList.entries()) { // if (cl['audit_amount_' + accountId] === null || cl['audit_amount_' + accountId] === '') { // toastr.error('清单第' + (i+1) + '行审批变更数量不能为空'); // returnflag = false; // } else { clist.push(cl.id + '_' + cl['audit_amount_' + accountId]); // } } $('#change-list-approval').val(clist.join(',')); if(returnflag) { $('input[name="w_code"]').val($.trim($('#w_code').val())); $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '
').replace(/\n/g, '
').replace(/\s/g, ' ')); if ($('#warning-text').length) $('#warning-text').remove() $('#success-approval').submit(); } } else { const sdesc = $('#fail-approval').find('textarea').val(); if (sdesc === '') { toastr.error('审批意见不能为空!'); returnflag = false; } const type = $('#fail-approval').find('input[name="status"]:checked').val(); if (type === undefined) { // toastr.error('请选择退回类型!'); if (!$('#warning-text').length) { $('#change-back-content').prepend('

请选择退回流程

'); } returnflag = false; } if(returnflag) { $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '
').replace(/\n/g, '
').replace(/\s/g, ' ')); $('input[name="w_code"]').val($.trim($('#w_code').val())); $('#fail-approval').submit(); } } }) }); const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) { if (showWaiting) showWaitingView(); $.ajax({ type:"POST", url: url, data: {'data': JSON.stringify(data)}, dataType: 'json', cache: false, async: false, timeout: 60000, beforeSend: function(xhr) { let csrfToken = Cookies.get('csrfToken_j'); xhr.setRequestHeader('x-csrf-token', csrfToken); }, success: function(result){ if (result.err === 0) { if (successCallback) { successCallback(result.data); } } else { toastr.error(result.msg); if (errorCallBack) { errorCallBack(result.msg); } } if (showWaiting) closeWaitingView(); }, error: function(jqXHR, textStatus, errorThrown){ toastr.error('error: ' + textStatus + " " + errorThrown); if (errorCallBack) { errorCallBack(); } if (showWaiting) closeWaitingView(); } }); }; function auditCheck(i) { const inlineRadio1 = $('#change-back:checked').val() const inlineRadio2 = $('#chagne-backnew:checked').val() const opinion = $('textarea[name="sdesc"]').eq(i).val().replace(/\r\n/g, '
').replace(/\n/g, '
').replace(/\s/g, ' '); $('textarea[name="sdesc"]').eq(i).val(opinion); if (i === 1) { if (!inlineRadio1 && !inlineRadio2) { if (!$('#warning-text').length) { $('#reject-process').prepend('

请选择退回流程

'); } return false; } if ($('#warning-text').length) $('#warning-text').remove() } return true; }