12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178 |
- 'use strict';
- /**
- *
- *
- * @author Zhong
- * @date 2018/6/11
- * @version
- */
- const billsGuidance = (function () {
- let currentLib = null;
- //库类型
- const libType = {'guidance': 1, 'elf': 2}; //清单指引、清单精灵
- const libTypeText = {1: '清单指引', 2: '清单精灵'};
- const libSel = $('#stdBillsGuidanceLibSelect');
- //工作内容
- let stdBillsJobData = [];
- //项目特征
- let stdBillsFeatureData = [];
- const bills = {
- dom: $('#billsGuidance_bills'),
- workBook: null,
- cache: [],
- tree: null,
- controller: null,
- treeSetting: {
- emptyRowHeader: true,
- rowHeaderWidth: 15,
- treeCol: 0,
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [40],
- defaultRowHeight: 21,
- cols: [{
- width: 160,
- readOnly: true,
- head: {
- titleNames: ["项目编码"],
- spanCols: [1],
- spanRows: [1],
- vAlign: [1],
- hAlign: [1],
- font: ["Arial"]
- },
- data: {
- field: "code",
- vAlign: 1,
- hAlign: 0,
- font: "Arial"
- }
- }, {
- width: 220,
- readOnly: true,
- head: {
- titleNames: ["项目名称"],
- spanCols: [1],
- spanRows: [1],
- vAlign: [1],
- hAlign: [1],
- font: ["Arial"]
- },
- data: {
- field: "name",
- vAlign: 1,
- hAlign: 0,
- font: "Arial"
- }
- },
- {
- width: 45,
- readOnly: true,
- showHint: true,
- head: {
- titleNames: ["计量单位"],
- spanCols: [1],
- spanRows: [1],
- vAlign: [1],
- hAlign: [1],
- font: ["Arial"]
- },
- data: {
- field: "unit",
- vAlign: 1,
- hAlign: 1,
- font: "Arial"
- }
- }
- ]
- },
- headers: [
- {name: '项目编码', dataCode: 'code', width: 160, vAlign: 'center', hAlign: 'left', formatter: '@'},
- {name: '项目名称', dataCode: 'name', width: 220, vAlign: 'center', hAlign: 'left', formatter: '@'},
- {name: '单位', dataCode: 'unit', width: 45, vAlign: 'center', hAlign: 'center', formatter: '@'},
- ],
- events: {
- SelectionChanging: function (sender, info) {
- billsInitSel(info.newSelections[0].row);
- },
- CellDoubleClick: function (sender, args) {
- if(!bills.tree){
- return;
- }
- let node = bills.tree.items[args.row];
- if(!node){
- return;
- }
- if(node.children.length === 0){
- //插入清单
- if (/\//.test(node.data.unit)) {
- let canAdd = true;
- $.bootstrapLoading.start();
- let existB = projectObj.project.Bills.sameStdCodeBillsData(node.data.code);
- if (existB) {
- let std = JSON.parse(JSON.stringify(node.data));
- std.unit = existB.unit;
- canAdd = ProjectController.addBills(projectObj.project, projectObj.mainController, std);
- if(canAdd !== null || canAdd !== false){
- //插入选中的定额
- let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
- insertRations(addRationDatas);
- }
- if(canAdd === false && $.bootstrapLoading.isLoading()){
- $.bootstrapLoading.end();
- }
- } else {
- ConfirmModal.stdBillsUnit.check(node.data, function (std) {
- canAdd = ProjectController.addBills(projectObj.project, projectObj.mainController, std);
- if(canAdd !== null || canAdd !== false){
- //插入选中的定额
- let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
- insertRations(addRationDatas);
- }
- if(canAdd === false && $.bootstrapLoading.isLoading()){
- $.bootstrapLoading.end();
- }
- }, function () {
- if($.bootstrapLoading.isLoading()){
- $.bootstrapLoading.end();
- }
- });
- }
- }
- else {
- let insert = billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, node);
- if(insert){
- //插入选中的定额
- let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
- insertRations(addRationDatas);
- }
- }
- }
- else {
- node.setExpanded(!node.expanded);
- //设置展开收起状态
- sessionStorage.setItem('stdBillsGuidanceExpState', bills.tree.getExpState(bills.tree.items));
- renderSheetFunc(args.sheet, function () {
- let iCount = node.posterityCount(), i, child;
- for (i = 0; i < iCount; i++) {
- child = bills.tree.items[args.row + i + 1];
- args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
- }
- args.sheet.invalidateLayout();
- });
- args.sheet.repaint();
- }
- }
- }
- };
- //项目指引类型
- const itemType = {
- job: 0,
- ration: 1
- };
- const guideItem = {
- dom: $('#billsGuidance_items'),
- workBook: null,
- tree: null,
- controller: null,
- treeSetting: {
- treeCol: 1,
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [40],
- defaultRowHeight: 21,
- cols: [
- {
- width: 35,
- readOnly: false,
- head: {
- titleNames: ["选择"],
- spanCols: [1],
- spanRows: [1],
- vAlign: [1],
- hAlign: [1],
- font: ["Arial"]
- },
- data: {
- field: "select",
- vAlign: 1,
- hAlign: 1,
- font: "Arial"
- }
- },
- {
- width: 420,
- readOnly: false,
- head: {
- titleNames: ["项目指引"],
- spanCols: [1],
- spanRows: [1],
- vAlign: [1],
- hAlign: [1],
- font: ["Arial"]
- },
- data: {
- field: "name",
- vAlign: 1,
- hAlign: 0,
- font: "Arial"
- }
- }
- ]
- },
- headers: [
- {name: '选择', dataCode: 'select', width: 35, vAlign: 'center', hAlign: 'center', formatter: '@'},
- {name: '项目指引', dataCode: 'name', width: 300, vAlign: 'center', hAlign: 'left', formatter: '@'},
- ],
- events: {
- EditStarting: function (sender, args) {
- if(!bills.tree || guideItem.headers[args.col]['dataCode'] === 'name'){
- args.cancel = true;
- }
- },
- ButtonClicked: function (sender, args) {
- if(args.sheet.isEditing()){
- args.sheet.endEdit(true);
- }
- refreshInsertRation();
- },
- CellDoubleClick: function (sender, args) {
- if(!bills.tree || !bills.tree.selected){
- return;
- }
- let node = bills.tree.selected.guidance.tree.selected;
- if(!node){
- return;
- }
- if(node.children.length === 0){
- if(guideItem.headers[args.col]['dataCode'] === 'name'){
- insertRations(getInsertRationData([args.row]));
- }
- }
- else {
- node.setExpanded(!node.expanded);
- renderSheetFunc(args.sheet, function () {
- let iCount = node.posterityCount(), i, child;
- for (i = 0; i < iCount; i++) {
- child = bills.tree.selected.guidance.tree.items[args.row + i + 1];
- args.sheet.setRowVisible(args.row + i + 1, child.visible, args.sheetArea);
- }
- args.sheet.invalidateLayout();
- });
- args.sheet.repaint();
- }
- }
- }
- };
- const elfItem = {
- dom: $('#billsGuidance_items'),
- workBook: null,
- tree: null,
- controller: null,
- treeSetting: {
- treeCol: 0,
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [40],
- defaultRowHeight: 21,
- cols: [
- {
- width: 250,
- readOnly: true,
- head: {
- titleNames: ["施工工序"],
- spanCols: [1],
- spanRows: [1],
- vAlign: [1],
- hAlign: [1],
- font: ["Arial"]
- },
- data: {
- field: "name",
- vAlign: 1,
- hAlign: 1,
- font: "Arial"
- }
- },
- {
- width: 250,
- readOnly: false,
- head: {
- titleNames: ["选项"],
- spanCols: [1],
- spanRows: [1],
- vAlign: [1],
- hAlign: [1],
- font: ["Arial"]
- },
- data: {
- field: "options",
- vAlign: 1,
- hAlign: 0,
- font: "Arial"
- }
- }
- ]
- },
- headers: [
- {name: '施工工序', dataCode: 'name', width: 250, vAlign: 'center', hAlign: 'center', formatter: '@'},
- {name: '选项', dataCode: 'options', width: 250, vAlign: 'center', hAlign: 'left', formatter: '@'},
- ],
- events: {
- CellClick: function (sender, args) {
- if(elfItem.headers[args.col]['dataCode'] === 'options' && args.sheetArea === 3){
- if(!args.sheet.getCell(args.row, args.col).locked() && !args.sheet.isEditing()){
- args.sheet.startEdit();
- }
- }
- },
- ClipboardPasting: function (sender, info) {
- info.cancel = true;
- }
- }
- };
- const options = {
- workBook: {
- tabStripVisible: false,
- allowContextMenu: false,
- allowCopyPasteExcelStyle : false,
- allowExtendPasteRange: false,
- allowUserDragDrop : false,
- allowUserDragFill: false,
- scrollbarMaxAlign : true
- },
- sheet: {
- protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
- clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
- }
- };
- //渲染时方法,停止渲染
- //@param {Object}sheet {Function}func @return {void}
- function renderSheetFunc(sheet, func){
- sheet.suspendEvent();
- sheet.suspendPaint();
- if(func){
- func();
- }
- sheet.resumeEvent();
- sheet.resumePaint();
- }
- //设置表选项
- //@param {Object}workBook {Object}opts @return {void}
- function setOptions (workBook, opts) {
- for(let opt in opts.workBook){
- workBook.options[opt] = opts.workBook[opt];
- }
- for(let opt in opts.sheet){
- workBook.getActiveSheet().options[opt] = opts.sheet[opt];
- }
- }
- //建表头
- //@param {Object}sheet {Array}headers @return {void}
- function buildHeader(sheet, headers) {
- let fuc = function () {
- sheet.setColumnCount(headers.length);
- sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
- for(let i = 0, len = headers.length; i < len; i++){
- sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
- sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
- if(headers[i].formatter){
- sheet.setFormatter(-1, i, headers[i].formatter);
- }
- sheet.getRange(-1, i, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[i]['hAlign']]);
- sheet.getRange(-1, i, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[i]['vAlign']]);
- }
- };
- renderSheetFunc(sheet, fuc);
- }
- //表监听事件
- //@param {Object}workBook @return {void}
- function bindEvent(workBook, events) {
- if(Object.keys(events).length === 0){
- return;
- }
- const Events = GC.Spread.Sheets.Events;
- for(let event in events){
- workBook.bind(Events[event], events[event]);
- }
- }
- //建表
- //@param {Object}module @return {void}
- function buildSheet(module) {
- if(!module.workBook){
- module.workBook = new GC.Spread.Sheets.Workbook(module.dom[0], {sheetCount: 1});
- sheetCommonObj.spreadDefaultStyle(module.workBook);
- let sheet = module.workBook.getActiveSheet();
- if(module === bills){
- //默认初始可控制焦点在清单表中
- module.workBook.focus();
- sheet.options.isProtected = true;
- sheet.name('stdBillsGuidance_bills');
- //设置悬浮提示
- TREE_SHEET_HELPER.initSetting(bills.dom[0], bills.treeSetting);
- }
- if(module === guideItem){
- sheet.options.isProtected = true;
- sheet.getRange(-1, 0, -1, 1).locked(false);
- sheet.getRange(-1, 1, -1, 1).locked(true);
- }
- if(module === elfItem){
- sheet.options.isProtected = true;
- sheet.getRange(-1, 0, -1, 1).locked(true);
- sheet.getRange(-1, 1, -1, 1).locked(false);
- }
- setOptions(module.workBook, options);
- buildHeader(module.workBook.getActiveSheet(), module.headers);
- bindEvent(module.workBook, module.events);
- }
- }
- //清空表数据
- //@param {Object}sheet {Array}headers {Number}rowCount @return {void}
- function cleanData(sheet, headers, rowCount){
- renderSheetFunc(sheet, function () {
- sheet.clear(-1, 0, -1, headers.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
- if (rowCount > 0) {
- sheet.setRowCount(rowCount);
- }
- });
- }
- //初始化各工作表
- //@param {Array}modules @return {void}
- function initWorkBooks(modules){
- for(let module of modules){
- buildSheet(module);
- }
- }
- //初始化并输出树
- //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
- function initTree(module, sheet, treeSetting, datas){
- module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
- module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
- module.tree.loadDatas(datas);
- if(module === bills){
- initExpandStat();
- }
- module.controller.showTreeData();
- }
- //项目指引表焦点控制
- //@param {Number}row @return {void}
- function guideItemInitSel(row){
- let billsNode = bills.tree.selected;
- let node = null;
- if(billsNode && billsNode.guidance.tree){
- node = billsNode.guidance.tree.items[row];
- if(node){
- billsNode.guidance.tree.selected = node;
- }
- }
- }
- //清单精灵表焦点控制
- //@param {Number}row @return {void}
- function elfItemInitSel(row){
- let billsNode = bills.tree.selected;
- let node = null;
- if(billsNode && billsNode.elf.tree){
- node = billsNode.elf.tree.items[row];
- if(node){
- billsNode.elf.tree.selected = node;
- }
- }
- }
- //根据项目指引的类型设置单元格类型,定额类型的项目指引为复选框
- //@param {Array}nodes @return {void}
- function setItemCellType(nodes){
- //设置单元格类型
- const base = new GC.Spread.Sheets.CellTypes.Base();
- const checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
- const sheet = guideItem.workBook.getActiveSheet();
- renderSheetFunc(sheet, function(){
- for(let node of nodes){
- sheet.setCellType(node.serialNo(), 0, node.data.type === itemType.ration ? checkBox : base);
- }
- });
- }
- //清单表焦点控制
- //@param {Number}row @return {void}
- function billsInitSel(row){
- if(currentLib.type && currentLib.type === libType.elf){
- billsSelElf(row);
- }else {
- billsSelGuidance(row);
- }
- }
- //清单焦点变换-清单指引操作
- //@param {Number}row @return {void}
- function billsSelGuidance(row){
- let guideSheet = guideItem.workBook.getActiveSheet();
- cleanData(guideSheet, guideItem.headers, -1);
- if(!bills.tree){
- return;
- }
- let node = bills.tree.items[row];
- if(!node){
- return;
- }
- bills.tree.selected = node;
- refreshInsertRation();
- if(!node.guidance.tree){
- CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: libSel.val(), billsID: node.getID()}, function (rstData) {
- initTree(node.guidance, guideSheet, guideItem.treeSetting, rstData);
- setItemCellType(node.guidance.tree.items);
- //项目指引初始焦点
- guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
- });
- }
- else{
- node.guidance.controller.showTreeData();
- setItemCellType(node.guidance.tree.items);
- //项目指引初始焦点
- guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
- }
- }
- //清单焦点变换-清单精灵操作
- //@param {Number}row @return {void}
- function billsSelElf(row) {
- let elfSheet = elfItem.workBook.getActiveSheet();
- cleanData(elfSheet, elfItem.headers, -1);
- if(!bills.tree){
- return;
- }
- let node = bills.tree.items[row];
- if(!node){
- return;
- }
- bills.tree.selected = node;
- refreshInsertRation();
- if(!node.elf.tree){
- CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: libSel.val(), billsID: node.getID()}, function (rstData) {
- //定额数据删除编号信息
- for(let rData of rstData){
- if(rData.type === itemType.ration){
- let nameArr = rData.name.split(' ');
- if(nameArr.length > 0){
- nameArr.splice(0, 1);
- rData.name = nameArr.join(' ');
- }
- }
- }
- node.elf.datas = rstData;
- //第一层节点数据
- let firstLevelDatas = _.filter(rstData, function (data) {
- return data.ParentID == -1;
- });
- //初始数据的选项显示请选择
- for(let fData of firstLevelDatas){
- let options = getOptions(fData, rstData);
- fData.options = options.length > 0 ? '请选择' : '';
- }
- initTree(node.elf, elfSheet, elfItem.treeSetting, firstLevelDatas);
- setOptionsCellType(node.elf.tree.items);
- //elfSheet.getRange(-1, 1, -1, 1).cellType(getOptionsCellType(null, null, null));
- //setItemCellType(node.guidance.tree.items);
- //项目指引初始焦点
- elfItemInitSel(elfSheet.getActiveRowIndex() ? elfSheet.getActiveRowIndex() : 0);
- });
- }
- else{
- node.elf.controller.showTreeData();
- //elfSheet.getRange(-1, 1, -1, 1).cellType(getOptionsCellType(null, null, null));
- setOptionsCellType(node.elf.tree.items);
- //项目指引初始焦点
- elfItemInitSel(elfSheet.getActiveRowIndex() ? elfSheet.getActiveRowIndex() : 0);
- }
- }
- //获取施工工序含有的选项(即当前施工工序的子项),获取的顺序按照NextSiblingID排序
- //@param {Object}process {Array}datas @return {Array}
- function getOptions(process, datas) {
- let rst = [];
- if(!process || !process.ID){
- return [];
- }
- let options = _.filter(datas, function (data) {
- return data.ParentID == process.ID;
- });
- if(options.length === 0){
- return [];
- }
- //根据NextSiblingID排序
- let IDMapping = {};
- for(let opt of options){
- IDMapping[opt.ID] = {self: opt, next: null, pre: null};
- }
- for(let opt of options){
- let next = IDMapping[opt.NextSiblingID] ? IDMapping[opt.NextSiblingID] : null;
- if(next){
- next.pre = IDMapping[opt.ID];
- IDMapping[opt.ID]['next'] = next;
- }
- }
- let first = null,
- rank = 0;
- for(let ID in IDMapping){
- let obj = IDMapping[ID];
- if(!obj.pre){
- first = obj;
- }
- }
- while(first){
- rank++;
- first.self.rank = rank;
- rst.push(first.self);
- first = first.next;
- }
- return rst;
- }
- //设置清单精灵选项单元格
- //@param {Array}nodes @return {void}
- function setOptionsCellType(nodes) {
- let elfSheet = elfItem.workBook.getActiveSheet();
- for(let node of nodes){
- if(node.data.options !== ''){
- elfSheet.getCell(node.serialNo(), 1).locked(false).cellType(getOptionsCellType());
- }
- else {
- elfSheet.getCell(node.serialNo(), 1).locked(true).cellType(new GC.Spread.Sheets.CellTypes.Base());
- }
- }
- }
- //获取选项下拉多选单元格
- //@param {void} @return {void}
- function getOptionsCellType() {
- let me = this;
- let elfSheet= elfItem.workBook.getActiveSheet();
- function OptionsCellType() {
- this.isEscKey=false;
- this.displayText='';
- }
- function getHtml(node, cellRect, cellStyle) {
- if(!node){
- return '';
- }
- let height = cellRect.height;
- let htmlArr = [];
- let options = getOptions(node.data, bills.tree.selected.elf.datas);
- let optionsTitle = node.data.options.split(';').join('\n');
- htmlArr.push(`<div title="${optionsTitle}" style="height: ${height}px; background: ${cellStyle.backColor};overflow: hidden; white-space: nowrap; text-overflow: ellipsis">${node.data.options}</div><div style="background: ${cellStyle.backColor};border: 1px solid; overflow: auto; height: ${options.length > 6 ? height*6 : height*options.length+5}px; font-size: 0.9rem;">`);
- for(let opt of options){
- htmlArr.push(`<div title="${opt.name ? opt.name : ''}" class="elf-options" style="height: ${height}px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis">
- <input rank="${opt.rank}" value="${opt.ID}" style="margin-left: 5px; vertical-align: middle" type="checkbox"
- ${node.data.optionChecked && _.find(node.data.optionChecked, {ID: opt.ID}) ? 'checked' : ''}> ${opt.name ? opt.name : ''}</div>`);
- }
- htmlArr.push(`</div>`);
- return htmlArr.join('');
- }
- //选择后处理
- function doAfterSel(node) {
- let checkedSels = $('.elf-options').find('input:checked');
- let checkedNameArr = [],
- optionChecked= [];
- for(let checkSel of checkedSels){
- let opt = _.cloneDeep(_.find(bills.tree.selected.elf.datas, {ID: $(checkSel).val()}));
- opt.rank = $(checkSel).attr('rank');
- checkedNameArr.push(opt.name);
- optionChecked.push(opt);
- }
- this.displayText = checkedNameArr.length > 0 ? checkedNameArr.join(';') : '请选择';
- node.data.options = this.displayText;
- node.data.optionChecked = optionChecked;
- //删除节点
- let deleteInfo = getDeleteInfo(node, optionChecked);
- for(let dInfo of deleteInfo){
- if(node.tree.delete(dInfo.node)){
- elfSheet.deleteRows(dInfo.deleteRow, dInfo.deleteCount);
- }
- }
- //插入节点
- for(let perCheked of optionChecked){
- let exist = false;
- for(let subNode of node.children){
- if(subNode.data.ID === perCheked.ID){
- exist = true;
- }
- }
- //不重复且不为定额时插入
- if(!exist && perCheked.type !== itemType.ration){
- insertNodeByData(node, perCheked);
- }
- }
- TREE_SHEET_HELPER.refreshTreeNodeData(elfItem.treeSetting, elfSheet, node.tree.items, false);
- setOptionsCellType(node.tree.items);
- refreshInsertRation();
- }
- //获取删除节点信息
- function getDeleteInfo(node, optionChecked) {
- let rst = [];
- for(let subNode of node.children){
- let exist = false;
- for(let perChecked of optionChecked){
- if(subNode.data.ID === perChecked.ID){
- exist = true;
- }
- }
- if(!exist){
- let deleteRow = subNode.serialNo(),
- deleteCount = subNode.posterityCount() + 1;
- rst.push({node: subNode, deleteRow: deleteRow, deleteCount: deleteCount});
- }
- }
- return rst;
- }
- //插入单个节点,node:当前操作的节点
- function insertNodeByData(node, data) {
- let sameDepthNodes = node.children;
- let insertNextSiblingID = -1,
- insertParentID = node.data.ID;
- data.options = getOptions(data, bills.tree.selected.elf.datas).length > 0 ? '请选择' : '';
- //确定插入位置
- for(let subNode of sameDepthNodes){
- if(data.rank < subNode.data.rank){
- insertNextSiblingID = subNode.data.ID;
- break;
- }
- }
- let newNode = node.tree.insertByData(data, insertParentID, insertNextSiblingID);
- elfSheet.addRows(newNode.serialNo(), 1);
- node.tree.selected = newNode;
- elfSheet.setSelection(newNode.serialNo(), elfSheet.getSelections()[0].col, 1, 1);
- }
- OptionsCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
- OptionsCellType.prototype.createEditorElement = function (context) {
- let element = document.createElement("div");//这里创建的,会自动销毁
- return element
- };
- OptionsCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect, context) {
- if (editorContext) {
- let $editor = $(editorContext);
- $editor.css("position", "fixed");
- $editor.css("background", "white");
- $editor.css("width", cellRect.width);
- $editor.attr("gcUIElement", "gcEditingInput");
- let node = bills.tree.selected.elf.tree.items[elfSheet.getActiveRowIndex()];
- $editor.html(getHtml(node, cellRect, cellStyle));
- }
- }
- OptionsCellType.prototype.deactivateEditor = function (editorContext, context) {
- };
- OptionsCellType.prototype.setEditorValue = function (editor, value, context) {
- this.displayText = value;
- };
- OptionsCellType.prototype.getEditorValue = function (editor, context) {
- let me = this;
- let node = bills.tree.selected.elf.tree.items[elfSheet.getActiveRowIndex()];
- if(this.isEscKey !=true){
- renderSheetFunc(elfSheet, function () {
- doAfterSel.call(me, node);
- });
- }
- this.isEscKey = false;
- return this.displayText;
- };
- OptionsCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context) {
- };
- OptionsCellType.prototype.isReservedKey = function (e, context) {
- //cell type handle tab key by itself
- this.isEscKey = e.keyCode === GC.Spread.Commands.Key.esc;
- return false;
- };
- /* OptionsCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
- if(style.backColor){
- ctx.fillStyle = style.backColor;
- ctx.fillRect(x, y, w, h);
- ctx.save();
- }
- //边长
- const l = 7;
- let leftPointX = x + w - 15,
- rightPointX = leftPointX + l,
- middlePointX = (leftPointX + rightPointX)/2;
- const cos30 = Math.cos(2*Math.PI * 30 / 360);
- let hL = l * cos30;
- let beginY = y + h/2 - hL;
- ctx.beginPath();
- ctx.moveTo(leftPointX, beginY);
- ctx.lineTo(rightPointX, beginY);
- ctx.lineTo(middlePointX, beginY + hL);
- ctx.fillStyle = 'black';
- ctx.fill();
- ctx.save();
- };*/
- // override getHitInfo to allow cell type get mouse messages
- OptionsCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
- return {
- x: x,
- y: y,
- row: context.row,
- col: context.col,
- cellStyle: cellStyle,
- cellRect: cellRect,
- sheetArea: context.sheetArea
- };
- };
- return new OptionsCellType();
- }
- //初始化清单的工作内容和项目特征
- //@param {Number}billsLibId @return {void}
- function initJobAndCharacter(billsLibId){
- CommonAjax.post('/stdBillsEditor/getJobContent', {userId: userID, billsLibId: billsLibId}, function (datas) {
- stdBillsJobData = datas;
- });
- CommonAjax.post('/stdBillsEditor/getItemCharacter', {userId: userID, billsLibId: billsLibId}, function (datas) {
- stdBillsFeatureData = datas;
- });
- }
- //初始化清单展开收起状态
- //@return {void}
- function initExpandStat(){
- //读取展开收起状态
- let currentExpState = sessionStorage.getItem('stdBillsGuidanceExpState');
- if(currentExpState){
- bills.tree.setExpandedByState(bills.tree.items, currentExpState);
- }
- //非叶子节点默认收起
- else{
- bills.tree.setRootExpanded(bills.tree.roots, false);
- }
- }
- //设置tag以悬浮提示
- function setTagForHint(nodes){
- let sheet = bills.workBook.getActiveSheet();
- renderSheetFunc(sheet, function () {
- for(let node of nodes){
- sheet.setTag(node.serialNo(), 2, node.data.ruleText ? node.data.ruleText : '');
- }
- });
- }
- //初始选择清单指引库
- //@param {Number}libID @return {void}
- function libInitSel(libID){
- //获取清单
- $.bootstrapLoading.start();
- CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function(rstData){
- currentLib = rstData.guidanceLib;
- if(guideItem.workBook){
- guideItem.workBook.destroy();
- guideItem.workBook = null;
- }
- if(elfItem.workBook){
- elfItem.workBook.destroy();
- elfItem.workBook = null;
- }
- initViews();
- //获取清单库中的工作内容和项目特征
- initJobAndCharacter(rstData.guidanceLib.billsLibId);
- initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, rstData.bills);
- //清单精灵
- if(rstData.guidanceLib.type && rstData.guidanceLib.type == libType.elf){
- $('#stdBillsGuidanceTab').text('清单精灵');
- //每一个清单节点下挂载一棵清单精灵树
- for(let node of bills.tree.items){
- node.elf = {tree: null, controller: null, datas: []}; //挂载全部数据,数据不一定全成为树节点
- }
- }
- //清单指引
- else {
- $('#stdBillsGuidanceTab').text('清单指引');
- //每一棵项目指引树挂在清单节点上
- for(let node of bills.tree.items){
- node.guidance = {tree: null, controller: null};
- }
- }
- setTagForHint(bills.tree.items);
- //默认初始节点
- billsInitSel(0);
- $.bootstrapLoading.end();
- }, function () {
- $.bootstrapLoading.end();
- });
- }
- //初始化清单指引库
- //@param {Array}libDats @return {void}
- function initLibs(libDatas){
- libSel.empty();
- if(!libDatas){
- return;
- }
- let selectedLib = sessionStorage.getItem('stdBillsGuidance');
- for(let libData of libDatas){
- let opt = $('<option>').val(libData.id).text(libData.name);
- if(selectedLib && libData.id == selectedLib){
- opt.attr('selected', 'selected');
- }
- libSel.append(opt);
- }
- //初始默认选择
- libInitSel(libSel.select().val());
- }
- //初始化视图
- //@param {void} @return {void}
- function initViews(){
- //赋初始高度
- if($('#billsGuidance_bills').height() === 0 || $('#billsGuidance_items').height() === 0){
- let height = $(window).height()-$(".header").height()-$(".toolsbar").height()-$(".tools-bar-height-z").height();
- $('#billsGuidance_bills').height(height / 2);
- $('#billsGuidance_items').height(height / 2);
- }
- let modules = [bills];
- if(currentLib.type && currentLib.type === libType.elf){
- modules.push(elfItem);
- }
- else {
- modules.push(guideItem);
- }
- initWorkBooks(modules);
- }
- //获取选中的行
- //@return {Array}
- function getCheckedRows(){
- let rst = [];
- let itemSheet = guideItem.workBook.getActiveSheet();
- for(let row = 0; row < itemSheet.getRowCount(); row++){
- let rowV = itemSheet.getValue(row, 0);
- if(rowV){
- rst.push(row);
- }
- }
- return rst;
- }
- //获取清单精灵生成的定额数据
- //@return {Array}
- function getInsertElfRationData(){
- let rst = [];
- if(!bills.tree.selected){
- return [];
- }
- if(!bills.tree.selected.elf){
- return [];
- }
- let tree = bills.tree.selected.elf.tree;
- if(!tree){
- return [];
- }
- for(let node of tree.items){
- if(node.children.length === 0 && node.data.optionChecked){//定额数据只能在最底层节点中
- for(let perChecked of node.data.optionChecked){
- if(perChecked.type === itemType.ration){
- rst.push({itemQuery: {userID: userID, ID: perChecked.rationID}, rationType: rationType.ration});
- }
- }
- }
- }
- return rst;
- }
- //获取选中的定额数据
- //@param {Array}rows @return {Array}
- function getInsertRationData(rows){
- let rst = [];
- for(let row of rows){
- let node = bills.tree.selected.guidance.tree.items[row];
- if(node && node.data.type === itemType.ration){
- rst.push({itemQuery: {userID: userID, ID: node.data.rationID}, rationType: rationType.ration});
- }
- }
- return rst;
- }
- //插入定额
- //@return {void}
- function insertRations(addRationDatas){
- if(addRationDatas.length > 0){
- projectObj.project.Ration.addMultiRation(addRationDatas, function () {
- //恢复
- if(!currentLib.type || currentLib.type === libType.guidance){
- let sheet = guideItem.workBook.getActiveSheet();
- renderSheetFunc(sheet, function () {
- for(let row = 0; row < sheet.getRowCount(); row++){
- if(sheet.getValue(row, 0)){
- sheet.setValue(row, 0, false);
- }
- }
- });
- }
- refreshInsertRation();
- projectObj.setActiveCell('quantity', true);
- });
- }
- }
- //更新插入定额按钮有效性
- function refreshInsertRation(){
- if(currentLib.type && currentLib.type === libType.elf){
- if(getInsertElfRationData().length > 0){
- $('#guidanceInsertRation').removeClass('disabled');
- }
- else {
- $('#guidanceInsertRation').addClass('disabled');
- }
- }
- else {
- //勾选了定额,插入定额按钮才有效
- if(getCheckedRows().length > 0){
- $('#guidanceInsertRation').removeClass('disabled');
- }
- else {
- $('#guidanceInsertRation').addClass('disabled');
- }
- }
- }
- //展开至搜索出来点的节点
- //@param {Array}nodes @return {void}
- function expandSearchNodes(nodes){
- let that = this;
- let billsSheet = bills.workBook.getActiveSheet();
- renderSheetFunc(billsSheet, function () {
- function expParentNode(node){
- if(node.parent && !node.parent.expanded){
- node.parent.setExpanded(true);
- expParentNode(node.parent);
- }
- }
- for(let node of nodes){
- expParentNode(node);
- }
- TREE_SHEET_HELPER.refreshTreeNodeData(bills.treeSetting, billsSheet, bills.tree.roots, true);
- TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.roots, billsSheet, true);
- });
- }
- //各按钮监听事件
- //@return {void}
- function bindBtn(){
- //打开清单指引库
- $('#stdBillsGuidanceTab').click(function () {
- if(libSel.children().length === 0 && !projectReadOnly && !$(this).hasClass('disabled')){
- initLibs(projectInfoObj.projectInfo.engineeringInfo.billsGuidance_lib);
- }
- });
- //更改清单指引库
- $('#stdBillsGuidanceLibSelect').change(function () {
- //关闭搜索窗口
- $('#billsGuidanceSearchResult').hide();
- billsLibObj.clearHighLight(bills.workBook);
- libInitSel($(this).select().val());
- //记住选项
- sessionStorage.setItem('stdBillsGuidance', $(this).select().val());
- //清除展开收起状态sessionStorage
- sessionStorage.removeItem('stdBillsGuidanceExpState');
- });
- //插入定额
- $('#guidanceInsertRation').click(function () {
- let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
- insertRations(addRationDatas);
- });
- //插入清单
- $('#guidanceInsertBills').click(function () {
- //插入清单
- if(!bills.tree || !bills.tree.selected){
- return;
- }
- if(bills.tree.selected.children.length === 0){
- let insert = billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, bills.tree.selected);
- if(insert){
- //插入选中的定额
- let addRationDatas = currentLib.type && currentLib.type === libType.elf ? getInsertElfRationData() : getInsertRationData(getCheckedRows());
- insertRations(addRationDatas);
- }
- }
- });
- //搜索
- $('#stdBillsGuidanceSearch>div>button').click(function () {
- if(!bills.tree){
- return;
- }
- let billsSheet = bills.workBook.getActiveSheet();
- billsLibObj.clearHighLight(bills.workBook);
- let keyword = $('#stdBillsGuidanceSearch>input').val();
- if (!keyword || keyword === '') {
- $('#billsGuidanceSearchResult').hide();
- return;
- }
- let result = bills.tree.items.filter(function (item) {
- let codeIs = item.data.code ? item.data.code.indexOf(keyword) !== -1 : false;
- let nameIs = item.data.name ? item.data.name.indexOf(keyword) !== -1 : false;
- return codeIs || nameIs;
- });
- result.sort(function (x, y) {
- return x.serialNo() - y.serialNo();
- });
- if (result.length !== 0) {
- //展开搜索出来的节点
- expandSearchNodes(result);
- //设置记住展开
- sessionStorage.setItem('stdBillsGuidanceExpState', bills.tree.getExpState(bills.tree.items));
- let sel = billsSheet.getSelections();
- renderSheetFunc(billsSheet, function () {
- bills.controller.setTreeSelected(result[0]);
- billsSheet.setSelection(result[0].serialNo(), sel[0].col, 1, 1);
- billsInitSel(result[0].serialNo());
- for (let node of result) {
- billsSheet.getRange(node.serialNo(), -1, 1, -1).backColor('lemonChiffon');
- }
- });
- //搜索初始定位
- billsSheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
- $('#nextBillsGuidance').show();
- $('#nextBillsGuidance').unbind('click');
- $('#nextBillsGuidance').bind('click', function () {
- let cur = bills.tree.selected, resultIndex = result.indexOf(cur), sel = billsSheet.getSelections();
- if (resultIndex === result.length - 1) {
- bills.controller.setTreeSelected(result[0]);
- billsSheet.setSelection(result[0].serialNo(), sel[0].col, 1, 1);
- billsInitSel(result[0].serialNo());
- billsSheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
- } else {
- bills.controller.setTreeSelected(result[resultIndex + 1]);
- billsSheet.setSelection(result[resultIndex + 1].serialNo(), sel[0].col, 1, 1);
- billsInitSel(result[resultIndex + 1].serialNo());
- billsSheet.showRow(result[resultIndex + 1].serialNo(), GC.Spread.Sheets.VerticalPosition.bottom);
- }
- });
- } else {
- billsLibObj.clearHighLight(bills.workBook);
- $('#nextBillsGuidance').hide();
- }
- $('#billsGuidanceSearchResultCount').text('搜索结果:' + result.length);
- $('#billsGuidanceSearchResult').show();
- });
- //搜索框回车
- $('#stdBillsGuidanceSearch>input').bind('keypress', function (event) {
- if(event.keyCode === 13){
- $(this).blur();
- $('#stdBillsGuidanceSearch>div>button').click();
- }
- });
- // 关闭搜索结果
- $('#closeSearchBillsGuidance').click(function () {
- $('#billsGuidanceSearchResult').hide();
- billsLibObj.clearHighLight(bills.workBook);
- refreshWorkBook();
- });
- }
- //刷新表
- //@return {void}
- function refreshWorkBook(){
- if(bills.workBook){
- bills.workBook.refresh();
- }
- if(guideItem.workBook){
- guideItem.workBook.refresh();
- }
- if(elfItem.workBook){
- elfItem.workBook.refresh();
- }
- }
- return {initViews, bindBtn, refreshWorkBook, refreshInsertRation, bills};
- })();
- $(document).ready(function(){
- billsGuidance.bindBtn();
- });
|