|
@@ -11,6 +11,10 @@
|
|
|
const billsGuidance = (function () {
|
|
|
|
|
|
const libSel = $('#stdBillsGuidanceLibSelect');
|
|
|
+ //工作内容
|
|
|
+ let stdBillsJobData = [];
|
|
|
+ //项目特征
|
|
|
+ let stdBillsFeatureData = [];
|
|
|
const bills = {
|
|
|
dom: $('#billsGuidance_bills'),
|
|
|
workBook: null,
|
|
@@ -66,6 +70,35 @@ const billsGuidance = (function () {
|
|
|
events: {
|
|
|
SelectionChanging: function (sender, info) {
|
|
|
billsInitSel(info.newSelections[0].row);
|
|
|
+ },
|
|
|
+ CellDoubleClick: function (sender, args) {
|
|
|
+ let node = bills.tree.items[args.row];
|
|
|
+ if(!node){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(node.children.length === 0){
|
|
|
+ //插入清单
|
|
|
+ let insert = billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, node);
|
|
|
+ if(insert){
|
|
|
+ //插入选中的定额
|
|
|
+ let addRationDatas = 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();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
};
|
|
@@ -125,7 +158,7 @@ const billsGuidance = (function () {
|
|
|
},
|
|
|
headers: [
|
|
|
{name: '项目指引', dataCode: 'name', width: 300, vAlign: 'center', hAlign: 'left', formatter: '@'},
|
|
|
- {name: '选择', dataCode: 'name', width: 50, vAlign: 'center', hAlign: 'center', formatter: '@'},
|
|
|
+ {name: '选择', dataCode: 'select', width: 50, vAlign: 'center', hAlign: 'center', formatter: '@'},
|
|
|
],
|
|
|
events: {
|
|
|
EditStarting: function (sender, args) {
|
|
@@ -138,6 +171,32 @@ const billsGuidance = (function () {
|
|
|
args.sheet.endEdit(true);
|
|
|
}
|
|
|
},
|
|
|
+ CellDoubleClick: function (sender, args) {
|
|
|
+ if(!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 options = {
|
|
@@ -201,7 +260,6 @@ const billsGuidance = (function () {
|
|
|
return;
|
|
|
}
|
|
|
const Events = GC.Spread.Sheets.Events;
|
|
|
- let sheet = workBook.getActiveSheet();
|
|
|
for(let event in events){
|
|
|
workBook.bind(Events[event], events[event]);
|
|
|
}
|
|
@@ -216,6 +274,7 @@ const billsGuidance = (function () {
|
|
|
//默认初始可控制焦点在清单表中
|
|
|
module.workBook.focus();
|
|
|
sheet.options.isProtected = true;
|
|
|
+ sheet.name('stdBillsGuidance_bills');
|
|
|
}
|
|
|
if(module === guideItem){
|
|
|
sheet.options.isProtected = true;
|
|
@@ -250,6 +309,9 @@ const billsGuidance = (function () {
|
|
|
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();
|
|
|
}
|
|
|
//项目指引表焦点控制
|
|
@@ -263,8 +325,6 @@ const billsGuidance = (function () {
|
|
|
billsNode.guidance.tree.selected = node;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
//根据项目指引的类型设置单元格类型,定额类型的项目指引为复选框
|
|
|
//@param {Array}nodes @return {void}
|
|
@@ -304,11 +364,36 @@ const billsGuidance = (function () {
|
|
|
guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
|
|
|
}
|
|
|
}
|
|
|
+ //初始化清单的工作内容和项目特征
|
|
|
+ //@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);
|
|
|
+ }
|
|
|
+ }
|
|
|
//初始选择清单指引库
|
|
|
//@param {Number}libID @return {void}
|
|
|
function libInitSel(libID){
|
|
|
//获取清单
|
|
|
CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function(rstData){
|
|
|
+ //获取清单库中的工作内容和项目特征
|
|
|
+ initJobAndCharacter(rstData.guidanceLib.billsLibId);
|
|
|
initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, rstData.bills);
|
|
|
//每一棵项目指引树挂在清单节点上
|
|
|
for(let node of bills.tree.items){
|
|
@@ -322,8 +407,12 @@ const billsGuidance = (function () {
|
|
|
//@param {Array}libDats @return {void}
|
|
|
function initLibs(libDatas){
|
|
|
libSel.empty();
|
|
|
+ let selectedLib = sessionStorage.getItem('stdBillsGuidance');
|
|
|
for(let libData of libDatas){
|
|
|
- let opt = `<option value="${libData.id}">${libData.name}</option>`;
|
|
|
+ let opt = $('<option>').val(libData.id).text(libData.name);
|
|
|
+ if(selectedLib && libData.id == selectedLib){
|
|
|
+ opt.attr('selected', 'selected');
|
|
|
+ }
|
|
|
libSel.append(opt);
|
|
|
}
|
|
|
//初始默认选择
|
|
@@ -336,6 +425,67 @@ const billsGuidance = (function () {
|
|
|
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, 1);
|
|
|
+ if(rowV){
|
|
|
+ rst.push(row);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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 () {
|
|
|
+ //恢复
|
|
|
+ let sheet = guideItem.workBook.getActiveSheet();
|
|
|
+ renderSheetFunc(sheet, function () {
|
|
|
+ for(let row = 0; row < sheet.getRowCount(); row++){
|
|
|
+ if(sheet.getValue(row, 1)){
|
|
|
+ sheet.setValue(row, 1, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //展开至搜索出来点的节点
|
|
|
+ //@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(){
|
|
@@ -347,15 +497,94 @@ const billsGuidance = (function () {
|
|
|
});
|
|
|
//更改清单指引库
|
|
|
$('#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 = getInsertRationData(getCheckedRows());
|
|
|
+ insertRations(addRationDatas);
|
|
|
});
|
|
|
//插入清单
|
|
|
$('#guidanceInsertBills').click(function () {
|
|
|
+ //插入清单
|
|
|
+ if(!bills.tree.selected){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(bills.tree.selected.children.length === 0){
|
|
|
+ let insert = billsLibObj.insertBills(stdBillsJobData, stdBillsFeatureData, bills.tree.selected);
|
|
|
+ if(insert){
|
|
|
+ //插入选中的定额
|
|
|
+ let addRationDatas = getInsertRationData(getCheckedRows());
|
|
|
+ insertRations(addRationDatas);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //搜索
|
|
|
+ $('#stdBillsGuidanceSearch>span>button').click(function () {
|
|
|
+ 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();
|
|
|
+ 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');
|
|
|
+ }
|
|
|
+
|
|
|
+ $('#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());
|
|
|
+ } else {
|
|
|
+ bills.controller.setTreeSelected(result[resultIndex + 1]);
|
|
|
+ billsSheet.setSelection(result[resultIndex + 1].serialNo(), sel[0].col, 1, 1);
|
|
|
+ billsInitSel(result[resultIndex + 1].serialNo());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ billsLibObj.clearHighLight(bills.workBook);
|
|
|
+ $('#nextBillsGuidance').hide();
|
|
|
+ }
|
|
|
+ $('#billsGuidanceSearchResultCount').text('搜索结果:' + result.length);
|
|
|
+ $('#billsGuidanceSearchResult').show();
|
|
|
+ });
|
|
|
+ // 关闭搜索结果
|
|
|
+ $('#closeSearchBillsGuidance').click(function () {
|
|
|
+ $('#billsGuidanceSearchResult').hide();
|
|
|
+ billsLibObj.clearHighLight(bills.workBook);
|
|
|
+ refreshWorkBook();
|
|
|
});
|
|
|
}
|
|
|
//刷新表
|
|
@@ -369,7 +598,7 @@ const billsGuidance = (function () {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return {initViews, bindBtn, refreshWorkBook};
|
|
|
+ return {initViews, bindBtn, refreshWorkBook, bills};
|
|
|
})();
|
|
|
|
|
|
$(document).ready(function(){
|