billsGuidance.js 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2018/6/1
  7. * @version
  8. */
  9. const billsGuidance = (function () {
  10. function _isDef(v) {
  11. return typeof v !== 'undefined' && v !== null;
  12. }
  13. function sortByCode(arr) {
  14. function recurCompare(a, b, index){
  15. if (a[index] && !b[index]) {
  16. return 1;
  17. } else if (!a[index] && b[index]) {
  18. return -1;
  19. } else if (a[index] && b[index]) {
  20. let aV = a[index],
  21. bV = b[index];
  22. if (!isNaN(aV) && !isNaN(bV)) {
  23. aV = parseFloat(a[index]);
  24. bV = parseFloat(b[index]);
  25. }
  26. if (aV > bV) {
  27. return 1;
  28. } else if (aV < bV) {
  29. return -1;
  30. } else {
  31. return recurCompare(a, b, index + 1);
  32. }
  33. }
  34. return 0;
  35. }
  36. arr.sort(function (a, b) {
  37. if (!_isDef(a.code) || !_isDef(b.code)) {
  38. return 0;
  39. }
  40. let aArr = a.code.split('-'),
  41. bArr = b.code.split('-');
  42. return recurCompare(aArr, bArr, 0);
  43. });
  44. }
  45. const locked = lockUtil.getLocked();
  46. let moduleName = 'stdBillsGuidance';
  47. //上下拖动的拖动条高度
  48. const verticalResize = 10;
  49. //自执行函数全局变量定义
  50. const libID = getQueryString('libID');
  51. //总工作内容数据
  52. let stdBillsJobData = [];
  53. //总项目特征数据
  54. let stdBillsFeatureData = [];
  55. const bills = {
  56. dom: $('#billsSpread'),
  57. workBook: null,
  58. cache: [],
  59. tree: null,
  60. controller: null,
  61. treeSetting: {
  62. treeCol: 0,
  63. emptyRows: 0,
  64. headRows: 1,
  65. headRowHeight: [40],
  66. defaultRowHeight: 21,
  67. cols: [{
  68. width: 200,
  69. readOnly: true,
  70. showHint: true,
  71. head: {
  72. titleNames: ["项目编码"],
  73. spanCols: [1],
  74. spanRows: [1],
  75. vAlign: [1],
  76. hAlign: [1],
  77. font: ["Arial"]
  78. },
  79. data: {
  80. field: "code",
  81. vAlign: 1,
  82. hAlign: 0,
  83. font: "Arial"
  84. }
  85. }, {
  86. width: 200,
  87. readOnly: true,
  88. head: {
  89. titleNames: ["项目名称"],
  90. spanCols: [1],
  91. spanRows: [1],
  92. vAlign: [1],
  93. hAlign: [1],
  94. font: ["Arial"]
  95. },
  96. data: {
  97. field: "name",
  98. vAlign: 1,
  99. hAlign: 0,
  100. font: "Arial"
  101. }
  102. }]
  103. },
  104. headers: [
  105. {name: '项目编码', dataCode: 'code', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'},
  106. {name: '项目名称', dataCode: 'name', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'}
  107. ],
  108. events: {
  109. SelectionChanged: function (sender, info) {
  110. billsInitSel(info.newSelections[0].row, info.oldSelections[0]);
  111. }
  112. }
  113. };
  114. const selectedBgColor = '#DFE8F9';
  115. const searchBgColor = 'lemonChiffon';
  116. //项目指引类型
  117. const itemType = {
  118. job: 0,
  119. ration: 1
  120. };
  121. //项目指引复制整块localStorage key
  122. const itemCopyBlockKey = 'guideItemCopyBlock';
  123. const updateType = {
  124. create: 'create',
  125. update: 'update',
  126. del: 'delete'
  127. };
  128. //项目指引节点状态:展开全部、收起定额
  129. const itemExpandState = {
  130. expand: 1,
  131. contract: 0
  132. };
  133. //项目指引当前节点展开收缩状态,默认展开全部
  134. let curExpandState = 1;
  135. const guideItem = {
  136. dom: $('#guideItemSpread'),
  137. workBook: null,
  138. tree: null,
  139. controller: null,
  140. treeSetting: {
  141. treeCol: 0,
  142. emptyRows: 0,
  143. headRows: 1,
  144. headRowHeight: [40],
  145. defaultRowHeight: 21,
  146. cols: [{
  147. width: 400,
  148. readOnly: locked,
  149. head: {
  150. titleNames: ["项目指引"],
  151. spanCols: [1],
  152. spanRows: [1],
  153. vAlign: [1],
  154. hAlign: [1],
  155. font: ["Arial"]
  156. },
  157. data: {
  158. field: "name",
  159. vAlign: 1,
  160. hAlign: 0,
  161. font: "Arial"
  162. }
  163. },
  164. {
  165. width: 40,
  166. readOnly: true,
  167. head: {
  168. titleNames: ["输出特征"],
  169. spanCols: [1],
  170. spanRows: [1],
  171. vAlign: [1],
  172. hAlign: [1],
  173. font: ["Arial"]
  174. },
  175. data: {
  176. field: "outputItemCharacter",
  177. vAlign: 1,
  178. hAlign: 1,
  179. font: "Arial"
  180. }
  181. },
  182. {
  183. width: 40,
  184. readOnly: true,
  185. head: {
  186. titleNames: ["必填"],
  187. spanCols: [1],
  188. spanRows: [1],
  189. vAlign: [1],
  190. hAlign: [1],
  191. font: ["Arial"]
  192. },
  193. data: {
  194. field: "required",
  195. vAlign: 1,
  196. hAlign: 1,
  197. font: "Arial"
  198. }
  199. }
  200. ]
  201. },
  202. headers: [
  203. {name: '项目指引', dataCode: 'name', width: 400, vAlign: 'center', hAlign: 'left', formatter: '@'},
  204. {name: '输出特征', dataCode: 'outputItemCharacter', width: 40, vAlign: 'center', hAlign: 'center'},
  205. {name: '必填', dataCode: 'required', width: 40, vAlign: 'center', hAlign: 'center'},
  206. ],
  207. events: {
  208. SelectionChanged: function (sender, info) {
  209. guideItemInitSel(info.newSelections[0].row)
  210. },
  211. EditEnded: function (sender, args) {
  212. edit(args.sheet, [{row: args.row, col: args.col}]);
  213. },
  214. ButtonClicked: function (sender, args) {
  215. edit(args.sheet, [{row: args.row, col: args.col}]);
  216. },
  217. RangeChanged: function (sender, args) {
  218. edit(args.sheet, args.changedCells);
  219. }
  220. }
  221. };
  222. //定额章节树
  223. const section = {
  224. dom: $('#sectionSpread'),
  225. workBook: null,
  226. cache: [],
  227. tree: null,
  228. controller: null,
  229. treeSetting: {
  230. treeCol: 0,
  231. emptyRows: 0,
  232. headRows: 1,
  233. headRowHeight: [40],
  234. defaultRowHeight: 21,
  235. cols: [{
  236. width: 400,
  237. readOnly: true,
  238. head: {
  239. titleNames: ["名称"],
  240. spanCols: [1],
  241. spanRows: [1],
  242. vAlign: [1],
  243. hAlign: [1],
  244. font: ["Arial"]
  245. },
  246. data: {
  247. field: "name",
  248. vAlign: 1,
  249. hAlign: 0,
  250. font: "Arial"
  251. }
  252. }]
  253. },
  254. headers: [
  255. {name: '名称', dataCode: 'name', width: 400, vAlign: 'center', hAlign: 'left', formatter: '@'},
  256. ],
  257. events: {
  258. SelectionChanged: function (sender, info) {
  259. sectionInitSel(info.newSelections[0].row)
  260. }
  261. }
  262. };
  263. const ration = {
  264. dom: $('#rationSpread'),
  265. workBook: null,
  266. datas: [],//所有的数据,搜索定额时,从所有数据中筛选
  267. cache: [],//显示在表格上的数据,添加定额可以有效根据行识别定额
  268. headers: [
  269. {name: '选择', dataCode: 'select', width: 50, vAlign: 'center', hAlign: 'center'},
  270. {name: '编码', dataCode: 'code', width: 110, vAlign: 'center', hAlign: 'left', formatter: '@'},
  271. {name: '名称', dataCode: 'name', width: 250, vAlign: 'center', hAlign: 'left', formatter: '@'},
  272. {name: '单位', dataCode: 'unit', width: 100, vAlign: 'center', hAlign: 'left', formatter: '@'}
  273. ],
  274. events: {
  275. ButtonClicked: function (sender, args) {
  276. if(args.sheet.isEditing()){
  277. args.sheet.endEdit(true);
  278. }
  279. },
  280. CellDoubleClick: function (sender, args) {
  281. if(ration.headers[args.col].dataCode === 'name'){
  282. let insertDatas = getInsertRations([args.row]);
  283. if(insertDatas.length > 0){
  284. insert(insertDatas, false);
  285. }
  286. }
  287. }
  288. }
  289. };
  290. const options = {
  291. workBook: {
  292. tabStripVisible: false,
  293. allowContextMenu: false,
  294. allowCopyPasteExcelStyle : false,
  295. allowExtendPasteRange: false,
  296. allowUserDragDrop : false,
  297. allowUserDragFill: false,
  298. scrollbarMaxAlign : true
  299. },
  300. sheet: {
  301. protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
  302. clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
  303. }
  304. };
  305. //渲染时方法,停止渲染
  306. //@param {Object}sheet {Function}func @return {void}
  307. function renderSheetFunc(sheet, func){
  308. sheet.suspendEvent();
  309. sheet.suspendPaint();
  310. if(func){
  311. func();
  312. }
  313. sheet.resumeEvent();
  314. sheet.resumePaint();
  315. }
  316. //设置表选项
  317. //@param {Object}workBook {Object}opts @return {void}
  318. function setOptions (workBook, opts) {
  319. for(let opt in opts.workBook){
  320. workBook.options[opt] = opts.workBook[opt];
  321. }
  322. for(let opt in opts.sheet){
  323. workBook.getActiveSheet().options[opt] = opts.sheet[opt];
  324. }
  325. }
  326. //建表头
  327. //@param {Object}sheet {Array}headers @return {void}
  328. function buildHeader(sheet, headers) {
  329. let fuc = function () {
  330. sheet.setColumnCount(headers.length);
  331. sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
  332. for(let i = 0, len = headers.length; i < len; i++){
  333. sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
  334. sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
  335. sheet.getCell(0, i, GC.Spread.Sheets.SheetArea.colHeader).wordWrap(true);
  336. if(headers[i].formatter){
  337. sheet.setFormatter(-1, i, headers[i].formatter);
  338. }
  339. sheet.getRange(-1, i, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[i]['hAlign']]);
  340. sheet.getRange(-1, i, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[i]['vAlign']]);
  341. }
  342. };
  343. renderSheetFunc(sheet, fuc);
  344. }
  345. //表监听事件
  346. //@param {Object}workBook @return {void}
  347. function bindEvent(workBook, events) {
  348. if(Object.keys(events).length === 0){
  349. return;
  350. }
  351. const Events = GC.Spread.Sheets.Events;
  352. let sheet = workBook.getActiveSheet();
  353. for(let event in events){
  354. workBook.bind(Events[event], events[event]);
  355. }
  356. }
  357. //建表
  358. //@param {Object}module @return {void}
  359. function buildSheet(module) {
  360. if(!module.workBook){
  361. module.workBook = new GC.Spread.Sheets.Workbook(module.dom[0], {sheetCount: 1});
  362. let sheet = module.workBook.getActiveSheet();
  363. if(module === bills){
  364. sheet.name('stdBillsGuidance_bills');
  365. //默认初始可控制焦点在清单表中
  366. module.workBook.focus();
  367. sheet.options.isProtected = true;
  368. }
  369. else if(module === ration){
  370. sheet.options.isProtected = true;
  371. sheet.getRange(-1, 0, -1, 1).locked(locked);
  372. sheet.getRange(-1, 1, -1, -1).locked(true);
  373. }
  374. else if(module === guideItem){
  375. sheetCommonObj.bindEscKey(module.workBook, [{sheet: sheet, editStarting: null, editEnded: module.events.EditEnded}]);
  376. }
  377. setOptions(module.workBook, options);
  378. buildHeader(module.workBook.getActiveSheet(), module.headers);
  379. bindEvent(module.workBook, module.events);
  380. }
  381. lockUtil.lockSpreads([module.workBook], locked);
  382. }
  383. //清空表数据
  384. //@param {Object}sheet {Array}headers {Number}rowCount @return {void}
  385. function cleanData(sheet, headers, rowCount){
  386. renderSheetFunc(sheet, function () {
  387. sheet.clear(-1, 0, -1, headers.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  388. if (rowCount >= 0) {
  389. sheet.setRowCount(rowCount);
  390. }
  391. });
  392. }
  393. //根据清单获取项目指引
  394. //@param {String}guidanceLibID {Number}billsID {Function}callback @return {void}
  395. function getItemsByBills(guidanceLibID, billsID, callback){
  396. CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: guidanceLibID, billsID: billsID}, function (rstData) {
  397. if(callback){
  398. callback(rstData);
  399. }
  400. });
  401. }
  402. //清单表焦点控制
  403. //@param {Number}row @return {void}
  404. function billsInitSel(row, oldSel){
  405. let guideSheet = guideItem.workBook.getActiveSheet();
  406. cleanData(guideSheet, guideItem.headers, -1);
  407. let node = bills.tree.items[row];
  408. if(!node){
  409. return;
  410. }
  411. const billSheet = bills.workBook.getActiveSheet();
  412. setBgColor(billSheet, row, selectedBgColor);
  413. if (oldSel && row !== oldSel.row) {
  414. const orgNode = bills.tree.items[oldSel.row]
  415. setBgColor(billSheet, oldSel.row, orgNode && orgNode.isSearch ? searchBgColor : 'white');
  416. }
  417. bills.tree.selected = node;
  418. //显示备注
  419. $('.main-side-bottom').find('textarea').val(node.data.comment ? node.data.comment : '');
  420. if(!node.guidance.tree){
  421. getItemsByBills(libID, node.data.ID, function (rstData) {
  422. initTree(node.guidance, guideSheet, guideItem.treeSetting, rstData);
  423. setNodesExpandState(node.guidance.tree.items, curExpandState);
  424. showCheckBox(guideSheet, node.guidance.tree.items);
  425. renderSheetFunc(guideSheet, function () {
  426. TREE_SHEET_HELPER.refreshNodesVisible(node.guidance.tree.roots, guideSheet, true);
  427. });
  428. //设置底色
  429. setNodesColor(guideSheet, node.guidance.tree.items);
  430. //项目指引初始焦点
  431. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  432. });
  433. } else{
  434. setNodesExpandState(node.guidance.tree.items, curExpandState);
  435. node.guidance.controller.showTreeData();
  436. showCheckBox(guideSheet, node.guidance.tree.items);
  437. //设置底色
  438. setNodesColor(guideSheet, node.guidance.tree.items);
  439. //项目指引初始焦点
  440. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  441. }
  442. }
  443. function showCheckBox(sheet, nodes) {
  444. // const checkBoxType = locked ? sheetCommonObj.getReadOnlyCheckBox() : sheetCommonObj.getCheckBox();
  445. const checkBoxType = new GC.Spread.Sheets.CellTypes.CheckBox();
  446. const baseType = new GC.Spread.Sheets.CellTypes.Base();
  447. renderSheetFunc(sheet, function () {
  448. nodes.forEach(node => {
  449. const row = node.serialNo();
  450. if (node.depth() % 2 === 0 && _isDef(node.data.type) && node.data.type === itemType.job) {
  451. sheet.setCellType(row, 1, checkBoxType);
  452. sheet.setCellType(row, 2, checkBoxType);
  453. sheet.setValue(row, 1, node.data.outputItemCharacter || false);
  454. sheet.setValue(row, 2, node.data.required || false);
  455. } else {
  456. sheet.setCellType(row, 1, baseType);
  457. sheet.setCellType(row, 2, baseType);
  458. sheet.setValue(row, 1, '');
  459. sheet.setValue(row, 2, '');
  460. }
  461. })
  462. });
  463. }
  464. //设置项目节点展开收起状态:展开全部、收起定额
  465. //@param {Array}nodes(当前清单下的所有项目指引节点) {Number}expandState(展开全部1或收起定额0).
  466. function setNodesExpandState(nodes, expandState) {
  467. if(expandState === itemExpandState.contract) {
  468. //找出所有定额的父节点
  469. let rations = _.filter(nodes, function (node) {
  470. return node.data.type === itemType.ration;
  471. });
  472. let rationParentIDs = [];
  473. for(let ration of rations){
  474. if(ration.data.ParentID != -1){
  475. rationParentIDs.push(ration.data.ParentID);
  476. }
  477. }
  478. rationParentIDs = Array.from(new Set(rationParentIDs));
  479. let rationParentNodes = _.filter(nodes, function (node) {
  480. return rationParentIDs.includes(node.data.ID);
  481. });
  482. //收起定额
  483. for(let node of rationParentNodes){
  484. node.setExpanded(false);
  485. }
  486. } else {
  487. for(let node of nodes){
  488. node.setExpanded(true);
  489. }
  490. }
  491. }
  492. // 设置行底色
  493. function setBgColor(sheet, row, color) {
  494. const style = new GC.Spread.Sheets.Style();
  495. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  496. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  497. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  498. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  499. style.backColor = color;
  500. sheet.setStyle(row, -1, style);
  501. }
  502. //根据奇偶层级设置节点底色,奇数层为蓝色(树节点深度为偶数)
  503. //@param {Object}sheet {Array}nodes @return {void}
  504. function setNodesColor(sheet, nodes) {
  505. renderSheetFunc(sheet, function () {
  506. for(let node of nodes){
  507. const nDepth = node.depth();
  508. const color = nDepth % 2 == 0 && _isDef(node.data.type) && node.data.type === itemType.job ? selectedBgColor : 'White';
  509. setBgColor(sheet, node.serialNo(), color);
  510. }
  511. });
  512. }
  513. //选中的节点是否全是同层节点
  514. //@param {Object}sheet {Array}items @return {Boolean}
  515. function itemsSameDepth(sheet, items) {
  516. let sels = sheet.getSelections();
  517. if(sels.length === 0 || items.length === 0){
  518. return false;
  519. }
  520. let depths = [];
  521. for(let i = 0; i < sels[0].rowCount; i++){
  522. let row = sels[0].row + i;
  523. let node = items[row];
  524. if(node){
  525. depths.push(node.depth());
  526. }
  527. }
  528. }
  529. //节点子项是否全是工作内容
  530. //@param {Object}node @return {Boolean}
  531. function allJobChildren(node){
  532. for(let c of node.children){
  533. if(c.data.type === itemType.ration){
  534. return false;
  535. }
  536. }
  537. return true;
  538. }
  539. //节点子项是否全是定额
  540. //@param {Object}node @return {Boolean}
  541. function allRationChildren(node){
  542. for(let c of node.children){
  543. if(c.data.type === itemType.job){
  544. return false;
  545. }
  546. }
  547. return true;
  548. }
  549. //刷新按钮有效性
  550. //@param {Object}node @return {void}
  551. function refreshBtn(node){
  552. if (locked) {
  553. return;
  554. }
  555. //全部设为无效
  556. $('.tools-btn').children().addClass('disabled');
  557. $('#insertRation').addClass('disabled');
  558. $('#insertAll').addClass('disabled');
  559. $('.main-bottom-content').find('textarea').attr('readonly', true);
  560. //插入
  561. if(bills.tree.selected && bills.tree.selected.guidance.tree){
  562. $('#insert').removeClass('disabled');
  563. if(node && node.data.type === itemType.ration){
  564. $('#insert').addClass('disabled');
  565. }
  566. }
  567. //删除
  568. if(node){
  569. $('#del').removeClass('disabled');
  570. }
  571. if(node && node.data.type === itemType.job){
  572. //升级
  573. if(node.parent){
  574. $('#upLevel').removeClass('disabled');
  575. if(node.nextSibling && node.children.length > 0 && !allJobChildren(node)){
  576. $('#upLevel').addClass('disabled');
  577. }
  578. }
  579. //降级
  580. if(node.preSibling){
  581. $('#downLevel').removeClass('disabled');
  582. if(node.preSibling.children.length > 0 && !allJobChildren(node.preSibling)){
  583. $('#downLevel').addClass('disabled');
  584. }
  585. }
  586. }
  587. //上移
  588. if(node && node.preSibling){
  589. $('#upMove').removeClass('disabled')
  590. }
  591. //下移
  592. if(node && node.nextSibling){
  593. $('#downMove').removeClass('disabled');
  594. }
  595. //收起定额、展开全部
  596. $('#expandContract').removeClass('disabled');
  597. //插入定额
  598. if(node && (node.children.length === 0 || allRationChildren(node))){
  599. $('#insertRation').removeClass('disabled');
  600. $('#insertAll').removeClass('disabled');
  601. }
  602. //备注,奇数节点可用
  603. if(node && (node.depth() + 1) % 2 === 1 && node.data.type !== itemType.ration){
  604. $('.main-bottom-content').find('textarea').attr('readonly', false);
  605. }
  606. }
  607. //项目指引表焦点控制
  608. //@param {Number}row @return {void}
  609. function guideItemInitSel(row){
  610. let billsNode = bills.tree.selected;
  611. let node = null;
  612. if(billsNode && billsNode.guidance.tree){
  613. node = billsNode.guidance.tree.items[row];
  614. if(node){
  615. billsNode.guidance.tree.selected = node;
  616. //显示备注
  617. $('.main-bottom-content').find('textarea').val(node.data.comment ? node.data.comment : '');
  618. }
  619. }
  620. refreshBtn(node);
  621. }
  622. //初始化当前库名
  623. //@param {String} @return {void}
  624. function initLibName(libName) {
  625. $('#libName')[0].outerHTML = $('#libName')[0].outerHTML.replace("XXX清单指引", libName);
  626. }
  627. //初始化各工作表
  628. //@param {Array}modules @return {void}
  629. function initWorkBooks(modules){
  630. for(let module of modules){
  631. buildSheet(module);
  632. }
  633. }
  634. function tipDivCheck(){
  635. setTimeout(function () {
  636. let tips = $('#autoTip');
  637. if(ration.tipDiv == 'show'){
  638. return;
  639. } else if(ration.tipDiv == 'hide'&&tips){
  640. tips.hide();
  641. ration._toolTipElement = null;
  642. }
  643. },600)
  644. }
  645. //获取悬浮提示单元格
  646. //@param {Object}sheet @return {Object}
  647. function getTipCellType(sheet) {
  648. let setting = {};
  649. let TipCellType = function () {};
  650. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  651. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  652. return {
  653. x: x,
  654. y: y,
  655. row: context.row,
  656. col: context.col,
  657. cellStyle: cellStyle,
  658. cellRect: cellRect,
  659. sheet: context.sheet,
  660. sheetArea: context.sheetArea
  661. };
  662. };
  663. TipCellType.prototype.processMouseEnter = function (hitinfo) {
  664. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  665. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  666. if(tag !== undefined && tag){
  667. text = tag;
  668. }
  669. if(sheet && sheet.getParent().qo){
  670. setting.pos = SheetDataHelper.getObjPos(sheet.getParent().qo);
  671. }
  672. let delayTimes = 500; //延时时间
  673. let now_timeStamp = +new Date();
  674. this.tipTimeStamp = now_timeStamp;
  675. let me = this;
  676. setTimeout(function () {
  677. if(now_timeStamp - me.tipTimeStamp == 0){//鼠标停下的时候才显示
  678. if (setting.pos && text && text !== '') {
  679. //固定不显示的div,存储文本获取固定div宽度,toolTipElement由于显示和隐藏,获取宽度不正确
  680. if(!me._fixedTipElement){
  681. let div = $('#fixedTip1')[0];
  682. if (!div) {
  683. div = document.createElement("div");
  684. $(div).css("padding", 5)
  685. .attr("id", 'fixedTip');
  686. $(div).hide();
  687. document.body.insertBefore(div, null);
  688. }
  689. me._fixedTipElement = div;
  690. }
  691. $(me._fixedTipElement).width('');
  692. $(me._fixedTipElement).html(text);
  693. if (!me._toolTipElement) {
  694. let div = $('#autoTip1')[0];
  695. if (!div) {
  696. div = document.createElement("div");
  697. $(div).css("position", "absolute")
  698. .css("border", "1px #C0C0C0 solid")
  699. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  700. .css("font", "0.9rem Calibri")
  701. .css("background", "white")
  702. .css("padding", 5)
  703. .attr("id", 'autoTip1');
  704. $(div).hide();
  705. document.body.insertBefore(div, null);
  706. }
  707. me._toolTipElement = div;
  708. $(me._toolTipElement).width('');
  709. //实时读取位置信息
  710. if(hitinfo.sheet && hitinfo.sheet.getParent().qo){
  711. setting.pos = SheetDataHelper.getObjPos(hitinfo.sheet.getParent().qo);
  712. }
  713. $(me._toolTipElement).html(text);
  714. //定额库定额特殊处理
  715. if($(hitinfo.sheet.getParent().qo).attr('id') === 'rationSpread'){
  716. let divWidth = $(me._fixedTipElement).width(),
  717. divHeight = $(me._fixedTipElement).height();
  718. if(divWidth > 600){
  719. divWidth = 590;
  720. $(me._toolTipElement).width(divWidth);
  721. }
  722. let top = setting.pos.y + hitinfo.y - divHeight < 0 ? 0 : setting.pos.y + hitinfo.cellRect.y - divHeight;
  723. $(me._toolTipElement).css("top", top).css("left", setting.pos.x - divWidth);
  724. }
  725. else{
  726. $(me._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  727. }
  728. //名称
  729. if(hitinfo.col === 2){
  730. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  731. zoom = hitinfo.sheet.zoom();
  732. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  733. let textLength = me.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  734. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  735. if(textLength > cellWidth){
  736. $(me._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  737. $(me._toolTipElement).show("fast");
  738. ration.tipDiv = 'show';//做个标记
  739. }
  740. }
  741. else {
  742. $(me._toolTipElement).show("fast");
  743. ration.tipDiv = 'show';//做个标记
  744. }
  745. }
  746. }
  747. }
  748. },delayTimes);
  749. };
  750. TipCellType.prototype.processMouseLeave = function (hininfo) {
  751. this.tipTimeStamp = +new Date();
  752. ration.tipDiv = 'hide';
  753. if (this._toolTipElement) {
  754. $(this._toolTipElement).hide();
  755. this._toolTipElement = null;
  756. }
  757. tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  758. }
  759. return new TipCellType();
  760. }
  761. //输出表数据(定额表)
  762. //@param {Object}sheet {Array}headers {Array}datas @return {void}
  763. function showData(sheet, headers, datas){
  764. let fuc = function () {
  765. sheet.setRowCount(datas.length);
  766. //复选框
  767. let checkBoxType = new GC.Spread.Sheets.CellTypes.CheckBox();
  768. let tipCellType = getTipCellType(sheet);
  769. sheet.setCellType(-1, 0, checkBoxType);
  770. for(let col = 0, cLen = headers.length; col < cLen; col++){
  771. for(let row = 0, rLen = datas.length; row < rLen; row++){
  772. sheet.setValue(row, col, datas[row][headers[col]['dataCode']]);
  773. if(col === 1){
  774. sheet.setTag(row, col, datas[row]['hint']);
  775. }
  776. }
  777. }
  778. sheet.setCellType(-1, 1, tipCellType);
  779. sheet.setCellType(-1, 2, tipCellType);
  780. };
  781. renderSheetFunc(sheet, fuc);
  782. }
  783. //根据定额章节树ID获取定额(从数据缓存中获取,定额数据一开始一次性拉取)
  784. //@param {Number}sectionId {Array}rations @return {Array}
  785. function getRationsBySectionId(sectionId, rations) {
  786. if(!sectionId || !rations){
  787. return [];
  788. }
  789. return _.filter(rations, {sectionId});
  790. }
  791. //定额章节树焦点控制
  792. //@param {Number}row @return {void}
  793. function sectionInitSel(row) {
  794. let rationSheet = ration.workBook.getActiveSheet();
  795. let sectionNode = section.tree ? section.tree.items[row] : null;
  796. if(sectionNode && sectionNode.children.length === 0){
  797. let sectionRations = getRationsBySectionId(sectionNode.data.ID, ration.datas);
  798. ration.cache = sectionRations;
  799. showData(rationSheet, ration.headers, sectionRations);
  800. }
  801. else {
  802. cleanData(rationSheet, ration.headers, 0);
  803. }
  804. }
  805. //初始化定额条目
  806. //@param {Number}rationLibId @return {void}
  807. function initRationItems(rationLibId){
  808. $.bootstrapLoading.start();
  809. //获取定额章节树
  810. let sectionSheet = section.workBook.getActiveSheet();
  811. CommonAjax.post('/rationRepository/api/getRationTree', {rationLibId: rationLibId}, function (sectionDatas) {
  812. //获取所有定额数据
  813. let reqEntity = {rationLibId: rationLibId, showHint: true, returnFields: '-_id code ID sectionId name unit basePrice rationGljList jobContent annotation'};
  814. CommonAjax.post('/rationRepository/api/getRationItemsByLib', reqEntity, function (rstData) {
  815. section.cache = sectionDatas;
  816. initTree(section, section.workBook.getActiveSheet(), section.treeSetting, sectionDatas);
  817. //初始焦点在第一行(切换库)
  818. sectionSheet.setActiveCell(0, 0);
  819. sortByCode(rstData);
  820. /* rstData.sort(function (a, b) {
  821. let rst = 0;
  822. if(a.code > b.code){
  823. rst = 1;
  824. }
  825. else if(a.code < b.code){
  826. rst = -1;
  827. }
  828. return rst;
  829. }); */
  830. ration.datas = rstData;
  831. sectionInitSel(0);
  832. $.bootstrapLoading.end();
  833. }, function () {
  834. $.bootstrapLoading.end();
  835. });
  836. }, function () {
  837. $.bootstrapLoading.end();
  838. });
  839. }
  840. //初始化定额库选择
  841. //@param {String}compilationId @return {void}
  842. function initRationLibs(compilationId){
  843. CommonAjax.post('/rationRepository/api/getRationLibsByCompilation', {compilationId: compilationId}, function (rstData) {
  844. $('#rationLibSel').empty();
  845. for(let rationLib of rstData){
  846. let opt = `<option value="${rationLib.ID}">${rationLib.dispName}</option>`;
  847. $('#rationLibSel').append(opt);
  848. }
  849. //初始选择
  850. initRationItems(parseInt($('#rationLibSel').select().val()));
  851. $('#rationLibSel').change(function () {
  852. let rationLibId = parseInt($(this).select().val());
  853. initRationItems(rationLibId);
  854. })
  855. });
  856. }
  857. // 设置清单名称文本色
  858. function setBillsForeColor(billsNodes) {
  859. const sheet = bills.workBook.getActiveSheet();
  860. renderSheetFunc(sheet, function () {
  861. for(let bills of billsNodes){
  862. const row = bills.serialNo();
  863. sheet.setStyle(row, 1, { foreColor: bills.data.hasGuide ? 'darkgreen' : 'black' });
  864. }
  865. });
  866. }
  867. //清单设置悬浮提示信息
  868. //@param {Array}billsNodes(清单节点) {Array}jobs(总的工作内容数据) {Array}items(总的项目特征数据)
  869. function setBillsHint(billsNodes, jobs, items) {
  870. let jobsMapping = {},
  871. itemsMapping = {};
  872. for(let job of jobs){
  873. jobsMapping[job.id] = job;
  874. }
  875. for(let item of items){
  876. itemsMapping[item.id] = item;
  877. }
  878. let tagInfo = [];
  879. for(let billsNode of billsNodes){
  880. let hintArr = [];
  881. let billsItems = billsNode.data.items;
  882. if(billsItems.length > 0){
  883. //项目特征
  884. hintArr.push('项目特征:');
  885. }
  886. let itemCount = 1,
  887. jobCount = 1;
  888. for(let billsItem of billsItems){
  889. let itemData = itemsMapping[billsItem.id];
  890. if(itemData){
  891. //特征值
  892. let eigens = [];
  893. for(let eigen of itemData.itemValue){
  894. eigens.push(eigen.value);
  895. }
  896. eigens = eigens.join(';');
  897. hintArr.push(`${itemCount}.${itemData.content}${eigens === '' ? '' : ': ' + eigens}`);
  898. itemCount ++;
  899. }
  900. }
  901. //工作内容
  902. let billsJobs = billsNode.data.jobs;
  903. if(billsJobs.length > 0){
  904. hintArr.push('工作内容:');
  905. }
  906. for(let billsJob of billsJobs){
  907. let jobData = jobsMapping[billsJob.id];
  908. if(jobData){
  909. hintArr.push(`${jobCount}.${jobData.content}`);
  910. jobCount ++;
  911. }
  912. }
  913. /*if(billsNode.data.ruleText && billsNode.data.ruleText !== ''){
  914. hintArr.push('工程量计算规则:');
  915. hintArr.push(billsNode.data.ruleText);
  916. }
  917. if(billsNode.data.recharge && billsNode.data.recharge !== ''){
  918. hintArr.push('补注:');
  919. hintArr.push(billsNode.data.recharge);
  920. }*/
  921. if(hintArr.length > 0){
  922. tagInfo.push({row: billsNode.serialNo(), value: hintArr.join('\n')});
  923. }
  924. }
  925. let sheet = bills.workBook.getActiveSheet();
  926. renderSheetFunc(sheet, function () {
  927. for(let tagI of tagInfo){
  928. sheet.setTag(tagI.row, 0, tagI.value);
  929. }
  930. });
  931. }
  932. //初始化清单的工作内容和项目特征
  933. //@param {Number}billsLibId {Function}callback @return {void}
  934. function initJobAndCharacter(billsLibId, callback){
  935. CommonAjax.post('/stdBillsEditor/getJobContent', {billsLibId: billsLibId}, function (datas) {
  936. stdBillsJobData = datas;
  937. CommonAjax.post('/stdBillsEditor/getItemCharacter', {billsLibId: billsLibId}, function (datas) {
  938. stdBillsFeatureData = datas;
  939. if(callback){
  940. callback();
  941. }
  942. });
  943. });
  944. }
  945. let billsLibId = 0;
  946. //获取指引库信息及关联的清单
  947. //@param {Number}libID {Function}callback @return {Object}
  948. function getLibWithBills(libID, callback){
  949. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function (rstData) {
  950. billsLibId = rstData.guidanceLib.billsLibId;
  951. initRationLibs(rstData.guidanceLib.compilationId);
  952. bills.cache = rstData.bills;
  953. initLibName(rstData.guidanceLib.name);
  954. /*initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  955. //每一棵项目指引树挂在清单节点上
  956. for(let node of bills.tree.items){
  957. node.guidance = {tree: null, controller: null};
  958. }
  959. //默认初始节点
  960. billsInitSel(0);
  961. if(callback){
  962. callback(rstData);
  963. }*/
  964. let initDataCallback = function () {
  965. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  966. //每一棵项目指引树挂在清单节点上
  967. for(let node of bills.tree.items){
  968. node.guidance = {tree: null, controller: null};
  969. }
  970. //默认初始节点
  971. billsInitSel(0);
  972. if(callback){
  973. callback(rstData);
  974. }
  975. };
  976. initJobAndCharacter(rstData.guidanceLib.billsLibId, initDataCallback);
  977. }, function (msg) {
  978. window.location.href = '/billsGuidance/main';
  979. });
  980. }
  981. //初始化并输出树
  982. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  983. function initTree(module, sheet, treeSetting, datas){
  984. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  985. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  986. module.tree.loadDatas(datas);
  987. if(module === bills){
  988. module.tree.roots.forEach(root => {
  989. root.setExpanded(false);
  990. })
  991. }
  992. module.controller.showTreeData();
  993. if(module === bills){
  994. setBillsHint(bills.tree.items, stdBillsJobData, stdBillsFeatureData);
  995. setBillsForeColor(bills.tree.items);
  996. }
  997. }
  998. // 展开收起清单树()
  999. //更新清单备注
  1000. function updateBillsComment(updateData, callback, errCB) {
  1001. CommonAjax.post('/stdBillsEditor/updateBills', updateData, function () {
  1002. if (callback) {
  1003. callback();
  1004. }
  1005. }, function () {
  1006. if(errCB) {
  1007. errCB();
  1008. }
  1009. });
  1010. }
  1011. //更新项目指引
  1012. //@param {Array}updateDatas {Function}callback @return {void}
  1013. function updateGuideItems(updateDatas, callback, errCB){
  1014. CommonAjax.post('/billsGuidance/api/updateItems', {updateDatas: updateDatas}, function (rstData) {
  1015. if(callback){
  1016. callback(rstData);
  1017. }
  1018. }, function () {
  1019. if(errCB) {
  1020. errCB();
  1021. }
  1022. $.bootstrapLoading.end();
  1023. });
  1024. }
  1025. //编辑后自动去除换行符回车符
  1026. const deESC = /[\n]/g;
  1027. //项目指引编辑
  1028. //@param {Object}sheet {Array}cells
  1029. function edit(sheet, cells){
  1030. let updateDatas = [];
  1031. //同步节点数据
  1032. let syncDatas = [];
  1033. for(let cell of cells){
  1034. const field = guideItem.headers[cell.col].dataCode;
  1035. let node = bills.tree.selected.guidance.tree.items[cell.row];
  1036. if (field === 'name') {
  1037. let text = sheet.getValue(cell.row, cell.col);
  1038. text = text ? text.toString() : '';
  1039. text = text.replace(deESC, '');
  1040. sheet.setValue(cell.row, cell.col, text);
  1041. if(node.data.name != text){
  1042. syncDatas.push({node: node, text: text, field, cell});
  1043. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {name: text}});
  1044. }
  1045. } else if (field === 'outputItemCharacter' || field === 'required') {
  1046. const val = !sheet.getValue(cell.row, cell.col);
  1047. sheet.setValue(cell.row, cell.col, val);
  1048. syncDatas.push({node: node, text: val, field, cell });
  1049. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {[field]: val}});
  1050. }
  1051. }
  1052. if(updateDatas.length > 0){
  1053. updateGuideItems(updateDatas, function () {
  1054. for(let syncData of syncDatas){
  1055. syncData.node.data[syncData.field] = syncData.text;
  1056. }
  1057. }, function () {
  1058. //失败恢复
  1059. renderSheetFunc(sheet, function () {
  1060. for(let syncData of syncDatas){
  1061. sheet.setValue(syncData.node.serialNo(), syncData.cell.col, syncData.node.data[syncData.field] ? syncData.node.data[syncData.field] : '');
  1062. }
  1063. });
  1064. });
  1065. }
  1066. }
  1067. //项目指引插入,支持一次插入多条数据
  1068. //@param {Array}datas {Boolean}tobeChild(插入成为子项) {Function}callback @return {void}
  1069. function insert(datas, tobeChild, callback = null){
  1070. $.bootstrapLoading.start();
  1071. let sheet = guideItem.workBook.getActiveSheet();
  1072. let controller = bills.tree.selected.guidance.controller;
  1073. let selected = bills.tree.selected.guidance.tree.selected;
  1074. let updateDatas = [];
  1075. //建立数组下标索引
  1076. let newDataIndex = {};
  1077. for(let i = 0; i < datas.length; i++){
  1078. let newNodeData = {
  1079. libID: libID, ID: uuid.v1(), ParentID: selected ? selected.getParentID() : -1, NextSiblingID: selected ? selected.getNextSiblingID() : -1,
  1080. billsID: bills.tree.selected.getID()
  1081. };
  1082. //定额类型插入当前工作内容焦点行,
  1083. if(selected && ((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  1084. newNodeData.ParentID = selected.getID();
  1085. newNodeData.NextSiblingID = -1;
  1086. }
  1087. Object.assign(newNodeData, datas[i]);
  1088. newDataIndex[i] = newNodeData;
  1089. }
  1090. for(let i = 0; i < datas.length; i++){
  1091. //第一个节点
  1092. if(i === 0){
  1093. //非插入成子节点,更新选中节点NestSiblingID
  1094. if(selected && !((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  1095. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: newDataIndex[i].ID}});
  1096. }
  1097. }
  1098. //非最后一个节点
  1099. if(i !== datas.length - 1){
  1100. newDataIndex[i].NextSiblingID = newDataIndex[i + 1].ID;
  1101. }
  1102. updateDatas.push({updateType: updateType.create, updateData: newDataIndex[i]});
  1103. }
  1104. updateGuideItems(updateDatas, function () {
  1105. for(let updateData of updateDatas){
  1106. if(updateData.updateType === updateType.create){
  1107. let newNode = controller.insertByIDS(updateData.updateData.ID, updateData.updateData.ParentID, updateData.updateData.NextSiblingID);
  1108. //同步data
  1109. Object.assign(newNode.data, updateData.updateData);
  1110. const row = newNode.serialNo();
  1111. sheet.setValue(row, 0, newNode.data.name);
  1112. if (newNode.data.outputItemCharacter !== undefined) {
  1113. sheet.setValue(row, 1, newNode.data.outputItemCharacter);
  1114. }
  1115. showCheckBox(sheet, [newNode]);
  1116. refreshBtn(newNode);
  1117. }
  1118. }
  1119. if (!bills.tree.selected.data.hasGuide && bills.tree.selected.guidance.tree.items.length) {
  1120. bills.tree.selected.data.hasGuide = true;
  1121. setBillsForeColor([bills.tree.selected]);
  1122. }
  1123. if(callback){
  1124. callback();
  1125. }
  1126. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1127. guideItem.workBook.focus(true);
  1128. $.bootstrapLoading.end();
  1129. });
  1130. }
  1131. // 删除定额(嵌套删除自身及后代定额)
  1132. function delRations() {
  1133. const selected = bills.tree.selected.guidance.tree.selected;
  1134. if (!selected) {
  1135. return;
  1136. }
  1137. if (selected.data.type === itemType.ration) {
  1138. del({ row: selected.serialNo(), col: 0, rowCount: 1, colCount: 1 });
  1139. return;
  1140. }
  1141. const rations = selected.getPosterity().filter(item => item.data.type === itemType.ration);
  1142. if (!rations.length) {
  1143. return;
  1144. }
  1145. const updateDatas = rations.map(item => ({ updateType: updateType.del, findData: { ID: item.data.ID } }));
  1146. const rationIDs = rations.map(r => r.data.ID);
  1147. $.bootstrapLoading.start();
  1148. updateGuideItems(updateDatas, function () {
  1149. const guideSheet = guideItem.workBook.getSheet(0);
  1150. const treeNodes = bills.tree.selected.guidance.tree.items.filter(item => !rationIDs.includes(item.data.ID));
  1151. const state = bills.tree.selected.guidance.tree.getExpState(treeNodes);
  1152. const treeData = treeNodes.map(item => item.data);
  1153. initTree(bills.tree.selected.guidance, guideSheet, guideItem.treeSetting, treeData);
  1154. bills.tree.selected.guidance.tree.setExpandedByState(bills.tree.selected.guidance.tree.items, state);
  1155. renderSheetFunc(guideSheet, function () {
  1156. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.selected.guidance.tree.roots, guideSheet, true);
  1157. });
  1158. //设置底色
  1159. setNodesColor(guideSheet, bills.tree.selected.guidance.tree.items);
  1160. //项目指引初始焦点
  1161. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  1162. $.bootstrapLoading.end();
  1163. guideItem.workBook.focus(true)
  1164. });
  1165. }
  1166. //项目指引删除操作
  1167. //@return {void}
  1168. function del(selArea = null){
  1169. $.bootstrapLoading.start();
  1170. let controller = bills.tree.selected.guidance.controller;
  1171. let selNodes = [];
  1172. let sheet = guideItem.workBook.getSheet(0);
  1173. let sel = selArea ? selArea : sheet.getSelections()[0];
  1174. if(sel){
  1175. sel.row = sel.row === -1 ? 0 : sel.row;
  1176. for(let i = 0; i < sel.rowCount; i++){
  1177. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1178. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1179. }
  1180. }
  1181. }
  1182. //选中的块节点
  1183. let blockNodes = getBlockNodes(selNodes);
  1184. let updateDatas = [];
  1185. function getDelDatas(nodes){
  1186. for (let node of nodes) {
  1187. updateDatas.push({updateType: updateType.del, findData: {ID: node.getID()}});
  1188. if (node.children.length > 0) {
  1189. getDelDatas(node.children);
  1190. }
  1191. }
  1192. }
  1193. getDelDatas(blockNodes);
  1194. //更新相关的前节点
  1195. for (let node of blockNodes) {
  1196. if (node.preSibling && !blockNodes.includes(node.preSibling)) {
  1197. let next = node;
  1198. while (next.nextSibling && blockNodes.includes(next.nextSibling)) {
  1199. next = next.nextSibling;
  1200. }
  1201. updateDatas.push({updateType: updateType.update, findData: {ID: node.preSibling.getID()}, updateData: {NextSiblingID: next.getNextSiblingID()}});
  1202. }
  1203. }
  1204. updateGuideItems(updateDatas, function () {
  1205. console.log(blockNodes);
  1206. controller.m_delete(blockNodes);
  1207. guideItemInitSel(sheet.getActiveRowIndex());
  1208. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1209. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1210. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1211. if (bills.tree.selected.data.hasGuide && !bills.tree.selected.guidance.tree.items.length) {
  1212. bills.tree.selected.data.hasGuide = false;
  1213. setBillsForeColor([bills.tree.selected]);
  1214. }
  1215. $.bootstrapLoading.end();
  1216. guideItem.workBook.focus(true)
  1217. });
  1218. }
  1219. //项目指引升级
  1220. //@return {void}
  1221. function upLevel(){
  1222. $.bootstrapLoading.start();
  1223. let controller = bills.tree.selected.guidance.controller;
  1224. let selected = bills.tree.selected.guidance.tree.selected;
  1225. let updateDatas = [];
  1226. //更新父节点
  1227. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getParentID()}, updateData: {NextSiblingID: selected.getID()}});
  1228. //更新选中节点
  1229. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()},
  1230. updateData: {ParentID: selected.parent.getParentID(), NextSiblingID: selected.parent.getNextSiblingID()}});
  1231. if(selected.nextSibling && selected.children.length > 0){
  1232. //更新选中节点最末子节点
  1233. let lastChild = selected.children[selected.children.length - 1];
  1234. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: -1}});
  1235. }
  1236. //选中节点的所有后兄弟节点成为选中节点的子项
  1237. let selectedNextIDs = [];
  1238. let sNext = selected.nextSibling;
  1239. while(sNext){
  1240. selectedNextIDs.push(sNext.getID());
  1241. sNext = sNext.nextSibling;
  1242. }
  1243. for(let sID of selectedNextIDs){
  1244. updateDatas.push({updateType: updateType.update, findData: {ID: sID}, updateData: {ParentID: selected.getID()}});
  1245. }
  1246. updateGuideItems(updateDatas, function () {
  1247. controller.upLevel();
  1248. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1249. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1250. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1251. $.bootstrapLoading.end();
  1252. guideItem.workBook.focus(true)//31574
  1253. });
  1254. }
  1255. //项目指引降级
  1256. //@return {void}
  1257. function downLevel(){
  1258. $.bootstrapLoading.start();
  1259. let controller = bills.tree.selected.guidance.controller;
  1260. let selected = bills.tree.selected.guidance.tree.selected;
  1261. let updateDatas = [];
  1262. //更新前兄弟节点
  1263. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1264. //更新前兄弟节点最末子节点
  1265. if(selected.preSibling.children.length > 0){
  1266. let lastChild = selected.preSibling.children[selected.preSibling.children.length - 1];
  1267. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1268. }
  1269. //更新选中节点
  1270. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {ParentID: selected.preSibling.getID(), NextSiblingID: -1}});
  1271. updateGuideItems(updateDatas, function () {
  1272. controller.downLevel();
  1273. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1274. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1275. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1276. $.bootstrapLoading.end();
  1277. guideItem.workBook.focus(true)
  1278. });
  1279. }
  1280. //项目指引上移
  1281. //@return {void}
  1282. function upMove(){
  1283. $.bootstrapLoading.start();
  1284. let controller = bills.tree.selected.guidance.controller;
  1285. let selected = bills.tree.selected.guidance.tree.selected;
  1286. let updateDatas = [];
  1287. //更新前节点
  1288. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1289. //更新前前节点
  1290. if(selected.preSibling.preSibling){
  1291. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.preSibling.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1292. }
  1293. //更新选中节点
  1294. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.preSibling.getID()}});
  1295. updateGuideItems(updateDatas, function () {
  1296. controller.upMove();
  1297. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1298. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1299. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1300. $.bootstrapLoading.end();
  1301. guideItem.workBook.focus(true)
  1302. });
  1303. }
  1304. //项目指引下移
  1305. //@return {void}
  1306. function downMove(){
  1307. $.bootstrapLoading.start();
  1308. let controller = bills.tree.selected.guidance.controller;
  1309. let selected = bills.tree.selected.guidance.tree.selected;
  1310. let updateDatas = [];
  1311. //更新下节点
  1312. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getNextSiblingID()}, updateData: {NextSiblingID: selected.getID()}});
  1313. //更新前节点
  1314. if(selected.preSibling){
  1315. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1316. }
  1317. //更新选中节点
  1318. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.nextSibling.getNextSiblingID()}});
  1319. updateGuideItems(updateDatas, function () {
  1320. controller.downMove();
  1321. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1322. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1323. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1324. $.bootstrapLoading.end();
  1325. guideItem.workBook.focus(true)
  1326. });
  1327. }
  1328. //获取定额类型的项目指引名称,通过定额转换
  1329. //@param {Object}ration @return {String}
  1330. function getRationItemName(ration){
  1331. let arr = [];
  1332. arr.push(ration.code ? ration.code : '');
  1333. arr.push(ration.name ? ration.name : '');
  1334. arr.push(ration.basePrice ? ration.basePrice : '');
  1335. let rst = arr.join(' ');
  1336. rst += `/${ration.unit ? ration.unit : ''}`;
  1337. return rst;
  1338. }
  1339. //获取选中的定额表行
  1340. //@return {Array}
  1341. function getCheckedRationRows(all){
  1342. let rst = [];
  1343. let sheet = ration.workBook.getActiveSheet();
  1344. for(let i = 0; i < sheet.getRowCount(); i++){
  1345. // 全选
  1346. if (all) {
  1347. rst.push(i);
  1348. continue;
  1349. }
  1350. let checked = sheet.getValue(i, 0);
  1351. if(checked){
  1352. rst.push(i);
  1353. }
  1354. }
  1355. return rst;
  1356. }
  1357. //清空选中定额表行
  1358. //@param {Array}rows @return {void}
  1359. function clearCheckedRation(rows) {
  1360. let sheet = ration.workBook.getActiveSheet();
  1361. renderSheetFunc(sheet, function () {
  1362. for(let row of rows){
  1363. sheet.setValue(row, 0, 0);
  1364. }
  1365. });
  1366. }
  1367. //获取要插入的定额数据
  1368. //@param {Array}rows @return {Array}
  1369. function getInsertRations(rows){
  1370. let rst = [];
  1371. //当前已存在定额
  1372. let curRationIems = [];
  1373. let selected = bills.tree.selected.guidance.tree.selected;
  1374. if(selected){
  1375. if(selected.data.type === itemType.job){
  1376. curRationIems = selected.children;
  1377. }
  1378. else {
  1379. curRationIems = selected.parent ? selected.parent.children : selected.tree.roots;
  1380. }
  1381. }
  1382. for(let row of rows){
  1383. let selRation = ration.cache[row];
  1384. if(selRation){
  1385. //添加的定额是否已存在,不重复添加
  1386. let isExist = false;
  1387. for(let curRation of curRationIems){
  1388. if(curRation.data.rationID == selRation.ID){
  1389. isExist = true;
  1390. break;
  1391. }
  1392. }
  1393. if(!isExist){
  1394. rst.push({type: itemType.ration, name: getRationItemName(selRation), rationID: selRation.ID});
  1395. }
  1396. }
  1397. }
  1398. return rst;
  1399. }
  1400. //获取块节点父项不存在于选中节点中的节点
  1401. //@param {Array}nodes(选中的节点) @return {Array}
  1402. function getBlockNodes(nodes) {
  1403. let nodeMapping = {};
  1404. for(let node of nodes){
  1405. nodeMapping[node.data.ID] = node;
  1406. }
  1407. //块节点,父项不存在于选中节点中的节点
  1408. let blockNodes = [];
  1409. for(let node of nodes){
  1410. if(!nodeMapping[node.data.ParentID]){
  1411. blockNodes.push(node);
  1412. }
  1413. }
  1414. return blockNodes;
  1415. }
  1416. //允许复制整块,如果有多个块节点,且块节点的父项不同,则不可复制
  1417. //@param {Array}nodes(块节点) @return {Boolean}
  1418. function canCopyBlock(nodes) {
  1419. if(!nodes || nodes.length === 0){
  1420. return false;
  1421. }
  1422. let pID = nodes[0].data.ParentID;
  1423. for(let node of nodes){
  1424. if(node.data.ParentID !== pID){
  1425. return false;
  1426. }
  1427. }
  1428. return true;
  1429. }
  1430. //允许粘贴整块 有粘贴数据,节点存在,如果粘贴到的节点为定额数据,粘贴数据为全定额数据
  1431. //@param {Object}node(粘贴到的节点)
  1432. function canPasteBlock(node) {
  1433. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1434. if(!pasteDatas || pasteDatas.length === 0){
  1435. return false;
  1436. }
  1437. if(!node){
  1438. return false;
  1439. }
  1440. //若粘贴到定额节点,则数据须全为定额
  1441. if(node.data.type === itemType.ration){
  1442. for(let data of pasteDatas){
  1443. if(data.type !== itemType.ration){
  1444. return false;
  1445. }
  1446. }
  1447. }
  1448. //若粘贴到非定额节点,则粘贴的顶层数据须全为非定额
  1449. else {
  1450. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1451. for(let topData of topDatas){
  1452. if(topData.type === itemType.ration){
  1453. return false;
  1454. }
  1455. }
  1456. }
  1457. return true;
  1458. }
  1459. //复制整块,将块节点下所有节点数据复制一份,并且重新生成ID、ParentID、NextSiblingID,使用localStorage存储
  1460. //@param {Array}nodes(块节点) @return {void}
  1461. function copyBlocks(nodes) {
  1462. nodes = _.cloneDeep(nodes);
  1463. //将块节点的ParentID暂时设置为-1
  1464. for(let topNode of nodes){
  1465. topNode.data.ParentID = -1;
  1466. }
  1467. let copyDatas = [];
  1468. let copyNodes = [];
  1469. //获取块节点包含的所有节点(包括自己)
  1470. function containNodes(nodes) {
  1471. for(let node of nodes){
  1472. copyNodes.push(node);
  1473. if(node.children.length > 0){
  1474. containNodes(node.children);
  1475. }
  1476. }
  1477. }
  1478. containNodes(nodes);
  1479. for(let node of copyNodes){
  1480. copyDatas.push(node.data);
  1481. }
  1482. console.log(`copyDatas`);
  1483. console.log(copyDatas);
  1484. setLocalCache(itemCopyBlockKey, JSON.stringify(copyDatas));
  1485. }
  1486. //粘贴整块,整块数据粘贴到相关节点,并成为其后项
  1487. //@param {Object}node(粘贴到的节点) @return {void}
  1488. function pasteBlock(node) {
  1489. let itemObj = bills.tree.selected.guidance;
  1490. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1491. //整理ID
  1492. let IDMapping = {};
  1493. for(let data of pasteDatas){
  1494. data.newID = uuid.v1();
  1495. IDMapping[data.ID] = data;
  1496. }
  1497. for(let data of pasteDatas){
  1498. let nextData = IDMapping[data.NextSiblingID];
  1499. data.NextSiblingID = nextData ? nextData.newID : -1;
  1500. let parentData = IDMapping[data.ParentID];
  1501. data.ParentID = parentData ? parentData.newID : -1;
  1502. }
  1503. for(let data of pasteDatas){
  1504. data.ID = data.newID;
  1505. delete data.newID;
  1506. }
  1507. let updateDatas = [];
  1508. //将最顶层的块数据的ParentID设置成粘贴到节点的ParentID,并设置新的billsID
  1509. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1510. for(let topData of topDatas){
  1511. topData.ParentID = node.getParentID();
  1512. }
  1513. //更新数据
  1514. //更新插入的最末顶层数据NextSiblingID
  1515. if(node.nextSibling){
  1516. topDatas[topDatas.length - 1].NextSiblingID = node.getNextSiblingID();
  1517. }
  1518. //新建节点
  1519. for(let data of pasteDatas){
  1520. data.libID = libID;
  1521. data.billsID = node.data.billsID;
  1522. delete data._id;
  1523. updateDatas.push({updateType: updateType.create, updateData: data});
  1524. }
  1525. console.log(`pasteDatas`);
  1526. console.log(pasteDatas);
  1527. //更新粘贴到的节点的NextSiblingID
  1528. updateDatas.push({updateType: updateType.update, findData: {ID: node.data.ID}, updateData: {NextSiblingID: topDatas[0].ID}})
  1529. $.bootstrapLoading.start();
  1530. updateGuideItems(updateDatas, function (rstData) {
  1531. $.bootstrapLoading.end();
  1532. node.data.NextSiblingID = topDatas[0].ID;
  1533. let newNodes = itemObj.tree.insertDatasTo(node.data, pasteDatas);
  1534. cleanData(guideItem.workBook.getActiveSheet(), guideItem.headers, -1);
  1535. itemObj.controller.showTreeData();
  1536. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1537. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1538. }, function () {
  1539. $.bootstrapLoading.end();
  1540. });
  1541. }
  1542. //初始化右键菜单
  1543. //@return {void}
  1544. function initContextMenu() {
  1545. $.contextMenu({
  1546. selector: '#guideItemSpread',
  1547. build: function($triggerElement, e){
  1548. //控制允许右键菜单在哪个位置出现
  1549. let sheet = guideItem.workBook.getSheet(0);
  1550. let offset = $("#guideItemSpread").offset(),
  1551. x = e.pageX - offset.left,
  1552. y = e.pageY - offset.top;
  1553. let target = sheet.hitTest(x, y);
  1554. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  1555. let sel = sheet.getSelections()[0];
  1556. if(sel && sel.rowCount === 1){
  1557. sheet.setActiveCell(target.row, target.col);
  1558. }
  1559. sel = sheet.getSelections()[0];
  1560. let selNodes = [];
  1561. if(sel){
  1562. sel.row = sel.row === -1 ? 0 : sel.row;
  1563. for(let i = 0; i < sel.rowCount; i++){
  1564. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1565. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1566. }
  1567. }
  1568. }
  1569. //块节点
  1570. let blockNodes = getBlockNodes(selNodes);
  1571. //右键在多选内则不重设焦点
  1572. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  1573. sheet.setActiveCell(target.row, target.col);
  1574. }
  1575. guideItemInitSel(target.row);
  1576. return {
  1577. callback: function(){},
  1578. items: {
  1579. "copy": {
  1580. name: "复制整块",
  1581. disabled: function () {
  1582. return locked || !canCopyBlock(blockNodes);
  1583. },
  1584. icon: "fa-copy",
  1585. callback: function (key, opt) {
  1586. copyBlocks(blockNodes);
  1587. }},
  1588. "paste": {
  1589. name: "粘贴整块",
  1590. disabled: function () {
  1591. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1592. return locked || !canPasteBlock(pasteNode);
  1593. },
  1594. icon: "fa-paste",
  1595. callback: function (key, opt) {
  1596. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1597. pasteBlock(pasteNode);
  1598. }},
  1599. "delRations": {
  1600. name: '删除定额',
  1601. disabled: function () {
  1602. let node = bills.tree.selected.guidance.tree.items[target.row];
  1603. return locked || !node
  1604. },
  1605. icon: "fa-remove",
  1606. callback: function (key, opt) {
  1607. $('#delRationAlert').modal('show');
  1608. }
  1609. },
  1610. "del": {
  1611. name: '删除',
  1612. disabled: function () {
  1613. let node = bills.tree.selected.guidance.tree.items[target.row];
  1614. return locked || !node
  1615. },
  1616. icon: "fa-remove",
  1617. callback: function (key, opt) {
  1618. $('#delAlert').modal('show');
  1619. }
  1620. },
  1621. "insertSibling": {
  1622. name: '插入行',
  1623. disabled: function () {
  1624. let node = bills.tree.selected.guidance.tree.items[target.row];
  1625. return locked || !node || node.data.type !== itemType.job;
  1626. },
  1627. icon: "fa-arrow-left",
  1628. callback: function (key, opt) {
  1629. insert([{type: itemType.job, name: ''}], false);
  1630. }
  1631. },
  1632. "insertChild": {
  1633. name: '插入子项',
  1634. disabled: function () {
  1635. let node = bills.tree.selected.guidance.tree.items[target.row];
  1636. return locked || !node || node.data.type !== itemType.job || !allJobChildren(node);
  1637. },
  1638. icon: 'fa-arrow-left',
  1639. callback: function (key, opt) {
  1640. insert([{type: itemType.job, name: ''}], true);
  1641. }
  1642. }
  1643. }
  1644. };
  1645. }
  1646. else{
  1647. return false;
  1648. }
  1649. }
  1650. });
  1651. }
  1652. //展开至搜索出来点的节点
  1653. //@param {Array}nodes @return {void}
  1654. function expandSearchNodes(sheet, nodes, roots){
  1655. renderSheetFunc(sheet, function () {
  1656. function expParentNode(node){
  1657. if(node.parent){
  1658. if (!node.parent.expanded) {
  1659. node.parent.setExpanded(true);
  1660. }
  1661. expParentNode(node.parent);
  1662. }
  1663. }
  1664. for(let node of nodes){
  1665. expParentNode(node);
  1666. }
  1667. TREE_SHEET_HELPER.refreshNodesVisible(roots, sheet, true);
  1668. });
  1669. }
  1670. // 清空搜索高亮
  1671. function clearHighLight(sheet) {
  1672. renderSheetFunc(sheet, () => {
  1673. for (let i = 0; i < sheet.getRowCount(); i++){
  1674. setBgColor(sheet, i, 'white')
  1675. }
  1676. });
  1677. }
  1678. // 清空搜索状态
  1679. // 关闭搜索清单结果
  1680. function closeSearchBills(sheet) {
  1681. if (!bills.tree) {
  1682. return;
  1683. }
  1684. $('#searchBillsResult').hide();
  1685. bills.tree.items.forEach(node => {
  1686. node.isSearch = false;
  1687. });
  1688. clearHighLight(sheet);
  1689. setBgColor(sheet, sheet.getActiveRowIndex(), selectedBgColor);
  1690. }
  1691. // 搜索清单
  1692. function searchBills() {
  1693. if (!bills.tree || !bills.workBook) {
  1694. return;
  1695. }
  1696. const sheet = bills.workBook.getActiveSheet();
  1697. const str = $('#searchBillText').val().trim();
  1698. // 空搜索字符,关闭搜索
  1699. if (!str) {
  1700. if ($('#searchBillsResult').is(':visible')) {
  1701. closeSearchBills(sheet);
  1702. }
  1703. return;
  1704. }
  1705. // 过滤清单
  1706. const result = bills.tree.items.filter(item => {
  1707. const codeIs = item.data.code ? item.data.code.indexOf(str) !== -1 : false;
  1708. const nameIs = item.data.name ? item.data.name.indexOf(str) !== -1 : false;
  1709. return codeIs || nameIs;
  1710. });
  1711. if (!result.length) {
  1712. closeSearchBills(sheet);
  1713. return;
  1714. }
  1715. // 显示搜索结果
  1716. $("#searchBillsResult").show();
  1717. $('#searchBillsCount').text(result.length);
  1718. //展开搜索出来的节点
  1719. expandSearchNodes(sheet, result, bills.tree.roots);
  1720. // 标黄结果
  1721. clearHighLight(sheet);
  1722. const col = sheet.getActiveColumnIndex();
  1723. renderSheetFunc(sheet, function () {
  1724. bills.controller.setTreeSelected(result[0]);
  1725. bills.tree.items.forEach(node => {
  1726. if (result.includes(node)) {
  1727. setBgColor(sheet, node.serialNo(), searchBgColor);
  1728. node.isSearch = true; // 标记为搜索结果,防止被焦点行变更恢复颜色
  1729. } else {
  1730. node.isSearch = false;
  1731. }
  1732. })
  1733. });
  1734. //搜索初始定位
  1735. const row = sheet.getActiveRowIndex();
  1736. sheet.setSelection(result[0].serialNo(), col, 1, 1);
  1737. billsInitSel(result[0].serialNo(), { row });
  1738. sheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  1739. let curIndex = 0;
  1740. // 上一条
  1741. $('#preBill').unbind('click');
  1742. $('#preBill').bind('click', () => {
  1743. const node = result[curIndex - 1];
  1744. if (!node) {
  1745. return;
  1746. }
  1747. curIndex -= 1;
  1748. const col = sheet.getActiveColumnIndex();
  1749. const row = node.serialNo();
  1750. const orgRow = sheet.getActiveRowIndex();
  1751. sheet.setSelection(row, col, 1, 1);
  1752. billsInitSel(row, { row: orgRow });
  1753. sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
  1754. });
  1755. // 下一条
  1756. $('#nextBills').unbind('click');
  1757. $('#nextBills').bind('click', () => {
  1758. const node = result[curIndex + 1];
  1759. if (!node) {
  1760. return;
  1761. }
  1762. curIndex += 1;
  1763. const col = sheet.getActiveColumnIndex();
  1764. const row = node.serialNo();
  1765. const orgRow = sheet.getActiveRowIndex();
  1766. sheet.setSelection(row, col, 1, 1);
  1767. billsInitSel(row, { row: orgRow });
  1768. sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
  1769. });
  1770. }
  1771. //初始化个按钮点击
  1772. //@return {void}
  1773. function initBtn(){
  1774. $('#insert').click(function () {
  1775. insert([{type: itemType.job, name: '', outputItemCharacter: true }], false);
  1776. });
  1777. $('#delConfirm').click(function () {
  1778. del();
  1779. $('#delAlert').modal('hide');
  1780. });
  1781. $('#delRationConfirm').click(function () {
  1782. delRations();
  1783. $('#delRationAlert').modal('hide');
  1784. });
  1785. $('#del').click(function () {
  1786. $('#delAlert').modal('show');
  1787. });
  1788. $('#upLevel').click(function () {
  1789. upLevel();
  1790. });
  1791. $('#downLevel').click(function () {
  1792. downLevel();
  1793. });
  1794. $('#upMove').click(function () {
  1795. upMove();
  1796. });
  1797. $('#downMove').click(function () {
  1798. downMove();
  1799. });
  1800. // 收起清单至第二层
  1801. $('#expandToSecond').click(function() {
  1802. if (!bills.tree || !bills.workBook) {
  1803. return;
  1804. }
  1805. bills.tree.roots.forEach(root => {
  1806. root.setExpanded(true);
  1807. root.children.forEach(item => {
  1808. item.setExpanded(false);
  1809. });
  1810. });
  1811. const billSheet = bills.workBook.getActiveSheet();
  1812. renderSheetFunc(billSheet, function () {
  1813. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.roots, billSheet, true);
  1814. });
  1815. })
  1816. //收起定额、展开全部
  1817. $('#expandContract').click(function () {
  1818. //目前状态时展开全部节点状态,点击则收起定额
  1819. let tree = bills.tree.selected.guidance.tree,
  1820. itemSheet = guideItem.workBook.getActiveSheet();
  1821. if(curExpandState === itemExpandState.expand){
  1822. curExpandState = itemExpandState.contract;
  1823. $(this).html('<i class="fa fa-plus-square-o" aria-hidden="true"></i> 展开全部');
  1824. setNodesExpandState(tree.items, itemExpandState.contract);
  1825. } else {
  1826. curExpandState = itemExpandState.expand;
  1827. $(this).html('<i class="fa fa-minus-square-o" aria-hidden="true"></i> 收起定额');
  1828. setNodesExpandState(tree.items, itemExpandState.expand);
  1829. }
  1830. renderSheetFunc(itemSheet, function () {
  1831. TREE_SHEET_HELPER.refreshNodesVisible(tree.roots, itemSheet, true);
  1832. });
  1833. });
  1834. // 插入选中定额
  1835. $('#insertRation').click(function () {
  1836. let checkedRows = getCheckedRationRows();
  1837. let insertDatas = getInsertRations(checkedRows);
  1838. if(insertDatas.length > 0){
  1839. insert(insertDatas, false, function () {
  1840. //清空选择
  1841. clearCheckedRation(checkedRows);
  1842. });
  1843. }
  1844. else {
  1845. clearCheckedRation(checkedRows);
  1846. }
  1847. });
  1848. // 插入全部定额
  1849. $('#insertAll').click(function () {
  1850. let isAll = true;
  1851. let checkedRows = getCheckedRationRows(isAll);
  1852. let insertDatas = getInsertRations(checkedRows);
  1853. if(insertDatas.length > 0){
  1854. insert(insertDatas, false);
  1855. }
  1856. });
  1857. // 搜索清单
  1858. $("#searchBillBtn").click(searchBills);
  1859. $('#searchBillText').keyup(function (e) {
  1860. delayKeyup(function () {
  1861. $('#searchBillBtn').click();
  1862. });
  1863. });
  1864. // 关闭搜索清单
  1865. $('#closeSearchBills').click(() => {
  1866. if (!bills.workBook) {
  1867. return;
  1868. }
  1869. const sheet = bills.workBook.getActiveSheet();
  1870. closeSearchBills(sheet);
  1871. })
  1872. //搜索定额
  1873. $('#searchBtn').click(function () {
  1874. let searchStr = $('#searchText').val();
  1875. if(!searchStr || searchStr === ''){
  1876. ration.cache = ration.datas;
  1877. }
  1878. else{
  1879. let reg = new RegExp(searchStr, 'i');
  1880. ration.cache = _.filter(ration.datas, function (data) {
  1881. return reg.test(data.code) || reg.test(data.name);
  1882. });
  1883. }
  1884. $('.top-content').hide();
  1885. $('#searchCount').text(`搜索结果: ${ration.cache.length}`);
  1886. $('#rationSearchResult').show();
  1887. autoFlashHeight();
  1888. ration.workBook.refresh();
  1889. let rationSheet = ration.workBook.getActiveSheet();
  1890. renderSheetFunc(rationSheet, function () {
  1891. clearCheckedRation(getCheckedRationRows());
  1892. showData(rationSheet, ration.headers, ration.cache);
  1893. })
  1894. });
  1895. //关闭搜索
  1896. $('#rationSearchResult a').click(function () {
  1897. $('.top-content').show();
  1898. $('#rationSearchResult').hide();
  1899. autoFlashHeight();
  1900. renderSheetFunc(ration.workBook.getActiveSheet(), function () {
  1901. clearCheckedRation(getCheckedRationRows());
  1902. });
  1903. section.workBook.refresh();
  1904. ration.workBook.refresh();
  1905. $('#searchText').val('');
  1906. //恢复章节树下的定额
  1907. sectionInitSel(section.workBook.getActiveSheet().getActiveRowIndex());
  1908. });
  1909. let keyupTime = 0,
  1910. delayTime = 500;
  1911. function delayKeyup(callback) {
  1912. let nowTime = Date.now();
  1913. keyupTime = nowTime;
  1914. setTimeout(function () {
  1915. if (nowTime - keyupTime == 0) {
  1916. callback();
  1917. }
  1918. }, delayTime);
  1919. }
  1920. //执行搜索
  1921. $('#searchText').keyup(function (e) {
  1922. delayKeyup(function () {
  1923. $('#searchBtn').click();
  1924. });
  1925. });
  1926. //编辑清单备注
  1927. $('.main-side-bottom').find('textarea').keyup(function () {
  1928. let me = this;
  1929. let node = bills.tree.selected;
  1930. let comment = $(me).val();
  1931. delayKeyup(function () {
  1932. if (node) {
  1933. let updateData = {lastOperator: userAccount, billsLibId: billsLibId, updateId: node.getID(), field: 'comment', data: comment};
  1934. updateBillsComment(updateData, function () {
  1935. node.data.comment = comment;
  1936. }, function() {
  1937. $(me).val(node.data.comment || '');
  1938. })
  1939. }
  1940. });
  1941. });
  1942. //编辑选项备注
  1943. $('.main-bottom-content').find('textarea').keyup(function () {
  1944. let me = this;
  1945. let node = bills.tree.selected.guidance.tree.selected;
  1946. let comment = $(me).val();
  1947. delayKeyup(function () {
  1948. if(node){
  1949. let updateDatas = [{updateType: updateType.update, findData: {ID: node.getID()}, updateData: {comment: comment}}];
  1950. updateGuideItems(updateDatas, function (rstData) {
  1951. node.data.comment = comment;
  1952. }, function() {
  1953. $(me).val(node.data.comment || '');
  1954. });
  1955. }
  1956. });
  1957. });
  1958. //定额高度拖动调整
  1959. let heightEleObj = {
  1960. module: moduleName,
  1961. resize: $('#deResize'),
  1962. top: $('#topContent'),
  1963. topSpread: $('#sectionSpread'),
  1964. bottom: $('#bottomContent'),
  1965. bottomSpread: $('#rationSpread')
  1966. },
  1967. heightLimit = {
  1968. min: 150,
  1969. max: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-150-10`,
  1970. notTopSpread: 0,
  1971. notBottomSpread: 0,
  1972. };
  1973. SlideResize.verticalSlide(heightEleObj, heightLimit, function () {
  1974. if(section.workBook){
  1975. section.workBook.refresh();
  1976. }
  1977. if(ration.workBook){
  1978. ration.workBook.refresh();
  1979. }
  1980. });
  1981. /*slideResize(rationLibResizeEles, {min: 147, max: 680}, 'height', function() {
  1982. //autoFlashHeight();
  1983. if(section.workBook){
  1984. section.workBook.refresh();
  1985. }
  1986. if(ration.workBook){
  1987. ration.workBook.refresh();
  1988. }
  1989. });*/
  1990. //左右拖动
  1991. //清单表与项目指引表
  1992. let leftElesObj = {};
  1993. leftElesObj.module = moduleName;
  1994. leftElesObj.resize = $('#slideResizeLeft');
  1995. leftElesObj.parent = $('#dataRow');
  1996. leftElesObj.left = $('#leftContent');
  1997. leftElesObj.right = $('#midContent');
  1998. SlideResize.horizontalSlide(leftElesObj, {min: 200, max: `$('#dataRow').width() - $('#rightContent').width() - 200`}, function () {
  1999. refreshALlWorkBook();
  2000. });
  2001. //人材机表与人材机组成物表
  2002. let rightElesObj = {};
  2003. rightElesObj.module = moduleName;
  2004. rightElesObj.resize = $('#slideResizeRight');
  2005. rightElesObj.parent = $('#dataRow');
  2006. rightElesObj.left = $('#midContent');
  2007. rightElesObj.right = $('#rightContent');
  2008. SlideResize.horizontalSlide(rightElesObj, {min: 200, max: `$('#dataRow').width() - $('#leftContent').width() - 200`}, function () {
  2009. refreshALlWorkBook();
  2010. });
  2011. }
  2012. //刷新全部工作簿
  2013. //@return {void}
  2014. function refreshALlWorkBook() {
  2015. if (bills.workBook) {
  2016. bills.workBook.refresh();
  2017. }
  2018. if (guideItem.workBook) {
  2019. guideItem.workBook.refresh();
  2020. }
  2021. if (section.workBook) {
  2022. section.workBook.refresh();
  2023. }
  2024. if (ration.workBook) {
  2025. ration.workBook.refresh();
  2026. }
  2027. $('.main-side-bottom').find('textarea').height($('.main-side-bottom').height() - 20);
  2028. $('.main-side-bottom').find('textarea').width($('.main-side-bottom').width() - 25);
  2029. $('.main-bottom-content').find('textarea').height($('.main-bottom-content').height() - 20);
  2030. $('.main-bottom-content').find('textarea').width($('.main-bottom-content').width() - 25);
  2031. }
  2032. //读取拖动相关
  2033. //@return {void}
  2034. function initSlideSize() {
  2035. //定额表上下
  2036. let heightEleObj = {
  2037. module: moduleName,
  2038. top: $('#topContent'),
  2039. topSpread: $('#sectionSpread'),
  2040. bottom: $('#bottomContent'),
  2041. bottomSpread: $('#rationSpread')
  2042. };
  2043. SlideResize.loadVerticalHeight(heightEleObj.module, heightEleObj,
  2044. {totalHeight: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-10`,
  2045. notTopSpread: 0, notBottomSpread: 0}, function () {
  2046. if(section.workBook){
  2047. section.workBook.refresh();
  2048. }
  2049. if(ration.workBook){
  2050. ration.workBook.refresh();
  2051. }
  2052. });
  2053. //水平
  2054. SlideResize.loadHorizonWidth(moduleName, [$('#slideResizeLeft'), $('#slideResizeRight')], [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
  2055. refreshALlWorkBook();
  2056. });
  2057. }
  2058. //初始化视图
  2059. //@param {void} @return {void}
  2060. function initViews(){
  2061. let modules = [bills, guideItem, section, ration];
  2062. initWorkBooks(modules);
  2063. lockUtil.lockTools($(document.body), locked);
  2064. getLibWithBills(libID);
  2065. initBtn();
  2066. initContextMenu();
  2067. initSlideSize();
  2068. }
  2069. return {initViews, initSlideSize};
  2070. })();
  2071. $(document).ready(function () {
  2072. billsGuidance.initViews();
  2073. });