settle_ledger.js 15 KB

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