billsGuidance.js 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921
  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. const locked = lockUtil.getLocked();
  46. let moduleName = 'stdBillsGuidance';
  47. //上下拖动的拖动条高度
  48. const verticalResize = 10;
  49. //自执行函数全局变量定义
  50. const libID = getQueryString('libID');
  51. //总工作内容数据
  52. let stdBillsJobData = [];
  53. //总项目特征数据
  54. let stdBillsFeatureData = [];
  55. const bills = {
  56. dom: $('#billsSpread'),
  57. workBook: null,
  58. cache: [],
  59. tree: null,
  60. controller: null,
  61. treeSetting: {
  62. treeCol: 0,
  63. emptyRows: 0,
  64. headRows: 1,
  65. headRowHeight: [40],
  66. defaultRowHeight: 21,
  67. cols: [{
  68. width: 200,
  69. readOnly: true,
  70. showHint: true,
  71. head: {
  72. titleNames: ["项目编码"],
  73. spanCols: [1],
  74. spanRows: [1],
  75. vAlign: [1],
  76. hAlign: [1],
  77. font: ["Arial"]
  78. },
  79. data: {
  80. field: "code",
  81. vAlign: 1,
  82. hAlign: 0,
  83. font: "Arial"
  84. }
  85. }, {
  86. width: 200,
  87. readOnly: true,
  88. head: {
  89. titleNames: ["项目名称"],
  90. spanCols: [1],
  91. spanRows: [1],
  92. vAlign: [1],
  93. hAlign: [1],
  94. font: ["Arial"]
  95. },
  96. data: {
  97. field: "name",
  98. vAlign: 1,
  99. hAlign: 0,
  100. font: "Arial"
  101. }
  102. }]
  103. },
  104. headers: [
  105. {name: '项目编码', dataCode: 'code', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'},
  106. {name: '项目名称', dataCode: 'name', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'}
  107. ],
  108. events: {
  109. SelectionChanged: function (sender, info) {
  110. billsInitSel(info.newSelections[0].row);
  111. }
  112. }
  113. };
  114. //项目指引类型
  115. const itemType = {
  116. job: 0,
  117. ration: 1
  118. };
  119. //项目指引复制整块localStorage key
  120. const itemCopyBlockKey = 'guideItemCopyBlock';
  121. const updateType = {
  122. create: 'create',
  123. update: 'update',
  124. del: 'delete'
  125. };
  126. //项目指引节点状态:展开全部、收起定额
  127. const itemExpandState = {
  128. expand: 1,
  129. contract: 0
  130. };
  131. //项目指引当前节点展开收缩状态,默认展开全部
  132. let curExpandState = 1;
  133. const guideItem = {
  134. dom: $('#guideItemSpread'),
  135. workBook: null,
  136. tree: null,
  137. controller: null,
  138. treeSetting: {
  139. treeCol: 0,
  140. emptyRows: 0,
  141. headRows: 1,
  142. headRowHeight: [40],
  143. defaultRowHeight: 21,
  144. cols: [{
  145. width: 400,
  146. readOnly: locked,
  147. head: {
  148. titleNames: ["项目指引"],
  149. spanCols: [1],
  150. spanRows: [1],
  151. vAlign: [1],
  152. hAlign: [1],
  153. font: ["Arial"]
  154. },
  155. data: {
  156. field: "name",
  157. vAlign: 1,
  158. hAlign: 0,
  159. font: "Arial"
  160. }
  161. },
  162. {
  163. width: 40,
  164. readOnly: true,
  165. head: {
  166. titleNames: ["输出特征"],
  167. spanCols: [1],
  168. spanRows: [1],
  169. vAlign: [1],
  170. hAlign: [1],
  171. font: ["Arial"]
  172. },
  173. data: {
  174. field: "outputItemCharacter",
  175. vAlign: 1,
  176. hAlign: 1,
  177. font: "Arial"
  178. }
  179. },
  180. {
  181. width: 40,
  182. readOnly: true,
  183. head: {
  184. titleNames: ["必填"],
  185. spanCols: [1],
  186. spanRows: [1],
  187. vAlign: [1],
  188. hAlign: [1],
  189. font: ["Arial"]
  190. },
  191. data: {
  192. field: "required",
  193. vAlign: 1,
  194. hAlign: 1,
  195. font: "Arial"
  196. }
  197. }
  198. ]
  199. },
  200. headers: [
  201. {name: '项目指引', dataCode: 'name', width: 400, vAlign: 'center', hAlign: 'left', formatter: '@'},
  202. {name: '输出特征', dataCode: 'outputItemCharacter', width: 40, vAlign: 'center', hAlign: 'center'},
  203. {name: '必填', dataCode: 'required', width: 40, vAlign: 'center', hAlign: 'center'},
  204. ],
  205. events: {
  206. SelectionChanged: function (sender, info) {
  207. guideItemInitSel(info.newSelections[0].row)
  208. },
  209. EditEnded: function (sender, args) {
  210. edit(args.sheet, [{row: args.row, col: args.col}]);
  211. },
  212. ButtonClicked: function (sender, args) {
  213. edit(args.sheet, [{row: args.row, col: args.col}]);
  214. },
  215. RangeChanged: function (sender, args) {
  216. edit(args.sheet, args.changedCells);
  217. }
  218. }
  219. };
  220. //定额章节树
  221. const section = {
  222. dom: $('#sectionSpread'),
  223. workBook: null,
  224. cache: [],
  225. tree: null,
  226. controller: null,
  227. treeSetting: {
  228. treeCol: 0,
  229. emptyRows: 0,
  230. headRows: 1,
  231. headRowHeight: [40],
  232. defaultRowHeight: 21,
  233. cols: [{
  234. width: 400,
  235. readOnly: true,
  236. head: {
  237. titleNames: ["名称"],
  238. spanCols: [1],
  239. spanRows: [1],
  240. vAlign: [1],
  241. hAlign: [1],
  242. font: ["Arial"]
  243. },
  244. data: {
  245. field: "name",
  246. vAlign: 1,
  247. hAlign: 0,
  248. font: "Arial"
  249. }
  250. }]
  251. },
  252. headers: [
  253. {name: '名称', dataCode: 'name', width: 400, vAlign: 'center', hAlign: 'left', formatter: '@'},
  254. ],
  255. events: {
  256. SelectionChanged: function (sender, info) {
  257. sectionInitSel(info.newSelections[0].row)
  258. }
  259. }
  260. };
  261. const ration = {
  262. dom: $('#rationSpread'),
  263. workBook: null,
  264. datas: [],//所有的数据,搜索定额时,从所有数据中筛选
  265. cache: [],//显示在表格上的数据,添加定额可以有效根据行识别定额
  266. headers: [
  267. {name: '选择', dataCode: 'select', width: 50, vAlign: 'center', hAlign: 'center'},
  268. {name: '编码', dataCode: 'code', width: 110, vAlign: 'center', hAlign: 'left', formatter: '@'},
  269. {name: '名称', dataCode: 'name', width: 250, vAlign: 'center', hAlign: 'left', formatter: '@'},
  270. {name: '单位', dataCode: 'unit', width: 100, vAlign: 'center', hAlign: 'left', formatter: '@'}
  271. ],
  272. events: {
  273. ButtonClicked: function (sender, args) {
  274. if(args.sheet.isEditing()){
  275. args.sheet.endEdit(true);
  276. }
  277. },
  278. CellDoubleClick: function (sender, args) {
  279. if(ration.headers[args.col].dataCode === 'name'){
  280. let insertDatas = getInsertRations([args.row]);
  281. if(insertDatas.length > 0){
  282. insert(insertDatas, false);
  283. }
  284. }
  285. }
  286. }
  287. };
  288. const options = {
  289. workBook: {
  290. tabStripVisible: false,
  291. allowContextMenu: false,
  292. allowCopyPasteExcelStyle : false,
  293. allowExtendPasteRange: false,
  294. allowUserDragDrop : false,
  295. allowUserDragFill: false,
  296. scrollbarMaxAlign : true
  297. },
  298. sheet: {
  299. protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
  300. clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
  301. }
  302. };
  303. //渲染时方法,停止渲染
  304. //@param {Object}sheet {Function}func @return {void}
  305. function renderSheetFunc(sheet, func){
  306. sheet.suspendEvent();
  307. sheet.suspendPaint();
  308. if(func){
  309. func();
  310. }
  311. sheet.resumeEvent();
  312. sheet.resumePaint();
  313. }
  314. //设置表选项
  315. //@param {Object}workBook {Object}opts @return {void}
  316. function setOptions (workBook, opts) {
  317. for(let opt in opts.workBook){
  318. workBook.options[opt] = opts.workBook[opt];
  319. }
  320. for(let opt in opts.sheet){
  321. workBook.getActiveSheet().options[opt] = opts.sheet[opt];
  322. }
  323. }
  324. //建表头
  325. //@param {Object}sheet {Array}headers @return {void}
  326. function buildHeader(sheet, headers) {
  327. let fuc = function () {
  328. sheet.setColumnCount(headers.length);
  329. sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
  330. for(let i = 0, len = headers.length; i < len; i++){
  331. sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
  332. sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
  333. sheet.getCell(0, i, GC.Spread.Sheets.SheetArea.colHeader).wordWrap(true);
  334. if(headers[i].formatter){
  335. sheet.setFormatter(-1, i, headers[i].formatter);
  336. }
  337. sheet.getRange(-1, i, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[i]['hAlign']]);
  338. sheet.getRange(-1, i, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[i]['vAlign']]);
  339. }
  340. };
  341. renderSheetFunc(sheet, fuc);
  342. }
  343. //表监听事件
  344. //@param {Object}workBook @return {void}
  345. function bindEvent(workBook, events) {
  346. if(Object.keys(events).length === 0){
  347. return;
  348. }
  349. const Events = GC.Spread.Sheets.Events;
  350. let sheet = workBook.getActiveSheet();
  351. for(let event in events){
  352. workBook.bind(Events[event], events[event]);
  353. }
  354. }
  355. //建表
  356. //@param {Object}module @return {void}
  357. function buildSheet(module) {
  358. if(!module.workBook){
  359. module.workBook = new GC.Spread.Sheets.Workbook(module.dom[0], {sheetCount: 1});
  360. let sheet = module.workBook.getActiveSheet();
  361. if(module === bills){
  362. sheet.name('stdBillsGuidance_bills');
  363. //默认初始可控制焦点在清单表中
  364. module.workBook.focus();
  365. sheet.options.isProtected = true;
  366. }
  367. else if(module === ration){
  368. sheet.options.isProtected = true;
  369. sheet.getRange(-1, 0, -1, 1).locked(locked);
  370. sheet.getRange(-1, 1, -1, -1).locked(true);
  371. }
  372. else if(module === guideItem){
  373. sheetCommonObj.bindEscKey(module.workBook, [{sheet: sheet, editStarting: null, editEnded: module.events.EditEnded}]);
  374. }
  375. setOptions(module.workBook, options);
  376. buildHeader(module.workBook.getActiveSheet(), module.headers);
  377. bindEvent(module.workBook, module.events);
  378. }
  379. lockUtil.lockSpreads([module.workBook], locked);
  380. }
  381. //清空表数据
  382. //@param {Object}sheet {Array}headers {Number}rowCount @return {void}
  383. function cleanData(sheet, headers, rowCount){
  384. renderSheetFunc(sheet, function () {
  385. sheet.clear(-1, 0, -1, headers.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  386. if (rowCount >= 0) {
  387. sheet.setRowCount(rowCount);
  388. }
  389. });
  390. }
  391. //根据清单获取项目指引
  392. //@param {String}guidanceLibID {Number}billsID {Function}callback @return {void}
  393. function getItemsByBills(guidanceLibID, billsID, callback){
  394. CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: guidanceLibID, billsID: billsID}, function (rstData) {
  395. if(callback){
  396. callback(rstData);
  397. }
  398. });
  399. }
  400. //清单表焦点控制
  401. //@param {Number}row @return {void}
  402. function billsInitSel(row){
  403. let guideSheet = guideItem.workBook.getActiveSheet();
  404. cleanData(guideSheet, guideItem.headers, -1);
  405. let node = bills.tree.items[row];
  406. if(!node){
  407. return;
  408. }
  409. bills.tree.selected = node;
  410. //显示备注
  411. $('.main-side-bottom').find('textarea').val(node.data.comment ? node.data.comment : '');
  412. if(!node.guidance.tree){
  413. getItemsByBills(libID, node.data.ID, function (rstData) {
  414. initTree(node.guidance, guideSheet, guideItem.treeSetting, rstData);
  415. setNodesExpandState(node.guidance.tree.items, curExpandState);
  416. showCheckBox(guideSheet, node.guidance.tree.items);
  417. renderSheetFunc(guideSheet, function () {
  418. TREE_SHEET_HELPER.refreshNodesVisible(node.guidance.tree.roots, guideSheet, true);
  419. });
  420. //设置底色
  421. setNodesColor(guideSheet, node.guidance.tree.items);
  422. //项目指引初始焦点
  423. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  424. });
  425. } else{
  426. setNodesExpandState(node.guidance.tree.items, curExpandState);
  427. node.guidance.controller.showTreeData();
  428. showCheckBox(guideSheet, node.guidance.tree.items);
  429. //设置底色
  430. setNodesColor(guideSheet, node.guidance.tree.items);
  431. //项目指引初始焦点
  432. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  433. }
  434. }
  435. function showCheckBox(sheet, nodes) {
  436. // const checkBoxType = locked ? sheetCommonObj.getReadOnlyCheckBox() : sheetCommonObj.getCheckBox();
  437. const checkBoxType = new GC.Spread.Sheets.CellTypes.CheckBox();
  438. const baseType = new GC.Spread.Sheets.CellTypes.Base();
  439. renderSheetFunc(sheet, function () {
  440. nodes.forEach(node => {
  441. const row = node.serialNo();
  442. if (node.depth() % 2 === 0 && _isDef(node.data.type) && node.data.type === itemType.job) {
  443. sheet.setCellType(row, 1, checkBoxType);
  444. sheet.setCellType(row, 2, checkBoxType);
  445. sheet.setValue(row, 1, node.data.outputItemCharacter || false);
  446. sheet.setValue(row, 2, node.data.required || false);
  447. } else {
  448. sheet.setCellType(row, 1, baseType);
  449. sheet.setCellType(row, 2, baseType);
  450. sheet.setValue(row, 1, '');
  451. sheet.setValue(row, 2, '');
  452. }
  453. })
  454. });
  455. }
  456. //设置项目节点展开收起状态:展开全部、收起定额
  457. //@param {Array}nodes(当前清单下的所有项目指引节点) {Number}expandState(展开全部1或收起定额0).
  458. function setNodesExpandState(nodes, expandState) {
  459. if(expandState === itemExpandState.contract) {
  460. //找出所有定额的父节点
  461. let rations = _.filter(nodes, function (node) {
  462. return node.data.type === itemType.ration;
  463. });
  464. let rationParentIDs = [];
  465. for(let ration of rations){
  466. if(ration.data.ParentID != -1){
  467. rationParentIDs.push(ration.data.ParentID);
  468. }
  469. }
  470. rationParentIDs = Array.from(new Set(rationParentIDs));
  471. let rationParentNodes = _.filter(nodes, function (node) {
  472. return rationParentIDs.includes(node.data.ID);
  473. });
  474. //收起定额
  475. for(let node of rationParentNodes){
  476. node.setExpanded(false);
  477. }
  478. } else {
  479. for(let node of nodes){
  480. node.setExpanded(true);
  481. }
  482. }
  483. }
  484. //根据奇偶层级设置节点底色,奇数层为蓝色(树节点深度为偶数)
  485. //@param {Object}sheet {Array}nodes @return {void}
  486. function setNodesColor(sheet, nodes) {
  487. const color = '#DFE8F9';
  488. renderSheetFunc(sheet, function () {
  489. for(let node of nodes){
  490. let style = new GC.Spread.Sheets.Style();
  491. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  492. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  493. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  494. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  495. let nDepth = node.depth();
  496. style.backColor = nDepth % 2 == 0 && _isDef(node.data.type) && node.data.type === itemType.job ? color : 'White';
  497. sheet.setStyle(node.serialNo(), -1, style);
  498. }
  499. });
  500. }
  501. //选中的节点是否全是同层节点
  502. //@param {Object}sheet {Array}items @return {Boolean}
  503. function itemsSameDepth(sheet, items) {
  504. let sels = sheet.getSelections();
  505. if(sels.length === 0 || items.length === 0){
  506. return false;
  507. }
  508. let depths = [];
  509. for(let i = 0; i < sels[0].rowCount; i++){
  510. let row = sels[0].row + i;
  511. let node = items[row];
  512. if(node){
  513. depths.push(node.depth());
  514. }
  515. }
  516. }
  517. //节点子项是否全是工作内容
  518. //@param {Object}node @return {Boolean}
  519. function allJobChildren(node){
  520. for(let c of node.children){
  521. if(c.data.type === itemType.ration){
  522. return false;
  523. }
  524. }
  525. return true;
  526. }
  527. //节点子项是否全是定额
  528. //@param {Object}node @return {Boolean}
  529. function allRationChildren(node){
  530. for(let c of node.children){
  531. if(c.data.type === itemType.job){
  532. return false;
  533. }
  534. }
  535. return true;
  536. }
  537. //刷新按钮有效性
  538. //@param {Object}node @return {void}
  539. function refreshBtn(node){
  540. if (locked) {
  541. return;
  542. }
  543. //全部设为无效
  544. $('.tools-btn').children().addClass('disabled');
  545. $('#insertRation').addClass('disabled');
  546. $('#insertAll').addClass('disabled');
  547. $('.main-bottom-content').find('textarea').attr('readonly', true);
  548. //插入
  549. if(bills.tree.selected && bills.tree.selected.guidance.tree){
  550. $('#insert').removeClass('disabled');
  551. if(node && node.data.type === itemType.ration){
  552. $('#insert').addClass('disabled');
  553. }
  554. }
  555. //删除
  556. if(node){
  557. $('#del').removeClass('disabled');
  558. }
  559. if(node && node.data.type === itemType.job){
  560. //升级
  561. if(node.parent){
  562. $('#upLevel').removeClass('disabled');
  563. if(node.nextSibling && node.children.length > 0 && !allJobChildren(node)){
  564. $('#upLevel').addClass('disabled');
  565. }
  566. }
  567. //降级
  568. if(node.preSibling){
  569. $('#downLevel').removeClass('disabled');
  570. if(node.preSibling.children.length > 0 && !allJobChildren(node.preSibling)){
  571. $('#downLevel').addClass('disabled');
  572. }
  573. }
  574. }
  575. //上移
  576. if(node && node.preSibling){
  577. $('#upMove').removeClass('disabled')
  578. }
  579. //下移
  580. if(node && node.nextSibling){
  581. $('#downMove').removeClass('disabled');
  582. }
  583. //收起定额、展开全部
  584. $('#expandContract').removeClass('disabled');
  585. //插入定额
  586. if(node && (node.children.length === 0 || allRationChildren(node))){
  587. $('#insertRation').removeClass('disabled');
  588. $('#insertAll').removeClass('disabled');
  589. }
  590. //备注,奇数节点可用
  591. if(node && (node.depth() + 1) % 2 === 1 && node.data.type !== itemType.ration){
  592. $('.main-bottom-content').find('textarea').attr('readonly', false);
  593. }
  594. }
  595. //项目指引表焦点控制
  596. //@param {Number}row @return {void}
  597. function guideItemInitSel(row){
  598. let billsNode = bills.tree.selected;
  599. let node = null;
  600. if(billsNode && billsNode.guidance.tree){
  601. node = billsNode.guidance.tree.items[row];
  602. if(node){
  603. billsNode.guidance.tree.selected = node;
  604. //显示备注
  605. $('.main-bottom-content').find('textarea').val(node.data.comment ? node.data.comment : '');
  606. }
  607. }
  608. refreshBtn(node);
  609. }
  610. //初始化当前库名
  611. //@param {String} @return {void}
  612. function initLibName(libName) {
  613. $('#libName')[0].outerHTML = $('#libName')[0].outerHTML.replace("XXX清单指引", libName);
  614. }
  615. //初始化各工作表
  616. //@param {Array}modules @return {void}
  617. function initWorkBooks(modules){
  618. for(let module of modules){
  619. buildSheet(module);
  620. }
  621. }
  622. function tipDivCheck(){
  623. setTimeout(function () {
  624. let tips = $('#autoTip');
  625. if(ration.tipDiv == 'show'){
  626. return;
  627. } else if(ration.tipDiv == 'hide'&&tips){
  628. tips.hide();
  629. ration._toolTipElement = null;
  630. }
  631. },600)
  632. }
  633. //获取悬浮提示单元格
  634. //@param {Object}sheet @return {Object}
  635. function getTipCellType(sheet) {
  636. let setting = {};
  637. let TipCellType = function () {};
  638. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  639. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  640. return {
  641. x: x,
  642. y: y,
  643. row: context.row,
  644. col: context.col,
  645. cellStyle: cellStyle,
  646. cellRect: cellRect,
  647. sheet: context.sheet,
  648. sheetArea: context.sheetArea
  649. };
  650. };
  651. TipCellType.prototype.processMouseEnter = function (hitinfo) {
  652. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  653. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  654. if(tag !== undefined && tag){
  655. text = tag;
  656. }
  657. if(sheet && sheet.getParent().qo){
  658. setting.pos = SheetDataHelper.getObjPos(sheet.getParent().qo);
  659. }
  660. let delayTimes = 500; //延时时间
  661. let now_timeStamp = +new Date();
  662. this.tipTimeStamp = now_timeStamp;
  663. let me = this;
  664. setTimeout(function () {
  665. if(now_timeStamp - me.tipTimeStamp == 0){//鼠标停下的时候才显示
  666. if (setting.pos && text && text !== '') {
  667. //固定不显示的div,存储文本获取固定div宽度,toolTipElement由于显示和隐藏,获取宽度不正确
  668. if(!me._fixedTipElement){
  669. let div = $('#fixedTip1')[0];
  670. if (!div) {
  671. div = document.createElement("div");
  672. $(div).css("padding", 5)
  673. .attr("id", 'fixedTip');
  674. $(div).hide();
  675. document.body.insertBefore(div, null);
  676. }
  677. me._fixedTipElement = div;
  678. }
  679. $(me._fixedTipElement).width('');
  680. $(me._fixedTipElement).html(text);
  681. if (!me._toolTipElement) {
  682. let div = $('#autoTip1')[0];
  683. if (!div) {
  684. div = document.createElement("div");
  685. $(div).css("position", "absolute")
  686. .css("border", "1px #C0C0C0 solid")
  687. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  688. .css("font", "0.9rem Calibri")
  689. .css("background", "white")
  690. .css("padding", 5)
  691. .attr("id", 'autoTip1');
  692. $(div).hide();
  693. document.body.insertBefore(div, null);
  694. }
  695. me._toolTipElement = div;
  696. $(me._toolTipElement).width('');
  697. //实时读取位置信息
  698. if(hitinfo.sheet && hitinfo.sheet.getParent().qo){
  699. setting.pos = SheetDataHelper.getObjPos(hitinfo.sheet.getParent().qo);
  700. }
  701. $(me._toolTipElement).html(text);
  702. //定额库定额特殊处理
  703. if($(hitinfo.sheet.getParent().qo).attr('id') === 'rationSpread'){
  704. let divWidth = $(me._fixedTipElement).width(),
  705. divHeight = $(me._fixedTipElement).height();
  706. if(divWidth > 600){
  707. divWidth = 590;
  708. $(me._toolTipElement).width(divWidth);
  709. }
  710. let top = setting.pos.y + hitinfo.y - divHeight < 0 ? 0 : setting.pos.y + hitinfo.cellRect.y - divHeight;
  711. $(me._toolTipElement).css("top", top).css("left", setting.pos.x - divWidth);
  712. }
  713. else{
  714. $(me._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  715. }
  716. //名称
  717. if(hitinfo.col === 2){
  718. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  719. zoom = hitinfo.sheet.zoom();
  720. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  721. let textLength = me.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  722. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  723. if(textLength > cellWidth){
  724. $(me._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  725. $(me._toolTipElement).show("fast");
  726. ration.tipDiv = 'show';//做个标记
  727. }
  728. }
  729. else {
  730. $(me._toolTipElement).show("fast");
  731. ration.tipDiv = 'show';//做个标记
  732. }
  733. }
  734. }
  735. }
  736. },delayTimes);
  737. };
  738. TipCellType.prototype.processMouseLeave = function (hininfo) {
  739. this.tipTimeStamp = +new Date();
  740. ration.tipDiv = 'hide';
  741. if (this._toolTipElement) {
  742. $(this._toolTipElement).hide();
  743. this._toolTipElement = null;
  744. }
  745. tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  746. }
  747. return new TipCellType();
  748. }
  749. //输出表数据(定额表)
  750. //@param {Object}sheet {Array}headers {Array}datas @return {void}
  751. function showData(sheet, headers, datas){
  752. let fuc = function () {
  753. sheet.setRowCount(datas.length);
  754. //复选框
  755. let checkBoxType = new GC.Spread.Sheets.CellTypes.CheckBox();
  756. let tipCellType = getTipCellType(sheet);
  757. sheet.setCellType(-1, 0, checkBoxType);
  758. for(let col = 0, cLen = headers.length; col < cLen; col++){
  759. for(let row = 0, rLen = datas.length; row < rLen; row++){
  760. sheet.setValue(row, col, datas[row][headers[col]['dataCode']]);
  761. if(col === 1){
  762. sheet.setTag(row, col, datas[row]['hint']);
  763. }
  764. }
  765. }
  766. sheet.setCellType(-1, 1, tipCellType);
  767. sheet.setCellType(-1, 2, tipCellType);
  768. };
  769. renderSheetFunc(sheet, fuc);
  770. }
  771. //根据定额章节树ID获取定额(从数据缓存中获取,定额数据一开始一次性拉取)
  772. //@param {Number}sectionId {Array}rations @return {Array}
  773. function getRationsBySectionId(sectionId, rations) {
  774. if(!sectionId || !rations){
  775. return [];
  776. }
  777. return _.filter(rations, {sectionId});
  778. }
  779. //定额章节树焦点控制
  780. //@param {Number}row @return {void}
  781. function sectionInitSel(row) {
  782. let rationSheet = ration.workBook.getActiveSheet();
  783. let sectionNode = section.tree ? section.tree.items[row] : null;
  784. if(sectionNode && sectionNode.children.length === 0){
  785. let sectionRations = getRationsBySectionId(sectionNode.data.ID, ration.datas);
  786. ration.cache = sectionRations;
  787. showData(rationSheet, ration.headers, sectionRations);
  788. }
  789. else {
  790. cleanData(rationSheet, ration.headers, 0);
  791. }
  792. }
  793. //初始化定额条目
  794. //@param {Number}rationLibId @return {void}
  795. function initRationItems(rationLibId){
  796. $.bootstrapLoading.start();
  797. //获取定额章节树
  798. let sectionSheet = section.workBook.getActiveSheet();
  799. CommonAjax.post('/rationRepository/api/getRationTree', {rationLibId: rationLibId}, function (sectionDatas) {
  800. //获取所有定额数据
  801. let reqEntity = {rationLibId: rationLibId, showHint: true, returnFields: '-_id code ID sectionId name unit basePrice rationGljList jobContent annotation'};
  802. CommonAjax.post('/rationRepository/api/getRationItemsByLib', reqEntity, function (rstData) {
  803. section.cache = sectionDatas;
  804. initTree(section, section.workBook.getActiveSheet(), section.treeSetting, sectionDatas);
  805. //初始焦点在第一行(切换库)
  806. sectionSheet.setActiveCell(0, 0);
  807. sortByCode(rstData);
  808. /* rstData.sort(function (a, b) {
  809. let rst = 0;
  810. if(a.code > b.code){
  811. rst = 1;
  812. }
  813. else if(a.code < b.code){
  814. rst = -1;
  815. }
  816. return rst;
  817. }); */
  818. ration.datas = rstData;
  819. sectionInitSel(0);
  820. $.bootstrapLoading.end();
  821. }, function () {
  822. $.bootstrapLoading.end();
  823. });
  824. }, function () {
  825. $.bootstrapLoading.end();
  826. });
  827. }
  828. //初始化定额库选择
  829. //@param {String}compilationId @return {void}
  830. function initRationLibs(compilationId){
  831. CommonAjax.post('/rationRepository/api/getRationLibsByCompilation', {compilationId: compilationId}, function (rstData) {
  832. $('#rationLibSel').empty();
  833. for(let rationLib of rstData){
  834. let opt = `<option value="${rationLib.ID}">${rationLib.dispName}</option>`;
  835. $('#rationLibSel').append(opt);
  836. }
  837. //初始选择
  838. initRationItems(parseInt($('#rationLibSel').select().val()));
  839. $('#rationLibSel').change(function () {
  840. let rationLibId = parseInt($(this).select().val());
  841. initRationItems(rationLibId);
  842. })
  843. });
  844. }
  845. // 设置清单名称文本色
  846. function setBillsForeColor(billsNodes) {
  847. const sheet = bills.workBook.getActiveSheet();
  848. renderSheetFunc(sheet, function () {
  849. for(let bills of billsNodes){
  850. const row = bills.serialNo();
  851. sheet.setStyle(row, 1, { foreColor: bills.data.hasGuide ? 'darkgreen' : 'black' });
  852. }
  853. });
  854. }
  855. //清单设置悬浮提示信息
  856. //@param {Array}billsNodes(清单节点) {Array}jobs(总的工作内容数据) {Array}items(总的项目特征数据)
  857. function setBillsHint(billsNodes, jobs, items) {
  858. let jobsMapping = {},
  859. itemsMapping = {};
  860. for(let job of jobs){
  861. jobsMapping[job.id] = job;
  862. }
  863. for(let item of items){
  864. itemsMapping[item.id] = item;
  865. }
  866. let tagInfo = [];
  867. for(let billsNode of billsNodes){
  868. let hintArr = [];
  869. let billsItems = billsNode.data.items;
  870. if(billsItems.length > 0){
  871. //项目特征
  872. hintArr.push('项目特征:');
  873. }
  874. let itemCount = 1,
  875. jobCount = 1;
  876. for(let billsItem of billsItems){
  877. let itemData = itemsMapping[billsItem.id];
  878. if(itemData){
  879. //特征值
  880. let eigens = [];
  881. for(let eigen of itemData.itemValue){
  882. eigens.push(eigen.value);
  883. }
  884. eigens = eigens.join(';');
  885. hintArr.push(`${itemCount}.${itemData.content}${eigens === '' ? '' : ': ' + eigens}`);
  886. itemCount ++;
  887. }
  888. }
  889. //工作内容
  890. let billsJobs = billsNode.data.jobs;
  891. if(billsJobs.length > 0){
  892. hintArr.push('工作内容:');
  893. }
  894. for(let billsJob of billsJobs){
  895. let jobData = jobsMapping[billsJob.id];
  896. if(jobData){
  897. hintArr.push(`${jobCount}.${jobData.content}`);
  898. jobCount ++;
  899. }
  900. }
  901. /*if(billsNode.data.ruleText && billsNode.data.ruleText !== ''){
  902. hintArr.push('工程量计算规则:');
  903. hintArr.push(billsNode.data.ruleText);
  904. }
  905. if(billsNode.data.recharge && billsNode.data.recharge !== ''){
  906. hintArr.push('补注:');
  907. hintArr.push(billsNode.data.recharge);
  908. }*/
  909. if(hintArr.length > 0){
  910. tagInfo.push({row: billsNode.serialNo(), value: hintArr.join('\n')});
  911. }
  912. }
  913. let sheet = bills.workBook.getActiveSheet();
  914. renderSheetFunc(sheet, function () {
  915. for(let tagI of tagInfo){
  916. sheet.setTag(tagI.row, 0, tagI.value);
  917. }
  918. });
  919. }
  920. //初始化清单的工作内容和项目特征
  921. //@param {Number}billsLibId {Function}callback @return {void}
  922. function initJobAndCharacter(billsLibId, callback){
  923. CommonAjax.post('/stdBillsEditor/getJobContent', {billsLibId: billsLibId}, function (datas) {
  924. stdBillsJobData = datas;
  925. CommonAjax.post('/stdBillsEditor/getItemCharacter', {billsLibId: billsLibId}, function (datas) {
  926. stdBillsFeatureData = datas;
  927. if(callback){
  928. callback();
  929. }
  930. });
  931. });
  932. }
  933. let billsLibId = 0;
  934. //获取指引库信息及关联的清单
  935. //@param {Number}libID {Function}callback @return {Object}
  936. function getLibWithBills(libID, callback){
  937. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function (rstData) {
  938. billsLibId = rstData.guidanceLib.billsLibId;
  939. initRationLibs(rstData.guidanceLib.compilationId);
  940. bills.cache = rstData.bills;
  941. initLibName(rstData.guidanceLib.name);
  942. /*initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  943. //每一棵项目指引树挂在清单节点上
  944. for(let node of bills.tree.items){
  945. node.guidance = {tree: null, controller: null};
  946. }
  947. //默认初始节点
  948. billsInitSel(0);
  949. if(callback){
  950. callback(rstData);
  951. }*/
  952. let initDataCallback = function () {
  953. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  954. //每一棵项目指引树挂在清单节点上
  955. for(let node of bills.tree.items){
  956. node.guidance = {tree: null, controller: null};
  957. }
  958. //默认初始节点
  959. billsInitSel(0);
  960. if(callback){
  961. callback(rstData);
  962. }
  963. };
  964. initJobAndCharacter(rstData.guidanceLib.billsLibId, initDataCallback);
  965. }, function (msg) {
  966. window.location.href = '/billsGuidance/main';
  967. });
  968. }
  969. //初始化并输出树
  970. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  971. function initTree(module, sheet, treeSetting, datas){
  972. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  973. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  974. module.tree.loadDatas(datas);
  975. module.controller.showTreeData();
  976. if(module === bills){
  977. setBillsHint(bills.tree.items, stdBillsJobData, stdBillsFeatureData);
  978. setBillsForeColor(bills.tree.items);
  979. }
  980. }
  981. //更新清单备注
  982. function updateBillsComment(updateData, callback, errCB) {
  983. CommonAjax.post('/stdBillsEditor/updateBills', updateData, function () {
  984. if (callback) {
  985. callback();
  986. }
  987. }, function () {
  988. if(errCB) {
  989. errCB();
  990. }
  991. });
  992. }
  993. //更新项目指引
  994. //@param {Array}updateDatas {Function}callback @return {void}
  995. function updateGuideItems(updateDatas, callback, errCB){
  996. CommonAjax.post('/billsGuidance/api/updateItems', {updateDatas: updateDatas}, function (rstData) {
  997. if(callback){
  998. callback(rstData);
  999. }
  1000. }, function () {
  1001. if(errCB) {
  1002. errCB();
  1003. }
  1004. $.bootstrapLoading.end();
  1005. });
  1006. }
  1007. //编辑后自动去除换行符回车符
  1008. const deESC = /[\n]/g;
  1009. //项目指引编辑
  1010. //@param {Object}sheet {Array}cells
  1011. function edit(sheet, cells){
  1012. let updateDatas = [];
  1013. //同步节点数据
  1014. let syncDatas = [];
  1015. for(let cell of cells){
  1016. const field = guideItem.headers[cell.col].dataCode;
  1017. let node = bills.tree.selected.guidance.tree.items[cell.row];
  1018. if (field === 'name') {
  1019. let text = sheet.getValue(cell.row, cell.col);
  1020. text = text ? text.toString() : '';
  1021. text = text.replace(deESC, '');
  1022. sheet.setValue(cell.row, cell.col, text);
  1023. if(node.data.name != text){
  1024. syncDatas.push({node: node, text: text, field, cell});
  1025. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {name: text}});
  1026. }
  1027. } else if (field === 'outputItemCharacter' || field === 'required') {
  1028. const val = !sheet.getValue(cell.row, cell.col);
  1029. sheet.setValue(cell.row, cell.col, val);
  1030. syncDatas.push({node: node, text: val, field, cell });
  1031. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {[field]: val}});
  1032. }
  1033. }
  1034. if(updateDatas.length > 0){
  1035. updateGuideItems(updateDatas, function () {
  1036. for(let syncData of syncDatas){
  1037. syncData.node.data[syncData.field] = syncData.text;
  1038. }
  1039. }, function () {
  1040. //失败恢复
  1041. renderSheetFunc(sheet, function () {
  1042. for(let syncData of syncDatas){
  1043. sheet.setValue(syncData.node.serialNo(), syncData.cell.col, syncData.node.data[syncData.field] ? syncData.node.data[syncData.field] : '');
  1044. }
  1045. });
  1046. });
  1047. }
  1048. }
  1049. //项目指引插入,支持一次插入多条数据
  1050. //@param {Array}datas {Boolean}tobeChild(插入成为子项) {Function}callback @return {void}
  1051. function insert(datas, tobeChild, callback = null){
  1052. $.bootstrapLoading.start();
  1053. let sheet = guideItem.workBook.getActiveSheet();
  1054. let controller = bills.tree.selected.guidance.controller;
  1055. let selected = bills.tree.selected.guidance.tree.selected;
  1056. let updateDatas = [];
  1057. //建立数组下标索引
  1058. let newDataIndex = {};
  1059. for(let i = 0; i < datas.length; i++){
  1060. let newNodeData = {
  1061. libID: libID, ID: uuid.v1(), ParentID: selected ? selected.getParentID() : -1, NextSiblingID: selected ? selected.getNextSiblingID() : -1,
  1062. billsID: bills.tree.selected.getID()
  1063. };
  1064. //定额类型插入当前工作内容焦点行,
  1065. if(selected && ((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  1066. newNodeData.ParentID = selected.getID();
  1067. newNodeData.NextSiblingID = -1;
  1068. }
  1069. Object.assign(newNodeData, datas[i]);
  1070. newDataIndex[i] = newNodeData;
  1071. }
  1072. for(let i = 0; i < datas.length; i++){
  1073. //第一个节点
  1074. if(i === 0){
  1075. //非插入成子节点,更新选中节点NestSiblingID
  1076. if(selected && !((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  1077. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: newDataIndex[i].ID}});
  1078. }
  1079. }
  1080. //非最后一个节点
  1081. if(i !== datas.length - 1){
  1082. newDataIndex[i].NextSiblingID = newDataIndex[i + 1].ID;
  1083. }
  1084. updateDatas.push({updateType: updateType.create, updateData: newDataIndex[i]});
  1085. }
  1086. updateGuideItems(updateDatas, function () {
  1087. for(let updateData of updateDatas){
  1088. if(updateData.updateType === updateType.create){
  1089. let newNode = controller.insertByIDS(updateData.updateData.ID, updateData.updateData.ParentID, updateData.updateData.NextSiblingID);
  1090. //同步data
  1091. Object.assign(newNode.data, updateData.updateData);
  1092. const row = newNode.serialNo();
  1093. sheet.setValue(row, 0, newNode.data.name);
  1094. if (newNode.data.outputItemCharacter !== undefined) {
  1095. sheet.setValue(row, 1, newNode.data.outputItemCharacter);
  1096. }
  1097. showCheckBox(sheet, [newNode]);
  1098. refreshBtn(newNode);
  1099. }
  1100. }
  1101. if (!bills.tree.selected.data.hasGuide && bills.tree.selected.guidance.tree.items.length) {
  1102. bills.tree.selected.data.hasGuide = true;
  1103. setBillsForeColor([bills.tree.selected]);
  1104. }
  1105. if(callback){
  1106. callback();
  1107. }
  1108. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1109. guideItem.workBook.focus(true);
  1110. $.bootstrapLoading.end();
  1111. });
  1112. }
  1113. // 删除定额(嵌套删除自身及后代定额)
  1114. function delRations() {
  1115. const selected = bills.tree.selected.guidance.tree.selected;
  1116. if (!selected) {
  1117. return;
  1118. }
  1119. if (selected.data.type === itemType.ration) {
  1120. del({ row: selected.serialNo(), col: 0, rowCount: 1, colCount: 1 });
  1121. return;
  1122. }
  1123. const rations = selected.getPosterity().filter(item => item.data.type === itemType.ration);
  1124. if (!rations.length) {
  1125. return;
  1126. }
  1127. const updateDatas = rations.map(item => ({ updateType: updateType.del, findData: { ID: item.data.ID } }));
  1128. const rationIDs = rations.map(r => r.data.ID);
  1129. $.bootstrapLoading.start();
  1130. updateGuideItems(updateDatas, function () {
  1131. const guideSheet = guideItem.workBook.getSheet(0);
  1132. const treeNodes = bills.tree.selected.guidance.tree.items.filter(item => !rationIDs.includes(item.data.ID));
  1133. const state = bills.tree.selected.guidance.tree.getExpState(treeNodes);
  1134. const treeData = treeNodes.map(item => item.data);
  1135. initTree(bills.tree.selected.guidance, guideSheet, guideItem.treeSetting, treeData);
  1136. bills.tree.selected.guidance.tree.setExpandedByState(bills.tree.selected.guidance.tree.items, state);
  1137. renderSheetFunc(guideSheet, function () {
  1138. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.selected.guidance.tree.roots, guideSheet, true);
  1139. });
  1140. //设置底色
  1141. setNodesColor(guideSheet, bills.tree.selected.guidance.tree.items);
  1142. //项目指引初始焦点
  1143. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  1144. $.bootstrapLoading.end();
  1145. guideItem.workBook.focus(true)
  1146. });
  1147. }
  1148. //项目指引删除操作
  1149. //@return {void}
  1150. function del(selArea = null){
  1151. $.bootstrapLoading.start();
  1152. let controller = bills.tree.selected.guidance.controller;
  1153. let selNodes = [];
  1154. let sheet = guideItem.workBook.getSheet(0);
  1155. let sel = selArea ? selArea : sheet.getSelections()[0];
  1156. if(sel){
  1157. sel.row = sel.row === -1 ? 0 : sel.row;
  1158. for(let i = 0; i < sel.rowCount; i++){
  1159. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1160. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1161. }
  1162. }
  1163. }
  1164. //选中的块节点
  1165. let blockNodes = getBlockNodes(selNodes);
  1166. let updateDatas = [];
  1167. function getDelDatas(nodes){
  1168. for (let node of nodes) {
  1169. updateDatas.push({updateType: updateType.del, findData: {ID: node.getID()}});
  1170. if (node.children.length > 0) {
  1171. getDelDatas(node.children);
  1172. }
  1173. }
  1174. }
  1175. getDelDatas(blockNodes);
  1176. //更新相关的前节点
  1177. for (let node of blockNodes) {
  1178. if (node.preSibling && !blockNodes.includes(node.preSibling)) {
  1179. let next = node;
  1180. while (next.nextSibling && blockNodes.includes(next.nextSibling)) {
  1181. next = next.nextSibling;
  1182. }
  1183. updateDatas.push({updateType: updateType.update, findData: {ID: node.preSibling.getID()}, updateData: {NextSiblingID: next.getNextSiblingID()}});
  1184. }
  1185. }
  1186. updateGuideItems(updateDatas, function () {
  1187. console.log(blockNodes);
  1188. controller.m_delete(blockNodes);
  1189. guideItemInitSel(sheet.getActiveRowIndex());
  1190. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1191. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1192. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1193. if (bills.tree.selected.data.hasGuide && !bills.tree.selected.guidance.tree.items.length) {
  1194. bills.tree.selected.data.hasGuide = false;
  1195. setBillsForeColor([bills.tree.selected]);
  1196. }
  1197. $.bootstrapLoading.end();
  1198. guideItem.workBook.focus(true)
  1199. });
  1200. }
  1201. //项目指引升级
  1202. //@return {void}
  1203. function upLevel(){
  1204. $.bootstrapLoading.start();
  1205. let controller = bills.tree.selected.guidance.controller;
  1206. let selected = bills.tree.selected.guidance.tree.selected;
  1207. let updateDatas = [];
  1208. //更新父节点
  1209. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getParentID()}, updateData: {NextSiblingID: selected.getID()}});
  1210. //更新选中节点
  1211. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()},
  1212. updateData: {ParentID: selected.parent.getParentID(), NextSiblingID: selected.parent.getNextSiblingID()}});
  1213. if(selected.nextSibling && selected.children.length > 0){
  1214. //更新选中节点最末子节点
  1215. let lastChild = selected.children[selected.children.length - 1];
  1216. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: -1}});
  1217. }
  1218. //选中节点的所有后兄弟节点成为选中节点的子项
  1219. let selectedNextIDs = [];
  1220. let sNext = selected.nextSibling;
  1221. while(sNext){
  1222. selectedNextIDs.push(sNext.getID());
  1223. sNext = sNext.nextSibling;
  1224. }
  1225. for(let sID of selectedNextIDs){
  1226. updateDatas.push({updateType: updateType.update, findData: {ID: sID}, updateData: {ParentID: selected.getID()}});
  1227. }
  1228. updateGuideItems(updateDatas, function () {
  1229. controller.upLevel();
  1230. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1231. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1232. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1233. $.bootstrapLoading.end();
  1234. guideItem.workBook.focus(true)//31574
  1235. });
  1236. }
  1237. //项目指引降级
  1238. //@return {void}
  1239. function downLevel(){
  1240. $.bootstrapLoading.start();
  1241. let controller = bills.tree.selected.guidance.controller;
  1242. let selected = bills.tree.selected.guidance.tree.selected;
  1243. let updateDatas = [];
  1244. //更新前兄弟节点
  1245. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1246. //更新前兄弟节点最末子节点
  1247. if(selected.preSibling.children.length > 0){
  1248. let lastChild = selected.preSibling.children[selected.preSibling.children.length - 1];
  1249. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1250. }
  1251. //更新选中节点
  1252. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {ParentID: selected.preSibling.getID(), NextSiblingID: -1}});
  1253. updateGuideItems(updateDatas, function () {
  1254. controller.downLevel();
  1255. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1256. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1257. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1258. $.bootstrapLoading.end();
  1259. guideItem.workBook.focus(true)
  1260. });
  1261. }
  1262. //项目指引上移
  1263. //@return {void}
  1264. function upMove(){
  1265. $.bootstrapLoading.start();
  1266. let controller = bills.tree.selected.guidance.controller;
  1267. let selected = bills.tree.selected.guidance.tree.selected;
  1268. let updateDatas = [];
  1269. //更新前节点
  1270. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1271. //更新前前节点
  1272. if(selected.preSibling.preSibling){
  1273. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.preSibling.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1274. }
  1275. //更新选中节点
  1276. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.preSibling.getID()}});
  1277. updateGuideItems(updateDatas, function () {
  1278. controller.upMove();
  1279. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1280. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1281. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1282. $.bootstrapLoading.end();
  1283. guideItem.workBook.focus(true)
  1284. });
  1285. }
  1286. //项目指引下移
  1287. //@return {void}
  1288. function downMove(){
  1289. $.bootstrapLoading.start();
  1290. let controller = bills.tree.selected.guidance.controller;
  1291. let selected = bills.tree.selected.guidance.tree.selected;
  1292. let updateDatas = [];
  1293. //更新下节点
  1294. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getNextSiblingID()}, updateData: {NextSiblingID: selected.getID()}});
  1295. //更新前节点
  1296. if(selected.preSibling){
  1297. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1298. }
  1299. //更新选中节点
  1300. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.nextSibling.getNextSiblingID()}});
  1301. updateGuideItems(updateDatas, function () {
  1302. controller.downMove();
  1303. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1304. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1305. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1306. $.bootstrapLoading.end();
  1307. guideItem.workBook.focus(true)
  1308. });
  1309. }
  1310. //获取定额类型的项目指引名称,通过定额转换
  1311. //@param {Object}ration @return {String}
  1312. function getRationItemName(ration){
  1313. let arr = [];
  1314. arr.push(ration.code ? ration.code : '');
  1315. arr.push(ration.name ? ration.name : '');
  1316. arr.push(ration.basePrice ? ration.basePrice : '');
  1317. let rst = arr.join(' ');
  1318. rst += `/${ration.unit ? ration.unit : ''}`;
  1319. return rst;
  1320. }
  1321. //获取选中的定额表行
  1322. //@return {Array}
  1323. function getCheckedRationRows(all){
  1324. let rst = [];
  1325. let sheet = ration.workBook.getActiveSheet();
  1326. for(let i = 0; i < sheet.getRowCount(); i++){
  1327. // 全选
  1328. if (all) {
  1329. rst.push(i);
  1330. continue;
  1331. }
  1332. let checked = sheet.getValue(i, 0);
  1333. if(checked){
  1334. rst.push(i);
  1335. }
  1336. }
  1337. return rst;
  1338. }
  1339. //清空选中定额表行
  1340. //@param {Array}rows @return {void}
  1341. function clearCheckedRation(rows) {
  1342. let sheet = ration.workBook.getActiveSheet();
  1343. renderSheetFunc(sheet, function () {
  1344. for(let row of rows){
  1345. sheet.setValue(row, 0, 0);
  1346. }
  1347. });
  1348. }
  1349. //获取要插入的定额数据
  1350. //@param {Array}rows @return {Array}
  1351. function getInsertRations(rows){
  1352. let rst = [];
  1353. //当前已存在定额
  1354. let curRationIems = [];
  1355. let selected = bills.tree.selected.guidance.tree.selected;
  1356. if(selected){
  1357. if(selected.data.type === itemType.job){
  1358. curRationIems = selected.children;
  1359. }
  1360. else {
  1361. curRationIems = selected.parent ? selected.parent.children : selected.tree.roots;
  1362. }
  1363. }
  1364. for(let row of rows){
  1365. let selRation = ration.cache[row];
  1366. if(selRation){
  1367. //添加的定额是否已存在,不重复添加
  1368. let isExist = false;
  1369. for(let curRation of curRationIems){
  1370. if(curRation.data.rationID == selRation.ID){
  1371. isExist = true;
  1372. break;
  1373. }
  1374. }
  1375. if(!isExist){
  1376. rst.push({type: itemType.ration, name: getRationItemName(selRation), rationID: selRation.ID});
  1377. }
  1378. }
  1379. }
  1380. return rst;
  1381. }
  1382. //获取块节点父项不存在于选中节点中的节点
  1383. //@param {Array}nodes(选中的节点) @return {Array}
  1384. function getBlockNodes(nodes) {
  1385. let nodeMapping = {};
  1386. for(let node of nodes){
  1387. nodeMapping[node.data.ID] = node;
  1388. }
  1389. //块节点,父项不存在于选中节点中的节点
  1390. let blockNodes = [];
  1391. for(let node of nodes){
  1392. if(!nodeMapping[node.data.ParentID]){
  1393. blockNodes.push(node);
  1394. }
  1395. }
  1396. return blockNodes;
  1397. }
  1398. //允许复制整块,如果有多个块节点,且块节点的父项不同,则不可复制
  1399. //@param {Array}nodes(块节点) @return {Boolean}
  1400. function canCopyBlock(nodes) {
  1401. if(!nodes || nodes.length === 0){
  1402. return false;
  1403. }
  1404. let pID = nodes[0].data.ParentID;
  1405. for(let node of nodes){
  1406. if(node.data.ParentID !== pID){
  1407. return false;
  1408. }
  1409. }
  1410. return true;
  1411. }
  1412. //允许粘贴整块 有粘贴数据,节点存在,如果粘贴到的节点为定额数据,粘贴数据为全定额数据
  1413. //@param {Object}node(粘贴到的节点)
  1414. function canPasteBlock(node) {
  1415. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1416. if(!pasteDatas || pasteDatas.length === 0){
  1417. return false;
  1418. }
  1419. if(!node){
  1420. return false;
  1421. }
  1422. //若粘贴到定额节点,则数据须全为定额
  1423. if(node.data.type === itemType.ration){
  1424. for(let data of pasteDatas){
  1425. if(data.type !== itemType.ration){
  1426. return false;
  1427. }
  1428. }
  1429. }
  1430. //若粘贴到非定额节点,则粘贴的顶层数据须全为非定额
  1431. else {
  1432. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1433. for(let topData of topDatas){
  1434. if(topData.type === itemType.ration){
  1435. return false;
  1436. }
  1437. }
  1438. }
  1439. return true;
  1440. }
  1441. //复制整块,将块节点下所有节点数据复制一份,并且重新生成ID、ParentID、NextSiblingID,使用localStorage存储
  1442. //@param {Array}nodes(块节点) @return {void}
  1443. function copyBlocks(nodes) {
  1444. nodes = _.cloneDeep(nodes);
  1445. //将块节点的ParentID暂时设置为-1
  1446. for(let topNode of nodes){
  1447. topNode.data.ParentID = -1;
  1448. }
  1449. let copyDatas = [];
  1450. let copyNodes = [];
  1451. //获取块节点包含的所有节点(包括自己)
  1452. function containNodes(nodes) {
  1453. for(let node of nodes){
  1454. copyNodes.push(node);
  1455. if(node.children.length > 0){
  1456. containNodes(node.children);
  1457. }
  1458. }
  1459. }
  1460. containNodes(nodes);
  1461. for(let node of copyNodes){
  1462. copyDatas.push(node.data);
  1463. }
  1464. console.log(`copyDatas`);
  1465. console.log(copyDatas);
  1466. setLocalCache(itemCopyBlockKey, JSON.stringify(copyDatas));
  1467. }
  1468. //粘贴整块,整块数据粘贴到相关节点,并成为其后项
  1469. //@param {Object}node(粘贴到的节点) @return {void}
  1470. function pasteBlock(node) {
  1471. let itemObj = bills.tree.selected.guidance;
  1472. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1473. //整理ID
  1474. let IDMapping = {};
  1475. for(let data of pasteDatas){
  1476. data.newID = uuid.v1();
  1477. IDMapping[data.ID] = data;
  1478. }
  1479. for(let data of pasteDatas){
  1480. let nextData = IDMapping[data.NextSiblingID];
  1481. data.NextSiblingID = nextData ? nextData.newID : -1;
  1482. let parentData = IDMapping[data.ParentID];
  1483. data.ParentID = parentData ? parentData.newID : -1;
  1484. }
  1485. for(let data of pasteDatas){
  1486. data.ID = data.newID;
  1487. delete data.newID;
  1488. }
  1489. let updateDatas = [];
  1490. //将最顶层的块数据的ParentID设置成粘贴到节点的ParentID,并设置新的billsID
  1491. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1492. for(let topData of topDatas){
  1493. topData.ParentID = node.getParentID();
  1494. }
  1495. //更新数据
  1496. //更新插入的最末顶层数据NextSiblingID
  1497. if(node.nextSibling){
  1498. topDatas[topDatas.length - 1].NextSiblingID = node.getNextSiblingID();
  1499. }
  1500. //新建节点
  1501. for(let data of pasteDatas){
  1502. data.libID = libID;
  1503. data.billsID = node.data.billsID;
  1504. delete data._id;
  1505. updateDatas.push({updateType: updateType.create, updateData: data});
  1506. }
  1507. console.log(`pasteDatas`);
  1508. console.log(pasteDatas);
  1509. //更新粘贴到的节点的NextSiblingID
  1510. updateDatas.push({updateType: updateType.update, findData: {ID: node.data.ID}, updateData: {NextSiblingID: topDatas[0].ID}})
  1511. $.bootstrapLoading.start();
  1512. updateGuideItems(updateDatas, function (rstData) {
  1513. $.bootstrapLoading.end();
  1514. node.data.NextSiblingID = topDatas[0].ID;
  1515. let newNodes = itemObj.tree.insertDatasTo(node.data, pasteDatas);
  1516. cleanData(guideItem.workBook.getActiveSheet(), guideItem.headers, -1);
  1517. itemObj.controller.showTreeData();
  1518. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1519. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1520. }, function () {
  1521. $.bootstrapLoading.end();
  1522. });
  1523. }
  1524. //初始化右键菜单
  1525. //@return {void}
  1526. function initContextMenu() {
  1527. $.contextMenu({
  1528. selector: '#guideItemSpread',
  1529. build: function($triggerElement, e){
  1530. //控制允许右键菜单在哪个位置出现
  1531. let sheet = guideItem.workBook.getSheet(0);
  1532. let offset = $("#guideItemSpread").offset(),
  1533. x = e.pageX - offset.left,
  1534. y = e.pageY - offset.top;
  1535. let target = sheet.hitTest(x, y);
  1536. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  1537. let sel = sheet.getSelections()[0];
  1538. if(sel && sel.rowCount === 1){
  1539. sheet.setActiveCell(target.row, target.col);
  1540. }
  1541. sel = sheet.getSelections()[0];
  1542. let selNodes = [];
  1543. if(sel){
  1544. sel.row = sel.row === -1 ? 0 : sel.row;
  1545. for(let i = 0; i < sel.rowCount; i++){
  1546. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1547. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1548. }
  1549. }
  1550. }
  1551. //块节点
  1552. let blockNodes = getBlockNodes(selNodes);
  1553. //右键在多选内则不重设焦点
  1554. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  1555. sheet.setActiveCell(target.row, target.col);
  1556. }
  1557. guideItemInitSel(target.row);
  1558. return {
  1559. callback: function(){},
  1560. items: {
  1561. "copy": {
  1562. name: "复制整块",
  1563. disabled: function () {
  1564. return locked || !canCopyBlock(blockNodes);
  1565. },
  1566. icon: "fa-copy",
  1567. callback: function (key, opt) {
  1568. copyBlocks(blockNodes);
  1569. }},
  1570. "paste": {
  1571. name: "粘贴整块",
  1572. disabled: function () {
  1573. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1574. return locked || !canPasteBlock(pasteNode);
  1575. },
  1576. icon: "fa-paste",
  1577. callback: function (key, opt) {
  1578. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1579. pasteBlock(pasteNode);
  1580. }},
  1581. "delRations": {
  1582. name: '删除定额',
  1583. disabled: function () {
  1584. let node = bills.tree.selected.guidance.tree.items[target.row];
  1585. return locked || !node
  1586. },
  1587. icon: "fa-remove",
  1588. callback: function (key, opt) {
  1589. $('#delRationAlert').modal('show');
  1590. }
  1591. },
  1592. "del": {
  1593. name: '删除',
  1594. disabled: function () {
  1595. let node = bills.tree.selected.guidance.tree.items[target.row];
  1596. return locked || !node
  1597. },
  1598. icon: "fa-remove",
  1599. callback: function (key, opt) {
  1600. $('#delAlert').modal('show');
  1601. }
  1602. },
  1603. "insertSibling": {
  1604. name: '插入行',
  1605. disabled: function () {
  1606. let node = bills.tree.selected.guidance.tree.items[target.row];
  1607. return locked || !node || node.data.type !== itemType.job;
  1608. },
  1609. icon: "fa-arrow-left",
  1610. callback: function (key, opt) {
  1611. insert([{type: itemType.job, name: ''}], false);
  1612. }
  1613. },
  1614. "insertChild": {
  1615. name: '插入子项',
  1616. disabled: function () {
  1617. let node = bills.tree.selected.guidance.tree.items[target.row];
  1618. return locked || !node || node.data.type !== itemType.job || !allJobChildren(node);
  1619. },
  1620. icon: 'fa-arrow-left',
  1621. callback: function (key, opt) {
  1622. insert([{type: itemType.job, name: ''}], true);
  1623. }
  1624. }
  1625. }
  1626. };
  1627. }
  1628. else{
  1629. return false;
  1630. }
  1631. }
  1632. });
  1633. }
  1634. //初始化个按钮点击
  1635. //@return {void}
  1636. function initBtn(){
  1637. $('#insert').click(function () {
  1638. insert([{type: itemType.job, name: '', outputItemCharacter: true }], false);
  1639. });
  1640. $('#delConfirm').click(function () {
  1641. del();
  1642. $('#delAlert').modal('hide');
  1643. });
  1644. $('#delRationConfirm').click(function () {
  1645. delRations();
  1646. $('#delRationAlert').modal('hide');
  1647. });
  1648. $('#del').click(function () {
  1649. $('#delAlert').modal('show');
  1650. });
  1651. $('#upLevel').click(function () {
  1652. upLevel();
  1653. });
  1654. $('#downLevel').click(function () {
  1655. downLevel();
  1656. });
  1657. $('#upMove').click(function () {
  1658. upMove();
  1659. });
  1660. $('#downMove').click(function () {
  1661. downMove();
  1662. });
  1663. //收起定额、展开全部
  1664. $('#expandContract').click(function () {
  1665. //目前状态时展开全部节点状态,点击则收起定额
  1666. let tree = bills.tree.selected.guidance.tree,
  1667. itemSheet = guideItem.workBook.getActiveSheet();
  1668. if(curExpandState === itemExpandState.expand){
  1669. curExpandState = itemExpandState.contract;
  1670. $(this).html('<i class="fa fa-plus-square-o" aria-hidden="true"></i> 展开全部');
  1671. setNodesExpandState(tree.items, itemExpandState.contract);
  1672. } else {
  1673. curExpandState = itemExpandState.expand;
  1674. $(this).html('<i class="fa fa-minus-square-o" aria-hidden="true"></i> 收起定额');
  1675. setNodesExpandState(tree.items, itemExpandState.expand);
  1676. }
  1677. renderSheetFunc(itemSheet, function () {
  1678. TREE_SHEET_HELPER.refreshNodesVisible(tree.roots, itemSheet, true);
  1679. });
  1680. });
  1681. // 插入选中定额
  1682. $('#insertRation').click(function () {
  1683. let checkedRows = getCheckedRationRows();
  1684. let insertDatas = getInsertRations(checkedRows);
  1685. if(insertDatas.length > 0){
  1686. insert(insertDatas, false, function () {
  1687. //清空选择
  1688. clearCheckedRation(checkedRows);
  1689. });
  1690. }
  1691. else {
  1692. clearCheckedRation(checkedRows);
  1693. }
  1694. });
  1695. // 插入全部定额
  1696. $('#insertAll').click(function () {
  1697. let isAll = true;
  1698. let checkedRows = getCheckedRationRows(isAll);
  1699. let insertDatas = getInsertRations(checkedRows);
  1700. if(insertDatas.length > 0){
  1701. insert(insertDatas, false);
  1702. }
  1703. });
  1704. //搜索定额
  1705. $('#searchBtn').click(function () {
  1706. let searchStr = $('#searchText').val();
  1707. if(!searchStr || searchStr === ''){
  1708. ration.cache = ration.datas;
  1709. }
  1710. else{
  1711. let reg = new RegExp(searchStr, 'i');
  1712. ration.cache = _.filter(ration.datas, function (data) {
  1713. return reg.test(data.code) || reg.test(data.name);
  1714. });
  1715. }
  1716. $('.top-content').hide();
  1717. $('#searchCount').text(`搜索结果: ${ration.cache.length}`);
  1718. $('#rationSearchResult').show();
  1719. autoFlashHeight();
  1720. ration.workBook.refresh();
  1721. let rationSheet = ration.workBook.getActiveSheet();
  1722. renderSheetFunc(rationSheet, function () {
  1723. clearCheckedRation(getCheckedRationRows());
  1724. showData(rationSheet, ration.headers, ration.cache);
  1725. })
  1726. });
  1727. //关闭搜索
  1728. $('#rationSearchResult a').click(function () {
  1729. $('.top-content').show();
  1730. $('#rationSearchResult').hide();
  1731. autoFlashHeight();
  1732. renderSheetFunc(ration.workBook.getActiveSheet(), function () {
  1733. clearCheckedRation(getCheckedRationRows());
  1734. });
  1735. section.workBook.refresh();
  1736. ration.workBook.refresh();
  1737. $('#searchText').val('');
  1738. //恢复章节树下的定额
  1739. sectionInitSel(section.workBook.getActiveSheet().getActiveRowIndex());
  1740. });
  1741. let keyupTime = 0,
  1742. delayTime = 500;
  1743. function delayKeyup(callback) {
  1744. let nowTime = Date.now();
  1745. keyupTime = nowTime;
  1746. setTimeout(function () {
  1747. if (nowTime - keyupTime == 0) {
  1748. callback();
  1749. }
  1750. }, delayTime);
  1751. }
  1752. //执行搜索
  1753. $('#searchText').keyup(function (e) {
  1754. delayKeyup(function () {
  1755. $('#searchBtn').click();
  1756. });
  1757. });
  1758. //编辑清单备注
  1759. $('.main-side-bottom').find('textarea').keyup(function () {
  1760. let me = this;
  1761. let node = bills.tree.selected;
  1762. let comment = $(me).val();
  1763. delayKeyup(function () {
  1764. if (node) {
  1765. let updateData = {lastOperator: userAccount, billsLibId: billsLibId, updateId: node.getID(), field: 'comment', data: comment};
  1766. updateBillsComment(updateData, function () {
  1767. node.data.comment = comment;
  1768. }, function() {
  1769. $(me).val(node.data.comment || '');
  1770. })
  1771. }
  1772. });
  1773. });
  1774. //编辑选项备注
  1775. $('.main-bottom-content').find('textarea').keyup(function () {
  1776. let me = this;
  1777. let node = bills.tree.selected.guidance.tree.selected;
  1778. let comment = $(me).val();
  1779. delayKeyup(function () {
  1780. if(node){
  1781. let updateDatas = [{updateType: updateType.update, findData: {ID: node.getID()}, updateData: {comment: comment}}];
  1782. updateGuideItems(updateDatas, function (rstData) {
  1783. node.data.comment = comment;
  1784. }, function() {
  1785. $(me).val(node.data.comment || '');
  1786. });
  1787. }
  1788. });
  1789. });
  1790. //定额高度拖动调整
  1791. let heightEleObj = {
  1792. module: moduleName,
  1793. resize: $('#deResize'),
  1794. top: $('#topContent'),
  1795. topSpread: $('#sectionSpread'),
  1796. bottom: $('#bottomContent'),
  1797. bottomSpread: $('#rationSpread')
  1798. },
  1799. heightLimit = {
  1800. min: 150,
  1801. max: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-150-10`,
  1802. notTopSpread: 0,
  1803. notBottomSpread: 0,
  1804. };
  1805. SlideResize.verticalSlide(heightEleObj, heightLimit, function () {
  1806. if(section.workBook){
  1807. section.workBook.refresh();
  1808. }
  1809. if(ration.workBook){
  1810. ration.workBook.refresh();
  1811. }
  1812. });
  1813. /*slideResize(rationLibResizeEles, {min: 147, max: 680}, 'height', function() {
  1814. //autoFlashHeight();
  1815. if(section.workBook){
  1816. section.workBook.refresh();
  1817. }
  1818. if(ration.workBook){
  1819. ration.workBook.refresh();
  1820. }
  1821. });*/
  1822. //左右拖动
  1823. //清单表与项目指引表
  1824. let leftElesObj = {};
  1825. leftElesObj.module = moduleName;
  1826. leftElesObj.resize = $('#slideResizeLeft');
  1827. leftElesObj.parent = $('#dataRow');
  1828. leftElesObj.left = $('#leftContent');
  1829. leftElesObj.right = $('#midContent');
  1830. SlideResize.horizontalSlide(leftElesObj, {min: 200, max: `$('#dataRow').width() - $('#rightContent').width() - 200`}, function () {
  1831. refreshALlWorkBook();
  1832. });
  1833. //人材机表与人材机组成物表
  1834. let rightElesObj = {};
  1835. rightElesObj.module = moduleName;
  1836. rightElesObj.resize = $('#slideResizeRight');
  1837. rightElesObj.parent = $('#dataRow');
  1838. rightElesObj.left = $('#midContent');
  1839. rightElesObj.right = $('#rightContent');
  1840. SlideResize.horizontalSlide(rightElesObj, {min: 200, max: `$('#dataRow').width() - $('#leftContent').width() - 200`}, function () {
  1841. refreshALlWorkBook();
  1842. });
  1843. }
  1844. //刷新全部工作簿
  1845. //@return {void}
  1846. function refreshALlWorkBook() {
  1847. if (bills.workBook) {
  1848. bills.workBook.refresh();
  1849. }
  1850. if (guideItem.workBook) {
  1851. guideItem.workBook.refresh();
  1852. }
  1853. if (section.workBook) {
  1854. section.workBook.refresh();
  1855. }
  1856. if (ration.workBook) {
  1857. ration.workBook.refresh();
  1858. }
  1859. $('.main-side-bottom').find('textarea').height($('.main-side-bottom').height() - 20);
  1860. $('.main-side-bottom').find('textarea').width($('.main-side-bottom').width() - 25);
  1861. $('.main-bottom-content').find('textarea').height($('.main-bottom-content').height() - 20);
  1862. $('.main-bottom-content').find('textarea').width($('.main-bottom-content').width() - 25);
  1863. }
  1864. //读取拖动相关
  1865. //@return {void}
  1866. function initSlideSize() {
  1867. //定额表上下
  1868. let heightEleObj = {
  1869. module: moduleName,
  1870. top: $('#topContent'),
  1871. topSpread: $('#sectionSpread'),
  1872. bottom: $('#bottomContent'),
  1873. bottomSpread: $('#rationSpread')
  1874. };
  1875. SlideResize.loadVerticalHeight(heightEleObj.module, heightEleObj,
  1876. {totalHeight: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-10`,
  1877. notTopSpread: 0, notBottomSpread: 0}, function () {
  1878. if(section.workBook){
  1879. section.workBook.refresh();
  1880. }
  1881. if(ration.workBook){
  1882. ration.workBook.refresh();
  1883. }
  1884. });
  1885. //水平
  1886. SlideResize.loadHorizonWidth(moduleName, [$('#slideResizeLeft'), $('#slideResizeRight')], [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
  1887. refreshALlWorkBook();
  1888. });
  1889. }
  1890. //初始化视图
  1891. //@param {void} @return {void}
  1892. function initViews(){
  1893. let modules = [bills, guideItem, section, ration];
  1894. initWorkBooks(modules);
  1895. lockUtil.lockTools($(document.body), locked);
  1896. getLibWithBills(libID);
  1897. initBtn();
  1898. initContextMenu();
  1899. initSlideSize();
  1900. }
  1901. return {initViews, initSlideSize};
  1902. })();
  1903. $(document).ready(function () {
  1904. billsGuidance.initViews();
  1905. });