|
@@ -0,0 +1,923 @@
|
|
|
|
|
+'use strict';
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ *
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author EllisRan
|
|
|
|
|
+ * @date 2022/01/21
|
|
|
|
|
+ * @version
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+$(document).ready(() => {
|
|
|
|
|
+ $.subMenu({
|
|
|
|
|
+ menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
|
|
|
|
|
+ toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
|
|
|
|
|
+ key: 'menu.1.0.0',
|
|
|
|
|
+ miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
|
|
|
|
|
+ callback: function (info) {
|
|
|
|
|
+ if (info.mini) {
|
|
|
|
|
+ $('.panel-title').addClass('fluid');
|
|
|
|
|
+ $('#sub-menu').removeClass('panel-sidebar');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $('.panel-title').removeClass('fluid');
|
|
|
|
|
+ $('#sub-menu').addClass('panel-sidebar');
|
|
|
|
|
+ }
|
|
|
|
|
+ autoFlashHeight();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ handleFileList(fileList);
|
|
|
|
|
+
|
|
|
|
|
+ $('#file-ok').click(function () {
|
|
|
|
|
+ const files = Array.from($('#file-modal')[0].files)
|
|
|
|
|
+ const valiData = files.map(v => {
|
|
|
|
|
+ const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
|
|
|
|
|
+ return {
|
|
|
|
|
+ size: v.size,
|
|
|
|
|
+ ext
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ if (validateFiles(valiData)) {
|
|
|
|
|
+ if (files.length) {
|
|
|
|
|
+ const formData = new FormData();
|
|
|
|
|
+ files.forEach(file => {
|
|
|
|
|
+ formData.append('name', file.name);
|
|
|
|
|
+ formData.append('size', file.size);
|
|
|
|
|
+ formData.append('file', file);
|
|
|
|
|
+ })
|
|
|
|
|
+ postDataWithFile(preUrl + '/file/upload', formData, function (result) {
|
|
|
|
|
+ handleFileList(result);
|
|
|
|
|
+ $('#file-cancel').click();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ function handleFileList(files = []) {
|
|
|
|
|
+ $('#file-content').empty();
|
|
|
|
|
+ // const { uncheck, checkNo } = auditConst.status
|
|
|
|
|
+ const newFiles = files.map(file => {
|
|
|
|
|
+ let showDel = false;
|
|
|
|
|
+ if (file.uid === cur_uid) {
|
|
|
|
|
+ // if (!curAuditor) {
|
|
|
|
|
+ // advance.status === uncheck && cur_uid === advance.uid && (showDel = true)
|
|
|
|
|
+ // advance.status === checkNo && cur_uid === advance.uid && (showDel = true)
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // curAuditor.audit_id === cur_uid && (showDel = true)
|
|
|
|
|
+ // }
|
|
|
|
|
+ if (change.status === auditConst.status.checked) {
|
|
|
|
|
+ showDel = Boolean(file.extra_upload )
|
|
|
|
|
+ } else {
|
|
|
|
|
+ showDel = true
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return {...file, showDel}
|
|
|
|
|
+ })
|
|
|
|
|
+ let html = change.filePermission ? `<tr><td colspan="5"><a href="#addfujian" data-toggle="modal" class="btn btn-primary btn-sm" data-placement="bottom" title="">上传附件</a></td></tr>` : '';
|
|
|
|
|
+ newFiles.forEach((file, idx) => {
|
|
|
|
|
+ if (file.showDel) {
|
|
|
|
|
+ html += `<tr><td>${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="/tender/${file.tid}/change/plan/${file.cpid}/information/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a><a href="javascript: void(0);" class="text-danger file-del" data-id="${file.id}"><i class="fa fa-remove"></i></a></td></tr>`
|
|
|
|
|
+ } else {
|
|
|
|
|
+ html += `<tr><td width="70">${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="/tender/${file.tid}/change/plan/${file.cpid}/information/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a></td></tr>`
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ $('#file-content').append(html);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $('#file-content').on('click', 'a', function () {
|
|
|
|
|
+ if ($(this).hasClass('file-del')) {
|
|
|
|
|
+ const id = $(this).data('id');
|
|
|
|
|
+ postData(preUrl + '/file/delete', {id}, (result) => {
|
|
|
|
|
+ handleFileList(result);
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 回车提交
|
|
|
|
|
+ $('#plan-table input').on('keypress', function () {
|
|
|
|
|
+ if(window.event.keyCode === 13) {
|
|
|
|
|
+ $(this).blur();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ $('#plan-table input').blur(function () {
|
|
|
|
|
+ const val_name = $(this).data('name');
|
|
|
|
|
+ let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
|
|
|
|
|
+ switch(val_name) {
|
|
|
|
|
+ case 'code':
|
|
|
|
|
+ if(!val) {
|
|
|
|
|
+ toastr.error('方案编号不能为空');
|
|
|
|
|
+ $(this).val(change[val_name]);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'name':
|
|
|
|
|
+ if(val && val.length > 100) {
|
|
|
|
|
+ toastr.error('名称超过100个字,请缩减名称');
|
|
|
|
|
+ $(this).val(change[val_name]);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ if(val && val.length > 255) {
|
|
|
|
|
+ toastr.error('超出字段范围,请缩减');
|
|
|
|
|
+ $(this).val(change[val_name]);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(change[val_name] !== val) {
|
|
|
|
|
+ const _self = $(this);
|
|
|
|
|
+ postData(preUrl + '/save', { name: val_name, val}, function (result) {
|
|
|
|
|
+ change[val_name] = val;
|
|
|
|
|
+ _self.val(change[val_name]);
|
|
|
|
|
+ if (val_name === 'code') {
|
|
|
|
|
+ $('#change-plan-code').text(change[val_name]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }, function () {
|
|
|
|
|
+ _self.val(change[val_name]);
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $(this).val(change[val_name]);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ $('#plan-table textarea').blur(function () {
|
|
|
|
|
+ const val_name = $(this).data('name');
|
|
|
|
|
+ let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
|
|
|
|
|
+ if(change[val_name] !== val) {
|
|
|
|
|
+ const _self = $(this);
|
|
|
|
|
+ postData(preUrl + '/save', { name: val_name, val}, function (result) {
|
|
|
|
|
+ change[val_name] = val;
|
|
|
|
|
+ _self.val(change[val_name]);
|
|
|
|
|
+ }, function () {
|
|
|
|
|
+ _self.val(change[val_name]);
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $(this).val(change[val_name]);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ $('#plan-table select').change(function () {
|
|
|
|
|
+ const val_name = $(this).attr('data-name');
|
|
|
|
|
+ let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
|
|
|
|
|
+ if(change[val_name] !== val) {
|
|
|
|
|
+ const _self = $(this);
|
|
|
|
|
+ postData(preUrl + '/save', { name: val_name, val}, function (result) {
|
|
|
|
|
+ change[val_name] = val;
|
|
|
|
|
+ _self.val(change[val_name]);
|
|
|
|
|
+ }, function () {
|
|
|
|
|
+ _self.val(change[val_name]);
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $(this).val(change[val_name]);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const changeSpread = SpreadJsObj.createNewSpread($('#plan-spread')[0]);
|
|
|
|
|
+ const changeSpreadSheet = changeSpread.getActiveSheet();
|
|
|
|
|
+ const style1 = new GC.Spread.Sheets.Style();
|
|
|
|
|
+ style1.locked = true;
|
|
|
|
|
+
|
|
|
|
|
+ const changeSpreadSetting = {
|
|
|
|
|
+ cols: [
|
|
|
|
|
+ {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 110, formatter: '@', readOnly: 'readOnly.isEdit'},
|
|
|
|
|
+ {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 130, formatter: '@', readOnly: 'readOnly.isEdit'},
|
|
|
|
|
+ {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
|
|
|
|
|
+ {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.unit_price'},
|
|
|
|
|
+ {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.oamount'},
|
|
|
|
|
+ {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
|
|
|
|
|
+ {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.camount'},
|
|
|
|
|
+ {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
|
|
|
|
|
+ {title: '审批后变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.samount'},
|
|
|
|
|
+ {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.sa_tp'},
|
|
|
|
|
+ ],
|
|
|
|
|
+ emptyRows: !readOnly ? 3 : 0,
|
|
|
|
|
+ headRows: 2,
|
|
|
|
|
+ headRowHeight: [25, 25],
|
|
|
|
|
+ defaultRowHeight: 21,
|
|
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
|
|
+ font: '12px 微软雅黑',
|
|
|
|
|
+ readOnly: change.status === auditConst.status.checking ? false : readOnly,
|
|
|
|
|
+ localCache: {
|
|
|
|
|
+ key: 'changes-plan-list-spread',
|
|
|
|
|
+ colWidth: true,
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ console.log(changeList, change.listAudits);
|
|
|
|
|
+
|
|
|
|
|
+ if (change.status === auditConst.status.checking || change.status === auditConst.status.checked) {
|
|
|
|
|
+ for (const audit of change.listAudits) {
|
|
|
|
|
+ // const userinfo = _.find(auditList2, { 'aid': aid });
|
|
|
|
|
+ const newColcount = {
|
|
|
|
|
+ title: audit.name + ' 审批|数量',
|
|
|
|
|
+ colSpan: '2|1', rowSpan: '1|1',
|
|
|
|
|
+ field: 'audit_amount_' + audit.aid,
|
|
|
|
|
+ hAlign: 2, width: 60, type: 'Number',
|
|
|
|
|
+ readOnly: !(change.shenpiPower && audit.aid === parseInt(cur_uid))
|
|
|
|
|
+ };
|
|
|
|
|
+ const newColTp = {
|
|
|
|
|
+ title: '|金额',
|
|
|
|
|
+ colSpan: '|1', rowSpan: '|1',
|
|
|
|
|
+ field: 'sa_tp_' + audit.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));
|
|
|
|
|
+ },
|
|
|
|
|
+ samount: function (data) {
|
|
|
|
|
+ return ZhCalc.round(data.samount, findDecimal(data.unit));
|
|
|
|
|
+ },
|
|
|
|
|
+ sa_tp: function (data) {
|
|
|
|
|
+ return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.samount, findDecimal(data.unit))), totalPriceUnit);
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ readOnly: {
|
|
|
|
|
+ isEdit: function (data) {
|
|
|
|
|
+ return readOnly;
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ };
|
|
|
|
|
+ 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 audit of change.listAudits) {
|
|
|
|
|
+ c['audit_amount_' + audit.aid] = ZhCalc.round(c['audit_amount_' + audit.aid], findDecimal(c.unit));
|
|
|
|
|
+ c['sa_tp_' + audit.aid] = ZhCalc.round(ZhCalc.mul(c['audit_amount_' + audit.aid], ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ setRowValueAndSum: function (data, row, col) {
|
|
|
|
|
+ for (const j in change.listAudits) {
|
|
|
|
|
+ const sum = ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), parseFloat(changeSpreadSheet.getValue(row, 10 + parseInt(j)*2))), totalPriceUnit);
|
|
|
|
|
+ changeSpreadSheet.setValue(row, 11 + 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;
|
|
|
|
|
+ for(let i = 0; i < rowCount - 1; i++){
|
|
|
|
|
+ audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, col+1));
|
|
|
|
|
+ }
|
|
|
|
|
+ changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, col+1, audit_sum !== 0 ? audit_sum : null);
|
|
|
|
|
+ },
|
|
|
|
|
+ countSum: function() {
|
|
|
|
|
+ const rowCount = changeSpreadSheet.getRowCount();
|
|
|
|
|
+ let oSum = 0,
|
|
|
|
|
+ cSum = 0,
|
|
|
|
|
+ sSum = 0;
|
|
|
|
|
+ for (let i = 0; i < rowCount - 1; i++) {
|
|
|
|
|
+ oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 5));
|
|
|
|
|
+ cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 7));
|
|
|
|
|
+ sSum = ZhCalc.add(sSum, changeSpreadSheet.getValue(i, 9));
|
|
|
|
|
+ }
|
|
|
|
|
+ changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 5, oSum !== 0 ? oSum : null);
|
|
|
|
|
+ changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, cSum !== 0 ? cSum : null);
|
|
|
|
|
+ changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, sSum !== 0 ? sSum : null);
|
|
|
|
|
+ // 用户的数据合计
|
|
|
|
|
+ for (const j in change.listAudits) {
|
|
|
|
|
+ let audit_sum = 0;
|
|
|
|
|
+ for(let i = 0; i < rowCount - 1; i++){
|
|
|
|
|
+ audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, 11 + j*2));
|
|
|
|
|
+ }
|
|
|
|
|
+ changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 11 + j*2, audit_sum !== 0 ? audit_sum : null);
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ deletePress: function (sheet) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ },
|
|
|
|
|
+ showHideAudit: function (show = false) {
|
|
|
|
|
+ const count = changeSpreadSetting.cols.length;
|
|
|
|
|
+ for (let i = 10; i < count; i++) {
|
|
|
|
|
+ changeSpreadSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
|
|
+ }
|
|
|
|
|
+ changeSpreadSheet.setColumnVisible(8, !show, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
|
|
+ changeSpreadSheet.setColumnVisible(9, !show, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
|
|
+ },
|
|
|
|
|
+ valueChanged: function (e, info) {
|
|
|
|
|
+ // 防止ctrl+z撤销数据
|
|
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ if (!readOnly) {
|
|
|
|
|
+ changeSpreadObj.add = function () {
|
|
|
|
|
+ changeSpreadSheet.addRows(changeSpreadSheet.getRowCount() - 1, 1);
|
|
|
|
|
+ changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
|
|
|
|
|
+ // changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
|
|
|
|
|
+ };
|
|
|
|
|
+ changeSpreadObj.batchAdd = function (num) {
|
|
|
|
|
+ changeSpreadSheet.addRows(changeSpreadSheet.getRowCount() - 1, parseInt(num));
|
|
|
|
|
+ changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
|
|
|
|
|
+ };
|
|
|
|
|
+ changeSpreadObj.del = function (sheet) {
|
|
|
|
|
+ const selection = sheet.getSelections();
|
|
|
|
|
+ const row = selection[0].row, count = selection[0].rowCount;
|
|
|
|
|
+ const sortData = sheet.zh_data;
|
|
|
|
|
+ const ids = [];
|
|
|
|
|
+ let emptyRowNum = 0;
|
|
|
|
|
+ for (let iRow = 0; iRow < count; iRow++) {
|
|
|
|
|
+ if (sortData[iRow + row]) {
|
|
|
|
|
+ ids.push(sortData[iRow + row].id);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ emptyRowNum++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ids.length > 0) {
|
|
|
|
|
+ postData(preUrl + '/list/save', {type: 'del', ids}, function (result) {
|
|
|
|
|
+ changeList = result;
|
|
|
|
|
+ SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
|
|
|
|
|
+ changeSpreadObj.makeSjsFooter();
|
|
|
|
|
+ });
|
|
|
|
|
+ } else if (emptyRowNum > 0) {
|
|
|
|
|
+ changeSpreadSheet.deleteRows(changeList.length, emptyRowNum);
|
|
|
|
|
+ changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ changeSpreadObj.editEnded = function (e, info) {
|
|
|
|
|
+ if (info.sheet.zh_setting) {
|
|
|
|
|
+ const type = SpreadJsObj.getSelectObject(info.sheet) ? 'update' : 'add';
|
|
|
|
|
+ const select = type === 'update' ? SpreadJsObj.getSelectObject(info.sheet) : {unit: ''};
|
|
|
|
|
+ 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 = type === 'update' ? select[col.field] : '';
|
|
|
|
|
+ if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
|
|
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (col.field === 'oa_tp' || col.field === 'ca_tp') {
|
|
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 判断部分值是否输入的是数字判断和数据计算
|
|
|
|
|
+ if (col.type === 'Number') {
|
|
|
|
|
+ if (isNaN(validText)) {
|
|
|
|
|
+ toastr.error('不能输入其它非数字类型字符');
|
|
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (col.field === 'unit_price') {
|
|
|
|
|
+ validText = ZhCalc.round(validText, unitPriceUnit);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (col.field === 'unit') {
|
|
|
|
|
+ select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
|
|
|
|
|
+ select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(col.field === 'camount') {
|
|
|
|
|
+ select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ select[col.field] = validText;
|
|
|
|
|
+
|
|
|
|
|
+ console.log(select, type);
|
|
|
|
|
+ delete select.waitingLoading;
|
|
|
|
|
+
|
|
|
|
|
+ // 更新至服务器
|
|
|
|
|
+ postData(preUrl + '/list/save', { type, updateData: select }, function (result) {
|
|
|
|
|
+ if(type === 'update') {
|
|
|
|
|
+ changeList.splice(info.row, 1, select);
|
|
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
|
|
+ changeSpreadObj.countSum();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ changeList.push(result);
|
|
|
|
|
+ changeSpreadSheet.addRows(changeList.length - 1, 1);
|
|
|
|
|
+ SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
|
|
|
|
|
+ changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
|
|
|
|
|
+ // changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }, function () {
|
|
|
|
|
+ select[col.field] = orgValue;
|
|
|
|
|
+ if(col.field === 'camount') {
|
|
|
|
|
+ select.spamount = orgValue;
|
|
|
|
|
+ }
|
|
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ changeSpreadObj.clipboardPasted = function(e, info, cellRange) {
|
|
|
|
|
+ if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
|
|
|
|
|
+ info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
|
|
|
|
|
+ }
|
|
|
|
|
+ const hint = {
|
|
|
|
|
+ cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
|
|
|
|
|
+ numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
|
|
|
|
|
+ };
|
|
|
|
|
+ if (info.sheet.zh_setting) {
|
|
|
|
|
+ const sortData = info.sheet.zh_data || [];
|
|
|
|
|
+ const range = info.cellRange;
|
|
|
|
|
+ const data = [];
|
|
|
|
|
+ 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 = curRow >= sortData.length ? {unit: ''} : {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;
|
|
|
|
|
+ // cLData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
|
|
|
|
|
+
|
|
|
|
|
+ let validText = info.sheet.getText(curRow, curCol);
|
|
|
|
|
+ validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
|
|
|
|
|
+ const orgValue = curRow >= sortData.length ? '' : 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));
|
|
|
|
|
+ toastMessageUniq(hint.numberExpr);
|
|
|
|
|
+ bPaste = false;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (colSetting.field === 'unit_price') {
|
|
|
|
|
+ validText = ZhCalc.round(validText, unitPriceUnit);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ validText = ZhCalc.round(validText, findDecimal(cLData.unit)) || 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ let unitdecimal = validText;
|
|
|
|
|
+ if (colSetting.field === 'unit') {
|
|
|
|
|
+ //粘贴内容要为下拉列表里所有的单位,不然为空
|
|
|
|
|
+ if (changeUnits.indexOf(validText) === -1) {
|
|
|
|
|
+ unitdecimal = '';
|
|
|
|
|
+ // validText = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ cLData.camount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
|
|
|
|
|
+ cLData.oamount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].oamount, findDecimal(unitdecimal)) || 0;
|
|
|
|
|
+ cLData.spamount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ // sortData[curRow][colSetting.field] = validText;
|
|
|
|
|
+ if (colSetting.field === 'camount') {
|
|
|
|
|
+ cLData.spamount = ZhCalc.round(validText, findDecimal(unitdecimal)) || 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ cLData[colSetting.field] = validText;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ if (bPaste) {
|
|
|
|
|
+ delete cLData.oa_tp;
|
|
|
|
|
+ delete cLData.ca_tp;
|
|
|
|
|
+ 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(preUrl + '/list/save', { type:'paste', updateData: data }, function (result) {
|
|
|
|
|
+ changeList = result;
|
|
|
|
|
+ SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
|
|
|
|
|
+ changeSpreadObj.makeSjsFooter();
|
|
|
|
|
+ }, function () {
|
|
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
|
|
|
|
|
+ return;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ changeSpreadObj.updateOamount = function () {
|
|
|
|
|
+ const dataSource = listRule.source === 1 ? gclGatherData : dealBillList;
|
|
|
|
|
+ const updateList = [];
|
|
|
|
|
+ for (const c of changeList) {
|
|
|
|
|
+ const source = _.find(dataSource, function (item) {
|
|
|
|
|
+ if (((item.b_code && item.b_code === c.code) || (item.code && item.code === c.code)) && item.name === c.name) {
|
|
|
|
|
+ if (listRule.rule.length > 0) {
|
|
|
|
|
+ for(const r of listRule.rule) {
|
|
|
|
|
+ if (item[r] !== c[r]) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ });
|
|
|
|
|
+ if (source && source.quantity !== c.oamount) {
|
|
|
|
|
+ updateList.push({ id: c.id, oamount: source.quantity });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(updateList);
|
|
|
|
|
+ if(updateList.length > 0) {
|
|
|
|
|
+ postData(preUrl + '/list/save', { type:'paste', updateData: updateList }, function (result) {
|
|
|
|
|
+ changeList = result;
|
|
|
|
|
+ SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
|
|
|
|
|
+ changeSpreadObj.makeSjsFooter();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ // changeSpread.bind(spreadNS.Events.CellChanged, changeSpreadObj.cellChanged);
|
|
|
|
|
+ changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
|
|
|
|
|
+ changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
|
|
|
|
|
+ changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
|
|
|
|
|
+ SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
|
|
|
|
|
+
|
|
|
|
|
+ let batchInsertObj;
|
|
|
|
|
+ $.contextMenu.types.batchInsert = function (item, opt, root) {
|
|
|
|
|
+ const self = this;
|
|
|
|
|
+ if ($.isFunction(item.icon)) {
|
|
|
|
|
+ item._icon = item.icon.call(this, this, $t, key, item);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
|
|
|
|
|
+ // to enable font awesome
|
|
|
|
|
+ item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ this.addClass(item._icon);
|
|
|
|
|
+ const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="100" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
|
|
|
|
|
+ .appendTo(this);
|
|
|
|
|
+ const $input = $obj.find('input');
|
|
|
|
|
+ const event = () => {
|
|
|
|
|
+ if (self.hasClass('context-menu-disabled')) return;
|
|
|
|
|
+ item.batchInsert($input[0], root);
|
|
|
|
|
+ };
|
|
|
|
|
+ $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
|
|
|
|
|
+ $input.click((e) => {e.stopPropagation();})
|
|
|
|
|
+ .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
|
|
|
|
|
+ .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // 右键菜单
|
|
|
|
|
+ $.contextMenu({
|
|
|
|
|
+ selector: '#plan-spread',
|
|
|
|
|
+ build: function ($trigger, e) {
|
|
|
|
|
+ const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
|
|
|
|
|
+ return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
|
|
|
|
|
+ },
|
|
|
|
|
+ items: {
|
|
|
|
|
+ 'updateOamount': {
|
|
|
|
|
+ name: '原设计数量读取',
|
|
|
|
|
+ icon: '',
|
|
|
|
|
+ callback: function (key, opt) {
|
|
|
|
|
+ changeSpreadObj.updateOamount(changeSpreadSheet);
|
|
|
|
|
+ },
|
|
|
|
|
+ disabled: function (key, opt) {
|
|
|
|
|
+ // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
|
|
|
|
|
+ // const sel = changeSpreadSheet.getSelections()[0];
|
|
|
|
|
+ // // console.log(select, sel);
|
|
|
|
|
+ // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
|
|
|
|
|
+ // return false;
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // return true;
|
|
|
|
|
+ // }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ sprDel: '------------',
|
|
|
|
|
+ 'createAdd': {
|
|
|
|
|
+ name: '添加行',
|
|
|
|
|
+ icon: 'fa-sign-in',
|
|
|
|
|
+ callback: function (key, opt) {
|
|
|
|
|
+ changeSpreadObj.add(changeSpreadSheet);
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ 'batchInsert': {
|
|
|
|
|
+ name: '批量添加行',
|
|
|
|
|
+ type: 'batchInsert',
|
|
|
|
|
+ value: '2',
|
|
|
|
|
+ icon: 'fa-sign-in',
|
|
|
|
|
+ batchInsert: function (obj, root) {
|
|
|
|
|
+ if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
|
|
|
|
|
+ obj.value = obj.max;
|
|
|
|
|
+ toastr.warning('批量添加不可多于' + obj.max);
|
|
|
|
|
+ } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
|
|
|
|
|
+ obj.value = obj.min;
|
|
|
|
|
+ toastr.warning('批量添加不可少于' + obj.min);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
|
|
|
|
|
+ changeSpreadObj.batchAdd(obj.value);
|
|
|
|
|
+ root.$menu.trigger('contextmenu:hide');
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ 'delete': {
|
|
|
|
|
+ name: '删除',
|
|
|
|
|
+ icon: 'fa-remove',
|
|
|
|
|
+ callback: function (key, opt) {
|
|
|
|
|
+ changeSpreadObj.del(changeSpreadSheet);
|
|
|
|
|
+ },
|
|
|
|
|
+ disabled: function (key, opt) {
|
|
|
|
|
+ // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
|
|
|
|
|
+ if (changeSpreadSheet.zh_data) {
|
|
|
|
|
+ const selection = changeSpreadSheet.getSelections();
|
|
|
|
|
+ // return changeSpreadSheet.zh_data.length < selection[0].row + selection[0].rowCount;
|
|
|
|
|
+ return changeSpreadSheet.getRowCount() - 1 < selection[0].row + selection[0].rowCount;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ // const sel = changeSpreadSheet.getSelections()[0];
|
|
|
|
|
+ // // console.log(select, sel);
|
|
|
|
|
+ // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
|
|
|
|
|
+ // return false;
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // return true;
|
|
|
|
|
+ // }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ $('#shuliangguize').on('show.bs.modal', function () {
|
|
|
|
|
+ $('#shuliangguize input[name="data_source"][value="'+ listRule.source +'"]').prop('checked', true);
|
|
|
|
|
+ $('#shuliangguize input[name="data_rule"]').prop('checked', false);
|
|
|
|
|
+ for(const r of listRule.rule) {
|
|
|
|
|
+ $('#shuliangguize input[name="data_rule"][value="' + r +'"]').prop('checked', true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 设置原设计数量读取
|
|
|
|
|
+ $('#setListRule').click(function () {
|
|
|
|
|
+ const rule = [];
|
|
|
|
|
+ $('#shuliangguize input[name="data_rule"]:checked').each(function () {
|
|
|
|
|
+ rule.push($(this).val());
|
|
|
|
|
+ });
|
|
|
|
|
+ const newListRule = {
|
|
|
|
|
+ source: parseInt($('#shuliangguize input[name="data_source"]:checked').val()),
|
|
|
|
|
+ rule,
|
|
|
|
|
+ };
|
|
|
|
|
+ postData(preUrl + '/list/save', { type: 'list_rule', postData: JSON.stringify(newListRule) }, function (result) {
|
|
|
|
|
+ listRule = newListRule;
|
|
|
|
|
+ $('#shuliangguize').modal('hide');
|
|
|
|
|
+ });
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (change.shenpiPower) {
|
|
|
|
|
+ changeSpreadObj.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;
|
|
|
|
|
+ // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
|
|
|
|
|
+ }
|
|
|
|
|
+ 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(preUrl + '/list/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);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ changeSpreadObj.clipboardPasted = function(e, info) {
|
|
|
|
|
+ const hint = {
|
|
|
|
|
+ cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
|
|
|
|
|
+ numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
|
|
|
|
|
+ };
|
|
|
|
|
+ const range = info.cellRange;
|
|
|
|
|
+ const sortData = info.sheet.zh_data || [];
|
|
|
|
|
+ const data = [];
|
|
|
|
|
+ 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(hint.numberExpr);
|
|
|
|
|
+ bPaste = false;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ // cLData[colSetting.field] = validText;
|
|
|
|
|
+ sortData[curRow][colSetting.field] = validText;
|
|
|
|
|
+ cLData.spamount = validText;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (bPaste) {
|
|
|
|
|
+ data.push(cLData);
|
|
|
|
|
+ // rowData.push(curRow);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ changeSpreadObj.setAuditValue();
|
|
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, curRow);
|
|
|
|
|
+ // SpreadJsObj.reLoadRowData(info.sheet, curRow);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (data.length === 0) {
|
|
|
|
|
+ // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(data);
|
|
|
|
|
+ // 更新至服务器
|
|
|
|
|
+ postData(preUrl + '/list/save', { type:'paste_amount_rows', updateData: data }, function (result) {
|
|
|
|
|
+ changeList = result;
|
|
|
|
|
+ changeSpreadObj.setAuditValue();
|
|
|
|
|
+ SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
|
|
|
|
|
+ changeSpreadObj.makeSjsFooter();
|
|
|
|
|
+ }, function () {
|
|
|
|
|
+ changeSpreadObj.setAuditValue();
|
|
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
|
|
|
|
|
+ return;
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+ changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
|
|
|
|
|
+ changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
|
|
|
|
|
+ changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
|
|
|
|
|
+ SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let changeListData;
|
|
|
|
|
+ let gclGatherData;
|
|
|
|
|
+ let dealBillList;
|
|
|
|
|
+ const billUrl = window.location.pathname.split('/').slice(0, 4).join('/');
|
|
|
|
|
+ postData(billUrl + '/defaultBills', {}, function (result) {
|
|
|
|
|
+ gclGatherModel.loadLedgerData(result.bills);
|
|
|
|
|
+ gclGatherModel.loadPosData(result.pos);
|
|
|
|
|
+
|
|
|
|
|
+ gclGatherData = gclGatherModel.gatherGclData();
|
|
|
|
|
+ gclGatherData = _.filter(gclGatherData, function (item) {
|
|
|
|
|
+ return item.leafXmjs && item.leafXmjs.length !== 0;
|
|
|
|
|
+ });
|
|
|
|
|
+ // 数组去重
|
|
|
|
|
+ dealBillList = result.dealBills;
|
|
|
|
|
+ changeListData = gclGatherData;
|
|
|
|
|
+ console.log(changeListData, dealBillList);
|
|
|
|
|
+ SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
|
|
|
|
|
+ SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
|
|
|
|
|
+ if (change.status === auditConst.status.checking || change.status === auditConst.status.checked) changeSpreadObj.setAuditValue();
|
|
|
|
|
+ SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
|
|
|
|
|
+ changeSpreadObj.makeSjsFooter();
|
|
|
|
|
+ // 计算最新的变更总额和change的total_price是否一致,不一致则更新
|
|
|
|
|
+ if (change.status !== auditConst.status.checked) {
|
|
|
|
|
+ // let new_tp = 0;
|
|
|
|
|
+ const updateArray = [];
|
|
|
|
|
+ for (const c of changeList) {
|
|
|
|
|
+ const oneUpdate = {};
|
|
|
|
|
+ if (ZhCalc.round(c.spamount, findDecimal(c.unit)) !== c.spamount) oneUpdate.spamount = ZhCalc.round(c.spamount, findDecimal(c.unit));
|
|
|
|
|
+ if (ZhCalc.round(c.oamount, findDecimal(c.unit)) !== c.oamount) oneUpdate.oamount = ZhCalc.round(c.oamount, findDecimal(c.unit));
|
|
|
|
|
+ if (ZhCalc.round(c.camount, findDecimal(c.unit)) !== c.camount) oneUpdate.camount = ZhCalc.round(c.camount, findDecimal(c.unit));
|
|
|
|
|
+ if (ZhCalc.round(c.unit_price, unitPriceUnit) !== c.unit_price) oneUpdate.unit_price = ZhCalc.round(c.unit_price, unitPriceUnit);
|
|
|
|
|
+ const audit_amount = c.audit_amount ? c.audit_amount.split(',') : null;
|
|
|
|
|
+ if (audit_amount) {
|
|
|
|
|
+ for (const i in audit_amount) {
|
|
|
|
|
+ if (ZhCalc.round(parseFloat(audit_amount[i]), findDecimal(c.unit)) !== parseFloat(audit_amount[i])) audit_amount[i] = ZhCalc.round(parseFloat(audit_amount[i]), findDecimal(c.unit));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (c.audit_amount !== audit_amount.join(',')) oneUpdate.audit_amount = audit_amount.join(',');
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!_.isEmpty(oneUpdate)) {
|
|
|
|
|
+ oneUpdate.id = c.id;
|
|
|
|
|
+ updateArray.push(oneUpdate);
|
|
|
|
|
+ }
|
|
|
|
|
+ // new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(updateArray);
|
|
|
|
|
+ if (updateArray.length > 0) {
|
|
|
|
|
+ // 更新至服务器
|
|
|
|
|
+ postData(preUrl + '/list/save', { type:'paste', updateData: updateArray }, function (result) {
|
|
|
|
|
+ changeList = result;
|
|
|
|
|
+ if (change.status === auditConst.status.checking) changeSpreadObj.setAuditValue();
|
|
|
|
|
+ SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
|
|
|
|
|
+ changeSpreadObj.makeSjsFooter();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ // if (change.total_price && change.total_price !== new_tp) {
|
|
|
|
|
+ // postData(preUrl + '/list/save', {type: 'update_tp', updateData: new_tp}, function (result) {
|
|
|
|
|
+ // });
|
|
|
|
|
+ // }
|
|
|
|
|
+ if (change.status === auditConst.status.checked) {
|
|
|
|
|
+ changeSpreadObj.showHideAudit(false);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ changeSpreadObj.showHideAudit(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 审批流程展示与隐藏
|
|
|
|
|
+ $('#show-table-detail').on('click', function (e) {
|
|
|
|
|
+ if($(e.target).is('label')){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ changeSpreadObj.showHideAudit($(this).is(':checked'));
|
|
|
|
|
+ });
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 校验文件大小、格式
|
|
|
|
|
+ * @param {Array} files 文件数组
|
|
|
|
|
+ */
|
|
|
|
|
+function validateFiles(files) {
|
|
|
|
|
+ if (files.length > 10) {
|
|
|
|
|
+ toastr.error('至多同时上传10个文件');
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ return files.every(file => {
|
|
|
|
|
+ if (file.size > 1024 * 1024 * 30) {
|
|
|
|
|
+ toastr.error('文件大小限制为30MB');
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ if (whiteList.indexOf('.' + file.ext) === -1) {
|
|
|
|
|
+ toastr.error('请上传正确的格式文件');
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ return true
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function findDecimal(unit) {
|
|
|
|
|
+ let value = precision.other.value;
|
|
|
|
|
+ const changeUnits = precision;
|
|
|
|
|
+ for (const d in changeUnits) {
|
|
|
|
|
+ if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
|
|
|
|
|
+ value = changeUnits[d].value;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return value;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const is_numeric = (value) => {
|
|
|
|
|
+ if (typeof(value) === 'object') {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
|
|
|
|
|
+ }
|
|
|
|
|
+};
|