budgetTempSheet-leader.js 47 KB

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