billsGuidance.js 102 KB

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