12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091 |
- '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 微软雅黑',
- selectedBackColor: '#fffacd',
- readOnly,
- getColor: function (sheet, data, row, col, defaultColor) {
- if (!data) return defaultColor;
- if (data.rela_lid && data.rela_cid) return '#f5deb3';
- }
- };
- const priceBwSpreadSetting = {
- cols: [
- {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
- {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
- {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
- {title: '原单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
- ],
- headRows: 1,
- emptyRows: 0,
- headRowHeight: [25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- };
- sjsSettingObj.setFxTreeStyle(priceBwSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
- const priceChangeSpreadSetting = {
- cols: [
- {title: '变更令', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
- {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 1, width: 80, formatter: '@'},
- ],
- headRows: 1,
- emptyRows: 0,
- headRowHeight: [25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- };
- autoFlashHeight();
- const bcontent = $(".bcontent-wrap").length > 0 ? $(".bcontent-wrap").height() : 0;
- $(".sp-wrap").height(bcontent-30);
- const priceSpread = SpreadJsObj.createNewSpread($('#price-spread')[0]);
- const priceSheet = priceSpread.getActiveSheet();
- const priceBwSpread = SpreadJsObj.createNewSpread($('#price-bw-spread')[0]);
- const priceBwSheet = priceBwSpread.getActiveSheet();
- const priceChangeSpread = SpreadJsObj.createNewSpread($('#price-change-spread')[0]);
- const priceChangeSheet = priceChangeSpread.getActiveSheet();
- SpreadJsObj.initSheet(priceSheet, priceSpreadSetting);
- SpreadJsObj.initSheet(priceBwSheet, priceBwSpreadSetting);
- SpreadJsObj.initSheet(priceChangeSheet, priceChangeSpreadSetting);
- class RevisePrice {
- constructor () {
- this.data = [];
- this.tree = createNewPathTree('filter', {
- id: 'ledger_id',
- pid: 'ledger_pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- fullPath: 'full_path',
- keys: ['id', 'tender_id', 'ledger_id'],
- });
- }
- resortData() {
- this.data.sort(function (a, b) {
- return a.order - b.order;
- });
- }
- loadDatas(datas, treeData, changeData) {
- this.data = datas;
- this.tree.loadDatas(treeData);
- this.resortData();
- this.change = changeData;
- this.relaChange = [];
- if (this.data.length > 0) this.refreshRela(this.data[0]);
- }
- 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();
- }
- getSamePrice(price) {
- return this.data.filter(x => {
- if (x.id === price.id) return false;
- return x.b_code === price.b_code && x.name === price.name && x.unit === price.unit && x.org_price === price.org_price;
- });
- }
- refreshTreeRela(price, samePrice) {
- if (!samePrice) samePrice = this.getSamePrice(price);
- if (price.rela_lid) {
- this.tree.loadFilter(price.rela_lid);
- } else {
- const invalid = [];
- for (const sp of samePrice) {
- const lid = sp.rela_lid ? sp.rela_lid.split(',') : [];
- invalid.push(...lid);
- }
- this.tree.loadFilter(invalid.join(','), 'filter');
- }
- }
- refreshChangeRela(price, samePrice) {
- if (!samePrice) samePrice = this.getSamePrice(price);
- if (price.rela_cid) {
- const choose = price.rela_cid.split(',');
- for (const c of this.change) {
- c.rela = choose.indexOf(c.cid + '') >= 0;
- c.valid = !!c.rela;
- }
- } else if (readOnly && price.his_rela_cid) {
- const his = price.his_rela_cid.split(',');
- for (const c of this.change) {
- c.rela = his.indexOf(c.cid + '') >= 0;
- c.valid = !!c.rela;
- }
- } else {
- const invalid = [];
- for (const sp of samePrice) {
- const cid = sp.rela_cid ? sp.rela_cid.split(',') : [];
- invalid.push(...cid);
- }
- for (const c of this.change) {
- c.rela = invalid.indexOf(c.cid + '') >= 0;
- if (c.rela) {
- c.valid = 0;
- } else {
- const exist = c.bills.find(x => {
- return x.code === price.b_code && x.name === price.name && x.unit === price.unit && x.unit_price === price.org_price;
- });
- c.valid = !!exist;
- }
- }
- }
- this.relaChange.length = 0;
- for (const c of this.change) {
- if (c.valid){
- this.relaChange.push(c);
- c.visible = true;
- }
- }
- }
- refreshRela(price) {
- const samePrice = this.getSamePrice(price);
- this.refreshTreeRela(price, samePrice);
- this.refreshChangeRela(price, samePrice);
- }
- }
- 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)) && (!x.rela_lid || !x.rela_cid);
- });
- 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);
- });
- },
- addRevisePrices(datas) {
- if (datas.length === 0) {
- toastr.warning('请选择需要调整单价的清单');
- return;
- }
- const add = [];
- for (const data of datas) {
- 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)) && (!x.rela_lid || !x.rela_cid);
- });
- if (op) continue;
- add.push({ b_code: data.b_code, name: data.name, unit: data.unit, unit_price: data.unit_price });
- }
- if (add.length === 0) {
- toastr.warning('已存在该单价调整');
- return;
- }
- postData(window.location.pathname + '/update', { add }, 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);
- });
- },
- updateRelaLid: function (price, rela_lid) {
- const data = { update: { id: price.id, rela_lid } };
- postData(window.location.pathname + '/update', data, function (result) {
- revisePrice.loadUpdateData(result);
- revisePrice.refreshTreeRela(price);
- SpreadJsObj.refreshTreeRowVisible(priceBwSheet);
- SpreadJsObj.reloadRowBackColor(priceSheet, revisePrice.data.indexOf(price));
- });
- },
- updateRelaCid: function (price, rela_cid) {
- const data = { update: { id: price.id, rela_cid } };
- postData(window.location.pathname + '/update', data, function (result) {
- revisePrice.loadUpdateData(result);
- revisePrice.refreshChangeRela(price);
- SpreadJsObj.reLoadSheetData(priceChangeSheet);
- SpreadJsObj.reloadRowBackColor(priceSheet, revisePrice.data.indexOf(price));
- });
- },
- selectionChanged: function () {
- const price = SpreadJsObj.getSelectObject(priceSheet);
- revisePrice.refreshRela(price);
- SpreadJsObj.refreshTreeRowVisible(priceBwSheet);
- SpreadJsObj.reLoadSheetData(priceChangeSheet);
- },
- };
- 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;
- }
- },
- sprMove: '----',
- chooseRelaBw: {
- name: '选择应用部位',
- icon: 'fa-link',
- callback: function (key, opt) {
- const price = SpreadJsObj.getSelectObject(priceSheet);
- const samePrice = revisePrice.getSamePrice(price);
- chooseRelaBw.show(price, samePrice);
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(priceSheet);
- return !node;
- },
- visible: function (key, opt) {
- return !readOnly;
- }
- },
- chooseRelaChange: {
- name: '选择应用变更令',
- icon: 'fa-link',
- callback: function (key, opt) {
- const price = SpreadJsObj.getSelectObject(priceSheet);
- const samePrice = revisePrice.getSamePrice(price);
- chooseRelaChange.show(price, samePrice);
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(priceSheet);
- return !node;
- },
- visible: function (key, opt) {
- return !readOnly;
- }
- },
- noRelaChange: {
- name: '不应用于变更令',
- icon: 'fa-unlink',
- callback: function (key, opt) {
- const price = SpreadJsObj.getSelectObject(priceSheet);
- priceOprObj.updateRelaCid(price, '-1');
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(priceSheet);
- return !node;
- },
- visible: function (key, opt) {
- return !readOnly;
- }
- },
- },
- });
- }
- priceSpread.bind(spreadNS.Events.SelectionChanged, priceOprObj.selectionChanged);
- class LedgerGcl {
- constructor(setting) {
- const self = this;
- 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);
- if (gcl.settle_status === settleStatus.finish) {
- toastr.warning('该清单已结算,不可进行单价调整');
- return;
- }
- priceOprObj.addRevisePrice(gcl);
- });
- $.contextMenu({
- selector: setting.selector,
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.spread);
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {
- add: {
- name: '添加',
- icon: 'fa-sign-in',
- callback: function (key, opt) {
- const datas = [];
- const sel = self.sheet.getSelections()[0];
- const node = self.sheet.zh_data[sel.row];
- if (node.settle_status !== settleStatus.finish) datas.push(node);
- if (sel.rowCount > 1) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = self.sheet.zh_data[sel.row + r];
- if (rNode.settle_status === settleStatus.finish) continue;
- if (rNode) datas.push(rNode);
- }
- }
- if (datas.length === 0) {
- toastr.warning('选中清单已结算,不可进行单价调整');
- return;
- } else if (datas.length < sel.rowCount) {
- toastr.warning('部分选中清单已结算,已过滤');
- }
- priceOprObj.addRevisePrices(datas);
- },
- },
- },
- });
- }
- 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();
- priceBwSpread.refresh();
- priceChangeSpread.refresh();
- }
- });
- $.divResizer({
- select: '#revise-right-spr',
- callback: function () {
- priceSpread.refresh();
- priceBwSpread.refresh();
- priceChangeSpread.refresh();
- ledgerGcl.spread.refresh();
- ledgerGcl.xmjSpread.refresh();
- }
- });
- $.divResizer({
- select: '#gcl-spr',
- callback: function () {
- ledgerGcl.spread.refresh();
- ledgerGcl.xmjSpread.refresh();
- }
- });
- $.divResizer({
- select: '#price-resize',
- callback: function () {
- priceSpread.refresh();
- let bcontent = $(".bcontent-wrap").length > 0 ? $(".bcontent-wrap").height() : 0;
- $(".sp-wrap").height(bcontent-30);
- priceBwSpread.refresh();
- priceChangeSpread.refresh();
- }
- });
- class ChooseRelaBw {
- constructor() {
- const self = this;
- this.tree = createNewPathTree('ledger', {
- id: 'ledger_id',
- pid: 'ledger_pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- fullPath: 'full_path',
- keys: ['id', 'tender_id', 'ledger_id'],
- });
- $('#choose-rela-bw').on('shown.bs.modal', function() {
- self.initSpread();
- SpreadJsObj.reloadColData(self.sheet, 0, 1);
- SpreadJsObj.reloadRowBackColor(self.sheet, 0, self.tree.nodes.length);
- });
- $('#choose-rela-bw-ok').click(function() {
- const choose_lid = [];
- self.tree.nodes.forEach(x => {
- if (x.check) choose_lid.push(x.ledger_id);
- });
- priceOprObj.updateRelaLid(self.price, choose_lid.join(','));
- $('#choose-rela-bw').modal('hide');
- });
- }
- get locate() {
- return this._locate;
- }
- set locate(value) {
- if (!this.searchResult || this.searchResult.length === 0) return;
- this._locate = !value || value >= this.searchResult.length ? 0 : (value < 0 ? this.searchResult.length - 1 : value);
- SpreadJsObj.locateTreeNode(this.sheet, this.searchResult[this._locate].ledger_id, true);
- }
- search(keyword) {
- this.searchResult = [];
- for (const node of this.tree.nodes) {
- const code = node.code || '', name = node.name || '', b_code = node.b_code || '';
- if (code.indexOf(keyword) >= 0 || b_code.indexOf(keyword) >= 0 || name.indexOf(keyword) >= 0) this.searchResult.push(node);
- }
- $('#rela-bw-search-result').html(`结果:${this.searchResult.length}`);
- this.locate = 0;
- }
- initSpread() {
- if (this.spread) return;
- this.spread = SpreadJsObj.createNewSpread($('#rela-bw-spread')[0]);
- this.sheet = this.spread.getActiveSheet();
- const spreadSetting = {
- cols: [
- {title: '选择', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', cellType: 'checkbox'},
- {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
- {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
- {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
- {title: '原单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
- ],
- headRows: 1,
- emptyRows: 0,
- headRowHeight: [25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- getColor: function (sheet, data, row, col, defaultColor) {
- return data && data.invalid ? '#dddddd' : defaultColor;
- }
- };
- sjsSettingObj.setFxTreeStyle(spreadSetting, sjsSettingObj.FxTreeStyle.jz);
- SpreadJsObj.initSheet(this.sheet, spreadSetting);
- const self = this;
- this.spread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
- function checkInvalid(node) {
- if (node.invalid) return 1;
- if (self.tree.checkParent(node, 'invalid')) return 2;
- if (self.tree.checkChildren(node, 'invalid')) return 3;
- return 0;
- }
- const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
- if (!sheet.zh_setting) return;
- if (cellType instanceof spreadNS.CellTypes.CheckBox) {
- if (sheet.isEditing()) sheet.endEdit(true);
- }
- const col = sheet.zh_setting.cols[info.col];
- if (col.field !== 'check') return;
- const tree = sheet.zh_tree;
- const node = SpreadJsObj.getSelectObject(sheet);
- if (node.b_code) {
- toastr.warning('请选择部位');
- return;
- }
- if (!node.check && node.settle_status === settleStatus.finish) {
- toastr.warning('该部位已结算,不可选择');
- return;
- }
- if (!node.check) {
- const invalid = checkInvalid(node);
- const invalidHint = ['该部位已被选择,请勿重复选择', '该部位的父项已被选择,请勿选择', '该部位的子项已被选择,请勿在其子项中选择'];
- if (invalid) {
- toastr.warning(invalidHint[invalid-1]);
- return;
- }
- if (self.tree.checkParent(node)) {
- const rect = info.sheet.getCellRect(info.row, info.col);
- self.chooseConfirmPopover({
- x: rect.x + rect.width / 2 + 25,
- y: rect.y + rect.height / 2 + 3,
- }, '父项已勾选,继续将取消父项勾选。', function () {
- node.check = true;
- const parents = tree.getFullPathNodes(tree.getParent(node).full_path);
- const rows = [tree.nodes.indexOf(node)];
- for (const p of parents) {
- if (p.check) {
- p.check = false;
- rows.push(tree.nodes.indexOf(p));
- }
- }
- SpreadJsObj.reLoadRowsData(info.sheet, rows);
- });
- } else if (self.tree.checkChildren(node)) {
- const rect = info.sheet.getCellRect(info.row, info.col);
- self.chooseConfirmPopover({
- x: rect.x + rect.width / 2 + 25,
- y: rect.y + rect.height / 2 + 3,
- }, '子项已勾选,继续将取消子项勾选。', function () {
- node.check = true;
- const posterity = tree.getPosterity(node);
- const rows = [tree.nodes.indexOf(node)];
- for (const p of posterity) {
- if (p.check) {
- rows.push(tree.nodes.indexOf(p));
- p.check = false;
- }
- }
- SpreadJsObj.reLoadRowsData(info.sheet, rows);
- });
- } else {
- node.check = true;
- SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);
- }
- } else {
- node.check = false;
- SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);
- }
- });
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.tree);
- (function (select, sheet) {
- $(select).click(function () {
- if (!sheet.zh_tree) return;
- const tag = $(this).attr('tag');
- const tree = sheet.zh_tree;
- setTimeout(() => {
- showWaitingView();
- switch (tag) {
- case "1":
- case "2":
- case "3":
- case "4":
- case "5":
- tree.expandByLevel(parseInt(tag));
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "last":
- tree.expandByCustom(() => { return true; });
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "leafXmj":
- tree.expandToLeafXmj();
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- }
- closeWaitingView();
- }, 100);
- });
- })('a[name=showLevel]', this.sheet);
- $('#rela-bw-search-keyword').change(function () {
- self.search(this.value);
- });
- $('#rela-bw-search-pre').click(function () {
- self.locate = self.locate - 1;
- });
- $('#rela-bw-search-next').click(function () {
- self.locate = self.locate + 1;
- });
- }
- reBind(obj, eventName, fun) {
- obj.unbind(eventName);
- obj.bind(eventName, fun);
- }
- chooseConfirmPopover(pos, hint, okCallback) {
- const confirmObj = $('#choose-confirm'), hintObj = $('#choose-confirm-hint');
- const okObj = $('#choose-confirm-ok'), cancelObj = $('#choose-confirm-cancel');
- this.reBind(cancelObj, 'click', function () {
- confirmObj.hide();
- });
- this.reBind(okObj, 'click', function () {
- okCallback();
- confirmObj.hide();
- });
- hintObj.text(hint);
- confirmObj.css("top", pos.y).css("left", pos.x).show();
- }
- loadTree(data) {
- this.tree.loadDatas(data);
- this.tree.initNodeData('settle_status', settleStatus.non, values => { return values.length === 1 ? values[0] : settleStatus.part});
- }
- show(price, samePrice){
- this.price = price;
- this.choose = price.rela_lid ? price.rela_lid.split(',') : [];
- this.invalid = [];
- for (const sp of samePrice) {
- const lid = sp.rela_lid ? sp.rela_lid.split(',') : [];
- this.invalid.push(...lid);
- }
- for (const node of this.tree.nodes) {
- node.check = this.choose.indexOf(node.ledger_id + '') >= 0;
- node.invalid = this.invalid.indexOf(node.ledger_id + '') >= 0;
- }
- $('#choose-rela-bw').modal('show');
- }
- }
- const chooseRelaBw = new ChooseRelaBw();
- class ChooseRelaChange {
- constructor (){
- const self = this;
- $('#choose-rela-change').on('shown.bs.modal', function() {
- self.initSpread();
- SpreadJsObj.reloadColData(self.sheet, 0, 1);
- SpreadJsObj.reloadRowBackColor(self.sheet, 0, self.change.length);
- });
- $('#choose-rela-change-ok').click(function() {
- const choose_cid = [];
- self.change.forEach(x => {
- if (x.check) choose_cid.push(x.cid);
- });
- priceOprObj.updateRelaCid(self.price, choose_cid.join(','));
- $('#choose-rela-change').modal('hide');
- });
- }
- initSpread() {
- if (this.spread) return;
- this.spread = SpreadJsObj.createNewSpread($('#rela-change-spread')[0]);
- this.sheet = this.spread.getActiveSheet();
- const spreadSetting = {
- cols: [
- {title: '选择', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', cellType: 'checkbox'},
- {title: '变更令', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@'},
- {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
- {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
- ],
- headRows: 1,
- emptyRows: 0,
- headRowHeight: [25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- getColor: function (sheet, data, row, col, defaultColor) {
- return data && data.invalid ? '#dddddd' : defaultColor;
- }
- };
- SpreadJsObj.initSheet(this.sheet, spreadSetting);
- this.spread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
- const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
- if (!sheet.zh_setting) return;
- if (cellType instanceof spreadNS.CellTypes.CheckBox) {
- if (sheet.isEditing()) sheet.endEdit(true);
- }
- const col = sheet.zh_setting.cols[info.col];
- if (col.field !== 'check') return;
- const node = SpreadJsObj.getSelectObject(sheet);
- if (!node.check) {
- if (node.invalid) return;
- node.check = true;
- SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);
- } else {
- node.check = false;
- SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);
- }
- });
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, this.change);
- }
- loadChange(data) {
- this.change = data;
- }
- show(price, samePrice) {
- this.price = price;
- this.choose = price.rela_cid ? price.rela_cid.split(',') : [];
- this.invalid = [];
- for (const sp of samePrice) {
- const cid = sp.rela_cid ? sp.rela_cid.split(',') : [];
- this.invalid.push(...cid);
- }
- for (const c of this.change) {
- c.visible = true;
- c.check = this.choose.indexOf(c.cid + '') >= 0;
- c.invalid = this.invalid.indexOf(c.cid + '') >= 0;
- if (!c.check && !c.invalid) {
- const exist = c.bills.find(x => {
- return x.code === price.b_code && x.name === price.name && x.unit === price.unit && x.unit_price === price.org_price;
- });
- c.visible = !!exist;
- }
- }
- if (this.sheet) SpreadJsObj.refreshTreeRowVisible(this.sheet);
- $('#choose-rela-change').modal('show');
- }
- }
- const chooseRelaChange = new ChooseRelaChange();
- postData('load', { filter: 'bills;pos;price;change' }, result => {
- revisePrice.loadDatas(result.price, result.bills, result.change);
- SpreadJsObj.loadSheetData(priceSheet, SpreadJsObj.DataType.Data, revisePrice.data);
- ledgerGcl.loadData(result.bills, result.pos);
- chooseRelaBw.loadTree(result.bills);
- chooseRelaChange.loadChange(result.change);
- SpreadJsObj.loadSheetData(priceBwSheet, SpreadJsObj.DataType.Tree, revisePrice.tree);
- SpreadJsObj.loadSheetData(priceChangeSheet, SpreadJsObj.DataType.Data, revisePrice.relaChange);
- $("[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');
- $('#right-view .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();
- priceBwSpread.refresh();
- priceChangeSpread.refresh();
- });
- $('a', '.bcontent-wrap').click(function() {
- $('[name=priceRela]').removeClass('active');
- $(this).addClass('active');
- $('#priceRelaTab').children().removeClass('active');
- $(this.getAttribute('href')).addClass('active');
- priceBwSpread.refresh();
- priceChangeSpread.refresh();
- });
- });
|