schedule_ledger.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /**
  2. * 进度台账相关js
  3. *
  4. * @author Ellisran
  5. * @date 2020/11/6
  6. * @version
  7. */
  8. function getTenderId() {
  9. return window.location.pathname.split('/')[2];
  10. }
  11. const selects = [];
  12. $(function () {
  13. autoFlashHeight();
  14. // 初始化台账
  15. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  16. const treeSetting = {
  17. id: 'ledger_id',
  18. pid: 'ledger_pid',
  19. order: 'order',
  20. level: 'level',
  21. rootId: -1,
  22. fullPath: 'full_path',
  23. calcFields: ['total_price']
  24. //treeCacheKey: 'ledger_bills_fold' + '_' + getTenderId(),
  25. // markFoldKey: 'bills-fold',
  26. // markFoldSubKey: window.location.pathname.split('/')[2],
  27. };
  28. treeSetting.calcFun = function (node) {
  29. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  30. };
  31. const ledgerTree = createNewPathTree('base', treeSetting);
  32. const ledgerSpreadSetting = {
  33. cols: [
  34. {title: '', colSpan: '1', rowSpan: '2', field: 'is_select', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox'},
  35. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 185, formatter: '@', readOnly: true, cellType: 'tree'},
  36. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 205, formatter: '@', readOnly: true},
  37. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 100, formatter: '@', readOnly: true},
  38. {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'dgn_price', hAlign: 2, width: 100, type: 'Number', readOnly: true},
  39. {title: '工程量', colSpan: '1', rowSpan: '2', field: 'dgn_qty1', hAlign: 2, width: 100, type: 'Number', readOnly: true},
  40. {title: '金额', colSpan: '1', rowSpan: '2', field: 'total_price', hAlign: 2, width: 100, type: 'Number', readOnly: true},
  41. ],
  42. emptyRows: 0,
  43. headRows: 1,
  44. headRowHeight: [25, 25],
  45. defaultRowHeight: 21,
  46. headerFont: '12px 微软雅黑',
  47. font: '12px 微软雅黑',
  48. // readOnly: true,
  49. localCache: {
  50. key: 'ledger-bills',
  51. colWidth: true,
  52. }
  53. };
  54. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  55. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  56. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  57. SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet());
  58. postData(window.location.pathname + '/load', {}, function (data) {
  59. data = addIsSelect(data);
  60. ledgerTree.loadDatas(data);
  61. treeCalc.calculateAll(ledgerTree);
  62. // console.log(ledgerTree);
  63. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, ledgerTree);
  64. }, null, true);
  65. const ledgerSpreadObj = {
  66. refreshTree: function (sheet, data) {
  67. SpreadJsObj.massOperationSheet(sheet, function () {
  68. const tree = sheet.zh_tree;
  69. // 处理删除
  70. if (data.delete) {
  71. data.delete.sort(function (x, y) {
  72. return y.deleteIndex - x.deleteIndex;
  73. });
  74. for (const d of data.delete) {
  75. sheet.deleteRows(d.deleteIndex, 1);
  76. }
  77. }
  78. // 处理新增
  79. if (data.create) {
  80. const newNodes = data.create;
  81. if (newNodes) {
  82. newNodes.sort(function (a, b) {
  83. return a.index - b.index;
  84. });
  85. for (const node of newNodes) {
  86. sheet.addRows(node.index, 1);
  87. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  88. }
  89. }
  90. }
  91. // 处理更新
  92. if (data.update) {
  93. const rows = [];
  94. for (const u of data.update) {
  95. rows.push(tree.nodes.indexOf(u));
  96. }
  97. SpreadJsObj.reLoadRowsData(sheet, rows);
  98. }
  99. // 处理展开
  100. if (data.expand) {
  101. const expanded = [];
  102. for (const e of data.expand) {
  103. if (expanded.indexOf(e) === -1) {
  104. const posterity = tree.getPosterity(e);
  105. for (const p of posterity) {
  106. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  107. expanded.push(p);
  108. }
  109. }
  110. }
  111. }
  112. });
  113. },
  114. buttonClicked: function (e, info) {
  115. if (info.sheet.zh_setting) {
  116. const select = SpreadJsObj.getSelectObject(info.sheet);
  117. const col = info.sheet.zh_setting.cols[info.col];
  118. // if (materialCol.readOnly.isEdit(select)) {
  119. // return;
  120. // }
  121. if (col.field === 'is_select') {
  122. if (info.sheet.isEditing()) {
  123. info.sheet.endEdit(true);
  124. }
  125. // 选中和去除关联
  126. select.is_select = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  127. selects.splice(0, selects.length);
  128. selects.push(select);
  129. updateChildrenSelect(select.children, select.is_select);
  130. updateParentSelect(info.sheet.zh_tree, select.ledger_pid, select.is_select);
  131. // console.log(selects);
  132. const refreshNode = ledgerTree.loadPostData({update: selects});
  133. ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
  134. }
  135. }
  136. },
  137. };
  138. ledgerSpread.bind(spreadNS.Events.ButtonClicked, ledgerSpreadObj.buttonClicked);
  139. // // 显示层次
  140. // (function (select, sheet) {
  141. // $(select).click(function () {
  142. // const tag = $(this).attr('tag');
  143. // const tree = sheet.zh_tree;
  144. // if (!tree) return;
  145. // switch (tag) {
  146. // case "1":
  147. // case "2":
  148. // case "3":
  149. // case "4":
  150. // case "5":
  151. // tree.expandByLevel(parseInt(tag));
  152. // SpreadJsObj.refreshTreeRowVisible(sheet);
  153. // break;
  154. // case "last":
  155. // tree.expandByCustom(() => { return true; });
  156. // SpreadJsObj.refreshTreeRowVisible(sheet);
  157. // break;
  158. // case "leafXmj":
  159. // tree.expandToLeafXmj();
  160. // SpreadJsObj.refreshTreeRowVisible(sheet);
  161. // break;
  162. // }
  163. // });
  164. // })('a[name=showLevel]', ledgerSpread.getActiveSheet());
  165. });
  166. function addIsSelect(datas) {
  167. for (const d of datas) {
  168. d.is_select = selectedLedgerList.length === 0 ? 1: selectedLedgerList.indexOf(d.ledger_id) !== -1 ? 1 : 0;
  169. }
  170. return datas;
  171. }
  172. function updateChildrenSelect(datas, is_select) {
  173. for (const data of datas) {
  174. data.is_select = is_select;
  175. if(data.children && data.children.length > 0) {
  176. updateChildrenSelect(data.children, is_select);
  177. }
  178. selects.push(data);
  179. }
  180. }
  181. function updateParentSelect(tree, pid, is_select) {
  182. if (pid !== -1) {
  183. const parent = _.find(tree.nodes, { 'ledger_id': pid });
  184. if (parent) {
  185. const hadselectInfo = is_select === 0 ? _.findIndex(parent.children, { 'is_select': 1 }) : 1;
  186. parent.is_select = (hadselectInfo !== -1 && is_select === 0) || is_select === 1 ? 1 : 0;
  187. selects.push(parent);
  188. updateParentSelect(tree, parent.ledger_pid, is_select);
  189. }
  190. }
  191. }