billsGuidance.js 111 KB

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