|
@@ -292,7 +292,7 @@ const billsGuidance = (function () {
|
|
|
data: {
|
|
|
field: "name",
|
|
|
vAlign: 1,
|
|
|
- hAlign: 1,
|
|
|
+ hAlign: 0,
|
|
|
font: "Arial"
|
|
|
}
|
|
|
},
|
|
@@ -544,7 +544,6 @@ const billsGuidance = (function () {
|
|
|
return;
|
|
|
}
|
|
|
bills.tree.selected = node;
|
|
|
- refreshInsertRation();
|
|
|
if(!node.elf.tree){
|
|
|
CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: libSel.val(), billsID: node.getID()}, function (rstData) {
|
|
|
//定额数据删除编号信息
|
|
@@ -562,26 +561,54 @@ const billsGuidance = (function () {
|
|
|
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 ? '请选择' : '';
|
|
|
+ fData.options = options.length > 0 ? options[0].name : '';
|
|
|
+ //下挂的选项
|
|
|
+ fData.optionsData = options && options.length > 0 ? _.cloneDeep(options) : [];
|
|
|
+ fData.optionChecked = options && options.length > 0 ? [_.cloneDeep(options[0])] : [];
|
|
|
}
|
|
|
- initTree(node.elf, elfSheet, elfItem.treeSetting, firstLevelDatas);
|
|
|
+ renderSheetFunc(elfSheet, function () {
|
|
|
+ initTree(node.elf, elfSheet, elfItem.treeSetting, firstLevelDatas);
|
|
|
+ //初始选择选项
|
|
|
+ let initOptsOpr = [];
|
|
|
+ for(let elfNode of node.elf.tree.items){
|
|
|
+ if(elfNode.data.optionsData.length > 0){
|
|
|
+ initOptsOpr.push({node: elfNode, data: elfNode.data.optionsData[0]});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(let opr of initOptsOpr){
|
|
|
+ insertNodeByData(opr.node, opr.data);
|
|
|
+ }
|
|
|
+ TREE_SHEET_HELPER.refreshTreeNodeData(elfItem.treeSetting, elfSheet, node.elf.tree.items, false);
|
|
|
+ setOptionsCellType(node.elf.tree.items);
|
|
|
+ //项目指引初始焦点
|
|
|
+ elfItemInitSel(elfSheet.getActiveRowIndex() ? elfSheet.getActiveRowIndex() : 0);
|
|
|
+ refreshInsertRation();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ renderSheetFunc(elfSheet, function () {
|
|
|
+ node.elf.controller.showTreeData();
|
|
|
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);
|
|
|
+ refreshInsertRation();
|
|
|
});
|
|
|
}
|
|
|
- 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);
|
|
|
+ }
|
|
|
+ //获取选项的深度
|
|
|
+ //@param {Object}opt {Array}options(当前清单所有选项) @return {Array}
|
|
|
+ function getOptionDepth(opt, options) {
|
|
|
+ let parent = _.find(options, {ID: opt.ParentID});
|
|
|
+ let depth = 0;
|
|
|
+ while (parent){
|
|
|
+ depth++;
|
|
|
+ parent = _.find(options, {ID: parent.ParentID});
|
|
|
}
|
|
|
+ return depth;
|
|
|
}
|
|
|
//获取施工工序含有的选项(即当前施工工序的子项),获取的顺序按照NextSiblingID排序
|
|
|
//@param {Object}process {Array}datas @return {Array}
|
|
@@ -630,7 +657,7 @@ const billsGuidance = (function () {
|
|
|
function setOptionsCellType(nodes) {
|
|
|
let elfSheet = elfItem.workBook.getActiveSheet();
|
|
|
for(let node of nodes){
|
|
|
- if(node.data.options !== ''){
|
|
|
+ if(node.data.optionsData && node.data.optionsData.length > 0){
|
|
|
elfSheet.getCell(node.serialNo(), 1).locked(false).cellType(getOptionsCellType());
|
|
|
}
|
|
|
else {
|
|
@@ -638,6 +665,61 @@ const billsGuidance = (function () {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //递归插入节点:原始项目指引数据奇数层为需要插入的节点,偶数层为下拉选项
|
|
|
+ //@param {Object}node(当前操作的节点) {Object}data(选项) @return {void}
|
|
|
+ function insertNodeByData(node, data) {
|
|
|
+ let elfSheet = elfItem.workBook.getActiveSheet();
|
|
|
+ let sameDepthNodes = node.children;
|
|
|
+ let insertNextSiblingID = -1,
|
|
|
+ insertParentID = node.data.ID;
|
|
|
+ //当前操作节点的选项
|
|
|
+ let nodeOpts = getOptions(node.data, bills.tree.selected.elf.datas);
|
|
|
+ let subOpts = getOptions(data, bills.tree.selected.elf.datas);
|
|
|
+ let dataDepth = getOptionDepth(data, bills.tree.selected.elf.datas);
|
|
|
+ if(subOpts.length >0 && subOpts[0].type !== itemType.ration){
|
|
|
+ if((dataDepth + 1) % 2 === 0){
|
|
|
+ //排序后的数据
|
|
|
+ let dataWithRank = _.find(nodeOpts, {ID: data.ID});
|
|
|
+ //确定插入位置
|
|
|
+ for(let subOpt of subOpts){
|
|
|
+ for(let subNode of sameDepthNodes){
|
|
|
+ //同层节点原本选项数据
|
|
|
+ let subNodeOptData = _.find(bills.tree.selected.elf.datas, {ID: subNode.data.ID});
|
|
|
+ //同层节点原本父选项数据
|
|
|
+ let subNodeOptParent = _.find(bills.tree.selected.elf.datas, {ID: subNodeOptData.ParentID});
|
|
|
+ let subNodeOptParentWithRank = _.find(nodeOpts, {ID: subNodeOptParent.ID});
|
|
|
+ //父项顺序决定插入位置
|
|
|
+ if(dataWithRank.rank < subNodeOptParentWithRank.rank){
|
|
|
+ insertNextSiblingID = subNode.data.ID;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //父项顺序相同,根据子项顺序决定插入位置
|
|
|
+ else if(dataWithRank.rank = subNodeOptParentWithRank.rank){
|
|
|
+ if(subOpt.rank < subNode.data.rank){
|
|
|
+ insertNextSiblingID = subNode.data.ID;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let sub2Opts = getOptions(subOpt, bills.tree.selected.elf.datas);
|
|
|
+ subOpt.options = sub2Opts.length > 0 ? sub2Opts[0].name : '';
|
|
|
+ let cloneOpt = _.cloneDeep(subOpt);//不改变原本的数据,比如ParentID
|
|
|
+ cloneOpt.optionChecked = sub2Opts.length > 0 ? [_.cloneDeep(sub2Opts[0])] : [];
|
|
|
+ cloneOpt.optionsData = sub2Opts.length > 0 ? _.cloneDeep(sub2Opts) : [];
|
|
|
+ let newNode = node.tree.insertByData(cloneOpt, insertParentID, insertNextSiblingID);
|
|
|
+ elfSheet.addRows(newNode.serialNo(), 1);
|
|
|
+ node.tree.selected = newNode;
|
|
|
+ elfSheet.setSelection(newNode.serialNo(), elfSheet.getSelections()[0].col, 1, 1);
|
|
|
+ if(sub2Opts.length > 0 && sub2Opts[0].type !== itemType.ration){
|
|
|
+ insertNodeByData(newNode, sub2Opts[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ insertNodeByData(node, subOpts[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
//获取选项下拉多选单元格
|
|
|
//@param {void} @return {void}
|
|
|
function getOptionsCellType() {
|
|
@@ -654,8 +736,8 @@ const billsGuidance = (function () {
|
|
|
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;">`);
|
|
|
+ //let optionsTitle = node.data.options.split(';').join('\n');
|
|
|
+ htmlArr.push(`<div 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"
|
|
@@ -675,70 +757,56 @@ const billsGuidance = (function () {
|
|
|
checkedNameArr.push(opt.name);
|
|
|
optionChecked.push(opt);
|
|
|
}
|
|
|
- this.displayText = checkedNameArr.length > 0 ? checkedNameArr.join(';') : '请选择';
|
|
|
+ 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);
|
|
|
- }
|
|
|
+ let deleteNodes = getDeleteNodes(node, optionChecked);
|
|
|
+ for(let dNode of deleteNodes){
|
|
|
+ elfSheet.deleteRows(dNode.serialNo(), dNode.posterityCount() + 1);
|
|
|
+ node.tree.delete(dNode);
|
|
|
}
|
|
|
//插入节点
|
|
|
for(let perCheked of optionChecked){
|
|
|
let exist = false;
|
|
|
+ let subOpts = getOptions(perCheked, bills.tree.selected.elf.datas);
|
|
|
for(let subNode of node.children){
|
|
|
- if(subNode.data.ID === perCheked.ID){
|
|
|
- exist = true;
|
|
|
+ for(let subOpt of subOpts){
|
|
|
+ if(subNode.data.ID === subOpt.ID){
|
|
|
+ exist = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
//不重复且不为定额时插入
|
|
|
if(!exist && perCheked.type !== itemType.ration){
|
|
|
- insertNodeByData(node, perCheked);
|
|
|
+ insertNodeByData(node, perCheked);//这里递归,默认第一个
|
|
|
}
|
|
|
}
|
|
|
TREE_SHEET_HELPER.refreshTreeNodeData(elfItem.treeSetting, elfSheet, node.tree.items, false);
|
|
|
setOptionsCellType(node.tree.items);
|
|
|
refreshInsertRation();
|
|
|
}
|
|
|
- //获取删除节点信息
|
|
|
- function getDeleteInfo(node, optionChecked) {
|
|
|
+ //获取删除节点
|
|
|
+ function getDeleteNodes(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;
|
|
|
+ let subOpts = getOptions(perChecked, bills.tree.selected.elf.datas);
|
|
|
+ for(let subOpt of subOpts){
|
|
|
+ if(subNode.data.ID === subOpt.ID){
|
|
|
+ exist = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if(!exist){
|
|
|
- let deleteRow = subNode.serialNo(),
|
|
|
- deleteCount = subNode.posterityCount() + 1;
|
|
|
- rst.push({node: subNode, deleteRow: deleteRow, deleteCount: deleteCount});
|
|
|
+ rst.push(subNode);
|
|
|
}
|
|
|
}
|
|
|
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) {
|
|
@@ -951,16 +1019,24 @@ const billsGuidance = (function () {
|
|
|
}
|
|
|
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});
|
|
|
+ for(let perChecked of node.data.optionChecked){
|
|
|
+ //选项直接是定额
|
|
|
+ if(perChecked.type === itemType.ration){
|
|
|
+ rst.push({itemQuery: {userID: userID, ID: perChecked.rationID}, rationType: rationType.ration});
|
|
|
+ }
|
|
|
+ //选项下子选项是定额
|
|
|
+ else {
|
|
|
+ let rationOpts = getOptions(perChecked, bills.tree.selected.elf.datas);
|
|
|
+ for(let ration of rationOpts){
|
|
|
+ if(ration.type === itemType.ration){
|
|
|
+ rst.push({itemQuery: {userID: userID, ID: ration.rationID}, rationType: rationType.ration});
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|