/** * 标段相关js * * @author CaiAoLin * @date 2018/2/5 * @version */ // 属性 function loadCommonProperty () { // 合同信息 $('#build-name').val(property.deal_info.buildName); $('#deal-code').val(property.deal_info.dealCode); $('#deal-name').val(property.deal_info.dealName); // 参建单位 // 建设单位 $('#build-company').val(property.construction_unit.build.company); $('#build-corporation').val(property.construction_unit.build.corporation); $('#build-date').val(property.construction_unit.build.date); // 承包单位1 $('#contract1-company').val(property.construction_unit.contract1.company); $('#contract1-corporation').val(property.construction_unit.contract1.corporation); $('#contract1-date').val(property.construction_unit.contract1.date); // 承包单位2 $('#contract2-company').val(property.construction_unit.contract2.company); $('#contract2-corporation').val(property.construction_unit.contract2.corporation); $('#contract2-date').val(property.construction_unit.contract2.date); // 监理单位1 $('#supervision1-company').val(property.construction_unit.supervision1.company); $('#supervision1-corporation').val(property.construction_unit.supervision1.corporation); $('#supervision1-date').val(property.construction_unit.supervision1.date); // 监理单位2 $('#supervision2-company').val(property.construction_unit.supervision2.company); $('#supervision2-corporation').val(property.construction_unit.supervision2.corporation); $('#supervision2-date').val(property.construction_unit.supervision2.date); // 技术参数 $('#loadLevel').val(property.tech_param.loadLevel); $('#length').val(property.tech_param.loadLength); $('#start-peg').val(property.tech_param.startPeg); $('#end-peg').val(property.tech_param.endPeg); $('#lane-count').val(property.tech_param.laneCount); $('#deal-period').val(property.tech_param.dealPeriod); $('#start-date').val(property.tech_param.startDate); $('#plan-end-date').val(property.tech_param.planEndDate); } // 小数位数 function loadCalculateProperty () { $('#decimal-up').val(property.decimal.up); $('#decimal-tp').val(property.decimal.tp); $('#decimal-pay')[0].checked = property.decimal.pay; $('#decimal-pay-tp').val(property.decimal.payTp); } // 显示设置 function loadDisplayProperty () { $('#ledger-dgn-qty')[0].checked = property.display.ledger.dgnQty; $('#ledger-cl-qty')[0].checked = property.display.ledger.clQty; } // 设置某个div下全部的input、select是否只读 function setReadOnly(obj, readOnly) { if (readOnly) { $('input', obj).attr('readonly', ''); $('select', obj).attr('disabled', ''); $('input[type=checkbox]', obj).attr('disabled', ''); } else { $('input', obj).removeAttr('readonly'); $('select', obj).removeAttr('disabled'); $('input[type=checkbox]', obj).removeAttr('disabled'); } } // 根据Min Max限制Input输入 function limitInputMinMax (obj) { if (_.toNumber(obj.value) > _.toNumber(obj.max)) { obj.value = obj.max; } if(_.toNumber(obj.value) < _.toNumber(obj.min)) { obj.value = obj.min; } } // 根据Maxlength限制input输入 function limitMaxLength (obj) { if (obj.value.length > obj.maxLength) { obj.value = obj.value.substr(0, obj.maxLength); } } // 根据正则限制输入 function limitReg(obj, reg) { obj.value = obj.value.replace(reg, ''); } // 小数位数 input 输入限制 function limitDecimal(obj) { limitReg(obj, /[^\d]/g); limitMaxLength(obj); limitInputMinMax(obj); } function limitDealParamLength(obj) { limitReg(obj, /[^\d\.]/g); // 过滤数字和. limitReg(obj, /\.{2,}/g); // 过滤第二个. limitInputMinMax(obj); } function checkNumberValid(obj) { const value = _.toNumber(obj.value); obj.value = value ? value : ''; } $(document).ready(function() { // 清单精度 const precisionObj = (function () { const spread = SpreadJsObj.createNewSpread($('#precision-spread')[0]); spread.options.showVerticalScrollbar = false; spread.options.showHorizontalScrollbar = false; const sheet = spread.getActiveSheet(); SpreadJsObj.protectedSheet(sheet); sheet.options.rowHeaderVisible = false; sheet.options.colHeaderVisible = false; const vStyle = new spreadNS.Style(); vStyle.font = '12px 微软雅黑'; sheet.setDefaultStyle(vStyle, spreadNS.SheetArea.viewport); SpreadJsObj.massOperationSheet(sheet, function () { sheet.defaults.rowHeight = 25; sheet.setColumnCount(3); sheet.setRowCount(14); sheet.setColumnWidth(0, 1); sheet.setColumnWidth(1, 100); sheet.setColumnWidth(2, 60); sheet.setRowHeight(0, 1); sheet.getRange(1, 1, 14, 1).vAlign(1).backColor('#e4e7ea').locked(true); sheet.getRange(1, 2, 14, 1).vAlign(1).hAlign(2).locked(true); sheet.setText(1, 1, 't'); sheet.setText(2, 1, 'km'); sheet.setText(3, 1, 'm'); sheet.setText(4, 1, 'm2'); sheet.setText(5, 1, 'm3'); sheet.setText(6, 1, 'kg'); sheet.setText(7, 1, '个'); sheet.setText(8, 1, '台'); sheet.setText(9, 1, '套'); sheet.setText(10, 1, '棵'); sheet.setText(11, 1, '组'); sheet.setText(12, 1, '系统'); sheet.setText(13, 1, '其他未列单位'); const lineBorder = new spreadNS.LineBorder('#6a696e', spreadNS.LineStyle.thin); sheet.getRange(0, 0, 14, 3).setBorder(lineBorder, {all: true}); sheet.getRange(0, 0, 14, 3).formatter('@'); sheet.setSelection(1, 2, 1, 1); }); spread.bind(spreadNS.Events.EditEnded, function (e, info) { const value = _.toNumber(info.editingText); if (!_.isInteger(value)) { toastr.warning('请输入0-6的整数'); sheet.setText(info.row, info.col, '0'); } else if (value > 6) { toastr.warning('请输入0-6的整数'); sheet.setText(info.row, info.col, '6'); } else if (value < 0) { toastr.warning('请输入0-6的整数'); sheet.setText(info.row, info.col, '0'); } }); SpreadJsObj.addDeleteBind(spread, function (sheet) { const sel = sheet.getSelections()[0]; let calc = false; if (sel) { for (let iRow = sel.row, iRowLength = sel.row + sel.rowCount; iRow < iRowLength; iRow++) { if (iRow === 3) continue; for (let iCol = sel.col, iColLength = sel.col + sel.colCount; iCol < iColLength; iCol++) { if (iCol !== 2) continue; sheet.setText(iRow, iCol, '0'); if (iRow === 1 || iRow === 2) calc = true; } } } if (calc) calcHtjMinusZlj(); }); spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) { let bHint = false; for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) { const curRow = info.cellRange.row + iRow; for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) { const curCol = info.cellRange.col + iCol; const value = _.toNumber(info.sheet.getText(curRow, curCol)); if (_.isNaN(value) || !_.isInteger(value)) { bHint = true; info.sheet.setText(curRow, curCol, '0'); } else if (value > 6) { bHint = true; info.sheet.setText(curRow, curCol, '6'); } else if (value < 0) { bHint = true; info.sheet.setText(curRow, curCol, '0'); } } } if (bHint) { toastr.warning('请输入0-6的整数'); } }); function loadPrecisonProperty() { $('#hint-3').hide(); sheet.setValue(1, 2, property.precision.t.value); sheet.setValue(2, 2, property.precision.km.value); sheet.setValue(3, 2, property.precision.m.value); sheet.setValue(4, 2, property.precision.m2.value); sheet.setValue(5, 2, property.precision.m3.value); sheet.setValue(6, 2, property.precision.kg.value); sheet.setValue(7, 2, property.precision.ge.value); sheet.setValue(8, 2, property.precision.tai.value); sheet.setValue(9, 2, property.precision.tao.value); sheet.setValue(10, 2, property.precision.ke.value); sheet.setValue(11, 2, property.precision.zu.value); sheet.setValue(12, 2, property.precision.xitong.value); sheet.setValue(13, 2, property.precision.other.value); } function setReadOnly(readOnly) { sheet.getRange(1, 2, 14, 1).locked(readOnly); } function getNewPrecisionData() { const precision = JSON.parse(JSON.stringify(property.precision)); precision.t.value = _.toNumber(sheet.getText(1, 2)); precision.km.value = _.toNumber(sheet.getText(2, 2)); precision.m.value = _.toNumber(sheet.getText(3, 2)); precision.m2.value = _.toNumber(sheet.getText(4, 2)); precision.m3.value = _.toNumber(sheet.getText(5, 2)); precision.kg.value = _.toNumber(sheet.getText(6, 2)); precision.ge.value = _.toNumber(sheet.getText(7, 2)); precision.tai.value = _.toNumber(sheet.getText(8, 2)); precision.tao.value = _.toNumber(sheet.getText(9, 2)); precision.ke.value = _.toNumber(sheet.getText(10, 2)); precision.zu.value = _.toNumber(sheet.getText(11, 2)); precision.xitong.value = _.toNumber(sheet.getText(12, 2)); precision.other.value = _.toNumber(sheet.getText(13, 2)); return precision; } function checkPrecisionMinLimit(precision, limit) { for (const unit of precision) { if (precision[unit].value < limit[unit].value) { if (precision[unit].unit) { toastr.warning('台账已审批通过,清单精度不可减少,单位为' + limit[unit].unit + '的清单的精度不可小于' + limit[unit].value); } else { toastr.warning('台账已审批通过,清单精度不可减少,其他清单的精度不可小于' + limit[unit].value); } return false; } } return true; }; return {loadPrecisonProperty, setReadOnly, getNewPrecisionData, checkPrecisionMinLimit}; })(); // 合同参数 const dealObj = (function () { const spread = SpreadJsObj.createNewSpread($('#param-spread')[0]); spread.options.showVerticalScrollbar = false; spread.options.showHorizontalScrollbar = false; const sheet = spread.getActiveSheet(); SpreadJsObj.protectedSheet(sheet); const vStyle = new spreadNS.Style(); vStyle.font = '12px 微软雅黑'; sheet.setDefaultStyle(vStyle, spreadNS.SheetArea.viewport); SpreadJsObj.massOperationSheet(sheet, function () { sheet.options.rowHeaderVisible = false; sheet.options.colHeaderVisible = false; sheet.defaults.rowHeight = 25; sheet.setColumnCount(3); sheet.setRowCount(6); sheet.setColumnWidth(0, 1); sheet.setColumnWidth(1, 200); sheet.setColumnWidth(2, 200); sheet.setRowHeight(0, 1); sheet.getRange(1, 1, 5, 1).vAlign(1).backColor('#e4e7ea').locked(true); sheet.getRange(1, 2, 5, 1).vAlign(1).hAlign(2).locked(true); sheet.setText(1, 1, '签约合同价'); sheet.setText(2, 1, '暂列金额'); sheet.setText(3, 1, '签约合同价(不含暂列金)'); sheet.setText(4, 1, '签约开工预付款'); sheet.setText(5, 1, '签约材料预付款'); const lineBorder = new spreadNS.LineBorder('#6a696e', spreadNS.LineStyle.thin); sheet.getRange(0, 0, 6, 3).setBorder(lineBorder, {all: true}); sheet.getRange(0, 0, 6, 3).formatter('@'); sheet.setSelection(1, 2, 1, 1); }); function calcHtjMinusZlj() { const htj = _.toNumber(sheet.getText(1, 2)); const zlj = _.toNumber(sheet.getText(2, 2)); sheet.setValue(3, 2, accSub(zlj, htj)); } spread.bind(spreadNS.Events.EditEnded, function (e, info) { const value = _.toNumber(info.editingText); if (_.isNaN(value)) { toastr.warning('请输入不超过万亿的数字'); info.sheet.setText(info.row, info.col, '0'); } else if (value > Math.pow(10, 13)) { toastr.warning('请输入不超过万亿的数字'); info.sheet.setText(info.row, info.col, '0'); } if (info.row === 1 || info.row === 2) { calcHtjMinusZlj(); } }); SpreadJsObj.addDeleteBind(spread, function (sheet) { const sel = sheet.getSelections()[0]; let calc = false; if (sel) { for (let iRow = sel.row, iRowLength = sel.row + sel.rowCount; iRow < iRowLength; iRow++) { if (iRow === 3) continue; for (let iCol = sel.col, iColLength = sel.col + sel.colCount; iCol < iColLength; iCol++) { if (iCol !== 2) continue; sheet.setText(iRow, iCol, '0'); if (iRow === 1 || iRow === 2) calc = true; } } } if (calc) calcHtjMinusZlj(); }); spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) { let bHint = false; for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) { const curRow = info.cellRange.row + iRow; for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) { const curCol = info.cellRange.col + iCol; const value = _.toNumber(info.sheet.getText(curRow, curCol)); if (_.isNaN(value) || value > Math.pow(10, 13)) { bHint = true; info.sheet.setText(curRow, curCol, '0'); } } } if (bHint) { toastr.warning('请输入不超过万亿的数字'); } calcHtjMinusZlj(); }); function loadDealProperty() { $('#hint-4').hide(); sheet.setValue(1, 2, property.deal_param.contractPrice); sheet.setValue(2, 2, property.deal_param.zanLiePrice); sheet.setValue(3, 2, accSub(property.deal_param.zanLiePrice, property.deal_param.contractPrice)); sheet.setValue(4, 2, property.deal_param.startAdvance); sheet.setValue(5, 2, property.deal_param.materialAdvance); } function setReadOnly (readOnly) { sheet.getCell(1, 2).locked(readOnly); sheet.getCell(2, 2).locked(readOnly); sheet.getCell(4, 2).locked(readOnly); sheet.getCell(5, 2).locked(readOnly); } function getNewDealData () { const result = {}; result.contractPrice = _.toNumber(sheet.getText(1, 2)); result.zanLiePrice = _.toNumber(sheet.getText(2, 2)); result.startAdvance = _.toNumber(sheet.getText(4, 2)); result.materialAdvance = _.toNumber(sheet.getText(5, 2)); return result; } return { loadDealProperty, setReadOnly, getNewDealData, }; })(); // 章节设置 const chapterObj = (function () { const spreadSetting = { cols: [ {title: '章节', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 100, formatter: '@', readOnly: true}, {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true}, ], emptyRows: 0, headRows: 1, headRowHeight: [32], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', }; const spread = SpreadJsObj.createNewSpread($('#chapter-spread')[0]); spread.options.showVerticalScrollbar = false; spread.options.showHorizontalScrollbar = false; SpreadJsObj.initSheet(spread.getActiveSheet(), spreadSetting); function checkSheetData(sheet) { let hint = ''; for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) { const cell = sheet.getCell(iRow, 1); const defaultStype = sheet.getDefaultStyle(); if (cell.text().length > 50) { cell.backColor('#f8d7da'); hint = '章节名称的长度超出范围,请重新输入'; } else { cell.backColor(defaultStype.backColor); } } if (hint === '') { $('#hint-6').hide(); } else { $('#hint-6').html('' + hint).show(); } } spread.bind(spreadNS.Events.EditEnding, function (e, info) { checkSheetData(info.sheet); }); spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) { checkSheetData(info.sheet); }); function loadChapterProperty() { SpreadJsObj.loadSheetData(spread.getActiveSheet(), SpreadJsObj.DataType.Data, property.chapter); $('#hint-6').hide(); const sheet = spread.getActiveSheet(); const defaultStype = sheet.getDefaultStyle(); sheet.getRange(0, 0, sheet.getRowCount(), sheet.getColumnCount()).backColor(defaultStype.backColor); } function setReadOnly(readOnly) { SpreadJsObj.resetFieldReadOnly(spread.getActiveSheet(), 'name', readOnly); } function getNewChapterData() { const result = []; const sheet = spread.getActiveSheet(); for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) { const data = {}; for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) { const col = spreadSetting.cols[iCol]; data[col.field] = sheet.getText(iRow, iCol); if (col.field === 'name') { if (data.name.length > 50) { return null; } } } result.push(data); } return result; } return { loadChapterProperty, setReadOnly, getNewChapterData, } })(); // 标段属性 function loadTenderProperty() { // 加载属性 loadCommonProperty(); loadCalculateProperty(); precisionObj.loadPrecisonProperty(); dealObj.loadDealProperty(); loadDisplayProperty(); chapterObj.loadChapterProperty(); // 设置只读 setReadOnly('#shuxing', true); } loadTenderProperty(); /** * 属性 */ // 编辑 $('#edit-1').click(() => { setReadOnly('#v-pills-1', false); $('#post-1').parent().show(); $('#edit-1').parent().hide(); }); // 取消 $('#cancel-1').click(() => { setReadOnly('#v-pills-1', true); loadCommonProperty(); $('#post-1').parent().hide(); $('#edit-1').parent().show(); }); // 提交 $('#post-1').click(() => { const prop = { deal_info: { buildName: $('#build-name').val(), dealCode: $('#deal-code').val(), dealName: $('#deal-name').val(), }, construction_unit: { build: { company: $('#build-company').val(), corporation: $('#build-corporation').val(), date: $('#build-date').val(), }, contract1: { company: $('#contract1-company').val(), corporation: $('#contract1-corporation').val(), date: $('#contract1-date').val(), }, contract2: { company: $('#contract2-company').val(), corporation: $('#contract2-corporation').val(), date: $('#contract2-date').val(), }, supervision1: { company: $('#supervision1-company').val(), corporation: $('#supervision1-corporation').val(), date: $('#supervision1-date').val(), }, supervision2: { company: $('#supervision2-company').val(), corporation: $('#supervision2-corporation').val(), date: $('#supervision2-date').val(), }, }, tech_param: { loadLevel: _.toNumber($('#loadLevel').val()), loadLength: _.toNumber($('#length').val()), startPeg: $('#start-peg').val(), endPeg: $('#end-peg').val(), laneCount: _.toNumber($('#lane-count').val()), dealPeriod: $('#deal-period').val(), startDate: $('#start-date').val(), planEndDate: $('#plan-end-date').val(), } }; const tenderId = window.location.pathname.split('/')[2]; postData('/tender/' + tenderId + '/save', prop, function (data) { setReadOnly('#v-pills-1', true); property.deal_info = data.deal_info; property.construction_unit = data.construction_unit; property.tech_param = data.tech_param; $('#post-1').parent().hide(); $('#edit-1').parent().show(); }); }); /** * 计算参数 */ // 编辑 $('#edit-2').click(() => { setReadOnly('#v-pills-2', false); $('#post-2').parent().show(); $('#edit-2').parent().hide(); }); // 取消 $('#cancel-2').click(() => { setReadOnly('#v-pills-2', true); loadCalculateProperty(); $('#post-2').parent().hide(); $('#edit-2').parent().show(); }); // 提交 $('#post-2').click(() => { const prop = { decimal: { up: _.toNumber($('#decimal-up').val()), tp: _.toNumber($('#decimal-tp').val()), pay: $('#decimal-pay')[0].checked, payTp: _.toNumber($('#decimal-pay-tp').val()), } }; if (ledgerChecked) { if (prop.decimal.up < property.decimal.up) { toastr.warning('台账已审批完成,单价的小数位数,不可小于' + property.decimal.up); return; } if (prop.decimal.tp < property.decimal.tp) { toastr.warning('台账已审批完成,金额的小数位数,不可小于' + property.decimal.tp); return; } } if (firstStageChecked) { if (property.decimal.pay) { if (!prop.decimal.pay) { toastr.warning('第一期已审批完成,不可取消合同支付单独设置'); return; } if (prop.decimal.payTp < property.decimal.payTp) { toastr.warning('第一期已审批完成,单独设置的合同支付小数位数,不可小于' + property.decimal.payTp); return; } } else { if (prop.decimal.pay) { toastr.warning('第一期已审批完成,合同支付不可单独设置'); return; } } } if (ledgerChecked && !precisionObj.checkPrecisionMinLimit(prop.decimal, property.decimal)) return; const tenderId = window.location.pathname.split('/')[2]; postData('/tender/' + tenderId + '/save', prop, function (data) { setReadOnly('#v-pills-2', true); property.decimal = data.decimal; $('#post-2').parent().hide(); $('#edit-2').parent().show(); }, null, true); }); /** * 清单精度 */ // 编辑 $('#edit-3').click(() => { precisionObj.setReadOnly(false); $('#post-3').parent().show(); $('#edit-3').parent().hide(); }); // 取消 $('#cancel-3').click(() => { precisionObj.setReadOnly(true); precisionObj.loadPrecisonProperty(); $('#post-3').parent().hide(); $('#edit-3').parent().show(); }); // 提交 $('#post-3').click(() => { const prop = { precision: precisionObj.getNewPrecisionData() }; if (ledgerChecked && !precisionObj.checkPrecisionMinLimit(prop.precision, property.precision)) return; const tenderId = window.location.pathname.split('/')[2]; postData('/tender/' + tenderId + '/save', prop, function (data) { precisionObj.setReadOnly(true); property.precision = data.precision; $('#post-3').parent().hide(); $('#edit-3').parent().show(); }, null, true); }); /** * 合同参数 */ // 编辑 $('#edit-4').click(() => { dealObj.setReadOnly(false); $('#post-4').parent().show(); $('#edit-4').parent().hide(); }); // 取消 $('#cancel-4').click(() => { dealObj.setReadOnly(true); dealObj.loadDealProperty(); $('#post-4').parent().hide(); $('#edit-4').parent().show(); }); // 提交 $('#post-4').click(() => { const prop = { deal_param: dealObj.getNewDealData() }; const tenderId = window.location.pathname.split('/')[2]; postData('/tender/' + tenderId + '/save', prop, function (data) { dealObj.setReadOnly(true); property.deal_param = data.deal_param; $('#post-4').parent().hide(); $('#edit-4').parent().show(); dealObj.loadDealProperty(); }); }); /** * 显示设置 */ // 编辑 $('#edit-5').click(() => { setReadOnly('#v-pills-5', false); $('#post-5').parent().show(); $('#edit-5').parent().hide(); }); // 取消 $('#cancel-5').click(() => { setReadOnly('#v-pills-5', true); loadDisplayProperty(); $('#post-5').parent().hide(); $('#edit-5').parent().show(); }); // 提交 $('#post-5').click(() => { const prop = { display: { ledger: { dgnQty: $('#ledger-dgn-qty')[0].checked, clQty: $('#ledger-cl-qty')[0].checked, }, }, }; const tenderId = window.location.pathname.split('/')[2]; postData('/tender/' + tenderId + '/save', prop, function (data) { setReadOnly('#v-pills-5', true); property.display = data.display; $('#post-5').parent().hide(); $('#edit-5').parent().show(); }); }); /** * 章节设置 */ // 编辑 $('#edit-6').click(() => { chapterObj.setReadOnly(false); $('#post-6').parent().show(); $('#edit-6').parent().hide(); }); // 取消 $('#cancel-6').click(() => { chapterObj.loadChapterProperty(); chapterObj.setReadOnly(true); $('#hint-6').hide(); $('#post-6').parent().hide(); $('#edit-6').parent().show(); }); // 提交 $('#post-6').click(() => { const chapter = chapterObj.getNewChapterData(); if (!chapter) { return; } const tenderId = window.location.pathname.split('/')[2]; postData('/tender/' + tenderId + '/save', { chapter: chapter }, function (data) { chapterObj.setReadOnly(true); property.chapter = data.chapter; $('#post-6').parent().hide(); $('#edit-6').parent().show(); }); }); });