billsGuidance.js 108 KB

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