budget_compare.js 29 KB

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