budget_compare.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. 'use strict';
  2. /**
  3. * 从cookie中读取缓存的列显示设置,没有则取默认
  4. * @returns {*[]}
  5. */
  6. function customColDisplay () {
  7. const defaultSetting = [
  8. { title: '投资估算', fields: ['gu_dgn_qty', 'gu_dgn_price', 'gu_tp'], visible: true },
  9. { title: '设计概算', fields: ['gai_dgn_qty', 'gai_dgn_price', 'gai_tp'], visible: true },
  10. { title: '施工图预算', fields: ['yu_dgn_qty', 'yu_dgn_price', 'yu_tp'], visible: true },
  11. { title: '招标预算', fields: ['zb_dgn_qty', 'zb_dgn_price', 'zb_tp'], visible: true },
  12. { title: '台账', fields: ['dgn_qty', 'dgn_price', 'total_price'], visible: true },
  13. { title: '预估决算', fields: ['final_dgn_qty', 'final_dgn_price', 'final_tp'], visible: true },
  14. ];
  15. const settingStr = Cookies.get(ckColSetting);
  16. if (settingStr) {
  17. const customSetting = JSON.parse(settingStr);
  18. for (const ds of defaultSetting) {
  19. const cs = customSetting.find(x => {return x.title === ds.title});
  20. if (cs) ds.visible = cs.visible;
  21. }
  22. }
  23. return defaultSetting;
  24. }
  25. /**
  26. * 根据列显示设置,调整setting中的列是否显示
  27. * @param setting
  28. * @param customDisplay
  29. */
  30. function customizeTreeSetting(setting, customDisplay) {
  31. for (const cd of customDisplay) {
  32. for (const c of setting.cols) {
  33. if (cd.fields.indexOf(c.field) !== -1) {
  34. c.visible = c.defaultVisible === undefined ? cd.visible : c.defaultVisible && cd.visible;
  35. }
  36. }
  37. }
  38. }
  39. $(document).ready(() => {
  40. const compareTypeKey = 'budget-compareType';
  41. const stackedBarCoverKey = 'budget-stackedBarCover';
  42. const stackedBarKey = 'budget-stackedBar';
  43. autoFlashHeight();
  44. const compareSpread = SpreadJsObj.createNewSpread($('#cost-compare')[0]);
  45. const compareSheet = compareSpread.getActiveSheet();
  46. const getStackedBarTip = function (data) {
  47. return data.stackedBarTips.join('\n');
  48. };
  49. const spreadSetting = {
  50. cols: [
  51. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  52. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  53. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'unit'},
  54. {title: '投资估算|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'gu_dgn_qty', hAlign: 2, width: 80, bc_type: 'number'},
  55. {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'gu_dgn_price', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},
  56. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gu_tp', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},
  57. {title: '设计概算|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'gai_dgn_qty', hAlign: 2, width: 80, bc_type: 'number'},
  58. {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'gai_dgn_price', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},
  59. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gai_tp', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},
  60. {title: '施工图预算|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'yu_dgn_qty', hAlign: 2, width: 80, bc_type: 'number'},
  61. {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'yu_dgn_price', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},
  62. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'yu_tp', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},
  63. {title: '招标预算|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'zb_dgn_qty', hAlign: 2, width: 80, bc_type: 'number'},
  64. {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'zb_dgn_price', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},
  65. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'zb_tp', hAlign: 2, width: 80, type: 'Number', bc_type: 'number'},
  66. {title: '台账|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'dgn_qty', hAlign: 2, width: 80, bc_type: 'number', visible: false},
  67. {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'dgn_price', hAlign: 2, width: 80, type: 'Number', bc_type: 'number', visible: false},
  68. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 80, type: 'Number', bc_type: 'number', visible: false},
  69. {title: '预估决算|数量1/数量2', colSpan: '3|1', rowSpan: '1|1', field: 'final_dgn_qty', hAlign: 2, width: 80, bc_type: 'number', visible: false},
  70. {title: '|经济指标', colSpan: '|1', rowSpan: '|1', field: 'final_dgn_price', hAlign: 2, width: 80, type: 'Number', bc_type: 'number', visible: false},
  71. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'final_tp', hAlign: 2, width: 80, type: 'Number', bc_type: 'number', visible: false},
  72. {title: '数据对比', colSpan: '1', rowSpan: '2', field: 'stackedBar', hAlign: 0, width: 300, cellType: 'stackedBar', stackedBarCover: false, bc_type: 'grid', visible: false, getTip: getStackedBarTip},
  73. {title: '增幅%|数量1/数量2', colSpan: '2|1', rowSpan: '1|1', field: 'grow_dgn_qty', hAlign: 2, width: 80},
  74. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'grow_tp', hAlign: 2, width: 80, type: 'Number'},
  75. ],
  76. emptyRows: 0,
  77. headRows: 2,
  78. headRowHeight: [25, 25],
  79. defaultRowHeight: 21,
  80. headerFont: '12px 微软雅黑',
  81. font: '12px 微软雅黑',
  82. readOnly: true,
  83. frozenColCount: 3,
  84. frozenLineColor: '#93b5e4',
  85. localCache: { key: 'budget-compare', colWidth: true },
  86. };
  87. sjsSettingObj.setFxTreeStyle(spreadSetting, sjsSettingObj.FxTreeStyle.jz);
  88. let sfSelect;
  89. const compareObj = {
  90. curFinalId() {
  91. return this.finalInfo ? this.finalInfo.id : undefined;
  92. },
  93. initFinalCol() {
  94. const finalColField = ['dgn_qty', 'dgn_price', 'total_price', 'final_dgn_qty', 'final_dgn_price', 'final_tp', 'grow_dgn_qty', 'grow_tp'];
  95. const finalCol = spreadSetting.cols.filter(x => { return finalColField.indexOf(x.field) >= 0; });
  96. if (finalCol.length > 0 && !finalCol[0].visible) {
  97. finalCol.forEach(x => { x.visible = true; });
  98. this.initShowType();
  99. SpreadJsObj.refreshColumnVisible(compareSheet);
  100. }
  101. },
  102. initShowType() {
  103. const type = this.compareType;
  104. spreadSetting.cols.forEach(x => {
  105. if (!x.bc_type) return;
  106. x.visible = x.bc_type === type;
  107. });
  108. const colIndex = spreadSetting.cols.findIndex(x => { return x.field === 'stackedBar'});
  109. spreadSetting.cols[colIndex].stackedBarCover = parseInt(this.stackedBarCover);
  110. },
  111. expand(tree, tag) {
  112. switch (tag) {
  113. case "1":
  114. case "2":
  115. case "3":
  116. case "4":
  117. case "5":
  118. tree.expandByLevel(parseInt(tag));
  119. break;
  120. case "last":
  121. tree.expandByCustom(() => { return true; });
  122. break;
  123. }
  124. },
  125. calcStackedBar(tree) {
  126. const calcField = this.stackedBarField;
  127. const calcFieldColor = { 'gu_tp': '#657798', 'gai_tp': '#EE6666', 'yu_tp': '#74CBED', 'total_price': '#FAC858', 'final_tp': '#62DAAB' };
  128. const calcFieldCaption = { 'gu_tp': '估算', 'gai_tp': '概算', 'yu_tp': '预算', 'total_price': '台账', 'final_tp': '决算' };
  129. const calc = function(node, base){
  130. // const parent = tree.getParent(node);
  131. // if (!parent) {
  132. // base = 0;
  133. // for (const cf of calcField) {
  134. // base = Math.max(node[cf], base);
  135. // }
  136. // }
  137. node.stackedBar = [];
  138. node.stackedBarTips = [];
  139. for (const cf of calcField) {
  140. node.stackedBar.push({color: calcFieldColor[cf], percent: ZhCalc.div(node[cf], base), field: cf});
  141. node.stackedBarTips.push(`${calcFieldCaption[cf]}: ${node[cf] || 0}`);
  142. }
  143. if (node.children) {
  144. for (const child of node.children) {
  145. calc(child, base);
  146. }
  147. }
  148. };
  149. let commonBase = 0;
  150. tree.children.forEach(x => {
  151. for (const cf of calcField) {
  152. commonBase = Math.max(x[cf] || 0, commonBase);
  153. }
  154. });
  155. for (const child of tree.children) {
  156. calc(child, commonBase);
  157. }
  158. },
  159. loadBudgetData(result) {
  160. const compareTree = createNewPathTree('final', {
  161. id: 'id',
  162. pid: 'pid',
  163. order: 'order',
  164. level: 'level',
  165. rootId: -1,
  166. });
  167. const setting = { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] };
  168. const guTree = createNewPathTree('ledger', setting);
  169. guTree.loadDatas(result.gu);
  170. treeCalc.calculateAll(guTree);
  171. compareTree.loadTree(guTree, function (cur, source) {
  172. cur.base = true;
  173. cur.gu_dgn_qty1 = ZhCalc.add(cur.gu_dgn_qty1, source.dgn_qty1);
  174. cur.gu_dgn_qty2 = ZhCalc.add(cur.gu_dgn_qty2, source.dgn_qty2);
  175. cur.gu_tp = ZhCalc.add(cur.gu_tp, source.total_price);
  176. });
  177. const gaiTree = createNewPathTree('ledger', setting);
  178. gaiTree.loadDatas(result.gai);
  179. treeCalc.calculateAll(gaiTree);
  180. compareTree.loadTree(gaiTree, function (cur, source) {
  181. cur.base = true;
  182. cur.gai_dgn_qty1 = ZhCalc.add(cur.gai_dgn_qty1, source.dgn_qty1);
  183. cur.gai_dgn_qty2 = ZhCalc.add(cur.gai_dgn_qty2, source.dgn_qty2);
  184. cur.gai_tp = ZhCalc.add(cur.gai_tp, source.total_price);
  185. });
  186. const yuTree = createNewPathTree('ledger', setting);
  187. yuTree.loadDatas(result.yu);
  188. treeCalc.calculateAll(yuTree);
  189. compareTree.loadTree(yuTree, function (cur, source) {
  190. cur.base = true;
  191. cur.yu_dgn_qty1 = ZhCalc.add(cur.yu_dgn_qty1, source.dgn_qty1);
  192. cur.yu_dgn_qty2 = ZhCalc.add(cur.yu_dgn_qty2, source.dgn_qty2);
  193. cur.yu_tp = ZhCalc.add(cur.yu_tp, source.total_price);
  194. });
  195. const zbTree = createNewPathTree('ledger', setting);
  196. zbTree.loadDatas(result.zb);
  197. treeCalc.calculateAll(zbTree);
  198. compareTree.loadTree(zbTree, function (cur, source) {
  199. cur.base = true;
  200. cur.zb_dgn_qty1 = ZhCalc.add(cur.zb_dgn_qty1, source.dgn_qty1);
  201. cur.zb_dgn_qty2 = ZhCalc.add(cur.zb_dgn_qty2, source.dgn_qty2);
  202. cur.zb_tp = ZhCalc.add(cur.zb_tp, source.total_price);
  203. });
  204. compareTree.afterLoad(node => {
  205. node.gu_dgn_price = ZhCalc.div(node.gu_tp, node.gu_dgn_qty1, 2);
  206. node.gu_dgn_qty = node.gu_dgn_qty1
  207. ? (node.gu_dgn_qty2 ? node.gu_dgn_qty1 + '/' + node.gu_dgn_qty2 : node.gu_dgn_qty1)
  208. : (node.gu_dgn_qty2 ? '/' + node.gu_dgn_qty2 : '');
  209. node.gai_dgn_price = ZhCalc.div(node.gai_tp, node.gai_dgn_qty1, 2);
  210. node.gai_dgn_qty = node.gai_dgn_qty1
  211. ? (node.gai_dgn_qty2 ? node.gai_dgn_qty1 + '/' + node.gai_dgn_qty2 : node.gai_dgn_qty1)
  212. : (node.gai_dgn_qty2 ? '/' + node.gai_dgn_qty2 : '');
  213. node.yu_dgn_price = ZhCalc.div(node.yu_tp, node.yu_dgn_qty1, 2);
  214. node.yu_dgn_qty = node.yu_dgn_qty1
  215. ? (node.yu_dgn_qty2 ? node.yu_dgn_qty1 + '/' + node.yu_dgn_qty2 : node.yu_dgn_qty1)
  216. : (node.yu_dgn_qty2 ? '/' + node.yu_dgn_qty2 : '');
  217. node.zb_dgn_price = ZhCalc.div(node.zb_tp, node.zb_dgn_qty1, 2);
  218. node.zb_dgn_qty = node.zb_dgn_qty1
  219. ? (node.zb_dgn_qty2 ? node.zb_dgn_qty1 + '/' + node.zb_dgn_qty2 : node.zb_dgn_qty1)
  220. : (node.zb_dgn_qty2 ? '/' + node.zb_dgn_qty2 : '');
  221. });
  222. compareTree.resortChildrenByCustom(function (x, y) {
  223. const iCode = compareCode(x.code, y.code);
  224. if (iCode) return iCode;
  225. if (!x.name) return -1;
  226. if (!y.name) return 1;
  227. return x.name.localeCompare(y.name);
  228. });
  229. const expandTag = getLocalCache('revise-compare-level');
  230. if (expandTag) compareObj.expand(compareTree, expandTag);
  231. this.calcStackedBar(compareTree);
  232. SpreadJsObj.loadSheetData(compareSheet, SpreadJsObj.DataType.Tree, compareTree);
  233. },
  234. loadFinalData(result, msg) {
  235. if (msg) toastr.warning(msg);
  236. this.finalInfo = result.finalInfo;
  237. $('#final-info').html(`${moment(result.finalInfo.update_time).format('YYYY-MM-DD HH:mm:ss')} ${result.finalInfo.u_name}(${result.finalInfo.u_role})`);
  238. this.initFinalCol();
  239. const finalTree = createNewPathTree('ledger', {
  240. id: 'tree_id',
  241. pid: 'tree_pid',
  242. order: 'order',
  243. level: 'level',
  244. rootId: -1,
  245. });
  246. finalTree.loadDatas(result.final);
  247. const expandTag = getLocalCache('revise-compare-level');
  248. if (expandTag) compareObj.expand(finalTree, expandTag);
  249. this.calcStackedBar(finalTree);
  250. SpreadJsObj.loadSheetData(compareSheet, SpreadJsObj.DataType.Tree, finalTree);
  251. if (sfSelect) sfSelect.reloadSelect(this.finalInfo.tender);
  252. },
  253. loadCacheData(){
  254. let stackedBarCache = getLocalCache(stackedBarKey);
  255. if (stackedBarCache === null) stackedBarCache = 'gai_tp,total_price,final_tp';
  256. this.setStackedBarField(stackedBarCache ? stackedBarCache.split(',') : []);
  257. this.setCompareType(getLocalCache(compareTypeKey));
  258. this.setStackedBarCover(getLocalCache(stackedBarCoverKey));
  259. this.initShowType();
  260. },
  261. setStackedBarField(field){
  262. this.stackedBarField = field;
  263. setLocalCache(stackedBarKey, field.join(','));
  264. if (compareSheet.zh_tree) this.calcStackedBar(compareSheet.zh_tree);
  265. const colIndex = spreadSetting.cols.findIndex(x => { return x.field === 'stackedBar'});
  266. SpreadJsObj.reloadColData(compareSheet, colIndex);
  267. },
  268. setCompareType(type) {
  269. this.compareType = type || 'number';
  270. $('[name=showType]').removeClass('active');
  271. $(`[tag=${this.compareType}]`).addClass('active');
  272. if (this.compareType === 'grid') {
  273. $('.ml-grid').show();
  274. $('.ml-number').hide();
  275. } else {
  276. $('.ml-grid').hide();
  277. $('.ml-number').show();
  278. }
  279. spreadSetting.cols.forEach(x => {
  280. if (!x.bc_type) return;
  281. x.visible = x.bc_type === type;
  282. });
  283. setLocalCache(compareTypeKey, this.compareType);
  284. },
  285. setStackedBarCover(cover){
  286. this.stackedBarCover = '1'; //cover || '1';
  287. const colIndex = spreadSetting.cols.findIndex(x => { return x.field === 'stackedBar'});
  288. spreadSetting.cols[colIndex].stackedBarCover = parseInt(this.stackedBarCover);
  289. SpreadJsObj.reloadColData(compareSheet, colIndex);
  290. setLocalCache(stackedBarCoverKey, this.stackedBarCover);
  291. }
  292. };
  293. compareObj.loadCacheData();
  294. SpreadJsObj.initSheet(compareSheet, spreadSetting);
  295. function compareCode(str1, str2, symbol = '-') {
  296. if (!str1) {
  297. return 1;
  298. } else if (!str2) {
  299. return -1;
  300. }
  301. function compareSubCode(code1, code2) {
  302. if (numReg.test(code1)) {
  303. if (numReg.test(code2)) {
  304. return parseInt(code1) - parseInt(code2);
  305. } else {
  306. return -1
  307. }
  308. } else {
  309. if (numReg.test(code2)) {
  310. return 1;
  311. } else {
  312. return code1 === code2 ? 0 : (code1 < code2 ? -1 : 1); //code1.localeCompare(code2);
  313. }
  314. }
  315. }
  316. const numReg = /^[0-9]+$/;
  317. const aCodes = str1.split(symbol), bCodes = str2.split(symbol);
  318. for (let i = 0, iLength = Math.min(aCodes.length, bCodes.length); i < iLength; ++i) {
  319. const iCompare = compareSubCode(aCodes[i], bCodes[i]);
  320. if (iCompare !== 0) {
  321. return iCompare;
  322. }
  323. }
  324. return aCodes.length - bCodes.length;
  325. }
  326. postData(window.location.pathname + '/load', {}, function (result, msg) {
  327. if (result.final) {
  328. compareObj.loadFinalData(result, msg);
  329. } else {
  330. compareObj.loadBudgetData(result);
  331. }
  332. });
  333. $.subMenu({
  334. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  335. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  336. key: 'menu.1.0.0',
  337. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  338. callback: function (info) {
  339. if (info.mini) {
  340. $('.panel-title').addClass('fluid');
  341. $('#sub-menu').removeClass('panel-sidebar');
  342. } else {
  343. $('.panel-title').removeClass('fluid');
  344. $('#sub-menu').addClass('panel-sidebar');
  345. }
  346. autoFlashHeight();
  347. compareSpread.refresh();
  348. }
  349. });
  350. // 显示层次
  351. (function (select, sheet) {
  352. $(select).click(function () {
  353. if (!sheet.zh_tree) return;
  354. const tag = $(this).attr('tag');
  355. const tree = sheet.zh_tree;
  356. setTimeout(() => {
  357. showWaitingView();
  358. compareObj.expand(tree, tag);
  359. SpreadJsObj.refreshTreeRowVisible(sheet);
  360. setLocalCache('revise-compare-level', tag);
  361. closeWaitingView();
  362. }, 100);
  363. });
  364. })('a[name=showLevel]', compareSheet);
  365. class sfObject {
  366. constructor() {
  367. const self = this;
  368. this.selectTree = Tender2Tree.convert(category, tenderList, null, null, function (node, source) {
  369. node.lastStageOrder =`第${source.lastStageOrder}期`;
  370. node.lastStageStatus = source.lastStageStatus;
  371. });
  372. if (compareObj.finalInfo) {
  373. this.selectTree.datas.forEach(x => {
  374. x.selected = compareObj.finalInfo.tender.indexOf(x.tid + '') >= 0;
  375. })
  376. }
  377. const sfSpreadSetting = {
  378. cols: [
  379. {title: '选择', field: 'selected', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox'},
  380. {title: '名称', field: 'name', hAlign: 0, width: 180, formatter: '@', cellType: 'tree'},
  381. {title: '期数', field: 'lastStageOrder', hAlign: 1, width: 60, formatter: '@'},
  382. {title: '审批状态', field: 'lastStageStatus', hAlign: 1, width: 60, formatter: '@'},
  383. ],
  384. emptyRows: 0,
  385. headRows: 1,
  386. headRowHeight: [32],
  387. defaultRowHeight: 21,
  388. headerFont: '12px 微软雅黑',
  389. font: '12px 微软雅黑',
  390. headColWidth: [30],
  391. selectedBackColor: '#fffacd',
  392. readOnly: true,
  393. };
  394. this.spread = SpreadJsObj.createNewSpread($('#sf-spread')[0]);
  395. this.sheet = this.spread.getActiveSheet();
  396. SpreadJsObj.initSheet(this.sheet, sfSpreadSetting);
  397. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.selectTree);
  398. this.spread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  399. if (!info.sheet.zh_setting) return;
  400. const col = info.sheet.zh_setting.cols[info.col];
  401. if (col.field !== 'selected') return;
  402. const node = SpreadJsObj.getSelectObject(info.sheet);
  403. self.selectNode(node, !node[col.field]);
  404. SpreadJsObj.reloadColData(info.sheet, 0);
  405. });
  406. $('#sf-select-all').click(function() {
  407. for (const n of self.selectTree.nodes) {
  408. n.selected = this.checked;
  409. }
  410. SpreadJsObj.reloadColData(self.sheet, 0);
  411. });
  412. $('#select-final-ok').click(() => {
  413. const rela = self.getSelects();
  414. if (rela.length === 0) return;
  415. postData(window.location.pathname + '/final', {final_id: compareObj.curFinalId(), id: rela}, function(result, msg) {
  416. compareObj.loadFinalData(result, msg);
  417. $('#select-final').modal('hide');
  418. });
  419. });
  420. }
  421. reloadSelect(select) {
  422. if (compareObj.finalInfo) {
  423. this.selectTree.datas.forEach(x => {
  424. x.selected = select.indexOf(x.tid + '') >= 0;
  425. })
  426. }
  427. SpreadJsObj.reloadColData(this.sheet, 0);
  428. }
  429. selectNode(node, select) {
  430. const posterity = this.selectTree.getPosterity(node);
  431. posterity.unshift(node);
  432. for (const p of posterity) {
  433. p.selected = select;
  434. }
  435. }
  436. getSelects() {
  437. const select = [];
  438. for (const n of this.selectTree.nodes) {
  439. if ((!n.children || n.children.length === 0) && n.selected) select.push(n.tid);
  440. }
  441. return select;
  442. }
  443. }
  444. $('#select-final').on('shown.bs.modal', () => {
  445. if (!sfSelect) sfSelect = new sfObject();
  446. });
  447. $('#stackedBar-ok').click(function() {
  448. const checked = $('[name=stackedBar]:checked');
  449. const field = [];
  450. checked.each((i, x) => { field.push(x.value)});
  451. compareObj.setStackedBarField(field);
  452. });
  453. $('#dp-stackedBar').click(function() {
  454. const field = compareObj.stackedBarField;
  455. const checked = $('[name=stackedBar]');
  456. checked.each((i, x) => { x.checked = field.indexOf(x.value) >= 0; });
  457. });
  458. $('a[name=showType]').click(function () {
  459. const type = this.getAttribute('tag');
  460. compareObj.setCompareType(type);
  461. SpreadJsObj.refreshColumnVisible(compareSheet);
  462. });
  463. $('a[name=stackedBarCover]').click(function() {
  464. const cover = this.getAttribute('tag');
  465. compareObj.setStackedBarCover(cover);
  466. });
  467. $('#dp-cover').click(function() {
  468. const cover = compareObj.stackedBarCover;
  469. const checked = $('a[name=stackedBarCover]');
  470. checked.each((i, x) => {
  471. if (x.getAttribute('tag') === cover) {
  472. $('i', x).addClass('text-primary').removeClass('text-white');
  473. } else {
  474. $('i', x).removeClass('text-primary').addClass('text-white');
  475. }
  476. });
  477. });
  478. $('#row-view').on('show.bs.modal', function () {
  479. const html = [], customDisplay = customColDisplay();
  480. for (const cd of customDisplay) {
  481. html.push('<tr>');
  482. html.push('<td>', cd.title, '</td>');
  483. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  484. html.push('</tr>');
  485. }
  486. $('#row-view-list').html(html.join(''));
  487. });
  488. $('#row-view-ok').click(function () {
  489. const customDisplay = customColDisplay();
  490. const cvl = $('#row-view-list').children();
  491. for (const cv of cvl) {
  492. const title = $(cv).children()[0].innerHTML;
  493. const check = $('input', cv)[0].checked;
  494. const cd = customDisplay.find(function (c) {
  495. return c.title === title;
  496. });
  497. cd.visible = check;
  498. }
  499. customizeTreeSetting(spreadSetting, customDisplay);
  500. SpreadJsObj.refreshColumnVisible(compareSheet);
  501. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  502. $('#row-view').modal('hide');
  503. });
  504. });