billsGuidance.js 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548
  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. $('#insertRation').addClass('disabled');
  788. $('#insertAll').addClass('disabled');
  789. $('.main-bottom-content').find('textarea').attr('readonly', true);
  790. //插入
  791. if(bills.tree.selected && bills.tree.selected.guidance.tree){
  792. $('#insert').removeClass('disabled');
  793. if(node && node.data.type === itemType.ration){
  794. $('#insert').addClass('disabled');
  795. }
  796. }
  797. //删除
  798. if(node){
  799. $('#del').removeClass('disabled');
  800. }
  801. if(node && node.data.type === itemType.job){
  802. //升级
  803. if(node.parent){
  804. $('#upLevel').removeClass('disabled');
  805. if(node.nextSibling && node.children.length > 0 && !allJobChildren(node)){
  806. $('#upLevel').addClass('disabled');
  807. }
  808. }
  809. //降级
  810. if(node.preSibling){
  811. $('#downLevel').removeClass('disabled');
  812. if(node.preSibling.children.length > 0 && !allJobChildren(node.preSibling)){
  813. $('#downLevel').addClass('disabled');
  814. }
  815. }
  816. }
  817. //上移
  818. if(node && node.preSibling){
  819. $('#upMove').removeClass('disabled')
  820. }
  821. //下移
  822. if(node && node.nextSibling){
  823. $('#downMove').removeClass('disabled');
  824. }
  825. //收起定额、展开全部
  826. $('#expandContract').removeClass('disabled');
  827. //插入定额
  828. if(node && (node.children.length === 0 || allRationChildren(node))){
  829. $('#insertRation').removeClass('disabled');
  830. $('#insertAll').removeClass('disabled');
  831. }
  832. //备注,奇数节点可用
  833. if(isProcessNode(node)){
  834. $('.main-bottom-content').find('textarea').attr('readonly', false);
  835. }
  836. }
  837. //项目指引表焦点控制
  838. //@param {Number}row @return {void}
  839. function guideItemInitSel(row){
  840. let billsNode = bills.tree.selected;
  841. let node = null;
  842. if(billsNode && billsNode.guidance.tree){
  843. node = billsNode.guidance.tree.items[row];
  844. if(node){
  845. billsNode.guidance.tree.selected = node;
  846. //显示备注
  847. $('.main-bottom-content').find('textarea').val(node.data.comment ? node.data.comment : '');
  848. }
  849. }
  850. refreshBtn(node);
  851. }
  852. //初始化当前库名
  853. //@param {String} @return {void}
  854. function initLibName(libName) {
  855. $('#libName')[0].outerHTML = $('#libName')[0].outerHTML.replace("XXX清单指引", libName);
  856. }
  857. //初始化各工作表
  858. //@param {Array}modules @return {void}
  859. function initWorkBooks(modules){
  860. for(let module of modules){
  861. buildSheet(module);
  862. }
  863. }
  864. function tipDivCheck(){
  865. setTimeout(function () {
  866. let tips = $('#autoTip');
  867. if(ration.tipDiv == 'show'){
  868. return;
  869. } else if(ration.tipDiv == 'hide'&&tips){
  870. tips.hide();
  871. ration._toolTipElement = null;
  872. }
  873. },600)
  874. }
  875. //获取悬浮提示单元格
  876. //@param {Object}sheet @return {Object}
  877. function getTipCellType(sheet) {
  878. let setting = {};
  879. let TipCellType = function () {};
  880. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  881. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  882. return {
  883. x: x,
  884. y: y,
  885. row: context.row,
  886. col: context.col,
  887. cellStyle: cellStyle,
  888. cellRect: cellRect,
  889. sheet: context.sheet,
  890. sheetArea: context.sheetArea
  891. };
  892. };
  893. TipCellType.prototype.processMouseEnter = function (hitinfo) {
  894. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  895. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  896. if(tag !== undefined && tag){
  897. text = tag;
  898. }
  899. if(sheet && sheet.getParent().qo){
  900. setting.pos = SheetDataHelper.getObjPos(sheet.getParent().qo);
  901. }
  902. let delayTimes = 500; //延时时间
  903. let now_timeStamp = +new Date();
  904. this.tipTimeStamp = now_timeStamp;
  905. let me = this;
  906. setTimeout(function () {
  907. if(now_timeStamp - me.tipTimeStamp == 0){//鼠标停下的时候才显示
  908. if (setting.pos && text && text !== '') {
  909. //固定不显示的div,存储文本获取固定div宽度,toolTipElement由于显示和隐藏,获取宽度不正确
  910. if(!me._fixedTipElement){
  911. let div = $('#fixedTip1')[0];
  912. if (!div) {
  913. div = document.createElement("div");
  914. $(div).css("padding", 5)
  915. .attr("id", 'fixedTip');
  916. $(div).hide();
  917. document.body.insertBefore(div, null);
  918. }
  919. me._fixedTipElement = div;
  920. }
  921. $(me._fixedTipElement).width('');
  922. $(me._fixedTipElement).html(text);
  923. if (!me._toolTipElement) {
  924. let div = $('#autoTip1')[0];
  925. if (!div) {
  926. div = document.createElement("div");
  927. $(div).css("position", "absolute")
  928. .css("border", "1px #C0C0C0 solid")
  929. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  930. .css("font", "0.9rem Calibri")
  931. .css("background", "white")
  932. .css("padding", 5)
  933. .attr("id", 'autoTip1');
  934. $(div).hide();
  935. document.body.insertBefore(div, null);
  936. }
  937. me._toolTipElement = div;
  938. $(me._toolTipElement).width('');
  939. //实时读取位置信息
  940. if(hitinfo.sheet && hitinfo.sheet.getParent().qo){
  941. setting.pos = SheetDataHelper.getObjPos(hitinfo.sheet.getParent().qo);
  942. }
  943. $(me._toolTipElement).html(text);
  944. //定额库定额特殊处理
  945. if($(hitinfo.sheet.getParent().qo).attr('id') === 'rationSpread'){
  946. let divWidth = $(me._fixedTipElement).width(),
  947. divHeight = $(me._fixedTipElement).height();
  948. if(divWidth > 600){
  949. divWidth = 590;
  950. $(me._toolTipElement).width(divWidth);
  951. }
  952. let top = setting.pos.y + hitinfo.y - divHeight < 0 ? 0 : setting.pos.y + hitinfo.cellRect.y - divHeight;
  953. $(me._toolTipElement).css("top", top).css("left", setting.pos.x - divWidth);
  954. }
  955. else{
  956. $(me._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  957. }
  958. //名称
  959. if(hitinfo.col === 2){
  960. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  961. zoom = hitinfo.sheet.zoom();
  962. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  963. let textLength = me.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  964. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  965. if(textLength > cellWidth){
  966. $(me._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  967. $(me._toolTipElement).show("fast");
  968. ration.tipDiv = 'show';//做个标记
  969. }
  970. }
  971. else {
  972. $(me._toolTipElement).show("fast");
  973. ration.tipDiv = 'show';//做个标记
  974. }
  975. }
  976. }
  977. }
  978. },delayTimes);
  979. };
  980. TipCellType.prototype.processMouseLeave = function (hininfo) {
  981. this.tipTimeStamp = +new Date();
  982. ration.tipDiv = 'hide';
  983. if (this._toolTipElement) {
  984. $(this._toolTipElement).hide();
  985. this._toolTipElement = null;
  986. }
  987. tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  988. }
  989. return new TipCellType();
  990. }
  991. //输出表数据(定额表)
  992. //@param {Object}sheet {Array}headers {Array}datas @return {void}
  993. function showData(sheet, headers, datas){
  994. let fuc = function () {
  995. sheet.setRowCount(datas.length);
  996. //复选框
  997. let checkBoxType = new GC.Spread.Sheets.CellTypes.CheckBox();
  998. let tipCellType = getTipCellType(sheet);
  999. sheet.setCellType(-1, 0, checkBoxType);
  1000. for(let col = 0, cLen = headers.length; col < cLen; col++){
  1001. for(let row = 0, rLen = datas.length; row < rLen; row++){
  1002. sheet.setValue(row, col, datas[row][headers[col]['dataCode']]);
  1003. if(col === 1){
  1004. sheet.setTag(row, col, datas[row]['hint']);
  1005. }
  1006. }
  1007. }
  1008. sheet.setCellType(-1, 1, tipCellType);
  1009. sheet.setCellType(-1, 2, tipCellType);
  1010. };
  1011. renderSheetFunc(sheet, fuc);
  1012. }
  1013. //根据定额章节树ID获取定额(从数据缓存中获取,定额数据一开始一次性拉取)
  1014. //@param {Number}sectionId {Array}rations @return {Array}
  1015. function getRationsBySectionId(sectionId, rations) {
  1016. if(!sectionId || !rations){
  1017. return [];
  1018. }
  1019. return _.filter(rations, {sectionId});
  1020. }
  1021. //定额章节树焦点控制
  1022. //@param {Number}row @return {void}
  1023. function sectionInitSel(row) {
  1024. let rationSheet = ration.workBook.getActiveSheet();
  1025. let sectionNode = section.tree ? section.tree.items[row] : null;
  1026. if(sectionNode && sectionNode.children.length === 0){
  1027. let sectionRations = getRationsBySectionId(sectionNode.data.ID, ration.datas);
  1028. ration.cache = sectionRations;
  1029. showData(rationSheet, ration.headers, sectionRations);
  1030. }
  1031. else {
  1032. cleanData(rationSheet, ration.headers, 0);
  1033. }
  1034. }
  1035. //初始化定额条目
  1036. //@param {Number}rationLibId @return {void}
  1037. function initRationItems(rationLibId, successCb){
  1038. $.bootstrapLoading.start();
  1039. //获取定额章节树
  1040. let sectionSheet = section.workBook.getActiveSheet();
  1041. CommonAjax.post('/rationRepository/api/getRationTree', {rationLibId: rationLibId}, function (sectionDatas) {
  1042. //获取所有定额数据
  1043. let reqEntity = {rationLibId: rationLibId, showHint: true, returnFields: '-_id code ID sectionId name unit basePrice rationGljList jobContent annotation'};
  1044. CommonAjax.post('/rationRepository/api/getRationItemsByLib', reqEntity, function (rstData) {
  1045. section.cache = sectionDatas;
  1046. initTree(section, section.workBook.getActiveSheet(), section.treeSetting, sectionDatas);
  1047. //初始焦点在第一行(切换库)
  1048. sectionSheet.setActiveCell(0, 0);
  1049. sortByCode(rstData);
  1050. /* rstData.sort(function (a, b) {
  1051. let rst = 0;
  1052. if(a.code > b.code){
  1053. rst = 1;
  1054. }
  1055. else if(a.code < b.code){
  1056. rst = -1;
  1057. }
  1058. return rst;
  1059. }); */
  1060. ration.datas = rstData;
  1061. sectionInitSel(0);
  1062. $.bootstrapLoading.end();
  1063. if (successCb) {
  1064. successCb();
  1065. }
  1066. }, function () {
  1067. $.bootstrapLoading.end();
  1068. });
  1069. }, function () {
  1070. $.bootstrapLoading.end();
  1071. });
  1072. }
  1073. // 可用的定额库ID
  1074. const rationLibIDs = [];
  1075. //初始化定额库选择
  1076. //@param {String}compilationId @return {void}
  1077. function initRationLibs(compilationId){
  1078. CommonAjax.post('/rationRepository/api/getRationLibsByCompilation', {compilationId: compilationId}, function (rstData) {
  1079. $('#rationLibSel').empty();
  1080. for(let rationLib of rstData){
  1081. rationLibIDs.push(+rationLib.ID);
  1082. let opt = `<option value="${rationLib.ID}">${rationLib.dispName}</option>`;
  1083. $('#rationLibSel').append(opt);
  1084. }
  1085. //初始选择
  1086. initRationItems(parseInt($('#rationLibSel').select().val()));
  1087. $('#rationLibSel').change(function () {
  1088. let rationLibId = parseInt($(this).select().val());
  1089. initRationItems(rationLibId);
  1090. })
  1091. });
  1092. }
  1093. // 变更定额库
  1094. function changeRationLib(libID, successCb) {
  1095. $('#rationLibSel').val(libID);
  1096. initRationItems(libID, successCb);
  1097. }
  1098. // 设置清单名称文本色
  1099. function setBillsForeColor(billsNodes) {
  1100. const sheet = bills.workBook.getActiveSheet();
  1101. renderSheetFunc(sheet, function () {
  1102. for(let bills of billsNodes){
  1103. const row = bills.serialNo();
  1104. sheet.setStyle(row, 1, { foreColor: bills.data.hasGuide ? 'darkgreen' : 'black' });
  1105. }
  1106. });
  1107. }
  1108. //清单设置悬浮提示信息
  1109. //@param {Array}billsNodes(清单节点) {Array}jobs(总的工作内容数据) {Array}items(总的项目特征数据)
  1110. function setBillsHint(billsNodes, jobs, items) {
  1111. let jobsMapping = {},
  1112. itemsMapping = {};
  1113. for(let job of jobs){
  1114. jobsMapping[job.id] = job;
  1115. }
  1116. for(let item of items){
  1117. itemsMapping[item.id] = item;
  1118. }
  1119. let tagInfo = [];
  1120. for(let billsNode of billsNodes){
  1121. let hintArr = [];
  1122. let billsItems = billsNode.data.items;
  1123. if(billsItems.length > 0){
  1124. //项目特征
  1125. hintArr.push('项目特征:');
  1126. }
  1127. let itemCount = 1,
  1128. jobCount = 1;
  1129. for(let billsItem of billsItems){
  1130. let itemData = itemsMapping[billsItem.id];
  1131. if(itemData){
  1132. //特征值
  1133. let eigens = [];
  1134. for(let eigen of itemData.itemValue){
  1135. eigens.push(eigen.value);
  1136. }
  1137. eigens = eigens.join(';');
  1138. hintArr.push(`${itemCount}.${itemData.content}${eigens === '' ? '' : ': ' + eigens}`);
  1139. itemCount ++;
  1140. }
  1141. }
  1142. //工作内容
  1143. let billsJobs = billsNode.data.jobs;
  1144. if(billsJobs.length > 0){
  1145. hintArr.push('工作内容:');
  1146. }
  1147. for(let billsJob of billsJobs){
  1148. let jobData = jobsMapping[billsJob.id];
  1149. if(jobData){
  1150. hintArr.push(`${jobCount}.${jobData.content}`);
  1151. jobCount ++;
  1152. }
  1153. }
  1154. /*if(billsNode.data.ruleText && billsNode.data.ruleText !== ''){
  1155. hintArr.push('工程量计算规则:');
  1156. hintArr.push(billsNode.data.ruleText);
  1157. }
  1158. if(billsNode.data.recharge && billsNode.data.recharge !== ''){
  1159. hintArr.push('补注:');
  1160. hintArr.push(billsNode.data.recharge);
  1161. }*/
  1162. if(hintArr.length > 0){
  1163. tagInfo.push({row: billsNode.serialNo(), value: hintArr.join('\n')});
  1164. }
  1165. }
  1166. let sheet = bills.workBook.getActiveSheet();
  1167. renderSheetFunc(sheet, function () {
  1168. for(let tagI of tagInfo){
  1169. sheet.setTag(tagI.row, 0, tagI.value);
  1170. }
  1171. });
  1172. }
  1173. //初始化清单的工作内容和项目特征
  1174. //@param {Number}billsLibId {Function}callback @return {void}
  1175. function initJobAndCharacter(billsLibId, callback){
  1176. CommonAjax.post('/stdBillsEditor/getJobContent', {billsLibId: billsLibId}, function (datas) {
  1177. stdBillsJobData = datas;
  1178. CommonAjax.post('/stdBillsEditor/getItemCharacter', {billsLibId: billsLibId}, function (datas) {
  1179. stdBillsFeatureData = datas;
  1180. if(callback){
  1181. callback();
  1182. }
  1183. });
  1184. });
  1185. }
  1186. let billsLibId = 0;
  1187. //获取指引库信息及关联的清单
  1188. //@param {Number}libID {Function}callback @return {Object}
  1189. function getLibWithBills(libID, callback){
  1190. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function (rstData) {
  1191. billsLibId = rstData.guidanceLib.billsLibId;
  1192. initRationLibs(rstData.guidanceLib.compilationId);
  1193. curCompilationID = rstData.guidanceLib.compilationId;
  1194. bills.cache = rstData.bills;
  1195. initLibName(rstData.guidanceLib.name);
  1196. /*initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  1197. //每一棵项目指引树挂在清单节点上
  1198. for(let node of bills.tree.items){
  1199. node.guidance = {tree: null, controller: null};
  1200. }
  1201. //默认初始节点
  1202. billsInitSel(0);
  1203. if(callback){
  1204. callback(rstData);
  1205. }*/
  1206. let initDataCallback = function () {
  1207. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  1208. //每一棵项目指引树挂在清单节点上
  1209. for(let node of bills.tree.items){
  1210. node.guidance = {tree: null, controller: null};
  1211. }
  1212. //默认初始节点
  1213. billsInitSel(0);
  1214. if(callback){
  1215. callback(rstData);
  1216. }
  1217. };
  1218. initJobAndCharacter(rstData.guidanceLib.billsLibId, initDataCallback);
  1219. }, function (msg) {
  1220. window.location.href = '/billsGuidance/main';
  1221. });
  1222. }
  1223. //初始化并输出树
  1224. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  1225. function initTree(module, sheet, treeSetting, datas){
  1226. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  1227. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  1228. module.tree.loadDatas(datas);
  1229. if(module === bills){
  1230. module.tree.roots.forEach(root => {
  1231. root.setExpanded(false);
  1232. })
  1233. }
  1234. module.controller.showTreeData();
  1235. if(module === bills){
  1236. setBillsHint(bills.tree.items, stdBillsJobData, stdBillsFeatureData);
  1237. setBillsForeColor(bills.tree.items);
  1238. }
  1239. }
  1240. //更新清单备注
  1241. function updateBillsComment(updateData, callback, errCB) {
  1242. CommonAjax.post('/stdBillsEditor/updateBills', updateData, function () {
  1243. if (callback) {
  1244. callback();
  1245. }
  1246. }, function () {
  1247. if(errCB) {
  1248. errCB();
  1249. }
  1250. });
  1251. }
  1252. //更新项目指引
  1253. //@param {Array}updateDatas {Function}callback @return {void}
  1254. function updateGuideItems(updateDatas, callback, errCB){
  1255. CommonAjax.post('/billsGuidance/api/updateItems', {updateDatas: updateDatas}, function (rstData) {
  1256. if(callback){
  1257. callback(rstData);
  1258. }
  1259. }, function () {
  1260. if(errCB) {
  1261. errCB();
  1262. }
  1263. $.bootstrapLoading.end();
  1264. });
  1265. }
  1266. //编辑后自动去除换行符回车符
  1267. const deESC = /[\n]/g;
  1268. //项目指引编辑
  1269. //@param {Object}sheet {Array}cells
  1270. function edit(sheet, cells){
  1271. let updateDatas = [];
  1272. //同步节点数据
  1273. let syncDatas = [];
  1274. for(let cell of cells){
  1275. const field = guideItem.headers[cell.col].dataCode;
  1276. let node = bills.tree.selected.guidance.tree.items[cell.row];
  1277. if (field === 'name' || field === 'unit' || field === 'interval') {
  1278. let text = sheet.getValue(cell.row, cell.col);
  1279. text = text ? text.toString() : '';
  1280. text = text.replace(deESC, '');
  1281. sheet.setValue(cell.row, cell.col, text);
  1282. if(node.data[field] != text){
  1283. syncDatas.push({node: node, text: text, field, cell});
  1284. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {[field]: text}});
  1285. }
  1286. } else if (field === 'outputItemCharacter' || field === 'required' || field === 'isMaterial' || field === 'isDefaultOption') {
  1287. const val = !sheet.getValue(cell.row, cell.col);
  1288. sheet.setValue(cell.row, cell.col, val);
  1289. syncDatas.push({node: node, text: val, field, cell });
  1290. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {[field]: val}});
  1291. }
  1292. }
  1293. if(updateDatas.length > 0){
  1294. updateGuideItems(updateDatas, function () {
  1295. for(let syncData of syncDatas){
  1296. syncData.node.data[syncData.field] = syncData.text;
  1297. }
  1298. }, function () {
  1299. //失败恢复
  1300. renderSheetFunc(sheet, function () {
  1301. for(let syncData of syncDatas){
  1302. sheet.setValue(syncData.node.serialNo(), syncData.cell.col, syncData.node.data[syncData.field] ? syncData.node.data[syncData.field] : '');
  1303. }
  1304. });
  1305. });
  1306. }
  1307. }
  1308. //项目指引插入,支持一次插入多条数据
  1309. //@param {Array}datas {Boolean}tobeChild(插入成为子项) {Function}callback @return {void}
  1310. function insert(datas, tobeChild, callback = null){
  1311. $.bootstrapLoading.start();
  1312. let sheet = guideItem.workBook.getActiveSheet();
  1313. let controller = bills.tree.selected.guidance.controller;
  1314. let selected = bills.tree.selected.guidance.tree.selected;
  1315. let updateDatas = [];
  1316. //建立数组下标索引
  1317. let newDataIndex = {};
  1318. for(let i = 0; i < datas.length; i++){
  1319. let newNodeData = {
  1320. libID: libID, ID: uuid.v1(), ParentID: selected ? selected.getParentID() : -1, NextSiblingID: selected ? selected.getNextSiblingID() : -1,
  1321. billsID: bills.tree.selected.getID()
  1322. };
  1323. //定额类型插入当前工作内容焦点行,
  1324. if(selected && ((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  1325. newNodeData.ParentID = selected.getID();
  1326. newNodeData.NextSiblingID = -1;
  1327. }
  1328. Object.assign(newNodeData, datas[i]);
  1329. newDataIndex[i] = newNodeData;
  1330. }
  1331. for(let i = 0; i < datas.length; i++){
  1332. //第一个节点
  1333. if(i === 0){
  1334. //非插入成子节点,更新选中节点NestSiblingID
  1335. if(selected && !((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  1336. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: newDataIndex[i].ID}});
  1337. }
  1338. }
  1339. //非最后一个节点
  1340. if(i !== datas.length - 1){
  1341. newDataIndex[i].NextSiblingID = newDataIndex[i + 1].ID;
  1342. }
  1343. updateDatas.push({updateType: updateType.create, updateData: newDataIndex[i]});
  1344. }
  1345. updateGuideItems(updateDatas, function () {
  1346. const outputItemCol = guideItem.headers.findIndex(item => item.dataCode === 'outputItemCharacter');
  1347. for(let updateData of updateDatas){
  1348. if(updateData.updateType === updateType.create){
  1349. let newNode = controller.insertByIDS(updateData.updateData.ID, updateData.updateData.ParentID, updateData.updateData.NextSiblingID);
  1350. //同步data
  1351. Object.assign(newNode.data, updateData.updateData);
  1352. const row = newNode.serialNo();
  1353. sheet.setValue(row, 0, newNode.data.name);
  1354. if (newNode.data.outputItemCharacter !== undefined) {
  1355. sheet.setValue(row, outputItemCol, newNode.data.outputItemCharacter);
  1356. }
  1357. setProcessNodes(sheet, [newNode]);
  1358. refreshBtn(newNode);
  1359. }
  1360. }
  1361. if (!bills.tree.selected.data.hasGuide && bills.tree.selected.guidance.tree.items.length) {
  1362. bills.tree.selected.data.hasGuide = true;
  1363. setBillsForeColor([bills.tree.selected]);
  1364. }
  1365. if(callback){
  1366. callback();
  1367. }
  1368. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1369. guideItem.workBook.focus(true);
  1370. $.bootstrapLoading.end();
  1371. });
  1372. }
  1373. // 删除定额(嵌套删除自身及后代定额)
  1374. function delRations() {
  1375. const selected = bills.tree.selected.guidance.tree.selected;
  1376. if (!selected) {
  1377. return;
  1378. }
  1379. if (selected.data.type === itemType.ration) {
  1380. del({ row: selected.serialNo(), col: 0, rowCount: 1, colCount: 1 });
  1381. return;
  1382. }
  1383. const rations = selected.getPosterity().filter(item => item.data.type === itemType.ration);
  1384. if (!rations.length) {
  1385. return;
  1386. }
  1387. const updateDatas = rations.map(item => ({ updateType: updateType.del, findData: { ID: item.data.ID } }));
  1388. const rationIDs = rations.map(r => r.data.ID);
  1389. $.bootstrapLoading.start();
  1390. updateGuideItems(updateDatas, function () {
  1391. const guideSheet = guideItem.workBook.getSheet(0);
  1392. const treeNodes = bills.tree.selected.guidance.tree.items.filter(item => !rationIDs.includes(item.data.ID));
  1393. const state = bills.tree.selected.guidance.tree.getExpState(treeNodes);
  1394. const treeData = treeNodes.map(item => item.data);
  1395. initTree(bills.tree.selected.guidance, guideSheet, guideItem.treeSetting, treeData);
  1396. bills.tree.selected.guidance.tree.setExpandedByState(bills.tree.selected.guidance.tree.items, state);
  1397. renderSheetFunc(guideSheet, function () {
  1398. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.selected.guidance.tree.roots, guideSheet, true);
  1399. });
  1400. //设置底色
  1401. setNodesColor(guideSheet, bills.tree.selected.guidance.tree.items);
  1402. //项目指引初始焦点
  1403. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  1404. $.bootstrapLoading.end();
  1405. guideItem.workBook.focus(true)
  1406. });
  1407. }
  1408. //项目指引删除操作
  1409. //@return {void}
  1410. function del(selArea = null){
  1411. $.bootstrapLoading.start();
  1412. let controller = bills.tree.selected.guidance.controller;
  1413. let selNodes = [];
  1414. let sheet = guideItem.workBook.getSheet(0);
  1415. let sel = selArea ? selArea : sheet.getSelections()[0];
  1416. if(sel){
  1417. sel.row = sel.row === -1 ? 0 : sel.row;
  1418. for(let i = 0; i < sel.rowCount; i++){
  1419. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1420. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1421. }
  1422. }
  1423. }
  1424. //选中的块节点
  1425. let blockNodes = getBlockNodes(selNodes);
  1426. let updateDatas = [];
  1427. function getDelDatas(nodes){
  1428. for (let node of nodes) {
  1429. updateDatas.push({updateType: updateType.del, findData: {ID: node.getID()}});
  1430. if (node.children.length > 0) {
  1431. getDelDatas(node.children);
  1432. }
  1433. }
  1434. }
  1435. getDelDatas(blockNodes);
  1436. //更新相关的前节点
  1437. for (let node of blockNodes) {
  1438. if (node.preSibling && !blockNodes.includes(node.preSibling)) {
  1439. let next = node;
  1440. while (next.nextSibling && blockNodes.includes(next.nextSibling)) {
  1441. next = next.nextSibling;
  1442. }
  1443. updateDatas.push({updateType: updateType.update, findData: {ID: node.preSibling.getID()}, updateData: {NextSiblingID: next.getNextSiblingID()}});
  1444. }
  1445. }
  1446. updateGuideItems(updateDatas, function () {
  1447. console.log(blockNodes);
  1448. controller.m_delete(blockNodes);
  1449. guideItemInitSel(sheet.getActiveRowIndex());
  1450. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1451. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1452. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1453. if (bills.tree.selected.data.hasGuide && !bills.tree.selected.guidance.tree.items.length) {
  1454. bills.tree.selected.data.hasGuide = false;
  1455. setBillsForeColor([bills.tree.selected]);
  1456. }
  1457. $.bootstrapLoading.end();
  1458. guideItem.workBook.focus(true)
  1459. });
  1460. }
  1461. //项目指引升级
  1462. //@return {void}
  1463. function upLevel(){
  1464. $.bootstrapLoading.start();
  1465. let controller = bills.tree.selected.guidance.controller;
  1466. let selected = bills.tree.selected.guidance.tree.selected;
  1467. let updateDatas = [];
  1468. //更新父节点
  1469. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getParentID()}, updateData: {NextSiblingID: selected.getID()}});
  1470. //更新选中节点
  1471. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()},
  1472. updateData: {ParentID: selected.parent.getParentID(), NextSiblingID: selected.parent.getNextSiblingID(), unit: '', interval: ''}});
  1473. if(selected.nextSibling && selected.children.length > 0){
  1474. //更新选中节点最末子节点
  1475. let lastChild = selected.children[selected.children.length - 1];
  1476. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: -1}});
  1477. }
  1478. //选中节点的所有后兄弟节点成为选中节点的子项
  1479. let selectedNextIDs = [];
  1480. let sNext = selected.nextSibling;
  1481. while(sNext){
  1482. selectedNextIDs.push(sNext.getID());
  1483. sNext = sNext.nextSibling;
  1484. }
  1485. for(let sID of selectedNextIDs){
  1486. updateDatas.push({updateType: updateType.update, findData: {ID: sID}, updateData: {ParentID: selected.getID()}});
  1487. }
  1488. updateGuideItems(updateDatas, function () {
  1489. controller.upLevel();
  1490. const sheet = guideItem.workBook.getActiveSheet();
  1491. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1492. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1493. setProcessNodes(sheet, bills.tree.selected.guidance.tree.items);
  1494. const unitCol = guideItem.headers.findIndex(item => item.dataCode === 'unit');
  1495. const intervalCol = guideItem.headers.findIndex(item => item.dataCode === 'interval');
  1496. sheet.setValue(selected.serialNo(), unitCol, '');
  1497. sheet.setValue(selected.serialNo(), intervalCol, '');
  1498. $.bootstrapLoading.end();
  1499. guideItem.workBook.focus(true)//31574
  1500. });
  1501. }
  1502. //项目指引降级
  1503. //@return {void}
  1504. function downLevel(){
  1505. $.bootstrapLoading.start();
  1506. let controller = bills.tree.selected.guidance.controller;
  1507. let selected = bills.tree.selected.guidance.tree.selected;
  1508. let updateDatas = [];
  1509. //更新前兄弟节点
  1510. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1511. //更新前兄弟节点最末子节点
  1512. if(selected.preSibling.children.length > 0){
  1513. let lastChild = selected.preSibling.children[selected.preSibling.children.length - 1];
  1514. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1515. }
  1516. //更新选中节点
  1517. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {ParentID: selected.preSibling.getID(), NextSiblingID: -1, unit: '', interval: ''}});
  1518. updateGuideItems(updateDatas, function () {
  1519. controller.downLevel();
  1520. const sheet = guideItem.workBook.getActiveSheet();
  1521. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1522. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1523. setProcessNodes(sheet, bills.tree.selected.guidance.tree.items);
  1524. const unitCol = guideItem.headers.findIndex(item => item.dataCode === 'unit');
  1525. const intervalCol = guideItem.headers.findIndex(item => item.dataCode === 'interval');
  1526. sheet.setValue(selected.serialNo(), unitCol, '');
  1527. sheet.setValue(selected.serialNo(), intervalCol, '');
  1528. $.bootstrapLoading.end();
  1529. guideItem.workBook.focus(true)
  1530. });
  1531. }
  1532. //项目指引上移
  1533. //@return {void}
  1534. function upMove(){
  1535. $.bootstrapLoading.start();
  1536. let controller = bills.tree.selected.guidance.controller;
  1537. let selected = bills.tree.selected.guidance.tree.selected;
  1538. let updateDatas = [];
  1539. //更新前节点
  1540. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1541. //更新前前节点
  1542. if(selected.preSibling.preSibling){
  1543. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.preSibling.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1544. }
  1545. //更新选中节点
  1546. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.preSibling.getID()}});
  1547. updateGuideItems(updateDatas, function () {
  1548. controller.upMove();
  1549. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1550. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1551. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1552. $.bootstrapLoading.end();
  1553. guideItem.workBook.focus(true)
  1554. });
  1555. }
  1556. //项目指引下移
  1557. //@return {void}
  1558. function downMove(){
  1559. $.bootstrapLoading.start();
  1560. let controller = bills.tree.selected.guidance.controller;
  1561. let selected = bills.tree.selected.guidance.tree.selected;
  1562. let updateDatas = [];
  1563. //更新下节点
  1564. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getNextSiblingID()}, updateData: {NextSiblingID: selected.getID()}});
  1565. //更新前节点
  1566. if(selected.preSibling){
  1567. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1568. }
  1569. //更新选中节点
  1570. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.nextSibling.getNextSiblingID()}});
  1571. updateGuideItems(updateDatas, function () {
  1572. controller.downMove();
  1573. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1574. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1575. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1576. $.bootstrapLoading.end();
  1577. guideItem.workBook.focus(true)
  1578. });
  1579. }
  1580. //获取定额类型的项目指引名称,通过定额转换
  1581. //@param {Object}ration @return {String}
  1582. function getRationItemName(ration){
  1583. let arr = [];
  1584. arr.push(ration.code ? ration.code : '');
  1585. arr.push(ration.name ? ration.name : '');
  1586. arr.push(ration.basePrice ? ration.basePrice : '');
  1587. let rst = arr.join(' ');
  1588. rst += `/${ration.unit ? ration.unit : ''}`;
  1589. return rst;
  1590. }
  1591. //获取选中的定额表行
  1592. //@return {Array}
  1593. function getCheckedRationRows(all){
  1594. let rst = [];
  1595. let sheet = ration.workBook.getActiveSheet();
  1596. for(let i = 0; i < sheet.getRowCount(); i++){
  1597. // 全选
  1598. if (all) {
  1599. rst.push(i);
  1600. continue;
  1601. }
  1602. let checked = sheet.getValue(i, 0);
  1603. if(checked){
  1604. rst.push(i);
  1605. }
  1606. }
  1607. return rst;
  1608. }
  1609. //清空选中定额表行
  1610. //@param {Array}rows @return {void}
  1611. function clearCheckedRation(rows) {
  1612. let sheet = ration.workBook.getActiveSheet();
  1613. renderSheetFunc(sheet, function () {
  1614. for(let row of rows){
  1615. sheet.setValue(row, 0, 0);
  1616. }
  1617. });
  1618. }
  1619. //获取要插入的定额数据
  1620. //@param {Array}rows @return {Array}
  1621. function getInsertRations(rows){
  1622. let rst = [];
  1623. //当前已存在定额
  1624. let curRationIems = [];
  1625. let selected = bills.tree.selected.guidance.tree.selected;
  1626. if(selected){
  1627. if(selected.data.type === itemType.job){
  1628. curRationIems = selected.children;
  1629. }
  1630. else {
  1631. curRationIems = selected.parent ? selected.parent.children : selected.tree.roots;
  1632. }
  1633. }
  1634. for(let row of rows){
  1635. let selRation = ration.cache[row];
  1636. if(selRation){
  1637. //添加的定额是否已存在,不重复添加
  1638. let isExist = false;
  1639. for(let curRation of curRationIems){
  1640. if(curRation.data.rationID == selRation.ID){
  1641. isExist = true;
  1642. break;
  1643. }
  1644. }
  1645. if(!isExist){
  1646. rst.push({type: itemType.ration, name: getRationItemName(selRation), rationID: selRation.ID});
  1647. }
  1648. }
  1649. }
  1650. return rst;
  1651. }
  1652. //获取块节点父项不存在于选中节点中的节点
  1653. //@param {Array}nodes(选中的节点) @return {Array}
  1654. function getBlockNodes(nodes) {
  1655. let nodeMapping = {};
  1656. for(let node of nodes){
  1657. nodeMapping[node.data.ID] = node;
  1658. }
  1659. //块节点,父项不存在于选中节点中的节点
  1660. let blockNodes = [];
  1661. for(let node of nodes){
  1662. if(!nodeMapping[node.data.ParentID]){
  1663. blockNodes.push(node);
  1664. }
  1665. }
  1666. return blockNodes;
  1667. }
  1668. //允许复制整块,如果有多个块节点,且块节点的父项不同,则不可复制
  1669. //@param {Array}nodes(块节点) @return {Boolean}
  1670. function canCopyBlock(nodes) {
  1671. if(!nodes || nodes.length === 0){
  1672. return false;
  1673. }
  1674. let pID = nodes[0].data.ParentID;
  1675. for(let node of nodes){
  1676. if(node.data.ParentID !== pID){
  1677. return false;
  1678. }
  1679. }
  1680. return true;
  1681. }
  1682. //允许粘贴整块 有粘贴数据,节点存在,如果粘贴到的节点为定额数据,粘贴数据为全定额数据
  1683. //@param {Object}node(粘贴到的节点)
  1684. function canPasteBlock(node) {
  1685. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1686. if(!pasteDatas || pasteDatas.length === 0){
  1687. return false;
  1688. }
  1689. if(!node){
  1690. return false;
  1691. }
  1692. //若粘贴到定额节点,则数据须全为定额
  1693. if(node.data.type === itemType.ration){
  1694. for(let data of pasteDatas){
  1695. if(data.type !== itemType.ration){
  1696. return false;
  1697. }
  1698. }
  1699. }
  1700. //若粘贴到非定额节点,则粘贴的顶层数据须全为非定额
  1701. else {
  1702. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1703. for(let topData of topDatas){
  1704. if(topData.type === itemType.ration){
  1705. return false;
  1706. }
  1707. }
  1708. }
  1709. return true;
  1710. }
  1711. //复制整块,将块节点下所有节点数据复制一份,并且重新生成ID、ParentID、NextSiblingID,使用localStorage存储
  1712. //@param {Array}nodes(块节点) @return {void}
  1713. function copyBlocks(nodes) {
  1714. nodes = _.cloneDeep(nodes);
  1715. //将块节点的ParentID暂时设置为-1
  1716. for(let topNode of nodes){
  1717. topNode.data.ParentID = -1;
  1718. }
  1719. let copyDatas = [];
  1720. let copyNodes = [];
  1721. //获取块节点包含的所有节点(包括自己)
  1722. function containNodes(nodes) {
  1723. for(let node of nodes){
  1724. copyNodes.push(node);
  1725. if(node.children.length > 0){
  1726. containNodes(node.children);
  1727. }
  1728. }
  1729. }
  1730. containNodes(nodes);
  1731. for(let node of copyNodes){
  1732. copyDatas.push(node.data);
  1733. }
  1734. console.log(`copyDatas`);
  1735. console.log(copyDatas);
  1736. setLocalCache(itemCopyBlockKey, JSON.stringify(copyDatas));
  1737. }
  1738. //粘贴整块,整块数据粘贴到相关节点,并成为其后项
  1739. //@param {Object}node(粘贴到的节点) @return {void}
  1740. function pasteBlock(node) {
  1741. let itemObj = bills.tree.selected.guidance;
  1742. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1743. //整理ID
  1744. let IDMapping = {};
  1745. for(let data of pasteDatas){
  1746. data.newID = uuid.v1();
  1747. IDMapping[data.ID] = data;
  1748. }
  1749. for(let data of pasteDatas){
  1750. let nextData = IDMapping[data.NextSiblingID];
  1751. data.NextSiblingID = nextData ? nextData.newID : -1;
  1752. let parentData = IDMapping[data.ParentID];
  1753. data.ParentID = parentData ? parentData.newID : -1;
  1754. }
  1755. for(let data of pasteDatas){
  1756. data.ID = data.newID;
  1757. delete data.newID;
  1758. }
  1759. let updateDatas = [];
  1760. //将最顶层的块数据的ParentID设置成粘贴到节点的ParentID,并设置新的billsID
  1761. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1762. for(let topData of topDatas){
  1763. topData.ParentID = node.getParentID();
  1764. }
  1765. //更新数据
  1766. //更新插入的最末顶层数据NextSiblingID
  1767. if(node.nextSibling){
  1768. topDatas[topDatas.length - 1].NextSiblingID = node.getNextSiblingID();
  1769. }
  1770. //新建节点
  1771. for(let data of pasteDatas){
  1772. data.libID = libID;
  1773. data.billsID = node.data.billsID;
  1774. delete data._id;
  1775. updateDatas.push({updateType: updateType.create, updateData: data});
  1776. }
  1777. console.log(`pasteDatas`);
  1778. console.log(pasteDatas);
  1779. //更新粘贴到的节点的NextSiblingID
  1780. updateDatas.push({updateType: updateType.update, findData: {ID: node.data.ID}, updateData: {NextSiblingID: topDatas[0].ID}})
  1781. $.bootstrapLoading.start();
  1782. updateGuideItems(updateDatas, function (rstData) {
  1783. $.bootstrapLoading.end();
  1784. node.data.NextSiblingID = topDatas[0].ID;
  1785. let newNodes = itemObj.tree.insertDatasTo(node.data, pasteDatas);
  1786. cleanData(guideItem.workBook.getActiveSheet(), guideItem.headers, -1);
  1787. itemObj.controller.showTreeData();
  1788. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1789. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1790. }, function () {
  1791. $.bootstrapLoading.end();
  1792. });
  1793. }
  1794. // 双击定位定额
  1795. async function locateAtRation(row) {
  1796. const node = bills.tree.selected.guidance.tree.items[row];
  1797. if (!node || !node.data.rationID) {
  1798. return;
  1799. }
  1800. const rationItem = ration.datas.find(item => item.ID === node.data.rationID);
  1801. // 当前库没有找到,需要后端查找
  1802. if (!rationItem) {
  1803. const findedRation = await ajaxPost('/rationRepository/api/getRationByID',{ ID: node.data.rationID });
  1804. if (!findedRation || !rationLibIDs.includes(findedRation.rationRepId)) {
  1805. alert('无法定位此定额,此定额已被删除');
  1806. return;
  1807. }
  1808. changeRationLib(findedRation.rationRepId, () => {
  1809. located(findedRation.ID, findedRation.sectionId);
  1810. })
  1811. } else {
  1812. located(rationItem.ID, rationItem.sectionId);
  1813. }
  1814. function located(rationID, sectionID) {
  1815. if (!section.tree) {
  1816. return;
  1817. }
  1818. const sectionNode = section.tree.nodes[section.tree.prefix + sectionID];
  1819. if (!sectionNode) {
  1820. return;
  1821. }
  1822. // 定位到对应章节树
  1823. const sectionSheet = section.workBook.getActiveSheet();
  1824. const sectionRow = sectionNode.serialNo();
  1825. expandSearchNodes(sectionSheet, [sectionNode], section.tree.roots);
  1826. sectionSheet.setSelection(sectionRow, 0, 1, 1);
  1827. sectionSheet.showRow(sectionRow, GC.Spread.Sheets.VerticalPosition.center);
  1828. sectionInitSel(sectionRow);
  1829. // 定位到对应定额
  1830. const locatedRationRow = ration.cache.findIndex(item => item.ID === rationID);
  1831. if (locatedRationRow !== -1) {
  1832. const rationSheet = ration.workBook.getActiveSheet();
  1833. rationSheet.setSelection(locatedRationRow, 1, 1, 1);
  1834. rationSheet.showRow(locatedRationRow, GC.Spread.Sheets.VerticalPosition.center);
  1835. }
  1836. }
  1837. }
  1838. //初始化右键菜单
  1839. //@return {void}
  1840. function initContextMenu() {
  1841. $.contextMenu({
  1842. selector: '#guideItemSpread',
  1843. build: function($triggerElement, e){
  1844. //控制允许右键菜单在哪个位置出现
  1845. let sheet = guideItem.workBook.getSheet(0);
  1846. let offset = $("#guideItemSpread").offset(),
  1847. x = e.pageX - offset.left,
  1848. y = e.pageY - offset.top;
  1849. let target = sheet.hitTest(x, y);
  1850. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  1851. let sel = sheet.getSelections()[0];
  1852. if(sel && sel.rowCount === 1){
  1853. sheet.setActiveCell(target.row, target.col);
  1854. }
  1855. sel = sheet.getSelections()[0];
  1856. let selNodes = [];
  1857. if(sel){
  1858. sel.row = sel.row === -1 ? 0 : sel.row;
  1859. for(let i = 0; i < sel.rowCount; i++){
  1860. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1861. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1862. }
  1863. }
  1864. }
  1865. //块节点
  1866. let blockNodes = getBlockNodes(selNodes);
  1867. //右键在多选内则不重设焦点
  1868. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  1869. sheet.setActiveCell(target.row, target.col);
  1870. }
  1871. guideItemInitSel(target.row);
  1872. return {
  1873. callback: function(){},
  1874. items: {
  1875. "copy": {
  1876. name: "复制整块",
  1877. disabled: function () {
  1878. return locked || !canCopyBlock(blockNodes);
  1879. },
  1880. icon: "fa-copy",
  1881. callback: function (key, opt) {
  1882. copyBlocks(blockNodes);
  1883. }},
  1884. "paste": {
  1885. name: "粘贴整块",
  1886. disabled: function () {
  1887. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1888. return locked || !canPasteBlock(pasteNode);
  1889. },
  1890. icon: "fa-paste",
  1891. callback: function (key, opt) {
  1892. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1893. pasteBlock(pasteNode);
  1894. }},
  1895. "delRations": {
  1896. name: '删除定额',
  1897. disabled: function () {
  1898. let node = bills.tree.selected.guidance.tree.items[target.row];
  1899. return locked || !node
  1900. },
  1901. icon: "fa-remove",
  1902. callback: function (key, opt) {
  1903. $('#delRationAlert').modal('show');
  1904. }
  1905. },
  1906. "del": {
  1907. name: '删除',
  1908. disabled: function () {
  1909. let node = bills.tree.selected.guidance.tree.items[target.row];
  1910. return locked || !node
  1911. },
  1912. icon: "fa-remove",
  1913. callback: function (key, opt) {
  1914. $('#delAlert').modal('show');
  1915. }
  1916. },
  1917. "insertSibling": {
  1918. name: '插入行',
  1919. disabled: function () {
  1920. let node = bills.tree.selected.guidance.tree.items[target.row];
  1921. return locked || !node || node.data.type !== itemType.job;
  1922. },
  1923. icon: "fa-arrow-left",
  1924. callback: function (key, opt) {
  1925. insert([{type: itemType.job, name: ''}], false);
  1926. }
  1927. },
  1928. "insertChild": {
  1929. name: '插入子项',
  1930. disabled: function () {
  1931. let node = bills.tree.selected.guidance.tree.items[target.row];
  1932. return locked || !node || node.data.type !== itemType.job || !allJobChildren(node);
  1933. },
  1934. icon: 'fa-arrow-left',
  1935. callback: function (key, opt) {
  1936. insert([{type: itemType.job, name: ''}], true);
  1937. }
  1938. }
  1939. }
  1940. };
  1941. }
  1942. else{
  1943. return false;
  1944. }
  1945. }
  1946. });
  1947. }
  1948. // 替换定额
  1949. function replaceRation(newRation, orgItem) {
  1950. if (newRation.ID === orgItem.data.rationID) {
  1951. return;
  1952. }
  1953. $.bootstrapLoading.start();
  1954. const updateAttrs = {name: getRationItemName(newRation), rationID: newRation.ID};
  1955. const updateData = [{updateType: updateType.update, findData: {ID: orgItem.getID()}, updateData: updateAttrs }];
  1956. updateGuideItems(updateData, function () {
  1957. Object.assign(orgItem.data, updateAttrs);
  1958. const row = orgItem.serialNo();
  1959. guideItem.workBook.getSheet(0).setValue(row, 0, orgItem.data.name);
  1960. $.bootstrapLoading.end();
  1961. });
  1962. }
  1963. // 初始化清单右键菜单
  1964. function initRationContextMenu() {
  1965. $.contextMenu({
  1966. selector: '#rationSpread',
  1967. build: function($triggerElement, e){
  1968. //控制允许右键菜单在哪个位置出现
  1969. let sheet = ration.workBook.getActiveSheet();;
  1970. let offset = $("#rationSpread").offset(),
  1971. x = e.pageX - offset.left,
  1972. y = e.pageY - offset.top;
  1973. let target = sheet.hitTest(x, y);
  1974. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  1975. let sel = sheet.getSelections()[0];
  1976. if(sel && sel.rowCount === 1){
  1977. sheet.setActiveCell(target.row, target.col);
  1978. }
  1979. sel = sheet.getSelections()[0];
  1980. if(sel){
  1981. sel.row = sel.row === -1 ? 0 : sel.row;
  1982. }
  1983. //右键在多选内则不重设焦点
  1984. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  1985. sheet.setActiveCell(target.row, target.col);
  1986. }
  1987. return {
  1988. callback: function(){},
  1989. items: {
  1990. "replace": {
  1991. name: "替换定额",
  1992. disabled: function () {
  1993. 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;
  1994. },
  1995. icon: "fa-copy",
  1996. callback: function (key, opt) {
  1997. const row = sheet.getActiveRowIndex();
  1998. if (!ration.cache[row]) {
  1999. return;
  2000. }
  2001. replaceRation(ration.cache[row], bills.tree.selected.guidance.tree.selected);
  2002. // copyBlocks(blockNodes);
  2003. }},
  2004. }
  2005. };
  2006. }
  2007. else{
  2008. return false;
  2009. }
  2010. }
  2011. });
  2012. }
  2013. // 初始化定额右键菜单
  2014. function initBillsContextMenu() {
  2015. $.contextMenu({
  2016. selector: '#billsSpread',
  2017. build: function($triggerElement, e){
  2018. //控制允许右键菜单在哪个位置出现
  2019. let sheet = bills.workBook.getActiveSheet();;
  2020. let offset = $("#billsSpread").offset(),
  2021. x = e.pageX - offset.left,
  2022. y = e.pageY - offset.top;
  2023. let target = sheet.hitTest(x, y);
  2024. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  2025. let sel = sheet.getSelections()[0];
  2026. if(sel && sel.rowCount === 1){
  2027. sheet.setActiveCell(target.row, target.col);
  2028. }
  2029. sel = sheet.getSelections()[0];
  2030. if(sel){
  2031. sel.row = sel.row === -1 ? 0 : sel.row;
  2032. }
  2033. //右键在多选内则不重设焦点
  2034. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  2035. sheet.setActiveCell(target.row, target.col);
  2036. }
  2037. billsInitSel(target.row, { row: bills.tree.selected.serialNo() });
  2038. return {
  2039. callback: function(){},
  2040. items: {
  2041. "replace": {
  2042. name: "配置材料",
  2043. disabled: function () {
  2044. return !bills.tree.selected;
  2045. },
  2046. icon: "fa-edit",
  2047. callback: function (key, opt) {
  2048. $('#bill-material-modal').modal('show');
  2049. }},
  2050. }
  2051. };
  2052. }
  2053. else{
  2054. return false;
  2055. }
  2056. }
  2057. });
  2058. }
  2059. //展开至搜索出来点的节点
  2060. //@param {Array}nodes @return {void}
  2061. function expandSearchNodes(sheet, nodes, roots){
  2062. renderSheetFunc(sheet, function () {
  2063. function expParentNode(node){
  2064. if(node.parent){
  2065. if (!node.parent.expanded) {
  2066. node.parent.setExpanded(true);
  2067. }
  2068. expParentNode(node.parent);
  2069. }
  2070. }
  2071. for(let node of nodes){
  2072. expParentNode(node);
  2073. }
  2074. TREE_SHEET_HELPER.refreshNodesVisible(roots, sheet, true);
  2075. });
  2076. }
  2077. // 清空搜索高亮
  2078. function clearHighLight(sheet) {
  2079. renderSheetFunc(sheet, () => {
  2080. for (let i = 0; i < sheet.getRowCount(); i++){
  2081. setBgColor(sheet, i, 'white')
  2082. }
  2083. });
  2084. }
  2085. // 清空搜索状态
  2086. // 关闭搜索清单结果
  2087. function closeSearchBills(sheet) {
  2088. if (!bills.tree) {
  2089. return;
  2090. }
  2091. $('#searchBillsResult').hide();
  2092. bills.tree.items.forEach(node => {
  2093. node.isSearch = false;
  2094. });
  2095. clearHighLight(sheet);
  2096. setBgColor(sheet, sheet.getActiveRowIndex(), selectedBgColor);
  2097. }
  2098. // 搜索清单
  2099. function searchBills() {
  2100. if (!bills.tree || !bills.workBook) {
  2101. return;
  2102. }
  2103. const sheet = bills.workBook.getActiveSheet();
  2104. const str = $('#searchBillText').val().trim();
  2105. // 空搜索字符,关闭搜索
  2106. if (!str) {
  2107. if ($('#searchBillsResult').is(':visible')) {
  2108. closeSearchBills(sheet);
  2109. }
  2110. return;
  2111. }
  2112. // 过滤清单
  2113. const result = bills.tree.items.filter(item => {
  2114. const codeIs = item.data.code ? item.data.code.indexOf(str) !== -1 : false;
  2115. const nameIs = item.data.name ? item.data.name.indexOf(str) !== -1 : false;
  2116. return codeIs || nameIs;
  2117. });
  2118. if (!result.length) {
  2119. closeSearchBills(sheet);
  2120. return;
  2121. }
  2122. // 显示搜索结果
  2123. $("#searchBillsResult").show();
  2124. $('#searchBillsCount').text(result.length);
  2125. //展开搜索出来的节点
  2126. expandSearchNodes(sheet, result, bills.tree.roots);
  2127. // 标黄结果
  2128. clearHighLight(sheet);
  2129. const col = sheet.getActiveColumnIndex();
  2130. renderSheetFunc(sheet, function () {
  2131. bills.controller.setTreeSelected(result[0]);
  2132. bills.tree.items.forEach(node => {
  2133. if (result.includes(node)) {
  2134. setBgColor(sheet, node.serialNo(), searchBgColor);
  2135. node.isSearch = true; // 标记为搜索结果,防止被焦点行变更恢复颜色
  2136. } else {
  2137. node.isSearch = false;
  2138. }
  2139. })
  2140. });
  2141. //搜索初始定位
  2142. const row = sheet.getActiveRowIndex();
  2143. sheet.setSelection(result[0].serialNo(), col, 1, 1);
  2144. billsInitSel(result[0].serialNo(), { row });
  2145. sheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  2146. let curIndex = 0;
  2147. // 上一条
  2148. $('#preBill').unbind('click');
  2149. $('#preBill').bind('click', () => {
  2150. const node = result[curIndex - 1];
  2151. if (!node) {
  2152. return;
  2153. }
  2154. curIndex -= 1;
  2155. const col = sheet.getActiveColumnIndex();
  2156. const row = node.serialNo();
  2157. const orgRow = sheet.getActiveRowIndex();
  2158. sheet.setSelection(row, col, 1, 1);
  2159. billsInitSel(row, { row: orgRow });
  2160. sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
  2161. });
  2162. // 下一条
  2163. $('#nextBills').unbind('click');
  2164. $('#nextBills').bind('click', () => {
  2165. const node = result[curIndex + 1];
  2166. if (!node) {
  2167. return;
  2168. }
  2169. curIndex += 1;
  2170. const col = sheet.getActiveColumnIndex();
  2171. const row = node.serialNo();
  2172. const orgRow = sheet.getActiveRowIndex();
  2173. sheet.setSelection(row, col, 1, 1);
  2174. billsInitSel(row, { row: orgRow });
  2175. sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
  2176. });
  2177. }
  2178. //初始化dom时间
  2179. //@return {void}
  2180. function initDomEvents(){
  2181. // 清单材料窗口
  2182. $("#bill-material-modal").on('hidden.bs.modal', function () {
  2183. billMaterial.cache = [];
  2184. showBillMaterialData(billMaterial.workBook.getSheet(0), billMaterial.headers, billMaterial.cache, 30);
  2185. });
  2186. $("#bill-material-modal").on('shown.bs.modal', function () {
  2187. if (billMaterial.workBook) {
  2188. billMaterial.workBook.refresh();
  2189. getBillMaterials();
  2190. }
  2191. });
  2192. $('#insert').click(function () {
  2193. insert([{type: itemType.job, name: '', outputItemCharacter: true }], false);
  2194. });
  2195. $('#delConfirm').click(function () {
  2196. del();
  2197. $('#delAlert').modal('hide');
  2198. });
  2199. $('#delRationConfirm').click(function () {
  2200. delRations();
  2201. $('#delRationAlert').modal('hide');
  2202. });
  2203. $('#del').click(function () {
  2204. $('#delAlert').modal('show');
  2205. });
  2206. $('#upLevel').click(function () {
  2207. upLevel();
  2208. });
  2209. $('#downLevel').click(function () {
  2210. downLevel();
  2211. });
  2212. $('#upMove').click(function () {
  2213. upMove();
  2214. });
  2215. $('#downMove').click(function () {
  2216. downMove();
  2217. });
  2218. // 收起清单至第二层
  2219. $('#expandToSecond').click(function() {
  2220. if (!bills.tree || !bills.workBook) {
  2221. return;
  2222. }
  2223. bills.tree.roots.forEach(root => {
  2224. root.setExpanded(true);
  2225. root.children.forEach(item => {
  2226. item.setExpanded(false);
  2227. });
  2228. });
  2229. const billSheet = bills.workBook.getActiveSheet();
  2230. renderSheetFunc(billSheet, function () {
  2231. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.roots, billSheet, true);
  2232. });
  2233. })
  2234. //收起定额、展开全部
  2235. $('#expandContract').click(function () {
  2236. //目前状态时展开全部节点状态,点击则收起定额
  2237. let tree = bills.tree.selected.guidance.tree,
  2238. itemSheet = guideItem.workBook.getActiveSheet();
  2239. if(curExpandState === itemExpandState.expand){
  2240. curExpandState = itemExpandState.contract;
  2241. $(this).html('<i class="fa fa-plus-square-o" aria-hidden="true"></i> 展开全部');
  2242. setNodesExpandState(tree.items, itemExpandState.contract);
  2243. } else {
  2244. curExpandState = itemExpandState.expand;
  2245. $(this).html('<i class="fa fa-minus-square-o" aria-hidden="true"></i> 收起定额');
  2246. setNodesExpandState(tree.items, itemExpandState.expand);
  2247. }
  2248. renderSheetFunc(itemSheet, function () {
  2249. TREE_SHEET_HELPER.refreshNodesVisible(tree.roots, itemSheet, true);
  2250. });
  2251. });
  2252. // 插入选中定额
  2253. $('#insertRation').click(function () {
  2254. let checkedRows = getCheckedRationRows();
  2255. let insertDatas = getInsertRations(checkedRows);
  2256. if(insertDatas.length > 0){
  2257. insert(insertDatas, false, function () {
  2258. //清空选择
  2259. clearCheckedRation(checkedRows);
  2260. });
  2261. }
  2262. else {
  2263. clearCheckedRation(checkedRows);
  2264. }
  2265. });
  2266. // 插入全部定额
  2267. $('#insertAll').click(function () {
  2268. let isAll = true;
  2269. let checkedRows = getCheckedRationRows(isAll);
  2270. let insertDatas = getInsertRations(checkedRows);
  2271. if(insertDatas.length > 0){
  2272. insert(insertDatas, false);
  2273. }
  2274. });
  2275. // 搜索清单
  2276. $("#searchBillBtn").click(searchBills);
  2277. $('#searchBillText').keyup(function (e) {
  2278. delayKeyup(function () {
  2279. $('#searchBillBtn').click();
  2280. });
  2281. });
  2282. // 关闭搜索清单
  2283. $('#closeSearchBills').click(() => {
  2284. if (!bills.workBook) {
  2285. return;
  2286. }
  2287. const sheet = bills.workBook.getActiveSheet();
  2288. closeSearchBills(sheet);
  2289. })
  2290. //搜索定额
  2291. $('#searchBtn').click(function () {
  2292. let searchStr = $('#searchText').val();
  2293. if(!searchStr || searchStr === ''){
  2294. ration.cache = ration.datas;
  2295. }
  2296. else{
  2297. let reg = new RegExp(searchStr, 'i');
  2298. ration.cache = _.filter(ration.datas, function (data) {
  2299. return reg.test(data.code) || reg.test(data.name);
  2300. });
  2301. }
  2302. $('.top-content').hide();
  2303. $('#deResize').hide();
  2304. $('#searchCount').text(`搜索结果: ${ration.cache.length}`);
  2305. $('#rationSearchResult').show();
  2306. autoFlashHeight();
  2307. ration.workBook.refresh();
  2308. let rationSheet = ration.workBook.getActiveSheet();
  2309. renderSheetFunc(rationSheet, function () {
  2310. clearCheckedRation(getCheckedRationRows());
  2311. showData(rationSheet, ration.headers, ration.cache);
  2312. })
  2313. });
  2314. //关闭搜索
  2315. $('#rationSearchResult a').click(function () {
  2316. $('.top-content').show();
  2317. $('#deResize').show();
  2318. $('#rationSearchResult').hide();
  2319. autoFlashHeight();
  2320. renderSheetFunc(ration.workBook.getActiveSheet(), function () {
  2321. clearCheckedRation(getCheckedRationRows());
  2322. });
  2323. section.workBook.refresh();
  2324. ration.workBook.refresh();
  2325. $('#searchText').val('');
  2326. //恢复章节树下的定额
  2327. sectionInitSel(section.workBook.getActiveSheet().getActiveRowIndex());
  2328. });
  2329. let keyupTime = 0,
  2330. delayTime = 500;
  2331. function delayKeyup(callback) {
  2332. let nowTime = Date.now();
  2333. keyupTime = nowTime;
  2334. setTimeout(function () {
  2335. if (nowTime - keyupTime == 0) {
  2336. callback();
  2337. }
  2338. }, delayTime);
  2339. }
  2340. //执行搜索
  2341. $('#searchText').keyup(function (e) {
  2342. delayKeyup(function () {
  2343. $('#searchBtn').click();
  2344. });
  2345. });
  2346. //编辑清单备注
  2347. $('.main-side-bottom').find('textarea').keyup(function () {
  2348. let me = this;
  2349. let node = bills.tree.selected;
  2350. let comment = $(me).val();
  2351. delayKeyup(function () {
  2352. if (node) {
  2353. let updateData = {lastOperator: userAccount, billsLibId: billsLibId, updateId: node.getID(), field: 'comment', data: comment};
  2354. updateBillsComment(updateData, function () {
  2355. node.data.comment = comment;
  2356. }, function() {
  2357. $(me).val(node.data.comment || '');
  2358. })
  2359. }
  2360. });
  2361. });
  2362. //编辑选项备注
  2363. $('.main-bottom-content').find('textarea').keyup(function () {
  2364. let me = this;
  2365. let node = bills.tree.selected.guidance.tree.selected;
  2366. let comment = $(me).val();
  2367. delayKeyup(function () {
  2368. if(node){
  2369. let updateDatas = [{updateType: updateType.update, findData: {ID: node.getID()}, updateData: {comment: comment}}];
  2370. updateGuideItems(updateDatas, function (rstData) {
  2371. node.data.comment = comment;
  2372. }, function() {
  2373. $(me).val(node.data.comment || '');
  2374. });
  2375. }
  2376. });
  2377. });
  2378. //定额高度拖动调整
  2379. let heightEleObj = {
  2380. module: moduleName,
  2381. resize: $('#deResize'),
  2382. top: $('#topContent'),
  2383. topSpread: $('#sectionSpread'),
  2384. bottom: $('#bottomContent'),
  2385. bottomSpread: $('#rationSpread')
  2386. },
  2387. heightLimit = {
  2388. min: 150,
  2389. max: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-150-10`,
  2390. notTopSpread: 0,
  2391. notBottomSpread: 0,
  2392. };
  2393. SlideResize.verticalSlide(heightEleObj, heightLimit, function () {
  2394. if(section.workBook){
  2395. section.workBook.refresh();
  2396. }
  2397. if(ration.workBook){
  2398. ration.workBook.refresh();
  2399. }
  2400. });
  2401. /*slideResize(rationLibResizeEles, {min: 147, max: 680}, 'height', function() {
  2402. //autoFlashHeight();
  2403. if(section.workBook){
  2404. section.workBook.refresh();
  2405. }
  2406. if(ration.workBook){
  2407. ration.workBook.refresh();
  2408. }
  2409. });*/
  2410. //左右拖动
  2411. //清单表与项目指引表
  2412. let leftElesObj = {};
  2413. leftElesObj.module = moduleName;
  2414. leftElesObj.resize = $('#slideResizeLeft');
  2415. leftElesObj.parent = $('#dataRow');
  2416. leftElesObj.left = $('#leftContent');
  2417. leftElesObj.right = $('#midContent');
  2418. SlideResize.horizontalSlide(leftElesObj, {min: 200, max: `$('#dataRow').width() - $('#rightContent').width() - 200`}, function () {
  2419. refreshALlWorkBook();
  2420. });
  2421. //人材机表与人材机组成物表
  2422. let rightElesObj = {};
  2423. rightElesObj.module = moduleName;
  2424. rightElesObj.resize = $('#slideResizeRight');
  2425. rightElesObj.parent = $('#dataRow');
  2426. rightElesObj.left = $('#midContent');
  2427. rightElesObj.right = $('#rightContent');
  2428. SlideResize.horizontalSlide(rightElesObj, {min: 200, max: `$('#dataRow').width() - $('#leftContent').width() - 200`}, function () {
  2429. refreshALlWorkBook();
  2430. });
  2431. }
  2432. //刷新全部工作簿
  2433. //@return {void}
  2434. function refreshALlWorkBook() {
  2435. if (bills.workBook) {
  2436. bills.workBook.refresh();
  2437. }
  2438. if (guideItem.workBook) {
  2439. guideItem.workBook.refresh();
  2440. }
  2441. if (section.workBook) {
  2442. section.workBook.refresh();
  2443. }
  2444. if (ration.workBook) {
  2445. ration.workBook.refresh();
  2446. }
  2447. $('.main-side-bottom').find('textarea').height($('.main-side-bottom').height() - 20);
  2448. $('.main-side-bottom').find('textarea').width($('.main-side-bottom').width() - 25);
  2449. $('.main-bottom-content').find('textarea').height($('.main-bottom-content').height() - 20);
  2450. $('.main-bottom-content').find('textarea').width($('.main-bottom-content').width() - 25);
  2451. }
  2452. //读取拖动相关
  2453. //@return {void}
  2454. function initSlideSize() {
  2455. //定额表上下
  2456. let heightEleObj = {
  2457. module: moduleName,
  2458. top: $('#topContent'),
  2459. topSpread: $('#sectionSpread'),
  2460. bottom: $('#bottomContent'),
  2461. bottomSpread: $('#rationSpread')
  2462. };
  2463. if (!$('#rationSearchResult').is(':visible')) {
  2464. SlideResize.loadVerticalHeight(heightEleObj.module, heightEleObj,
  2465. {totalHeight: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-10`,
  2466. notTopSpread: 0, notBottomSpread: 0}, function () {
  2467. if(section.workBook){
  2468. section.workBook.refresh();
  2469. }
  2470. if(ration.workBook){
  2471. ration.workBook.refresh();
  2472. }
  2473. });
  2474. }
  2475. //水平
  2476. SlideResize.loadHorizonWidth(moduleName, [$('#slideResizeLeft'), $('#slideResizeRight')], [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
  2477. refreshALlWorkBook();
  2478. });
  2479. }
  2480. //初始化视图
  2481. //@param {void} @return {void}
  2482. function initViews(){
  2483. let modules = [bills, guideItem, section, ration, billMaterial];
  2484. initWorkBooks(modules);
  2485. lockUtil.lockTools($(document.body), locked);
  2486. getLibWithBills(libID);
  2487. initDomEvents();
  2488. initContextMenu();
  2489. initRationContextMenu();
  2490. initBillsContextMenu();
  2491. initSlideSize();
  2492. }
  2493. return {initViews, initSlideSize};
  2494. })();
  2495. $(document).ready(function () {
  2496. billsGuidance.initViews();
  2497. });