spss_check_tz.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. $(document).ready(function () {
  10. const error = {
  11. repeatBills: [],
  12. };
  13. autoFlashHeight();
  14. // 根据设置整理Spread设置
  15. const ledgerSpreadSetting = {
  16. cols: [
  17. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', cellType: 'tree'},
  18. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  19. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  20. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'unit'},
  21. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  22. {title: '项目节数量|数量1', colSpan: '2|1', rowSpan: '1|1', field: 'dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  23. {title: '|数量2', colSpan: '|1', rowSpan: '|1', field: 'dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  24. {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'dgn_price', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  25. {title: '设计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'sgfh_qty', hAlign: 2, width: 60, type: 'Number'},
  26. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sgfh_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  27. {title: '设计错漏增减|数量', colSpan: '2|1', rowSpan: '1|1', field: 'sjcl_qty', hAlign: 2, width: 60, type: 'Number'},
  28. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sjcl_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  29. {title: '其他错漏增减|数量', colSpan: '2|1', rowSpan: '1|1', field: 'qtcl_qty', hAlign: 2, width: 60, type: 'Number'},
  30. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'qtcl_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  31. {title: '台账小计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  32. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  33. {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  34. {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'}
  35. ],
  36. emptyRows: 2,
  37. headRows: 2,
  38. headRowHeight: [25, 25],
  39. defaultRowHeight: 21,
  40. headerFont: '12px 微软雅黑',
  41. font: '12px 微软雅黑',
  42. readOnly: true,
  43. };
  44. const posSpreadSetting = {
  45. cols: [
  46. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  47. {title: '位置', colSpan: '1', rowSpan: '2', field: 'position', hAlign: 0, width: 60, formatter: '@'},
  48. {title: '台账数量|设计量', colSpan: '4|1', rowSpan: '1|1', field: 'sgfh_qty', hAlign: 2, width: 100, type: 'Number'},
  49. {title: '|设计错漏增减', colSpan: '|1', rowSpan: '|1', field: 'sjcl_qty', hAlign: 2, width: 100, type: 'Number'},
  50. {title: '|其他错漏增减', colSpan: '|1', rowSpan: '|1', field: 'qtcl_qty', hAlign: 2, width: 100, type: 'Number'},
  51. {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  52. {title: '图册号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  53. ],
  54. emptyRows: 3,
  55. headRows: 2,
  56. headRowHeight: [25, 25],
  57. defaultRowHeight: 21,
  58. headerFont: '12px 微软雅黑',
  59. font: '12px 微软雅黑',
  60. readOnly: true,
  61. };
  62. // 初始化台账
  63. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  64. const billsSheet = billsSpread.getActiveSheet();
  65. SpreadJsObj.initSheet(billsSheet, ledgerSpreadSetting);
  66. // 初始化部位
  67. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  68. const posSheet = posSpread.getActiveSheet();
  69. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  70. const billsTree = createNewPathTree('ledger', {
  71. id: 'ledger_id',
  72. pid: 'ledger_pid',
  73. order: 'order',
  74. level: 'level',
  75. rootId: -1,
  76. keys: ['id', 'tender_id', 'ledger_id'],
  77. calcFields: ['deal_tp', 'sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
  78. });
  79. const pos = new PosData({
  80. id: 'id', ledgerId: 'lid',
  81. });
  82. // 获取部位明细数据
  83. function loadPosData(iRow) {
  84. if (!billsSheet.zh_tree) return;
  85. const node = billsSheet.zh_tree.nodes[iRow];
  86. if (node) {
  87. SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, node.pos);
  88. } else {
  89. SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, []);
  90. }
  91. SpreadJsObj.resetTopAndSelect(posSheet);
  92. }
  93. // 切换清单行,读取所属项目节数据
  94. billsSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  95. if (info.newSelections) {
  96. const iNewRow = info.newSelections[0].row;
  97. if (info.oldSelections) {
  98. const iOldRow = info.oldSelections[0].row;
  99. if (iNewRow !== iOldRow) {
  100. loadPosData(iNewRow);
  101. }
  102. } else {
  103. loadPosData(iNewRow);
  104. }
  105. }
  106. });
  107. // 右键
  108. $.contextMenu({
  109. selector: '#bills-spread',
  110. build: function ($trigger, e) {
  111. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  112. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  113. },
  114. items: {
  115. checkInvisibleNode: {
  116. name: '检查是否存在不可见节点',
  117. icon: '',
  118. callback: function (key, opt) {
  119. if (error.repeatBills.length === 0) {
  120. toastr.success('不存在不可见节点');
  121. } else {
  122. toastr.warning('存在不可见节点,详细见控制台打印');
  123. console.log('存在' + error.repeatBills.length + '个节点,无法加载至树结构:');
  124. const sql = [];
  125. for (const b of error.repeatBills) {
  126. console.log(b);
  127. sql.push("Delete From `zh_ledger` Where id = '" + b.id + "';");
  128. }
  129. console.log('可使用如下sql修复:');
  130. console.log(sql.join('\n'));
  131. console.log('如果标段已上报,请再使用以下sql更新缓存:');
  132. console.log('\n' +
  133. 'Update `zh_tender` t\n' +
  134. 'INNER JOIN (Select Sum(`total_price`) as tp, Max(`tender_id`) as id From `zh_ledger` where `tender_id` = \' + billsTree.datas[0].tender_id + \') c\n' +
  135. 'ON t.id = c.id\n' +
  136. 'Set t.`total_price` = c.tp');
  137. }
  138. },
  139. }
  140. },
  141. });
  142. // 选择
  143. $('#load-tz').click(function () {
  144. try {
  145. const id = parseInt($('input[name=tz-id]').val());
  146. if (id <= 0) return;
  147. postData('/tools/load', {id: id}, function (result) {
  148. billsTree.loadDatas(result.bills);
  149. treeCalc.calculateAll(billsTree);
  150. SpreadJsObj.loadSheetData(billsSheet, 'tree', billsTree);
  151. for (const b of result.bills) {
  152. const node = billsTree.getItems(b.ledger_id);
  153. if (!node || node.id !== b.id) error.repeatBills.push(b);
  154. }
  155. pos.loadDatas(result.pos);
  156. loadPosData();
  157. });
  158. } catch (err) {
  159. toastr.error('输入的标段ID非法');
  160. }
  161. });
  162. // 显示层次
  163. (function (select, sheet) {
  164. $(select).click(function () {
  165. if (!sheet.zh_tree) return;
  166. const tag = $(this).attr('tag');
  167. const tree = sheet.zh_tree;
  168. switch (tag) {
  169. case "1":
  170. case "2":
  171. case "3":
  172. case "4":
  173. case "5":
  174. tree.expandByLevel(parseInt(tag));
  175. SpreadJsObj.refreshTreeRowVisible(sheet);
  176. break;
  177. case "last":
  178. tree.expandByCustom(() => { return true; });
  179. SpreadJsObj.refreshTreeRowVisible(sheet);
  180. break;
  181. case "leafXmj":
  182. tree.expandToLeafXmj();
  183. SpreadJsObj.refreshTreeRowVisible(sheet);
  184. break;
  185. case "curMeasure":
  186. tree.expandByCalcFields();
  187. SpreadJsObj.refreshTreeRowVisible(sheet);
  188. break;
  189. }
  190. });
  191. })('a[name=showLevel]', billsSheet);
  192. // 导航栏
  193. $.subMenu({
  194. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  195. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  196. key: 'menu.1.0.0',
  197. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  198. callback: function (info) {
  199. if (info.mini) {
  200. $('.panel-title').addClass('fluid');
  201. $('#sub-menu').removeClass('panel-sidebar');
  202. } else {
  203. $('.panel-title').removeClass('fluid');
  204. $('#sub-menu').addClass('panel-sidebar');
  205. }
  206. autoFlashHeight();
  207. billsSpread.refresh();
  208. posSpread.refresh();
  209. }
  210. });
  211. // 上下窗口resizer
  212. $.divResizer({
  213. select: '#main-resize',
  214. callback: function () {
  215. billsSpread.refresh();
  216. let bcontent = $(".bcontent-wrap").length > 0 ? $(".bcontent-wrap").height() : 0;
  217. $(".sp-wrap").height(bcontent - 30);
  218. posSpread.refresh();
  219. }
  220. });
  221. });