settle_ledger.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. function getGxbyText(data) {
  2. const def = thirdParty.gxby.find(function (x) {
  3. return x.value === data.gxby_status;
  4. });
  5. return def ? def.name : '';
  6. }
  7. function getDaglText(data) {
  8. const def = thirdParty.dagl.find(function (x) {
  9. return x.value === data.dagl_status;
  10. });
  11. return def ? def.name : '';
  12. }
  13. const ckBillsSpread = window.location.pathname + '-billsSelect';
  14. $(document).ready(() => {
  15. autoFlashHeight();
  16. let searchLedger, settleAtt;
  17. const settleTreeSetting = {
  18. id: 'tree_id',
  19. pid: 'tree_pid',
  20. order: 'tree_order',
  21. level: 'tree_level',
  22. fullPath: 'tree_full_path',
  23. isLeaf: 'tree_is_leaf',
  24. rootId: -1,
  25. keys: ['id', 'tid', 'tree_id'],
  26. stageId: 'id',
  27. autoExpand: 3,
  28. markExpandKey: 'settle-select-expand',
  29. markExpandSubKey: window.location.pathname.split('/')[2],
  30. calcFields: ['total_price', 'cur_contract_tp', 'cur_qc_tp', 'cur_gather_tp', 'cur_correct_tp'],
  31. calcFun: function(node) {
  32. if (!node.children || node.children.length === 0) {
  33. node.cur_gather_qty = ZhCalc.add(node.cur_contract_qty, node.cur_qc_qty);
  34. if (node.cur_contract_qty) {
  35. node.cur_correct_tp = ZhCalc.add(node.cur_qc_tp, ZhCalc.mul(node.cur_contract_qty, node.unit_price, tenderInfo.decimal.tp));
  36. } else {
  37. node.cur_correct_tp = node.cur_gather_tp;
  38. }
  39. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  40. node.end_gather_qty = ZhCalc.add(node.end_contract_qty, node.end_qc_qty);
  41. if (node.end_contract_qty) {
  42. node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
  43. } else {
  44. node.end_correct_tp = node.end_gather_tp;
  45. }
  46. }
  47. node.cur_gather_tp = ZhCalc.add(node.cur_contract_tp, node.cur_qc_tp);
  48. node.cur_gather_percent = ZhCalc.mul(ZhCalc.div(node.cur_gather_tp, node.cur_final_tp), 100, 2);
  49. node.cur_correct_percent = ZhCalc.mul(ZhCalc.div(node.cur_correct_tp, node.cur_final_tp), 100, 2);
  50. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  51. node.pre_gather_percent = ZhCalc.mul(ZhCalc.div(node.pre_gather_tp, node.pre_final_tp), 100, 2);
  52. node.pre_correct_percent = ZhCalc.mul(ZhCalc.div(node.pre_correct_tp, node.pre_final_tp), 100, 2);
  53. node.end_gather_tp = ZhCalc.add(node.end_contract_tp, node.end_qc_tp);
  54. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  55. node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
  56. }
  57. };
  58. const settleTree = createNewPathTree('stage', settleTreeSetting);
  59. const settlePosSetting = {
  60. id: 'id', ledgerId: 'lid',
  61. calcFun: function(pos) {
  62. pos.cur_gather_qty = ZhCalc.add(pos.cur_contract_qty, pos.cur_qc_qty);
  63. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  64. pos.end_gather_qty = ZhCalc.add(pos.end_contract_qty, pos.end_qc_qty);
  65. }
  66. };
  67. const settlePos = new StagePosData(settlePosSetting);
  68. const slSpread = SpreadJsObj.createNewSpread($('#settle-bills')[0]);
  69. const slSheet = slSpread.getActiveSheet();
  70. slSheet.frozenColumnCount(billsSpreadSetting.cols.findIndex(x => { return x.field === 'total_price'; }) + 1);
  71. slSheet.options.frozenlineColor = '#93b5e4';
  72. const ratioCol = billsSpreadSetting.cols.find(x => {return x.field === 'cur_final_1_percent' || x.field === 'cur_correct_1_percent'});
  73. if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'cur_correct_1_percent' : 'cur_final_1_percent';
  74. billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  75. if (!data) return defaultColor;
  76. if (data.children && data.children.length > 0) return defaultColor;
  77. if (col.field === 'gxby') {
  78. const def = thirdParty.gxby.find(function (x) {
  79. return x.value === data.gxby_status;
  80. });
  81. if (def && def.color) return def.color;
  82. } else if (col.field === 'dagl') {
  83. const def = thirdParty.dagl.find(function (x) {
  84. return x.value === data.dagl_status;
  85. });
  86. if (def && def.color) return def.color;
  87. }
  88. };
  89. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  90. sjsSettingObj.set3FCols(billsSpreadSetting.cols, [
  91. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  92. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  93. ]);
  94. billsSpreadSetting.headColWidth = [50];
  95. billsSpreadSetting.rowHeader = [
  96. {
  97. rowHeaderType: 'tag',
  98. setting: {
  99. indent: 16,
  100. tagSize: 0.8,
  101. tagFont: '8px 微软雅黑',
  102. getColor: function (index, data) {
  103. if (!data) return;
  104. return billsTag.getBillsTagsColor(data.lid);
  105. },
  106. getTagHtml: function (index, data) {
  107. if (!data) return;
  108. const getHtml = function (list) {
  109. if (!list || list.length === 0) return '';
  110. const html = [];
  111. for (const l of list) {
  112. html.push('<div class="row mr-1">');
  113. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  114. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  115. html.push('</div>');
  116. }
  117. return html.join('');
  118. };
  119. return getHtml(billsTag.getBillsTagsInfo(data.lid));
  120. }
  121. },
  122. },
  123. ];
  124. billsSpreadSetting.afterLocate = function (node) {
  125. settleAtt.getCurAttHtml(node);
  126. };
  127. SpreadJsObj.initSheet(slSheet, billsSpreadSetting);
  128. const spSpread = SpreadJsObj.createNewSpread($('#settle-pos')[0]);
  129. const spSheet = spSpread.getActiveSheet();
  130. spSheet.frozenColumnCount(posSpreadSetting.cols.findIndex(x => { return x.field === 'total_price'; }) + 1);
  131. spSheet.options.frozenlineColor = '#93b5e4';
  132. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  133. if (!data) return defaultColor;
  134. if (col.field === 'gxby') {
  135. const def = thirdParty.gxby.find(function (x) {
  136. return x.value === data.gxby_status;
  137. });
  138. if (def && def.color) return def.color;
  139. } else if (col.field === 'dagl') {
  140. const def = thirdParty.dagl.find(function (x) {
  141. return x.value === data.dagl_status;
  142. });
  143. if (def && def.color) return def.color;
  144. }
  145. };
  146. sjsSettingObj.set3FCols(posSpreadSetting.cols, [
  147. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  148. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  149. ]);
  150. SpreadJsObj.initSheet(spSheet, posSpreadSetting);
  151. const settleBillsObj = {
  152. loadRelaData: function() {
  153. SpreadJsObj.saveTopAndSelect(slSheet, ckBillsSpread);
  154. SpreadJsObj.resetTopAndSelect(spSheet);
  155. settleBillsObj.loadRelaAtt();
  156. settlePosObj.loadCurPosData();
  157. },
  158. selectionChanged: function(e, info) {
  159. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  160. settleBillsObj.loadRelaData();
  161. }
  162. },
  163. topRowChanged(e, info) {
  164. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  165. },
  166. loadRelaAtt() {
  167. const node = SpreadJsObj.getSelectObject(slSheet);
  168. settleAtt.getCurAttHtml(node);
  169. }
  170. };
  171. slSpread.bind(spreadNS.Events.SelectionChanged, settleBillsObj.selectionChanged);
  172. slSpread.bind(spreadNS.Events.TopRowChanged, settleBillsObj.topRowChanged);
  173. const settlePosObj = {
  174. loadCurPosData: function() {
  175. const billsNode = SpreadJsObj.getSelectObject(slSheet);
  176. if (billsNode) {
  177. spSheet.zh_setting.readOnly = readOnly;
  178. const posRange = settlePos.getLedgerPos(billsNode.lid) || [];
  179. SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, posRange, readOnly);
  180. } else {
  181. spSheet.zh_setting.readOnly = true;
  182. SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, [], true);
  183. }
  184. }
  185. };
  186. const billsTag = $.billsTag({
  187. relaTree: settleTree,
  188. selector: '#bills-tag',
  189. relaSpread: slSpread,
  190. updateUrl: window.location.pathname + '/tag',
  191. key: 'lid',
  192. treeId: 'tree_id',
  193. afterModify: function (nodes) {
  194. SpreadJsObj.repaintNodesRowHeader(slSheet, nodes);
  195. },
  196. afterLocated: function () {
  197. settlePosObj.loadCurPosData();
  198. },
  199. afterShow: function () {
  200. slSpread.refresh();
  201. if (spSpread) spSpread.refresh();
  202. },
  203. });
  204. const addTag = newTag({ledgerSheet: slSheet, billsTag, key: 'lid'});
  205. $.contextMenu({
  206. selector: '#settle-bills',
  207. build: function ($trigger, e) {
  208. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  209. settleBillsObj.loadRelaData();
  210. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  211. },
  212. items: {
  213. tag: {
  214. name: '书签',
  215. callback: function (key, opt, menu, e) {
  216. const node = SpreadJsObj.getSelectObject(slSheet);
  217. addTag.do(node);
  218. },
  219. disabled: function (key, opt) {
  220. const node = SpreadJsObj.getSelectObject(slSheet);
  221. return !node;
  222. }
  223. }
  224. }
  225. });
  226. postData('load', {filter: 'settleBills;settlePos;tag;att'}, function(result) {
  227. settleTree.loadDatas(result.settleBills);
  228. treeCalc.calculateAll(settleTree);
  229. settlePos.loadDatas(result.settlePos);
  230. settlePos.calculateAll();
  231. for (const t of result.tag) {
  232. t.node = settleTree.nodes.find(x => {return x.lid === t.lid});
  233. }
  234. billsTag.loadDatas(result.tag);
  235. SpreadJsObj.loadSheetData(slSheet, SpreadJsObj.DataType.Tree, settleTree);
  236. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  237. settlePosObj.loadCurPosData();
  238. for (const r of result.att) {
  239. r.node = settleTree.datas.find(x => {return x.lid === r.lid});
  240. }
  241. settleAtt = $.ledger_att({
  242. selector: '#fujian',
  243. key: 'lid',
  244. uploadUrl: 'file/upload',
  245. deleteUrl: 'file/delete',
  246. checked: settleComplete,
  247. zipName: `${tenderName}-计量台账-第${settleOrder}期-附件.zip`,
  248. readOnly: false, // todo fileUploadPermission,
  249. locate: function (att) {
  250. if (!att) return;
  251. SpreadJsObj.locateTreeNode(slSheet, att.node.tree_id, true);
  252. settleBillsObj.loadRelaAtt();
  253. settlePosObj.loadCurPosData();
  254. }
  255. });
  256. settleAtt.loadDatas(result.att);
  257. settleAtt.getCurAttHtml(SpreadJsObj.getSelectObject(slSheet));
  258. });
  259. // 展开收起工具栏
  260. $('a', '.right-nav').bind('click', function () {
  261. const tab = $(this), tabPanel = $(tab.attr('content'));
  262. if (!tab.hasClass('active')) {
  263. $('a', '.side-menu').removeClass('active');
  264. $('.tab-content .tab-select-show').removeClass('active');
  265. tab.addClass('active');
  266. tabPanel.addClass('active');
  267. showSideTools(tab.hasClass('active'));
  268. if (tab.attr('content') === '#search' && !searchLedger) {
  269. searchLedger = $.billsSearch({
  270. selector: '#search',
  271. searchSpread: slSpread,
  272. searchOver: true,
  273. searchEmpty: true,
  274. keyId: 'tree_id',
  275. resultSpreadSetting: {
  276. cols: [
  277. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  278. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  279. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  280. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  281. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  282. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  283. ],
  284. emptyRows: 0,
  285. headRows: 1,
  286. headRowHeight: [32],
  287. headColWidth: [30],
  288. defaultRowHeight: 21,
  289. headerFont: '12px 微软雅黑',
  290. font: '12px 微软雅黑',
  291. selectedBackColor: '#fffacd',
  292. readOnly: true,
  293. },
  294. afterLocated: function () {
  295. settlePosObj.loadCurPosData();
  296. },
  297. });
  298. searchLedger.spread.refresh();
  299. }
  300. } else {
  301. tab.removeClass('active');
  302. tabPanel.removeClass('active');
  303. showSideTools(tab.hasClass('active'));
  304. }
  305. slSpread.refresh();
  306. spSpread.refresh();
  307. });
  308. $.subMenu({
  309. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  310. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  311. key: 'menu.1.0.0',
  312. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  313. callback: function (info) {
  314. if (info.mini) {
  315. $('.panel-title').addClass('fluid');
  316. $('#sub-menu').removeClass('panel-sidebar');
  317. } else {
  318. $('.panel-title').removeClass('fluid');
  319. $('#sub-menu').addClass('panel-sidebar');
  320. }
  321. autoFlashHeight();
  322. }
  323. });
  324. // 加载上下窗口resizer
  325. $.divResizer({
  326. select: '#main-resize',
  327. callback: function () {
  328. slSpread.refresh();
  329. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  330. $(".sp-wrap").height(bcontent-30);
  331. spSpread.refresh();
  332. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  333. }
  334. });
  335. // 工具栏resizer
  336. $.divResizer({
  337. select: '#right-spr',
  338. callback: function () {
  339. slSpread.refresh();
  340. spSpread.refresh();
  341. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  342. if (searchLedger) searchLedger.spread.refresh();
  343. }
  344. });
  345. // 显示层次
  346. (function (select, sheet) {
  347. $(select).click(function () {
  348. const tag = $(this).attr('tag');
  349. const tree = sheet.zh_tree;
  350. if (!tree) return;
  351. setTimeout(() => {
  352. showWaitingView();
  353. switch (tag) {
  354. case "1":
  355. case "2":
  356. case "3":
  357. case "4":
  358. case "5":
  359. tree.expandByLevel(parseInt(tag));
  360. SpreadJsObj.refreshTreeRowVisible(sheet);
  361. break;
  362. case "last":
  363. tree.expandByCustom(() => { return true; });
  364. SpreadJsObj.refreshTreeRowVisible(sheet);
  365. break;
  366. }
  367. closeWaitingView();
  368. }, 100);
  369. });
  370. })('a[name=showLevel]', slSheet);
  371. });