settle_ledger.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. selector: '#bills-tag',
  188. relaSpread: slSpread,
  189. updateUrl: window.location.pathname + '/tag',
  190. key: 'lid',
  191. treeId: 'tree_id',
  192. afterModify: function (nodes) {
  193. SpreadJsObj.repaintNodesRowHeader(slSheet, nodes);
  194. },
  195. afterLocated: function () {
  196. settlePosObj.loadCurPosData();
  197. },
  198. afterShow: function () {
  199. slSpread.refresh();
  200. if (spSpread) spSpread.refresh();
  201. },
  202. });
  203. const addTag = newTag({ledgerSheet: slSheet, billsTag, key: 'lid'});
  204. $.contextMenu({
  205. selector: '#settle-bills',
  206. build: function ($trigger, e) {
  207. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  208. settleBillsObj.loadRelaData();
  209. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  210. },
  211. items: {
  212. tag: {
  213. name: '书签',
  214. callback: function (key, opt, menu, e) {
  215. const node = SpreadJsObj.getSelectObject(slSheet);
  216. addTag.do(node);
  217. },
  218. disabled: function (key, opt) {
  219. const node = SpreadJsObj.getSelectObject(slSheet);
  220. return !node;
  221. }
  222. }
  223. }
  224. });
  225. postData('load', {filter: 'settleBills;settlePos;tag;att'}, function(result) {
  226. settleTree.loadDatas(result.settleBills);
  227. treeCalc.calculateAll(settleTree);
  228. settlePos.loadDatas(result.settlePos);
  229. settlePos.calculateAll();
  230. for (const t of result.tag) {
  231. t.node = settleTree.nodes.find(x => {return x.lid === t.lid});
  232. }
  233. billsTag.loadDatas(result.tag);
  234. SpreadJsObj.loadSheetData(slSheet, SpreadJsObj.DataType.Tree, settleTree);
  235. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  236. settlePosObj.loadCurPosData();
  237. for (const r of result.att) {
  238. r.node = settleTree.datas.find(x => {return x.lid === r.lid});
  239. }
  240. settleAtt = $.ledger_att({
  241. selector: '#fujian',
  242. key: 'lid',
  243. uploadUrl: 'file/upload',
  244. deleteUrl: 'file/delete',
  245. checked: settleComplete,
  246. zipName: `${tenderName}-计量台账-第${settleOrder}期-附件.zip`,
  247. readOnly: false, // todo fileUploadPermission,
  248. locate: function (att) {
  249. if (!att) return;
  250. SpreadJsObj.locateTreeNode(slSheet, att.node.tree_id, true);
  251. settleBillsObj.loadRelaAtt();
  252. settlePosObj.loadCurPosData();
  253. }
  254. });
  255. settleAtt.loadDatas(result.att);
  256. settleAtt.getCurAttHtml(SpreadJsObj.getSelectObject(slSheet));
  257. });
  258. // 展开收起工具栏
  259. $('a', '.right-nav').bind('click', function () {
  260. const tab = $(this), tabPanel = $(tab.attr('content'));
  261. if (!tab.hasClass('active')) {
  262. $('a', '.side-menu').removeClass('active');
  263. $('.tab-content .tab-select-show').removeClass('active');
  264. tab.addClass('active');
  265. tabPanel.addClass('active');
  266. showSideTools(tab.hasClass('active'));
  267. if (tab.attr('content') === '#search' && !searchLedger) {
  268. searchLedger = $.billsSearch({
  269. selector: '#search',
  270. searchSpread: slSpread,
  271. searchOver: true,
  272. searchEmpty: true,
  273. keyId: 'tree_id',
  274. resultSpreadSetting: {
  275. cols: [
  276. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  277. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  278. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  279. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  280. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  281. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  282. ],
  283. emptyRows: 0,
  284. headRows: 1,
  285. headRowHeight: [32],
  286. headColWidth: [30],
  287. defaultRowHeight: 21,
  288. headerFont: '12px 微软雅黑',
  289. font: '12px 微软雅黑',
  290. selectedBackColor: '#fffacd',
  291. readOnly: true,
  292. },
  293. afterLocated: function () {
  294. settlePosObj.loadCurPosData();
  295. },
  296. });
  297. searchLedger.spread.refresh();
  298. }
  299. } else {
  300. tab.removeClass('active');
  301. tabPanel.removeClass('active');
  302. showSideTools(tab.hasClass('active'));
  303. }
  304. slSpread.refresh();
  305. spSpread.refresh();
  306. });
  307. $.subMenu({
  308. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  309. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  310. key: 'menu.1.0.0',
  311. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  312. callback: function (info) {
  313. if (info.mini) {
  314. $('.panel-title').addClass('fluid');
  315. $('#sub-menu').removeClass('panel-sidebar');
  316. } else {
  317. $('.panel-title').removeClass('fluid');
  318. $('#sub-menu').addClass('panel-sidebar');
  319. }
  320. autoFlashHeight();
  321. }
  322. });
  323. // 加载上下窗口resizer
  324. $.divResizer({
  325. select: '#main-resize',
  326. callback: function () {
  327. slSpread.refresh();
  328. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  329. $(".sp-wrap").height(bcontent-30);
  330. spSpread.refresh();
  331. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  332. }
  333. });
  334. // 工具栏resizer
  335. $.divResizer({
  336. select: '#right-spr',
  337. callback: function () {
  338. slSpread.refresh();
  339. spSpread.refresh();
  340. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  341. if (searchLedger) searchLedger.spread.refresh();
  342. }
  343. });
  344. // 显示层次
  345. (function (select, sheet) {
  346. $(select).click(function () {
  347. const tag = $(this).attr('tag');
  348. const tree = sheet.zh_tree;
  349. if (!tree) return;
  350. setTimeout(() => {
  351. showWaitingView();
  352. switch (tag) {
  353. case "1":
  354. case "2":
  355. case "3":
  356. case "4":
  357. case "5":
  358. tree.expandByLevel(parseInt(tag));
  359. SpreadJsObj.refreshTreeRowVisible(sheet);
  360. break;
  361. case "last":
  362. tree.expandByCustom(() => { return true; });
  363. SpreadJsObj.refreshTreeRowVisible(sheet);
  364. break;
  365. }
  366. closeWaitingView();
  367. }, 100);
  368. });
  369. })('a[name=showLevel]', slSheet);
  370. });