budgetTempSheet-measure4ActualSta.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  1. var headerCount=2;//头部行高
  2. var nextDataRowIndex;//下条数据所在行
  3. var bgColor1 = 'rgb(210,218,228)';
  4. var bgColor2 = 'rgb(255,242,203)';
  5. var bgColor3 = 'rgb(194,214,155)';//绿的
  6. $(function(){
  7. spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 1 });
  8. initSpread();
  9. });
  10. function initSpread(){
  11. spread.suspendPaint();
  12. if(dbJson){//数据库
  13. // spread.fromJSON(JSON.parse(dbJson));
  14. spread.fromJSON(dbJson);
  15. }else {
  16. nextDataRowIndex = headerCount;
  17. initData();
  18. }
  19. var sheet = spread.getActiveSheet();
  20. var setting = sheet.tag();
  21. if(setting){
  22. if(setting.nextDataRowIndex){
  23. nextDataRowIndex = setting.nextDataRowIndex;
  24. }
  25. }
  26. if(!nextDataRowIndex){
  27. nextDataRowIndex = headerCount;
  28. }
  29. spread.options.newTabVisible = false;//取消新增sheet按钮
  30. spread.options.allowExtendPasteRange =true;//扩展粘贴区域
  31. bindEvent(spread);
  32. addContextMenu(spread);
  33. addDataCellMenu(spread)
  34. setMenuView(spread);
  35. // sheet.frozenRowCount(headRowCount);//冻结头部
  36. // sheet.options.frozenlineColor = 'red';//冻结线颜色
  37. setDefaultLock(sheet);
  38. // sheet.selectionPolicy(GC.Spread.Sheets.SelectionPolicy.single);//不让多选
  39. spread.bind(GC.Spread.Sheets.Events.RowChanging, function (e, info) {
  40. //info.propertyName="deleteRows" //删除行
  41. if(info.propertyName="deleteRows"){
  42. var deleteRow = info.row;
  43. var deleteCount = info.count;
  44. var sheetTag = sheet.tag();
  45. var ids = sheetTag.ids;
  46. for(var i=deleteRow;i<deleteRow+deleteCount;i++) {
  47. var rowTag = sheet.getTag(i,-1);
  48. if(!rowTag) continue;
  49. for(var j=0;j<ids.length;j++){
  50. if(ids[j]==rowTag.id){
  51. if(nextDataRowIndex>headerCount) nextDataRowIndex--;
  52. // delete ids[j];
  53. ids.splice(j,1);
  54. }
  55. }
  56. }
  57. addSheetTagValue(sheet,{ids:ids,nextDataRowIndex:nextDataRowIndex});
  58. }
  59. });
  60. sheet.frozenRowCount(2);
  61. sheet.frozenColumnCount(5);
  62. spread.resumePaint();
  63. }
  64. function initData() {
  65. var jsonHeader ;
  66. if(actualStaKind!='main'){
  67. jsonHeader = actual_sta_branch;
  68. }else {
  69. jsonHeader =actual_sta_main;
  70. }
  71. spread.fromJSON(jsonHeader);
  72. var sheet = spread.getActiveSheet();
  73. if(actualStaKind=='main'){
  74. initMainHeadData(sheet);
  75. }else {
  76. var budgetTitle ;
  77. if(actualStaKind=='labor'){
  78. budgetTitle='人工成本年度预算数';
  79. }else if(actualStaKind=='pu'){
  80. budgetTitle='采购成本年度预算数';
  81. }else if(actualStaKind=='maintain'){
  82. budgetTitle='维保费用年度预算数';
  83. }else if(actualStaKind=='other'){
  84. budgetTitle='其他费用年度预算数';
  85. }else if(actualStaKind=='manage'){
  86. budgetTitle='管理费用年度预算数';
  87. }
  88. initBranchHeadData(sheet);
  89. if(budgetTitle){
  90. sheet.setValue(0,2,budgetTitle);
  91. }
  92. }
  93. // actual_sta_branch
  94. for(var i=0;i<entityList.length;i++){
  95. var oneEntity=entityList[i];
  96. addOne(oneEntity);
  97. }
  98. sheet.autoFitColumn(1);
  99. }
  100. function addOne(one){
  101. var sheet = spread.getActiveSheet();
  102. var sheetTag = sheet.tag();
  103. if(!sheetTag) sheetTag={};
  104. if(!sheetTag.ids) sheetTag.ids=[];
  105. var id = one.id;
  106. if($.inArray(id, sheetTag.ids)!=-1){
  107. return;
  108. }
  109. sheetTag.ids.push(id);
  110. addSheetTagValue(sheet,{ids:sheetTag.ids});
  111. var row = nextDataRowIndex;
  112. sheet.addRows(row+1,1);
  113. var rowSetting={};//行变量
  114. var col=0;
  115. var bindEntityCol=0;
  116. if(actualStaKind !='main') {
  117. // 序号
  118. sheet.getCell(row,col).formula("row()-"+headerCount).backColor(bgColor1);
  119. col++;
  120. // sheet.setValue(row,colIndex,one.name);
  121. //项目名称
  122. sheet.getCell(row,col).backColor(bgColor1).value(one.name).hAlign(GC.Spread.Sheets.HorizontalAlign.left);
  123. bindEntityCol= col;
  124. col++;
  125. //度预算数
  126. sheet.getCell(row,col).backColor(bgColor1);
  127. var yearAmountCellStr = getCellStr(sheet,row,col);
  128. col++;
  129. var entityYearAmountIndex=col++;
  130. var entityYearAmountPerIndex=col++;
  131. var yearAmountCellArray=[];
  132. for(var i=0;i<12;i++){
  133. //发生额
  134. var monthAmountCellStr = getCellStr(sheet,row,col);
  135. yearAmountCellArray.push(monthAmountCellStr);
  136. sheet.getCell(row,col).backColor(bgColor2);
  137. col++;
  138. //占比
  139. var divFoumula = monthAmountCellStr+"/"+yearAmountCellStr;
  140. var formula="=IF(ISERROR("+divFoumula+"),0,"+divFoumula+")";
  141. sheet.getCell(row,col).formula(formula).backColor(bgColor2).formatter("0.00%");
  142. col++;
  143. }
  144. sheet.getCell(row,entityYearAmountIndex).formula(yearAmountCellArray.join('+')).backColor(bgColor2);
  145. var entityYearAmountCellStr = getCellStr(sheet,row,entityYearAmountIndex);
  146. var divFoumula = entityYearAmountCellStr+"/"+yearAmountCellStr;
  147. var formula="=IF(ISERROR("+divFoumula+"),0,"+divFoumula+")";
  148. sheet.getCell(row,entityYearAmountPerIndex).formula(formula).backColor(bgColor2).formatter("0.00%");
  149. }else {
  150. // 序号
  151. sheet.getCell(row,col).formula("row()-"+headerCount).backColor(bgColor1);
  152. col++;
  153. // sheet.setValue(row,colIndex,one.name);
  154. //项目名称
  155. sheet.getCell(row,col).backColor(bgColor1).value(one.name).hAlign(GC.Spread.Sheets.HorizontalAlign.left);
  156. bindEntityCol=col;
  157. col++;
  158. //度预算数
  159. sheet.getCell(row,col).backColor(bgColor1);
  160. var yearAmountCellStr = getCellStr(sheet,row,col);
  161. col++;
  162. var entityYearAmountIndex=col++;
  163. var entityYearAmountPerIndex=col++;
  164. var yearAmountCellArray=[];
  165. for(var i=0;i<5;i++){
  166. //发生额
  167. var monthAmountCellStr = getCellStr(sheet,row,col);
  168. yearAmountCellArray.push(monthAmountCellStr);
  169. sheet.getCell(row,col).backColor(bgColor2);
  170. col++;
  171. //占比
  172. var divFoumula = monthAmountCellStr+"/"+yearAmountCellStr;
  173. var formula="=IF(ISERROR("+divFoumula+"),0,"+divFoumula+")";
  174. sheet.getCell(row,col).formula(formula).backColor(bgColor2).formatter("0.00%");
  175. col++;
  176. }
  177. sheet.getCell(row,entityYearAmountIndex).formula(yearAmountCellArray.join('+')).backColor(bgColor3);
  178. var entityYearAmountCellStr = getCellStr(sheet,row,entityYearAmountIndex);
  179. var divFoumula = entityYearAmountCellStr+"/"+yearAmountCellStr;
  180. var formula="=IF(ISERROR("+divFoumula+"),0,"+divFoumula+")";
  181. sheet.getCell(row,entityYearAmountPerIndex).formula(formula).backColor(bgColor3).formatter("0.00%");
  182. }
  183. //
  184. setBorder(sheet,row);
  185. nextDataRowIndex++;
  186. addSheetTagValue(sheet,{nextDataRowIndex:nextDataRowIndex});
  187. rowSetting.id=id;
  188. rowSetting.entityId=id;
  189. addCellTagValue(sheet,row,-1,rowSetting);
  190. sheet.setSelection(row, bindEntityCol, 1, 1);
  191. setEntityValue(sheet,'row',{entityId:one.id,entityName:one.name});
  192. sheet.clearSelection();
  193. }
  194. function initBranchHeadData(sheet){
  195. //边框
  196. var row =1;
  197. setBorder(sheet,row);
  198. var col=2;
  199. var cellStr = getCellStr(sheet,row,col);
  200. var formula = sheet.getFormula(row,col);
  201. sheet.getCell(row,col).formula("round("+formula+",2)");
  202. var yearBudgetCell="C2";
  203. for(var i = 0;i<13;i++){
  204. col++;
  205. var cellStr = getCellStr(sheet,row,col);
  206. formula = sheet.getFormula(row,col);
  207. sheet.getCell(row,col).formula("round("+formula+",2)");
  208. col++;
  209. var divFoumula = cellStr+"/"+yearBudgetCell;
  210. var formula="=IF(ISERROR("+divFoumula+"),0,"+divFoumula+")";
  211. sheet.getCell(row,col).formula(formula).formatter("0.00%");
  212. }
  213. }
  214. function initMainHeadData(sheet){
  215. var row =1;
  216. setBorder(sheet,row);
  217. var col=2;
  218. var cellStr = getCellStr(sheet,row,col);
  219. var formula = sheet.getFormula(row,col);
  220. sheet.getCell(row,col).formula("round("+formula+",2)");
  221. var yearBudgetCell="C2";
  222. for(var i = 0;i<6;i++){
  223. col++;
  224. var cellStr = getCellStr(sheet,row,col);
  225. formula = sheet.getFormula(row,col);
  226. sheet.getCell(row,col).formula("round("+formula+",2)");
  227. col++;
  228. var divFoumula = cellStr+"/"+yearBudgetCell;
  229. var formula="=IF(ISERROR("+divFoumula+"),0,"+divFoumula+")";
  230. sheet.getCell(row,col).formula(formula).formatter("0.00%");
  231. }
  232. }
  233. function setBorder(sheet,row){
  234. var lineStyle = GC.Spread.Sheets.LineStyle.thin;
  235. var lineBorder = new GC.Spread.Sheets.LineBorder('black', lineStyle);
  236. var sheetArea = GC.Spread.Sheets.SheetArea.viewport;
  237. var columnCount = sheet.getColumnCount();
  238. for(var col=0;col<columnCount;col++) {
  239. sheet.getRange(row,col).setBorder(lineBorder, { left: true, right: true,top:true,bottom:true}, sheetArea);
  240. }
  241. }
  242. function bindEvent(spread){
  243. bindCheckNum(spread);
  244. spread.bind(GC.Spread.Sheets.Events.EnterCell, function (event, data) {//点击cell事件
  245. var row = data.row;
  246. var col = data.col;
  247. var sheet = data.sheet;
  248. var cellTag = sheet.getTag(row,col);
  249. disableBindButton(true);
  250. if(readOnly=='false') {
  251. $('#rowInfo').show();
  252. $('#colInfo').show();
  253. $('#info3').show();
  254. $('#info2').hide();
  255. if(cellTag) {
  256. var bindDirection=cellTag.bindDirection;
  257. if(bindDirection){//表头
  258. if(bindDirection=='row'){
  259. $('#rowTimeInput').val(cellTag.periodDetailName);
  260. $('#rowEntityInput').val(cellTag.entityName);
  261. if(cellTag.measureName) {
  262. $('#rowGoalsInput').val(cellTag.customCode + " " + cellTag.measureName);
  263. }
  264. $('input[name="includeTaxRow"][value=' + cellTag.includeTax + ']').attr('checked', 'checked');
  265. $('input[name="expectRow"][value=' + cellTag.expect + ']').attr('checked', 'checked');
  266. }else if(bindDirection=='col'){
  267. $('#colTimeInput').val(cellTag.periodDetailName);
  268. $('#colEntityInput').val(cellTag.entityName);
  269. if(cellTag.measureName){
  270. $('#colGoalsInput').val(cellTag.customCode+" "+cellTag.measureName);
  271. }
  272. $('input[name="includeTaxCol"][value=' + cellTag.includeTax + ']').attr('checked', 'checked');
  273. $('input[name="expectCol"][value=' + cellTag.expect + ']').attr('checked', 'checked');
  274. }
  275. }else {//非表头
  276. showCellBindInfo(sheet,row,col);
  277. }
  278. }
  279. }else if(readOnly=='true'){
  280. showCellBindInfo(sheet,row,col);
  281. }
  282. //单元格属性
  283. if(cellTag){
  284. var datatype =cellTag.datatype;
  285. var datatypeValue= measureDataTypeList[datatype];
  286. if(!datatypeValue) datatypeValue='';
  287. $('#goalsDataType').html(datatypeValue);
  288. if(cellTag.readOnly==1){
  289. $('#readOnly').html('是');
  290. }else {
  291. $('#readOnly').html('否');
  292. }
  293. var showFuntionTxt = $('#showFuntionTxt');
  294. if(cellTag.functionId){
  295. showFuntionTxt.show();
  296. showFuntionTxt.find('span').html(cellTag.functionTxt);
  297. }else{
  298. showFuntionTxt.hide();
  299. }
  300. var controlFlagNameDiv = $('#controlFlagName');
  301. if(cellTag.controlFlagName){
  302. controlFlagNameDiv.show();
  303. controlFlagNameDiv.find('span').html(cellTag.controlFlagName);
  304. }else {
  305. controlFlagNameDiv.hide();
  306. }
  307. }else {
  308. $('#readOnly').html('');
  309. $('#showFuntionTxt').hide();
  310. }
  311. // sheet.startEdit(false); //单击修改
  312. });
  313. /* spread.bind(GC.Spread.Sheets.Events.ButtonClicked, function (e, args) {//点击按钮事件
  314. var sheet = args.sheet, row = args.row, col = args.col;
  315. var cellType = sheet.getCellType(row, col);
  316. });*/
  317. spread.bind(GC.Spread.Sheets.Events.CellChanged, function (e, info) {
  318. // console.log(info)
  319. if(info.sheetArea === GC.Spread.Sheets.SheetArea.viewport){
  320. var sheet =info.sheet;
  321. var row = info.row;
  322. var col = info.col;
  323. if(info.propertyName=='value'){//值变化
  324. }
  325. if(info.propertyName=='formula'){//公式
  326. /*if(info.newValue==null){
  327. sheet.getCell(row,col).backColor('white');
  328. }else{
  329. sheet.getCell(row,col).backColor('yellow');
  330. }*/
  331. }
  332. }
  333. });
  334. // alert("Cell index (" + info.row + "," + info.col + ")");
  335. }
  336. function setDefaultLock(sheet){
  337. var option = {
  338. allowSelectLockedCells:true,
  339. allowSelectUnlockedCells:true,
  340. allowFilter: true,
  341. allowSort: false,
  342. allowResizeRows: true,
  343. allowResizeColumns: true,
  344. allowEditObjects: false,
  345. allowDragInsertRows: false,
  346. allowDragInsertColumns: false,
  347. allowInsertRows: true,
  348. allowInsertColumns: true,
  349. allowDeleteRows: true,
  350. allowDeleteColumns: true
  351. };
  352. sheet.options.protectionOptions = option;
  353. sheet.options.isProtected = true;
  354. var defaultStyle = sheet.getDefaultStyle() //默认的样式,
  355. defaultStyle.locked=false;
  356. defaultStyle.vAlign = GC.Spread.Sheets.VerticalAlign.center;
  357. defaultStyle.hAlign = GC.Spread.Sheets.HorizontalAlign.center;
  358. sheet.setDefaultStyle(defaultStyle);
  359. }
  360. function addContextMenu(){
  361. for(var i=0;i< spread.contextMenu.menuData.length;i++){
  362. var menu = spread.contextMenu.menuData[i];
  363. var menuName=menu.name;
  364. if(menuName=='gc.spread.filter' || menuName=='gc.spread.sort' ){//去掉过滤、排序
  365. delete spread.contextMenu.menuData[i];
  366. }
  367. }
  368. // command: showLoginDialog,
  369. }
  370. //固定后 右键菜单
  371. function addDataCellMenu(spread){
  372. var sheet=spread.getActiveSheet();
  373. var readOnly ={text: '只读',name: 'readOnly',workArea: 'viewport',dataCellMenu:1};
  374. readOnly.subMenu= [{text: '是',name: 'readOnly_yes',workArea: 'viewport',command:setReadonly}
  375. ,{text: '否',name: 'readOnly_no',workArea: 'viewport',command:setReadonly}]
  376. spread.contextMenu.menuData.push(readOnly);
  377. var clearNotSelectMenu ={text: '清空其他区域',name: 'clearNotSelect',workArea: 'viewport',command:clearNotSelect};
  378. spread.contextMenu.menuData.push(clearNotSelectMenu);
  379. addDimFunctionMenu(spread);
  380. addDimFunctionCostbreakdownMenu(spread);
  381. var dimMatchMenu ={text: '维度匹配',name: 'dimLike',workArea: 'viewport',command:dimMatch};
  382. dimMatchMenu.subMenu= [{text: '匹配行维度',name: 'dimLikeRow',workArea: 'viewport',command:dimMatchRow}
  383. ,{text: '匹配列维度',name: 'dimLikeCol',workArea: 'viewport',command:dimMatchCol}]
  384. spread.contextMenu.menuData.push(dimMatchMenu);
  385. }
  386. function setMenuView(spread){
  387. function CustomMenuView() {
  388. }
  389. CustomMenuView.prototype = new GC.Spread.Sheets.ContextMenu.MenuView();
  390. CustomMenuView.prototype.createMenuItemElement = function (menuItemData) {
  391. var self = this;
  392. if (menuItemData.name === "bind") {
  393. /* var containers = GC.Spread.Sheets.ContextMenu.MenuView.prototype.createMenuItemElement.call(self, menuItemData);
  394. var supMenuItemContainer = containers[0];
  395. while (supMenuItemContainer.firstChild) {
  396. supMenuItemContainer.removeChild(supMenuItemContainer.firstChild);
  397. }
  398. var colorPicker = createColorpicker();
  399. supMenuItemContainer.appendChild(colorPicker);
  400. return supMenuItemContainer;*/
  401. } else {
  402. var menuItemView = GC.Spread.Sheets.ContextMenu.MenuView.prototype.createMenuItemElement.call(self, menuItemData);
  403. return menuItemView;
  404. }
  405. };
  406. CustomMenuView.prototype.getCommandOptions = function (menuItemData, host, event) {
  407. var option={};
  408. if (menuItemData) {
  409. var name =menuItemData.name;
  410. if(name && name.indexOf('timeRowMenu')==0) {
  411. var text = menuItemData.text;
  412. for(var i=0;i<periodDetailList.length;i++){
  413. var detail = periodDetailList[i];
  414. if(detail.name==text){
  415. option.id=detail.id;
  416. option.name=detail.name;
  417. break;
  418. }
  419. }
  420. }
  421. if(name && name=='controlFlag1') {
  422. option.controlFlag=1;
  423. }
  424. if(name && name=='readOnly_yes') {
  425. option.readOnly=1;
  426. }else if(name && name=='readOnly_no'){
  427. option.readOnly=0;
  428. }
  429. /*if(name && name.indexOf('goalsDataType')==0){
  430. var code = name.substr('goalsDataType_'.length);
  431. for(var i=0;i<goalsDataTypeList.length;i++){
  432. var dataType = goalsDataTypeList[i];
  433. if(dataType.code==code){
  434. option.goalsDataType=code;
  435. option.goalsDataTypeName=dataType.name;
  436. break;
  437. }
  438. }
  439. }*/
  440. }
  441. // console.log(option);
  442. return option;
  443. };
  444. spread.contextMenu.menuView = new CustomMenuView();
  445. }
  446. //添加常用style
  447. function addNameStyle(sheet){
  448. var lockStyle = new GC.Spread.Sheets.Style();
  449. lockStyle.name='lock';
  450. lockStyle.locked = true;
  451. sheet.addNamedStyle(lockStyle);
  452. var unLockStyle = new GC.Spread.Sheets.Style();
  453. unLockStyle.name='unLock';
  454. unLockStyle.locked = false;
  455. sheet.addNamedStyle(unLockStyle);
  456. }
  457. function save(afterSaveFunction){
  458. var sheet = spread.getActiveSheet();
  459. var tag = sheet.tag();
  460. var hasFix = false;
  461. if(tag) {
  462. if(tag.fix==true){
  463. hasFix=true;
  464. }
  465. }
  466. if(!hasFix){
  467. _alert('请先生成数据单元格');
  468. return;
  469. }
  470. _commonSave({type:'normal'},afterSaveFunction);
  471. }
  472. function SheetSetting() {
  473. this.bindTime=false;
  474. this.bindIncludeTax=false;
  475. this.bindGoals=false;
  476. }
  477. SheetSetting.prototype.toJSON = function () {
  478. var settings ={};
  479. var keys =Object.keys(this);
  480. for(var i=0;i<keys.length;i++){
  481. var key =keys[i];
  482. settings[key]=this[key];
  483. }
  484. return settings;
  485. };
  486. SheetSetting.prototype.fromJSON = function (settings) {
  487. };
  488. function CellSetting() {
  489. }
  490. CellSetting.prototype.toJSON = function () {
  491. var settings ={};
  492. var keys =Object.keys(this);
  493. for(var i=0;i<keys.length;i++){
  494. var key =keys[i];
  495. settings[key]=this[key];
  496. }
  497. return settings;
  498. };
  499. CellSetting.prototype.fromJSON = function (settings) {
  500. console.log('fromjson');
  501. };
  502. function RowSetting(measureId,measureName) {
  503. this.measureId = measureId;
  504. this.measureName= measureName;
  505. }
  506. RowSetting.prototype.toJSON = function () {
  507. var settings ={};
  508. var keys =Object.keys(this);
  509. for(var i=0;i<keys.length;i++){
  510. var key =keys[i];
  511. settings[key]=this[key];
  512. }
  513. return settings;
  514. };
  515. RowSetting.prototype.fromJSON = function (settings) {
  516. };
  517. function ColSetting() {}
  518. ColSetting.prototype.toJSON = function () {
  519. var settings ={};
  520. var keys =Object.keys(this);
  521. for(var i=0;i<keys.length;i++){
  522. var key =keys[i];
  523. settings[key]=this[key];
  524. }
  525. return settings;
  526. };
  527. ColSetting.prototype.fromJSON = function (settings) {
  528. console.log('fromjson');
  529. };
  530. function _openDialog(url,title,okCallback,width,height){
  531. if(!width){
  532. width='500px';
  533. }
  534. if(!height){
  535. height='350px';
  536. }
  537. if(width=="100%"){
  538. width = window.top.document.body.offsetWidth;
  539. }
  540. if(height=="100%") {
  541. height =window.top.document.body.offsetHeight-100;
  542. }
  543. var _selectDialog= $.dialog({content:'url:'+url
  544. , zIndex: getzIndex()
  545. , title:title , lock: true, width:width, height: height, opacity: 0.4, button: [
  546. {name: '确定', callback:function () {
  547. var iframe = _selectDialog.iframe.contentWindow;
  548. if(okCallback){
  549. var b = okCallback(iframe);
  550. return b;
  551. }
  552. }
  553. , focus: true},
  554. {name: '取消', callback: function (){}}
  555. ]}).zindex();
  556. return _selectDialog;
  557. }
  558. function setIncludeTaxRow() {
  559. setIncludeTax('row');
  560. }
  561. function setIncludeTaxCol() {
  562. setIncludeTax('col');
  563. }
  564. function setIncludeTax(type){
  565. var sheet = spread.getActiveSheet();
  566. var itemName='';
  567. disableBindButton();
  568. if(type=='row'){
  569. itemName="includeTaxRow"
  570. }else {
  571. itemName="includeTaxCol"
  572. }
  573. $('input[name="'+itemName+'"]').removeAttr('disabled');
  574. var include = $('input[name="'+itemName+'"]:checked').val();
  575. beforeBindDim(sheet,type);
  576. setSelectionTagValue(sheet,'cell',{includeTax:include});
  577. setSelectionTagValue(sheet,'cell',{bindDirection:type});
  578. setHeader(sheet,type,{includeTax:include});
  579. }
  580. function setTimeRow(){
  581. setTime('row');
  582. }
  583. function setTimeCol(){
  584. setTime('col');
  585. }
  586. function setTime(type){
  587. var sheet = spread.getActiveSheet();
  588. var url ='budgetPeriodDetailController.do?select&periodYear='+periodYear;
  589. _select(url, '选择时间维度', function (selectedRows) {
  590. var one = selectedRows[0];
  591. var id = one.id;
  592. var name = one.name;
  593. var obj = {periodDetailId:id,periodDetailName:name};
  594. setTimeValue(sheet,type,obj);
  595. }, '800px', '600px');
  596. }
  597. function setTimeValue(sheet,type,valueObj){
  598. var name = valueObj.periodDetailName;
  599. disableBindButton();
  600. if(type=='row'){
  601. $('#rowTimeInput').val(name);
  602. $('#rowTimeBind').show();
  603. }else {
  604. $('#colTimeInput').val(name);
  605. $('#colTimeBind').show();
  606. }
  607. beforeBindDim(sheet,type);
  608. setSelectionTagValue(sheet,'cell',valueObj);
  609. setSelectionTagValue(sheet,'cell',{bindDirection:type});
  610. setHeader(sheet,type,valueObj);
  611. }
  612. function setMeasureRow() {
  613. setMeasure('row');
  614. }
  615. function setMeasureCol() {
  616. setMeasure('col');
  617. }
  618. function setMeasure(type){
  619. var sheet = spread.getActiveSheet();
  620. var url = 'budgetMeasureController.do?select';
  621. _openDialog(url,'选择预算指标',function(iframe){
  622. var selectedRows = iframe.getSelectedRow();
  623. if(selectedRows.length==0){
  624. iframe.tip('请选择预算指标');
  625. return false;
  626. }
  627. var one = selectedRows[0];
  628. var code = one.code;
  629. var id = one.id;
  630. var name = one.name;
  631. var o={measureId:id,measureName:name};
  632. o.datatype=one.datatype;
  633. o.fractionNum=one.fractionNum;
  634. o.currencySymbol=one.currencySymbol;
  635. o.showType=one.showType;
  636. o.thousandth=one.thousandth;
  637. o.controlFlag=one.controlFlag;
  638. o.customCode=one.customCode;
  639. setMeasureValue(sheet,type,o);
  640. },'800px','600px');
  641. }
  642. function setMeasureValue(sheet,type,valueObj){
  643. var name = valueObj.customCode+" "+valueObj.measureName;
  644. disableBindButton();
  645. if(type=='row'){
  646. $('#rowGoalsInput').val(name);
  647. $('#rowGoalsBind').show();
  648. }else {
  649. $('#colGoalsInput').val(name);
  650. $('#colGoalsBind').show();
  651. }
  652. beforeBindDim(sheet,type);
  653. setSelectionTagValue(sheet,'cell',valueObj);
  654. setSelectionTagValue(sheet,'cell',{bindDirection:type});
  655. setHeader(sheet,type,valueObj);
  656. }
  657. //生成数据单元格
  658. function fix() {
  659. var sheet = spread.getActiveSheet();
  660. var selections = sheet.getSelections();
  661. var changeCell =0;
  662. for(var i=0;i<selections.length;i++){
  663. var select = selections[i];
  664. var row = select.row;
  665. var col = select.col;
  666. var rowCount = select.rowCount;
  667. var colCount = select.colCount;
  668. for(var r=row;r<row+rowCount;r++){
  669. for(var c=col;c<col+colCount;c++){
  670. var rs = sheet.getTag(r,-1);
  671. var cs = sheet.getTag(-1,c);
  672. var cellSetting = sheet.getTag(r, c);
  673. if (!cellSetting) {
  674. cellSetting = new CellSetting();
  675. }
  676. if(rs&&rs.dimValue) $.extend(cellSetting,rs.dimValue);
  677. if(cs&&cs.dimValue) $.extend(cellSetting,cs.dimValue);
  678. $.extend(cellSetting,{'dataCell':true});
  679. var cellString = getCellStr(sheet,r,c);
  680. cellString=cellString.replace(/\$/g,'');
  681. if(!cellSetting.measureId) {
  682. _alert("单元格:"+cellString+"未绑定指标维度")
  683. return;
  684. }
  685. if(!cellSetting.periodDetailId) {
  686. _alert("单元格:"+cellString+"未绑定时间维度")
  687. return;
  688. }
  689. if(typeof cellSetting.includeTax =='undefined') {
  690. _alert("单元格:"+cellString+"未绑定含税维度")
  691. return;
  692. }
  693. if(typeof cellSetting.expect =='undefined') {
  694. _alert("单元格:"+cellString+"未绑定预实维度")
  695. return;
  696. }
  697. sheet.setTag(r,c, cellSetting);
  698. changeCell++;
  699. if(cellSetting.datatype=='amount'){
  700. var currencySymbol = cellSetting.currencySymbol;//货币符号
  701. var thousandth = cellSetting.thousandth;//千分位
  702. var fractionNum = cellSetting.fractionNum;//小数位
  703. var format='';
  704. if(currencySymbol) format+=currencySymbol+'* ';
  705. if(thousandth) format+='#,###';
  706. if(!fractionNum&&fractionNum!=0) {
  707. fractionNum='2';
  708. }
  709. if(fractionNum!=0){
  710. format+='.';
  711. for(var n=0;n<fractionNum;n++) {
  712. format+='0';
  713. }
  714. }
  715. sheet.setFormatter(r, c, format);
  716. }
  717. }
  718. }
  719. }
  720. if(changeCell>0){
  721. setSheetTag(sheet,{fix:true})
  722. $.messager.alert('信息','操作成功');
  723. }else{
  724. $.messager.alert('信息','请选择单元格');
  725. }
  726. }
  727. function setControlFlag(spread,options){
  728. var sheet = spread.getActiveSheet();
  729. setSelectionTagValue(sheet,'cell',options);
  730. }
  731. function setSheetTag(sheet,value) {
  732. var setting = sheet.tag();
  733. if(!setting){
  734. setting = new SheetSetting();
  735. }
  736. $.extend(setting,value);
  737. sheet.tag(setting);
  738. }
  739. function setDataStartIndex(sheet,type,row,col){
  740. }
  741. function setReadonly(spread,options){
  742. var sheet = spread.getActiveSheet();
  743. var selections = sheet.getSelections();
  744. var select = selections[0];
  745. var row = select.row;
  746. var col = select.col;
  747. if(options.readOnly==1){
  748. sheet.getCell(row,col).backColor('grey');
  749. }else {
  750. sheet.getCell(row,col).backColor('white');
  751. }
  752. setSelectionTagValue(sheet,'cell',options);
  753. }
  754. function setHeader(sheet,type,objValue){
  755. var o = {};
  756. //inst 会用到 显示行表头 或 列表头
  757. if(type=='row'){
  758. o[_vars.rowHeader]='true';
  759. loopSelection(sheet,function(row,col){
  760. addCellTagValue(sheet,row,-1,{dimValue:objValue});
  761. });
  762. }else if(type=='col'){
  763. o[_vars.colHeader]='true';
  764. loopSelection(sheet,function(row,col){
  765. addCellTagValue(sheet,-1,col,{dimValue:objValue});
  766. });
  767. }
  768. setSelectionTagValue(sheet,'cell',o);
  769. }
  770. function disableBindButton(clearValue){
  771. if(clearValue){
  772. $('#rowTimeInput').val('');
  773. $('#colTimeInput').val('');
  774. $('#rowGoalsInput').val('');
  775. $('#colGoalsInput').val('');
  776. $('#rowEntityInput').val('');
  777. $('#colEntityInput').val('');
  778. $('input[name="includeTaxRow"]').removeAttr('checked');
  779. $('input[name="includeTaxCol"]').removeAttr('checked');
  780. $('input[name="expectRow"]').removeAttr('checked');
  781. $('input[name="expectCol"]').removeAttr('checked');
  782. }
  783. /*
  784. $('#rowTimeBind').hide();
  785. $('#rowGoalsBind').hide();
  786. $('input[name="includeTaxRow"]').attr('disabled','disabled');
  787. $('input[name="expectRow"]').attr('disabled','disabled');
  788. $('#colTimeBind').hide();
  789. $('#colGoalsBind').hide();
  790. $('input[name="includeTaxCol"]').attr('disabled','disabled');
  791. $('input[name="expectCol"]').attr('disabled','disabled');
  792. */
  793. }
  794. function clearBind(sheet,type,row,col){
  795. var cellTag = sheet.getTag(row,col);
  796. if(type=='row'){
  797. removeDimValue(sheet,row,-1,cellTag);
  798. clearRowBindInput();
  799. }else {
  800. removeDimValue(sheet,-1,col,cellTag);
  801. clearColBindInput();
  802. }
  803. sheet.setTag(row,col,null);
  804. }
  805. function clearRowBindInput(){
  806. $('#rowTimeInput').val('');
  807. $('#rowGoalsInput').val('');
  808. $('#rowEntityInput').val('');
  809. $('input[name="includeTaxRow"]').removeAttr('checked');
  810. $('input[name="expectRow"]').removeAttr('checked');
  811. }
  812. function clearColBindInput(){
  813. $('#colTimeInput').val('');
  814. $('#colGoalsInput').val('');
  815. $('#colEntityInput').val('');
  816. $('input[name="includeTaxCol"]').removeAttr('checked');
  817. $('input[name="expectCol"]').removeAttr('checked');
  818. }
  819. function setExpectRow(){
  820. setExpect('row');
  821. }
  822. function setExpectCol(){
  823. setExpect('col');
  824. }
  825. function setExpect(type){
  826. var sheet = spread.getActiveSheet();
  827. var itemName='';
  828. disableBindButton();
  829. if(type=='row'){
  830. itemName="expectRow"
  831. }else {
  832. itemName="expectCol"
  833. }
  834. $('input[name="'+itemName+'"]').removeAttr('disabled');
  835. var expect = $('input[name="'+itemName+'"]:checked').val();
  836. beforeBindDim(sheet,type);
  837. setSelectionTagValue(sheet,'cell',{expect:expect});
  838. setSelectionTagValue(sheet,'cell',{bindDirection:type});
  839. setHeader(sheet,type,{expect:expect});
  840. }
  841. function dimMatchRow(spread,options){
  842. dimMatch(spread,options,'row')
  843. }
  844. function dimMatchCol(spread,options){
  845. dimMatch(spread,options,'col')
  846. }
  847. function dimMatch(spread,options,type) {
  848. var sheet = spread.getActiveSheet();
  849. var selections = sheet.getSelections();
  850. var select = selections[0];
  851. var row = select.row;
  852. var col = select.col;
  853. var rowCount = select.rowCount;
  854. var colCount = select.colCount;
  855. var params= {};
  856. var totalCol = col + colCount;
  857. var c = 0;
  858. for(var i=row;i<row+rowCount;i++) {
  859. for (var j = col; j < totalCol; j++) {
  860. var cellValue = sheet.getValue(i,j);
  861. if(cellValue){
  862. params['list['+c+'].row']=i;
  863. params['list['+c+'].col']=j;
  864. params['list['+c+'].cellValue']=cellValue;
  865. c++;
  866. }
  867. }
  868. }
  869. params.periodId=periodId;
  870. $.post('budgetTempSheetController.do?dimMatch',params,function(d){
  871. if(d.success){
  872. sheet.clearSelection();
  873. var list = d.obj.list;
  874. for(var i=0;i<list.length;i++){
  875. var one = list[i];
  876. var row =one.row;
  877. var col = one.col;
  878. var bindDirection =type?type:one.bindDirection;
  879. if(one.bindDim=='measure'){
  880. sheet.setSelection(row,col, 1, 1);
  881. setMeasureValue(sheet,bindDirection,one.bindValue);
  882. }
  883. if(one.bindDim=='period'){
  884. sheet.setSelection(row,col, 1, 1);
  885. setTimeValue(sheet,bindDirection,one.bindValue);
  886. }
  887. }
  888. sheet.clearSelection();
  889. tip('匹配成功');
  890. }else {
  891. tip('匹配失败');
  892. }
  893. },'json')
  894. }
  895. function beforeBindDim(sheet,type){
  896. checkChangeDircetion(sheet,type);
  897. }
  898. //检查是否换方向绑定
  899. function checkChangeDircetion(sheet,type){
  900. loopSelection(sheet,function(row,col){
  901. var cellTag=sheet.getTag(row,col);
  902. if(!cellTag) return;
  903. var oldBindDirection = cellTag.bindDirection;
  904. if(oldBindDirection && oldBindDirection!=type){
  905. clearBind(sheet,oldBindDirection,row,col);
  906. }
  907. });
  908. }
  909. function bindCheckNum(spread) {
  910. spread.bind(GC.Spread.Sheets.Events.EditEnding, function (sender, args) {
  911. var sheet = args.sheet;
  912. var row=args.row;
  913. var col=args.col;
  914. var cellTag = sheet.getTag(row,col);
  915. if(cellTag) {
  916. if(cellTag.dataCell==true && cellTag.datatype && cellTag.datatype!='txt'){
  917. var value =args.editingText;
  918. var reg=/^(-?\d+)(\.\d+)?$/;
  919. if(value){
  920. if(value.indexOf('=')!=0){
  921. if(!reg.test(value)){
  922. args.cancel = true;
  923. }
  924. }
  925. }
  926. }
  927. }
  928. });
  929. }
  930. //清空行维度
  931. function removeRowBind(){
  932. var sheet=spread.getActiveSheet();
  933. var selections = sheet.getSelections();
  934. var select = selections[0];
  935. var row = select.row;
  936. var col = select.col;
  937. var cellTag = sheet.getTag(row,col);
  938. if(cellTag){
  939. var bindDirection = cellTag.bindDirection;
  940. if(bindDirection){
  941. if(bindDirection=='row'){
  942. clearBind(sheet,'row',row,col);
  943. }
  944. }
  945. }
  946. }
  947. //清空列维度
  948. function removeColBind(){
  949. var sheet=spread.getActiveSheet();
  950. var selections = sheet.getSelections();
  951. var select = selections[0];
  952. var row = select.row;
  953. var col = select.col;
  954. var cellTag = sheet.getTag(row,col);
  955. if(cellTag){
  956. var bindDirection = cellTag.bindDirection;
  957. if(bindDirection){
  958. if(bindDirection=='col'){
  959. clearBind(sheet,'col',row,col);
  960. }
  961. }
  962. }
  963. }
  964. function showCellBindInfo(sheet,row,col){
  965. $('#rowInfo').hide();$('#colInfo').hide();
  966. $('#info3').show();$('#info2').show();
  967. var cellTag = sheet.getTag(row,col);
  968. var periodDetailName=cellTag.periodDetailName;
  969. var measureName=cellTag.customCode+" "+cellTag.measureName;
  970. var includeTax=cellTag.includeTax;
  971. var expect = cellTag.expect;
  972. var entityName = cellTag.entityName;
  973. $('#timeInput').val(periodDetailName);
  974. $('#goalsInput').val(measureName);
  975. $('#entityInput').val(entityName);
  976. $('input[name="includeTax"]').removeAttr('checked');
  977. $('input[name="includeTax"][value=' + includeTax + ']').attr('checked', 'checked');
  978. $('input[name="expect"]').removeAttr('checked');
  979. $('input[name="expect"][value=' + expect + ']').attr('checked', 'checked');
  980. }
  981. function setEntityRow() {
  982. setEntity('row');
  983. }
  984. function setEntityCol() {
  985. setEntity('col');
  986. }
  987. function setEntity(type){
  988. var sheet = spread.getActiveSheet();
  989. _openDialog('budgetEntityController.do?select','选择预算主体',function(iframe){
  990. var selectRows = iframe.getSelectRows();
  991. var one = selectRows[0];
  992. spread.suspendPaint();
  993. setEntityValue(sheet,type,{entityId:one.id,entityName:one.entityName});
  994. spread.resumePaint();
  995. },'800px','600px');
  996. }
  997. function setEntityValue(sheet,type,valueObj){
  998. var name = valueObj.entityName;
  999. disableBindButton();
  1000. if(type=='row'){
  1001. $('#rowEntityInput').val(name);
  1002. $('#rowEntityBind').show();
  1003. }else {
  1004. $('#colEntityInput').val(name);
  1005. $('#colEntityBind').show();
  1006. }
  1007. beforeBindDim(sheet,type);
  1008. setSelectionTagValue(sheet,'cell',valueObj);
  1009. setSelectionTagValue(sheet,'cell',{bindDirection:type});
  1010. setHeader(sheet,type,valueObj);
  1011. }