billsGuidance.js 106 KB

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