123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- const showSideTools = function (show) {
- const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
- if (show) {
- right.show();
- autoFlashHeight();
- const percent = 100 - right.outerWidth() /parent.width() * 100;
- left.css('width', percent + '%');
- } else {
- left.width(parent.width());
- right.hide();
- }
- };
- const setPriceHint = function (show) {
- const hinticon = show ? 'fa-bell' : undefined;
- subMiniMenu.$children[2].hinticon = hinticon;
- subMenu.$children[2].hinticon = hinticon;
- };
- $(document).ready(() => {
- const ledgerGclSpreadSetting = {
- cols: [
- { title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@' },
- { title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 200, formatter: '@' },
- { title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@' },
- { title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 80, type: 'Number' },
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- };
- const ledgerXmjSpreadSetting = {
- cols: [
- {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 100, formatter: '@'},
- {title: '单位工程', colSpan: '1', rowSpan: '1', field: 'dwgc', hAlign: 0, width: 80, formatter: '@'},
- {title: '分部工程', colSpan: '1', rowSpan: '1', field: 'fbgc', hAlign: 0, width: 80, formatter: '@'},
- {title: '分项工程', colSpan: '1', rowSpan: '1', field: 'fxgc', hAlign: 0, width: 80, formatter: '@'},
- {title: '细目', colSpan: '1', rowSpan: '1', field: 'jldy', hAlign: 0, width: 80, formatter: '@'},
- {title: '计量单元', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 80, formatter: '@'},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- };
- const priceSpreadSetting = {
- cols: [
- { title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 100, formatter: '@', readOnly: true },
- { title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 210, formatter: '@', readOnly: true },
- { title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true },
- { title: '当前单价', colSpan: '1', rowSpan: '2', field: 'org_price', hAlign: 2, width: 80, type: 'Number', readOnly: true },
- { title: '调整后单价', colSpan: '1', rowSpan: '2', field: 'new_price', hAlign: 2, width: 80, type: 'Number' },
- { title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 2, width: 150, formatter: '@' },
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly,
- };
- autoFlashHeight();
- const priceSpread = SpreadJsObj.createNewSpread($('#price-spread')[0]);
- const priceSheet = priceSpread.getActiveSheet();
- SpreadJsObj.initSheet(priceSheet, priceSpreadSetting);
- class RevisePrice {
- constructor () {
- this.data = [];
- }
- resortData() {
- this.data.sort(function (a, b) {
- return a.order - b.order;
- });
- }
- loadDatas(datas) {
- this.data = datas;
- this.resortData();
- }
- loadUpdateData(updateData) {
- if (updateData.add) {
- for (const a of updateData.add) {
- this.data.push(a);
- }
- }
- if (updateData.update) {
- for (const u of updateData.update) {
- const d = this.data.find(function (x) {
- return u.id === x.id;
- });
- if (d) {
- _.assign(d, u);
- } else {
- this.data.push(d);
- }
- }
- }
- if (updateData.del) {
- _.remove(this.data, function (d) {
- return updateData.del.indexOf(d.id) >= 0;
- });
- }
- this.resortData();
- }
- }
- const revisePrice = new RevisePrice();
- const priceOprObj = {
- addRevisePrice(data) {
- const op = revisePrice.data.find(x => {
- return x.b_code === data.b_code && x.name === x.name && x.unit === x.unit && checkZero(ZhCalc.sub(x.org_price, data.unit_price));
- });
- if (op) {
- toastr.warning('已存在该单价调整');
- SpreadJsObj.locateData(priceSheet, op);
- return;
- }
- postData(window.location.pathname + '/update', { add: { b_code: data.b_code, name: data.name, unit: data.unit, unit_price: data.unit_price } }, result => {
- revisePrice.loadUpdateData(result);
- SpreadJsObj.reLoadSheetData(priceSheet);
- setPriceHint(revisePrice.data.length > 0);
- });
- },
- /**
- * 删除按钮响应事件
- * @param sheet
- */
- deletePress: function (sheet) {
- if (!sheet.zh_setting || readOnly) return;
- const sortData = sheet.zh_data;
- const datas = [];
- const sels = sheet.getSelections();
- if (!sels || !sels[0]) return;
- for (let iRow = sels[0].row; iRow < sels[0].row + sels[0].rowCount; iRow++) {
- let bDel = false;
- const node = sortData[iRow];
- if (node) {
- const data = {id: node.id};
- for (let iCol = sels[0].col; iCol < sels[0].col + sels[0].colCount; iCol++) {
- const style = sheet.getStyle(iRow, iCol);
- if (!style.locked) {
- const colSetting = sheet.zh_setting.cols[iCol];
- data[colSetting.field] = null;
- bDel = true;
- }
- }
- if (bDel) {
- datas.push(data);
- }
- }
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/update', {update: datas}, function (result) {
- revisePrice.loadUpdateData(result);
- SpreadJsObj.reLoadSheetData(priceSheet);
- }, function () {
- SpreadJsObj.reLoadSheetData(priceSheet);
- });
- }
- },
- delete: function (sheet) {
- if (!sheet.zh_setting || readOnly) return;
- const sortData = sheet.zh_data;
- const datas = [];
- const sels = sheet.getSelections();
- if (!sels || !sels[0]) return;
- for (let iRow = sels[0].row, iLen = sels[0].row + sels[0].rowCount; iRow < iLen; iRow++) {
- const node = sortData[iRow];
- datas.push(node.id);
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/update', {del: datas}, function (result) {
- revisePrice.loadUpdateData(result);
- SpreadJsObj.reLoadSheetData(priceSheet);
- setPriceHint(revisePrice.data.length > 0);
- }, function () {
- SpreadJsObj.reLoadSheetData(priceSheet);
- });
- }
- },
- editEnded: function (e, info) {
- if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
- const node = info.sheet.zh_data[info.row];
- if (!node) return;
- const col = info.sheet.zh_setting.cols[info.col];
- const data = { update: { id: node.id, org_price: node.org_price } };
- const oldValue = node ? node[col.field] : null;
- const newValue = trimInvalidChar(info.editingText);
- if (oldValue == info.editingText || ((!oldValue || oldValue === '') && (newValue === ''))) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (col.type === 'Number') {
- const num = _.toNumber(newValue);
- if (num) data.update[col.field] = num;
- } else {
- data.update[col.field] = newValue;
- }
- postData(window.location.pathname + '/update', data, function (result) {
- revisePrice.loadUpdateData(result);
- SpreadJsObj.reLoadSheetData(info.sheet);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- },
- clipboardPasting(e, info) {
- const setting = info.sheet.zh_setting, sortData = info.sheet.zh_data;
- info.cancel = true;
- if (!setting || !sortData) return;
- const pasteData = info.pasteData.html
- ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
- : (info.pasteData.text === ''
- ? SpreadJsObj.Clipboard.getAnalysisPasteText()
- : SpreadJsObj.analysisPasteText(info.pasteData.text));
- const uDatas = [];
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
- const curRow = info.cellRange.row + iRow;
- const node = sortData[curRow];
- let bPaste = false;
- const data = {};
- for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
- const curCol = info.cellRange.col + iCol;
- const colSetting = setting.cols[curCol];
- const value = trimInvalidChar(pasteData[iRow][iCol]);
- if (colSetting.type === 'Number') {
- const num = _.toNumber(value);
- if (num) {
- data[colSetting.field] = num;
- bPaste = true;
- }
- } else {
- data[colSetting.field] = value;
- bPaste = true;
- }
- }
- if (bPaste) {
- data.id = node.id;
- uDatas.push(data);
- }
- }
- const updateData = {};
- if (uDatas.length > 0) updateData.update = uDatas;
- if (uDatas.length > 0) {
- postData(window.location.pathname + '/update', updateData, function (result) {
- revisePrice.loadUpdateData(result);
- SpreadJsObj.reLoadSheetData(info.sheet);
- });
- } else {
- SpreadJsObj.reLoadSheetData(info.sheet);
- }
- },
- upMove: function () {
- const sels = priceSheet.getSelections(), sortData = priceSheet.zh_data;
- const node = sortData[sels[0].row];
- const preNode = sortData[sels[0].row - 1];
- const data = [
- {id: node.id, order: preNode.order},
- {id: preNode.id, order: node.order}
- ];
- postData(window.location.pathname + '/update', {update: data}, function (result) {
- revisePrice.loadUpdateData(result);
- SpreadJsObj.reLoadRowsData(priceSheet, [sels[0].row, sels[0].row - 1]);
- priceSheet.setSelection(sels[0].row - 1, sels[0].col, sels[0].rowCount, sels[0].colCount);
- });
- },
- downMove: function () {
- const sels = priceSheet.getSelections(), sortData = priceSheet.zh_data;
- const node = sortData[sels[0].row];
- const nextNode = sortData[sels[0].row + 1];
- const data = [
- {id: node.id, order: nextNode.order},
- {id: nextNode.id, order: node.order}
- ];
- postData(window.location.pathname + '/update', {update: data}, function (result) {
- revisePrice.loadUpdateData(result);
- SpreadJsObj.reLoadRowsData(priceSheet, [sels[0].row, sels[0].row + 1]);
- priceSheet.setSelection(sels[0].row + 1, sels[0].col, sels[0].rowCount, sels[0].colCount);
- });
- }
- };
- if (!readOnly) {
- priceSheet.bind(spreadNS.Events.EditEnded, priceOprObj.editEnded);
- priceSheet.bind(spreadNS.Events.ClipboardPasting, priceOprObj.clipboardPasting);
- SpreadJsObj.addDeleteBind(priceSpread, priceOprObj.deletePress);
- $.contextMenu({
- selector: '#price-spread',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, priceSpread);
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {
- del: {
- name: '删除',
- icon: 'fa-remove',
- callback: function (key, opt) {
- priceOprObj.delete(priceSheet);
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(priceSheet);
- return node === undefined || node === null;
- },
- visible: function (key, opt) {
- return !readOnly;
- }
- },
- sprDel: '------------',
- upMove: {
- name: '上移',
- icon: 'fa-arrow-up',
- callback: function (key, opt) {
- priceOprObj.upMove();
- },
- disabled: function (key, opt) {
- const sels = priceSheet.getSelections();
- if (!sels || !sels[0] || sels[0].row === 0) return true;
- const row = sels[0].row;
- const node = revisePrice.data[row];
- return node === undefined || node === null;
- },
- visible: function (key, opt) {
- return !readOnly;
- }
- },
- downMove: {
- name: '下移',
- icon: 'fa-arrow-down',
- callback: function (key, opt) {
- priceOprObj.downMove();
- },
- disabled: function (key, opt) {
- const sels = priceSheet.getSelections();
- if (!sels || !sels[0] || sels[0].row >= revisePrice.data.length - 1) return true;
- const row = sels[0].row;
- const node = revisePrice.data[row];
- return node === undefined || node === null;
- },
- visible: function (key, opt) {
- return !readOnly;
- }
- }
- },
- });
- }
- class LedgerGcl {
- constructor(setting) {
- this.setting = setting;
- this.spread = SpreadJsObj.createNewSpread($(this.setting.selector)[0]);
- this.sheet = this.spread.getActiveSheet();
- SpreadJsObj.initSheet(this.sheet, this.setting.spreadSetting);
- this.xmjSpread = SpreadJsObj.createNewSpread($(this.setting.xmjSelector)[0]);
- this.xmjSheet = this.xmjSpread.getActiveSheet();
- SpreadJsObj.initSheet(this.xmjSheet, this.setting.xmjSpreadSetting);
- if (!readOnly) {
- this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
- const gcl = SpreadJsObj.getSelectObject(info.sheet);
- priceOprObj.addRevisePrice(gcl);
- });
- }
- const self = this;
- this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
- self.loadLeafXmj();
- });
- }
- loadData(bills, pos) {
- gclGatherModel.loadLedgerData(bills);
- gclGatherModel.loadPosData(pos);
- this.gcl = gclGatherModel.gatherGclData();
- this.sheet && SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, this.gcl);
- this.loadLeafXmj(0);
- }
- loadLeafXmj(iGclRow) {
- const gcl = iGclRow ? this.gcl[iGclRow] : SpreadJsObj.getSelectObject(this.sheet);
- SpreadJsObj.resetTopAndSelect(this.xmjSheet);
- if (gcl) {
- SpreadJsObj.loadSheetData(this.xmjSheet, SpreadJsObj.DataType.Data, gcl.leafXmjs);
- } else {
- SpreadJsObj.loadSheetData(this.xmjSheet, SpreadJsObj.DataType.Data, []);
- }
- }
- }
- const ledgerGcl = new LedgerGcl({
- selector: '#ledger-gcl-spread',
- spreadSetting: ledgerGclSpreadSetting,
- xmjSelector: '#ledger-xmj-spread',
- xmjSpreadSetting: ledgerXmjSpreadSetting,
- });
- $.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();
- priceSpread.refresh();
- ledgerGcl.spread.refresh();
- }
- });
- $.divResizer({
- select: '#revise-right-spr',
- callback: function () {
- priceSpread.refresh();
- ledgerGcl.spread.refresh();
- }
- });
- $.divResizer({
- select: '#gcl-spr',
- callback: function () {
- priceSpread.refresh();
- ledgerGcl.spread.refresh();
- ledgerGcl.xmjSpread.refresh();
- }
- });
- postData('load', { filter: 'bills;pos;price' }, result => {
- revisePrice.loadDatas(result.price);
- SpreadJsObj.loadSheetData(priceSheet, SpreadJsObj.DataType.Data, revisePrice.data);
- ledgerGcl.loadData(result.bills, result.pos);
- $("[content='#ledgerGcl']").click();
- });
- $('a', '#side-menu').bind('click', function (e) {
- e.preventDefault();
- const tab = $(this), tabPanel = $(tab.attr('content'));
- // 展开工具栏、切换标签
- if (!tab.hasClass('active')) {
- $('a', '#side-menu').removeClass('active');
- tab.addClass('active');
- $('.tab-content .tab-pane').removeClass('active');
- tabPanel.addClass('active');
- showSideTools(tab.hasClass('active'));
- ledgerGcl.spread.refresh();
- ledgerGcl.xmjSpread.refresh();
- } else {// 收起工具栏
- tab.removeClass('active');
- tabPanel.removeClass('active');
- showSideTools(tab.hasClass('active'));
- }
- priceSpread.refresh();
- });
- });
|