| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083 |
- var headerCount=2;//头部行高
- var nextDataRowIndex;//下条数据所在行
- var bgColor1 = 'rgb(210,218,228)';
- var bgColor2 = 'rgb(255,242,203)';
- var bgColor3 = 'rgb(194,214,155)';//绿的
- $(function(){
- spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 1 });
- initSpread();
- });
- function initSpread(){
- spread.suspendPaint();
- if(dbJson){//数据库
- // spread.fromJSON(JSON.parse(dbJson));
- spread.fromJSON(dbJson);
- }else {
- nextDataRowIndex = headerCount;
- initData();
- }
- var sheet = spread.getActiveSheet();
- var setting = sheet.tag();
- if(setting){
- if(setting.nextDataRowIndex){
- nextDataRowIndex = setting.nextDataRowIndex;
- }
- }
- if(!nextDataRowIndex){
- nextDataRowIndex = headerCount;
- }
- spread.options.newTabVisible = false;//取消新增sheet按钮
- spread.options.allowExtendPasteRange =true;//扩展粘贴区域
- bindEvent(spread);
- addContextMenu(spread);
- addDataCellMenu(spread)
- setMenuView(spread);
- // sheet.frozenRowCount(headRowCount);//冻结头部
- // sheet.options.frozenlineColor = 'red';//冻结线颜色
- setDefaultLock(sheet);
- // sheet.selectionPolicy(GC.Spread.Sheets.SelectionPolicy.single);//不让多选
- spread.bind(GC.Spread.Sheets.Events.RowChanging, function (e, info) {
- //info.propertyName="deleteRows" //删除行
- if(info.propertyName="deleteRows"){
- var deleteRow = info.row;
- var deleteCount = info.count;
- var sheetTag = sheet.tag();
- var ids = sheetTag.ids;
- for(var i=deleteRow;i<deleteRow+deleteCount;i++) {
- var rowTag = sheet.getTag(i,-1);
- if(!rowTag) continue;
- for(var j=0;j<ids.length;j++){
- if(ids[j]==rowTag.id){
- if(nextDataRowIndex>headerCount) nextDataRowIndex--;
- // delete ids[j];
- ids.splice(j,1);
- }
- }
- }
- addSheetTagValue(sheet,{ids:ids,nextDataRowIndex:nextDataRowIndex});
- }
- });
- sheet.frozenRowCount(2);
- sheet.frozenColumnCount(5);
- spread.resumePaint();
- }
- function initData() {
- var jsonHeader ;
- if(actualStaKind!='main'){
- jsonHeader = actual_sta_branch;
- }else {
- jsonHeader =actual_sta_main;
- }
- spread.fromJSON(jsonHeader);
- var sheet = spread.getActiveSheet();
- if(actualStaKind=='main'){
- initMainHeadData(sheet);
- }else {
- var budgetTitle ;
- if(actualStaKind=='labor'){
- budgetTitle='人工成本年度预算数';
- }else if(actualStaKind=='pu'){
- budgetTitle='采购成本年度预算数';
- }else if(actualStaKind=='maintain'){
- budgetTitle='维保费用年度预算数';
- }else if(actualStaKind=='other'){
- budgetTitle='其他费用年度预算数';
- }else if(actualStaKind=='manage'){
- budgetTitle='管理费用年度预算数';
- }
- initBranchHeadData(sheet);
- if(budgetTitle){
- sheet.setValue(0,2,budgetTitle);
- }
- }
- // actual_sta_branch
- for(var i=0;i<entityList.length;i++){
- var oneEntity=entityList[i];
- addOne(oneEntity);
- }
- sheet.autoFitColumn(1);
- }
- function addOne(one){
- var sheet = spread.getActiveSheet();
- var sheetTag = sheet.tag();
- if(!sheetTag) sheetTag={};
- if(!sheetTag.ids) sheetTag.ids=[];
- var id = one.id;
- if($.inArray(id, sheetTag.ids)!=-1){
- return;
- }
- sheetTag.ids.push(id);
- addSheetTagValue(sheet,{ids:sheetTag.ids});
- var row = nextDataRowIndex;
- sheet.addRows(row+1,1);
- var rowSetting={};//行变量
- var col=0;
- var bindEntityCol=0;
- if(actualStaKind !='main') {
- // 序号
- sheet.getCell(row,col).formula("row()-"+headerCount).backColor(bgColor1);
- col++;
- // sheet.setValue(row,colIndex,one.name);
- //项目名称
- sheet.getCell(row,col).backColor(bgColor1).value(one.name).hAlign(GC.Spread.Sheets.HorizontalAlign.left);
- bindEntityCol= col;
- col++;
- //度预算数
- sheet.getCell(row,col).backColor(bgColor1);
- var yearAmountCellStr = getCellStr(sheet,row,col);
- col++;
- var entityYearAmountIndex=col++;
- var entityYearAmountPerIndex=col++;
- var yearAmountCellArray=[];
- for(var i=0;i<12;i++){
- //发生额
- var monthAmountCellStr = getCellStr(sheet,row,col);
- yearAmountCellArray.push(monthAmountCellStr);
- sheet.getCell(row,col).backColor(bgColor2);
- col++;
- //占比
- var divFoumula = monthAmountCellStr+"/"+yearAmountCellStr;
- var formula="=IF(ISERROR("+divFoumula+"),0,"+divFoumula+")";
- sheet.getCell(row,col).formula(formula).backColor(bgColor2).formatter("0.00%");
- col++;
- }
- sheet.getCell(row,entityYearAmountIndex).formula(yearAmountCellArray.join('+')).backColor(bgColor2);
- var entityYearAmountCellStr = getCellStr(sheet,row,entityYearAmountIndex);
- var divFoumula = entityYearAmountCellStr+"/"+yearAmountCellStr;
- var formula="=IF(ISERROR("+divFoumula+"),0,"+divFoumula+")";
- sheet.getCell(row,entityYearAmountPerIndex).formula(formula).backColor(bgColor2).formatter("0.00%");
- }else {
- // 序号
- sheet.getCell(row,col).formula("row()-"+headerCount).backColor(bgColor1);
- col++;
- // sheet.setValue(row,colIndex,one.name);
- //项目名称
- sheet.getCell(row,col).backColor(bgColor1).value(one.name).hAlign(GC.Spread.Sheets.HorizontalAlign.left);
- bindEntityCol=col;
- col++;
- //度预算数
- sheet.getCell(row,col).backColor(bgColor1);
- var yearAmountCellStr = getCellStr(sheet,row,col);
- col++;
- var entityYearAmountIndex=col++;
- var entityYearAmountPerIndex=col++;
- var yearAmountCellArray=[];
- for(var i=0;i<5;i++){
- //发生额
- var monthAmountCellStr = getCellStr(sheet,row,col);
- yearAmountCellArray.push(monthAmountCellStr);
- sheet.getCell(row,col).backColor(bgColor2);
- col++;
- //占比
- var divFoumula = monthAmountCellStr+"/"+yearAmountCellStr;
- var formula="=IF(ISERROR("+divFoumula+"),0,"+divFoumula+")";
- sheet.getCell(row,col).formula(formula).backColor(bgColor2).formatter("0.00%");
- col++;
- }
- sheet.getCell(row,entityYearAmountIndex).formula(yearAmountCellArray.join('+')).backColor(bgColor3);
- var entityYearAmountCellStr = getCellStr(sheet,row,entityYearAmountIndex);
- var divFoumula = entityYearAmountCellStr+"/"+yearAmountCellStr;
- var formula="=IF(ISERROR("+divFoumula+"),0,"+divFoumula+")";
- sheet.getCell(row,entityYearAmountPerIndex).formula(formula).backColor(bgColor3).formatter("0.00%");
- }
- //
- setBorder(sheet,row);
- nextDataRowIndex++;
- addSheetTagValue(sheet,{nextDataRowIndex:nextDataRowIndex});
- rowSetting.id=id;
- rowSetting.entityId=id;
- addCellTagValue(sheet,row,-1,rowSetting);
- sheet.setSelection(row, bindEntityCol, 1, 1);
- setEntityValue(sheet,'row',{entityId:one.id,entityName:one.name});
- sheet.clearSelection();
- }
- function initBranchHeadData(sheet){
- //边框
- var row =1;
- setBorder(sheet,row);
- var col=2;
- var cellStr = getCellStr(sheet,row,col);
- var formula = sheet.getFormula(row,col);
- sheet.getCell(row,col).formula("round("+formula+",2)");
- var yearBudgetCell="C2";
- for(var i = 0;i<13;i++){
- col++;
- var cellStr = getCellStr(sheet,row,col);
- formula = sheet.getFormula(row,col);
- sheet.getCell(row,col).formula("round("+formula+",2)");
- col++;
- var divFoumula = cellStr+"/"+yearBudgetCell;
- var formula="=IF(ISERROR("+divFoumula+"),0,"+divFoumula+")";
- sheet.getCell(row,col).formula(formula).formatter("0.00%");
- }
- }
- function initMainHeadData(sheet){
- var row =1;
- setBorder(sheet,row);
- var col=2;
- var cellStr = getCellStr(sheet,row,col);
- var formula = sheet.getFormula(row,col);
- sheet.getCell(row,col).formula("round("+formula+",2)");
- var yearBudgetCell="C2";
- for(var i = 0;i<6;i++){
- col++;
- var cellStr = getCellStr(sheet,row,col);
- formula = sheet.getFormula(row,col);
- sheet.getCell(row,col).formula("round("+formula+",2)");
- col++;
- var divFoumula = cellStr+"/"+yearBudgetCell;
- var formula="=IF(ISERROR("+divFoumula+"),0,"+divFoumula+")";
- sheet.getCell(row,col).formula(formula).formatter("0.00%");
- }
- }
- function setBorder(sheet,row){
- var lineStyle = GC.Spread.Sheets.LineStyle.thin;
- var lineBorder = new GC.Spread.Sheets.LineBorder('black', lineStyle);
- var sheetArea = GC.Spread.Sheets.SheetArea.viewport;
- var columnCount = sheet.getColumnCount();
- for(var col=0;col<columnCount;col++) {
- sheet.getRange(row,col).setBorder(lineBorder, { left: true, right: true,top:true,bottom:true}, sheetArea);
- }
- }
- function bindEvent(spread){
- bindCheckNum(spread);
- spread.bind(GC.Spread.Sheets.Events.EnterCell, function (event, data) {//点击cell事件
- var row = data.row;
- var col = data.col;
- var sheet = data.sheet;
- var cellTag = sheet.getTag(row,col);
- disableBindButton(true);
- if(readOnly=='false') {
- $('#rowInfo').show();
- $('#colInfo').show();
- $('#info3').show();
- $('#info2').hide();
- if(cellTag) {
- var bindDirection=cellTag.bindDirection;
- if(bindDirection){//表头
- if(bindDirection=='row'){
- $('#rowTimeInput').val(cellTag.periodDetailName);
- $('#rowEntityInput').val(cellTag.entityName);
- if(cellTag.measureName) {
- $('#rowGoalsInput').val(cellTag.customCode + " " + cellTag.measureName);
- }
- $('input[name="includeTaxRow"][value=' + cellTag.includeTax + ']').attr('checked', 'checked');
- $('input[name="expectRow"][value=' + cellTag.expect + ']').attr('checked', 'checked');
- }else if(bindDirection=='col'){
- $('#colTimeInput').val(cellTag.periodDetailName);
- $('#colEntityInput').val(cellTag.entityName);
- if(cellTag.measureName){
- $('#colGoalsInput').val(cellTag.customCode+" "+cellTag.measureName);
- }
- $('input[name="includeTaxCol"][value=' + cellTag.includeTax + ']').attr('checked', 'checked');
- $('input[name="expectCol"][value=' + cellTag.expect + ']').attr('checked', 'checked');
- }
- }else {//非表头
- showCellBindInfo(sheet,row,col);
- }
- }
- }else if(readOnly=='true'){
- showCellBindInfo(sheet,row,col);
- }
- //单元格属性
- if(cellTag){
- var datatype =cellTag.datatype;
- var datatypeValue= measureDataTypeList[datatype];
- if(!datatypeValue) datatypeValue='';
- $('#goalsDataType').html(datatypeValue);
- if(cellTag.readOnly==1){
- $('#readOnly').html('是');
- }else {
- $('#readOnly').html('否');
- }
- var showFuntionTxt = $('#showFuntionTxt');
- if(cellTag.functionId){
- showFuntionTxt.show();
- showFuntionTxt.find('span').html(cellTag.functionTxt);
- }else{
- showFuntionTxt.hide();
- }
- var controlFlagNameDiv = $('#controlFlagName');
- if(cellTag.controlFlagName){
- controlFlagNameDiv.show();
- controlFlagNameDiv.find('span').html(cellTag.controlFlagName);
- }else {
- controlFlagNameDiv.hide();
- }
- }else {
- $('#readOnly').html('');
- $('#showFuntionTxt').hide();
- }
- // sheet.startEdit(false); //单击修改
- });
- /* spread.bind(GC.Spread.Sheets.Events.ButtonClicked, function (e, args) {//点击按钮事件
- var sheet = args.sheet, row = args.row, col = args.col;
- var cellType = sheet.getCellType(row, col);
- });*/
- spread.bind(GC.Spread.Sheets.Events.CellChanged, function (e, info) {
- // console.log(info)
- if(info.sheetArea === GC.Spread.Sheets.SheetArea.viewport){
- var sheet =info.sheet;
- var row = info.row;
- var col = info.col;
- if(info.propertyName=='value'){//值变化
- }
- if(info.propertyName=='formula'){//公式
- /*if(info.newValue==null){
- sheet.getCell(row,col).backColor('white');
- }else{
- sheet.getCell(row,col).backColor('yellow');
- }*/
- }
- }
- });
- // alert("Cell index (" + info.row + "," + info.col + ")");
- }
- function setDefaultLock(sheet){
- var option = {
- allowSelectLockedCells:true,
- allowSelectUnlockedCells:true,
- allowFilter: true,
- allowSort: false,
- allowResizeRows: true,
- allowResizeColumns: true,
- allowEditObjects: false,
- allowDragInsertRows: false,
- allowDragInsertColumns: false,
- allowInsertRows: true,
- allowInsertColumns: true,
- allowDeleteRows: true,
- allowDeleteColumns: true
- };
- sheet.options.protectionOptions = option;
- sheet.options.isProtected = true;
- var defaultStyle = sheet.getDefaultStyle() //默认的样式,
- defaultStyle.locked=false;
- defaultStyle.vAlign = GC.Spread.Sheets.VerticalAlign.center;
- defaultStyle.hAlign = GC.Spread.Sheets.HorizontalAlign.center;
- sheet.setDefaultStyle(defaultStyle);
- }
- function addContextMenu(){
- for(var i=0;i< spread.contextMenu.menuData.length;i++){
- var menu = spread.contextMenu.menuData[i];
- var menuName=menu.name;
- if(menuName=='gc.spread.filter' || menuName=='gc.spread.sort' ){//去掉过滤、排序
- delete spread.contextMenu.menuData[i];
- }
- }
- // command: showLoginDialog,
- }
- //固定后 右键菜单
- function addDataCellMenu(spread){
- var sheet=spread.getActiveSheet();
- var readOnly ={text: '只读',name: 'readOnly',workArea: 'viewport',dataCellMenu:1};
- readOnly.subMenu= [{text: '是',name: 'readOnly_yes',workArea: 'viewport',command:setReadonly}
- ,{text: '否',name: 'readOnly_no',workArea: 'viewport',command:setReadonly}]
- spread.contextMenu.menuData.push(readOnly);
- var clearNotSelectMenu ={text: '清空其他区域',name: 'clearNotSelect',workArea: 'viewport',command:clearNotSelect};
- spread.contextMenu.menuData.push(clearNotSelectMenu);
- addDimFunctionMenu(spread);
- addDimFunctionCostbreakdownMenu(spread);
- var dimMatchMenu ={text: '维度匹配',name: 'dimLike',workArea: 'viewport',command:dimMatch};
- dimMatchMenu.subMenu= [{text: '匹配行维度',name: 'dimLikeRow',workArea: 'viewport',command:dimMatchRow}
- ,{text: '匹配列维度',name: 'dimLikeCol',workArea: 'viewport',command:dimMatchCol}]
- spread.contextMenu.menuData.push(dimMatchMenu);
- }
- function setMenuView(spread){
- function CustomMenuView() {
- }
- CustomMenuView.prototype = new GC.Spread.Sheets.ContextMenu.MenuView();
- CustomMenuView.prototype.createMenuItemElement = function (menuItemData) {
- var self = this;
- if (menuItemData.name === "bind") {
- /* var containers = GC.Spread.Sheets.ContextMenu.MenuView.prototype.createMenuItemElement.call(self, menuItemData);
- var supMenuItemContainer = containers[0];
- while (supMenuItemContainer.firstChild) {
- supMenuItemContainer.removeChild(supMenuItemContainer.firstChild);
- }
- var colorPicker = createColorpicker();
- supMenuItemContainer.appendChild(colorPicker);
- return supMenuItemContainer;*/
- } else {
- var menuItemView = GC.Spread.Sheets.ContextMenu.MenuView.prototype.createMenuItemElement.call(self, menuItemData);
- return menuItemView;
- }
- };
- CustomMenuView.prototype.getCommandOptions = function (menuItemData, host, event) {
- var option={};
- if (menuItemData) {
- var name =menuItemData.name;
- if(name && name.indexOf('timeRowMenu')==0) {
- var text = menuItemData.text;
- for(var i=0;i<periodDetailList.length;i++){
- var detail = periodDetailList[i];
- if(detail.name==text){
- option.id=detail.id;
- option.name=detail.name;
- break;
- }
- }
- }
- if(name && name=='controlFlag1') {
- option.controlFlag=1;
- }
- if(name && name=='readOnly_yes') {
- option.readOnly=1;
- }else if(name && name=='readOnly_no'){
- option.readOnly=0;
- }
- /*if(name && name.indexOf('goalsDataType')==0){
- var code = name.substr('goalsDataType_'.length);
- for(var i=0;i<goalsDataTypeList.length;i++){
- var dataType = goalsDataTypeList[i];
- if(dataType.code==code){
- option.goalsDataType=code;
- option.goalsDataTypeName=dataType.name;
- break;
- }
- }
- }*/
- }
- // console.log(option);
- return option;
- };
- spread.contextMenu.menuView = new CustomMenuView();
- }
- //添加常用style
- function addNameStyle(sheet){
- var lockStyle = new GC.Spread.Sheets.Style();
- lockStyle.name='lock';
- lockStyle.locked = true;
- sheet.addNamedStyle(lockStyle);
- var unLockStyle = new GC.Spread.Sheets.Style();
- unLockStyle.name='unLock';
- unLockStyle.locked = false;
- sheet.addNamedStyle(unLockStyle);
- }
- function save(afterSaveFunction){
- var sheet = spread.getActiveSheet();
- var tag = sheet.tag();
- var hasFix = false;
- if(tag) {
- if(tag.fix==true){
- hasFix=true;
- }
- }
- if(!hasFix){
- _alert('请先生成数据单元格');
- return;
- }
- _commonSave({type:'normal'},afterSaveFunction);
- }
- function SheetSetting() {
- this.bindTime=false;
- this.bindIncludeTax=false;
- this.bindGoals=false;
- }
- SheetSetting.prototype.toJSON = function () {
- var settings ={};
- var keys =Object.keys(this);
- for(var i=0;i<keys.length;i++){
- var key =keys[i];
- settings[key]=this[key];
- }
- return settings;
- };
- SheetSetting.prototype.fromJSON = function (settings) {
- };
- function CellSetting() {
- }
- CellSetting.prototype.toJSON = function () {
- var settings ={};
- var keys =Object.keys(this);
- for(var i=0;i<keys.length;i++){
- var key =keys[i];
- settings[key]=this[key];
- }
- return settings;
- };
- CellSetting.prototype.fromJSON = function (settings) {
- console.log('fromjson');
- };
- function RowSetting(measureId,measureName) {
- this.measureId = measureId;
- this.measureName= measureName;
- }
- RowSetting.prototype.toJSON = function () {
- var settings ={};
- var keys =Object.keys(this);
- for(var i=0;i<keys.length;i++){
- var key =keys[i];
- settings[key]=this[key];
- }
- return settings;
- };
- RowSetting.prototype.fromJSON = function (settings) {
- };
- function ColSetting() {}
- ColSetting.prototype.toJSON = function () {
- var settings ={};
- var keys =Object.keys(this);
- for(var i=0;i<keys.length;i++){
- var key =keys[i];
- settings[key]=this[key];
- }
- return settings;
- };
- ColSetting.prototype.fromJSON = function (settings) {
- console.log('fromjson');
- };
- function _openDialog(url,title,okCallback,width,height){
- if(!width){
- width='500px';
- }
- if(!height){
- height='350px';
- }
- if(width=="100%"){
- width = window.top.document.body.offsetWidth;
- }
- if(height=="100%") {
- height =window.top.document.body.offsetHeight-100;
- }
- var _selectDialog= $.dialog({content:'url:'+url
- , zIndex: getzIndex()
- , title:title , lock: true, width:width, height: height, opacity: 0.4, button: [
- {name: '确定', callback:function () {
- var iframe = _selectDialog.iframe.contentWindow;
- if(okCallback){
- var b = okCallback(iframe);
- return b;
- }
- }
- , focus: true},
- {name: '取消', callback: function (){}}
- ]}).zindex();
- return _selectDialog;
- }
- function setIncludeTaxRow() {
- setIncludeTax('row');
- }
- function setIncludeTaxCol() {
- setIncludeTax('col');
- }
- function setIncludeTax(type){
- var sheet = spread.getActiveSheet();
- var itemName='';
- disableBindButton();
- if(type=='row'){
- itemName="includeTaxRow"
- }else {
- itemName="includeTaxCol"
- }
- $('input[name="'+itemName+'"]').removeAttr('disabled');
- var include = $('input[name="'+itemName+'"]:checked').val();
- beforeBindDim(sheet,type);
- setSelectionTagValue(sheet,'cell',{includeTax:include});
- setSelectionTagValue(sheet,'cell',{bindDirection:type});
- setHeader(sheet,type,{includeTax:include});
- }
- function setTimeRow(){
- setTime('row');
- }
- function setTimeCol(){
- setTime('col');
- }
- function setTime(type){
- var sheet = spread.getActiveSheet();
- var url ='budgetPeriodDetailController.do?select&periodYear='+periodYear;
- _select(url, '选择时间维度', function (selectedRows) {
- var one = selectedRows[0];
- var id = one.id;
- var name = one.name;
- var obj = {periodDetailId:id,periodDetailName:name};
- setTimeValue(sheet,type,obj);
- }, '800px', '600px');
- }
- function setTimeValue(sheet,type,valueObj){
- var name = valueObj.periodDetailName;
- disableBindButton();
- if(type=='row'){
- $('#rowTimeInput').val(name);
- $('#rowTimeBind').show();
- }else {
- $('#colTimeInput').val(name);
- $('#colTimeBind').show();
- }
- beforeBindDim(sheet,type);
- setSelectionTagValue(sheet,'cell',valueObj);
- setSelectionTagValue(sheet,'cell',{bindDirection:type});
- setHeader(sheet,type,valueObj);
- }
- function setMeasureRow() {
- setMeasure('row');
- }
- function setMeasureCol() {
- setMeasure('col');
- }
- function setMeasure(type){
- var sheet = spread.getActiveSheet();
- var url = 'budgetMeasureController.do?select';
- _openDialog(url,'选择预算指标',function(iframe){
- var selectedRows = iframe.getSelectedRow();
- if(selectedRows.length==0){
- iframe.tip('请选择预算指标');
- return false;
- }
- var one = selectedRows[0];
- var code = one.code;
- var id = one.id;
- var name = one.name;
- var o={measureId:id,measureName:name};
- o.datatype=one.datatype;
- o.fractionNum=one.fractionNum;
- o.currencySymbol=one.currencySymbol;
- o.showType=one.showType;
- o.thousandth=one.thousandth;
- o.controlFlag=one.controlFlag;
- o.customCode=one.customCode;
- setMeasureValue(sheet,type,o);
- },'800px','600px');
- }
- function setMeasureValue(sheet,type,valueObj){
- var name = valueObj.customCode+" "+valueObj.measureName;
- disableBindButton();
- if(type=='row'){
- $('#rowGoalsInput').val(name);
- $('#rowGoalsBind').show();
- }else {
- $('#colGoalsInput').val(name);
- $('#colGoalsBind').show();
- }
- beforeBindDim(sheet,type);
- setSelectionTagValue(sheet,'cell',valueObj);
- setSelectionTagValue(sheet,'cell',{bindDirection:type});
- setHeader(sheet,type,valueObj);
- }
- //生成数据单元格
- function fix() {
- var sheet = spread.getActiveSheet();
- var selections = sheet.getSelections();
- var changeCell =0;
- for(var i=0;i<selections.length;i++){
- var select = selections[i];
- var row = select.row;
- var col = select.col;
- var rowCount = select.rowCount;
- var colCount = select.colCount;
- for(var r=row;r<row+rowCount;r++){
- for(var c=col;c<col+colCount;c++){
- var rs = sheet.getTag(r,-1);
- var cs = sheet.getTag(-1,c);
- var cellSetting = sheet.getTag(r, c);
- if (!cellSetting) {
- cellSetting = new CellSetting();
- }
- if(rs&&rs.dimValue) $.extend(cellSetting,rs.dimValue);
- if(cs&&cs.dimValue) $.extend(cellSetting,cs.dimValue);
- $.extend(cellSetting,{'dataCell':true});
- var cellString = getCellStr(sheet,r,c);
- cellString=cellString.replace(/\$/g,'');
- if(!cellSetting.measureId) {
- _alert("单元格:"+cellString+"未绑定指标维度")
- return;
- }
- if(!cellSetting.periodDetailId) {
- _alert("单元格:"+cellString+"未绑定时间维度")
- return;
- }
- if(typeof cellSetting.includeTax =='undefined') {
- _alert("单元格:"+cellString+"未绑定含税维度")
- return;
- }
- if(typeof cellSetting.expect =='undefined') {
- _alert("单元格:"+cellString+"未绑定预实维度")
- return;
- }
- sheet.setTag(r,c, cellSetting);
- changeCell++;
- if(cellSetting.datatype=='amount'){
- var currencySymbol = cellSetting.currencySymbol;//货币符号
- var thousandth = cellSetting.thousandth;//千分位
- var fractionNum = cellSetting.fractionNum;//小数位
- var format='';
- if(currencySymbol) format+=currencySymbol+'* ';
- if(thousandth) format+='#,###';
- if(!fractionNum&&fractionNum!=0) {
- fractionNum='2';
- }
- if(fractionNum!=0){
- format+='.';
- for(var n=0;n<fractionNum;n++) {
- format+='0';
- }
- }
- sheet.setFormatter(r, c, format);
- }
- }
- }
- }
- if(changeCell>0){
- setSheetTag(sheet,{fix:true})
- $.messager.alert('信息','操作成功');
- }else{
- $.messager.alert('信息','请选择单元格');
- }
- }
- function setControlFlag(spread,options){
- var sheet = spread.getActiveSheet();
- setSelectionTagValue(sheet,'cell',options);
- }
- function setSheetTag(sheet,value) {
- var setting = sheet.tag();
- if(!setting){
- setting = new SheetSetting();
- }
- $.extend(setting,value);
- sheet.tag(setting);
- }
- function setDataStartIndex(sheet,type,row,col){
- }
- function setReadonly(spread,options){
- var sheet = spread.getActiveSheet();
- var selections = sheet.getSelections();
- var select = selections[0];
- var row = select.row;
- var col = select.col;
- if(options.readOnly==1){
- sheet.getCell(row,col).backColor('grey');
- }else {
- sheet.getCell(row,col).backColor('white');
- }
- setSelectionTagValue(sheet,'cell',options);
- }
- function setHeader(sheet,type,objValue){
- var o = {};
- //inst 会用到 显示行表头 或 列表头
- if(type=='row'){
- o[_vars.rowHeader]='true';
- loopSelection(sheet,function(row,col){
- addCellTagValue(sheet,row,-1,{dimValue:objValue});
- });
- }else if(type=='col'){
- o[_vars.colHeader]='true';
- loopSelection(sheet,function(row,col){
- addCellTagValue(sheet,-1,col,{dimValue:objValue});
- });
- }
- setSelectionTagValue(sheet,'cell',o);
- }
- function disableBindButton(clearValue){
- if(clearValue){
- $('#rowTimeInput').val('');
- $('#colTimeInput').val('');
- $('#rowGoalsInput').val('');
- $('#colGoalsInput').val('');
- $('#rowEntityInput').val('');
- $('#colEntityInput').val('');
- $('input[name="includeTaxRow"]').removeAttr('checked');
- $('input[name="includeTaxCol"]').removeAttr('checked');
- $('input[name="expectRow"]').removeAttr('checked');
- $('input[name="expectCol"]').removeAttr('checked');
- }
- /*
- $('#rowTimeBind').hide();
- $('#rowGoalsBind').hide();
- $('input[name="includeTaxRow"]').attr('disabled','disabled');
- $('input[name="expectRow"]').attr('disabled','disabled');
- $('#colTimeBind').hide();
- $('#colGoalsBind').hide();
- $('input[name="includeTaxCol"]').attr('disabled','disabled');
- $('input[name="expectCol"]').attr('disabled','disabled');
- */
- }
- function clearBind(sheet,type,row,col){
- var cellTag = sheet.getTag(row,col);
- if(type=='row'){
- removeDimValue(sheet,row,-1,cellTag);
- clearRowBindInput();
- }else {
- removeDimValue(sheet,-1,col,cellTag);
- clearColBindInput();
- }
- sheet.setTag(row,col,null);
- }
- function clearRowBindInput(){
- $('#rowTimeInput').val('');
- $('#rowGoalsInput').val('');
- $('#rowEntityInput').val('');
- $('input[name="includeTaxRow"]').removeAttr('checked');
- $('input[name="expectRow"]').removeAttr('checked');
- }
- function clearColBindInput(){
- $('#colTimeInput').val('');
- $('#colGoalsInput').val('');
- $('#colEntityInput').val('');
- $('input[name="includeTaxCol"]').removeAttr('checked');
- $('input[name="expectCol"]').removeAttr('checked');
- }
- function setExpectRow(){
- setExpect('row');
- }
- function setExpectCol(){
- setExpect('col');
- }
- function setExpect(type){
- var sheet = spread.getActiveSheet();
- var itemName='';
- disableBindButton();
- if(type=='row'){
- itemName="expectRow"
- }else {
- itemName="expectCol"
- }
- $('input[name="'+itemName+'"]').removeAttr('disabled');
- var expect = $('input[name="'+itemName+'"]:checked').val();
- beforeBindDim(sheet,type);
- setSelectionTagValue(sheet,'cell',{expect:expect});
- setSelectionTagValue(sheet,'cell',{bindDirection:type});
- setHeader(sheet,type,{expect:expect});
- }
- function dimMatchRow(spread,options){
- dimMatch(spread,options,'row')
- }
- function dimMatchCol(spread,options){
- dimMatch(spread,options,'col')
- }
- function dimMatch(spread,options,type) {
- var sheet = spread.getActiveSheet();
- var selections = sheet.getSelections();
- var select = selections[0];
- var row = select.row;
- var col = select.col;
- var rowCount = select.rowCount;
- var colCount = select.colCount;
- var params= {};
- var totalCol = col + colCount;
- var c = 0;
- for(var i=row;i<row+rowCount;i++) {
- for (var j = col; j < totalCol; j++) {
- var cellValue = sheet.getValue(i,j);
- if(cellValue){
- params['list['+c+'].row']=i;
- params['list['+c+'].col']=j;
- params['list['+c+'].cellValue']=cellValue;
- c++;
- }
- }
- }
- params.periodId=periodId;
- $.post('budgetTempSheetController.do?dimMatch',params,function(d){
- if(d.success){
- sheet.clearSelection();
- var list = d.obj.list;
- for(var i=0;i<list.length;i++){
- var one = list[i];
- var row =one.row;
- var col = one.col;
- var bindDirection =type?type:one.bindDirection;
- if(one.bindDim=='measure'){
- sheet.setSelection(row,col, 1, 1);
- setMeasureValue(sheet,bindDirection,one.bindValue);
- }
- if(one.bindDim=='period'){
- sheet.setSelection(row,col, 1, 1);
- setTimeValue(sheet,bindDirection,one.bindValue);
- }
- }
- sheet.clearSelection();
- tip('匹配成功');
- }else {
- tip('匹配失败');
- }
- },'json')
- }
- function beforeBindDim(sheet,type){
- checkChangeDircetion(sheet,type);
- }
- //检查是否换方向绑定
- function checkChangeDircetion(sheet,type){
- loopSelection(sheet,function(row,col){
- var cellTag=sheet.getTag(row,col);
- if(!cellTag) return;
- var oldBindDirection = cellTag.bindDirection;
- if(oldBindDirection && oldBindDirection!=type){
- clearBind(sheet,oldBindDirection,row,col);
- }
- });
- }
- function bindCheckNum(spread) {
- spread.bind(GC.Spread.Sheets.Events.EditEnding, function (sender, args) {
- var sheet = args.sheet;
- var row=args.row;
- var col=args.col;
- var cellTag = sheet.getTag(row,col);
- if(cellTag) {
- if(cellTag.dataCell==true && cellTag.datatype && cellTag.datatype!='txt'){
- var value =args.editingText;
- var reg=/^(-?\d+)(\.\d+)?$/;
- if(value){
- if(value.indexOf('=')!=0){
- if(!reg.test(value)){
- args.cancel = true;
- }
- }
- }
- }
- }
- });
- }
- //清空行维度
- function removeRowBind(){
- var sheet=spread.getActiveSheet();
- var selections = sheet.getSelections();
- var select = selections[0];
- var row = select.row;
- var col = select.col;
- var cellTag = sheet.getTag(row,col);
- if(cellTag){
- var bindDirection = cellTag.bindDirection;
- if(bindDirection){
- if(bindDirection=='row'){
- clearBind(sheet,'row',row,col);
- }
- }
- }
- }
- //清空列维度
- function removeColBind(){
- var sheet=spread.getActiveSheet();
- var selections = sheet.getSelections();
- var select = selections[0];
- var row = select.row;
- var col = select.col;
- var cellTag = sheet.getTag(row,col);
- if(cellTag){
- var bindDirection = cellTag.bindDirection;
- if(bindDirection){
- if(bindDirection=='col'){
- clearBind(sheet,'col',row,col);
- }
- }
- }
- }
- function showCellBindInfo(sheet,row,col){
- $('#rowInfo').hide();$('#colInfo').hide();
- $('#info3').show();$('#info2').show();
- var cellTag = sheet.getTag(row,col);
- var periodDetailName=cellTag.periodDetailName;
- var measureName=cellTag.customCode+" "+cellTag.measureName;
- var includeTax=cellTag.includeTax;
- var expect = cellTag.expect;
- var entityName = cellTag.entityName;
- $('#timeInput').val(periodDetailName);
- $('#goalsInput').val(measureName);
- $('#entityInput').val(entityName);
- $('input[name="includeTax"]').removeAttr('checked');
- $('input[name="includeTax"][value=' + includeTax + ']').attr('checked', 'checked');
- $('input[name="expect"]').removeAttr('checked');
- $('input[name="expect"][value=' + expect + ']').attr('checked', 'checked');
- }
- function setEntityRow() {
- setEntity('row');
- }
- function setEntityCol() {
- setEntity('col');
- }
- function setEntity(type){
- var sheet = spread.getActiveSheet();
- _openDialog('budgetEntityController.do?select','选择预算主体',function(iframe){
- var selectRows = iframe.getSelectRows();
- var one = selectRows[0];
- spread.suspendPaint();
- setEntityValue(sheet,type,{entityId:one.id,entityName:one.entityName});
- spread.resumePaint();
- },'800px','600px');
- }
- function setEntityValue(sheet,type,valueObj){
- var name = valueObj.entityName;
- disableBindButton();
- if(type=='row'){
- $('#rowEntityInput').val(name);
- $('#rowEntityBind').show();
- }else {
- $('#colEntityInput').val(name);
- $('#colEntityBind').show();
- }
- beforeBindDim(sheet,type);
- setSelectionTagValue(sheet,'cell',valueObj);
- setSelectionTagValue(sheet,'cell',{bindDirection:type});
- setHeader(sheet,type,valueObj);
- }
|