billsGuidance.js 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894
  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. //@param {Array}billsNodes(清单节点) {Array}jobs(总的工作内容数据) {Array}items(总的项目特征数据)
  847. function setBillsHint(billsNodes, jobs, items) {
  848. let jobsMapping = {},
  849. itemsMapping = {};
  850. for(let job of jobs){
  851. jobsMapping[job.id] = job;
  852. }
  853. for(let item of items){
  854. itemsMapping[item.id] = item;
  855. }
  856. let tagInfo = [];
  857. for(let billsNode of billsNodes){
  858. let hintArr = [];
  859. let billsItems = billsNode.data.items;
  860. if(billsItems.length > 0){
  861. //项目特征
  862. hintArr.push('项目特征:');
  863. }
  864. let itemCount = 1,
  865. jobCount = 1;
  866. for(let billsItem of billsItems){
  867. let itemData = itemsMapping[billsItem.id];
  868. if(itemData){
  869. //特征值
  870. let eigens = [];
  871. for(let eigen of itemData.itemValue){
  872. eigens.push(eigen.value);
  873. }
  874. eigens = eigens.join(';');
  875. hintArr.push(`${itemCount}.${itemData.content}${eigens === '' ? '' : ': ' + eigens}`);
  876. itemCount ++;
  877. }
  878. }
  879. //工作内容
  880. let billsJobs = billsNode.data.jobs;
  881. if(billsJobs.length > 0){
  882. hintArr.push('工作内容:');
  883. }
  884. for(let billsJob of billsJobs){
  885. let jobData = jobsMapping[billsJob.id];
  886. if(jobData){
  887. hintArr.push(`${jobCount}.${jobData.content}`);
  888. jobCount ++;
  889. }
  890. }
  891. /*if(billsNode.data.ruleText && billsNode.data.ruleText !== ''){
  892. hintArr.push('工程量计算规则:');
  893. hintArr.push(billsNode.data.ruleText);
  894. }
  895. if(billsNode.data.recharge && billsNode.data.recharge !== ''){
  896. hintArr.push('补注:');
  897. hintArr.push(billsNode.data.recharge);
  898. }*/
  899. if(hintArr.length > 0){
  900. tagInfo.push({row: billsNode.serialNo(), value: hintArr.join('\n')});
  901. }
  902. }
  903. let sheet = bills.workBook.getActiveSheet();
  904. renderSheetFunc(sheet, function () {
  905. for(let tagI of tagInfo){
  906. sheet.setTag(tagI.row, 0, tagI.value);
  907. }
  908. });
  909. }
  910. //初始化清单的工作内容和项目特征
  911. //@param {Number}billsLibId {Function}callback @return {void}
  912. function initJobAndCharacter(billsLibId, callback){
  913. CommonAjax.post('/stdBillsEditor/getJobContent', {billsLibId: billsLibId}, function (datas) {
  914. stdBillsJobData = datas;
  915. CommonAjax.post('/stdBillsEditor/getItemCharacter', {billsLibId: billsLibId}, function (datas) {
  916. stdBillsFeatureData = datas;
  917. if(callback){
  918. callback();
  919. }
  920. });
  921. });
  922. }
  923. let billsLibId = 0;
  924. //获取指引库信息及关联的清单
  925. //@param {Number}libID {Function}callback @return {Object}
  926. function getLibWithBills(libID, callback){
  927. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function (rstData) {
  928. billsLibId = rstData.guidanceLib.billsLibId;
  929. initRationLibs(rstData.guidanceLib.compilationId);
  930. bills.cache = rstData.bills;
  931. initLibName(rstData.guidanceLib.name);
  932. /*initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  933. //每一棵项目指引树挂在清单节点上
  934. for(let node of bills.tree.items){
  935. node.guidance = {tree: null, controller: null};
  936. }
  937. //默认初始节点
  938. billsInitSel(0);
  939. if(callback){
  940. callback(rstData);
  941. }*/
  942. let initDataCallback = function () {
  943. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  944. //每一棵项目指引树挂在清单节点上
  945. for(let node of bills.tree.items){
  946. node.guidance = {tree: null, controller: null};
  947. }
  948. //默认初始节点
  949. billsInitSel(0);
  950. if(callback){
  951. callback(rstData);
  952. }
  953. };
  954. initJobAndCharacter(rstData.guidanceLib.billsLibId, initDataCallback);
  955. }, function (msg) {
  956. window.location.href = '/billsGuidance/main';
  957. });
  958. }
  959. //初始化并输出树
  960. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  961. function initTree(module, sheet, treeSetting, datas){
  962. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  963. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  964. module.tree.loadDatas(datas);
  965. module.controller.showTreeData();
  966. if(module === bills){
  967. setBillsHint(bills.tree.items, stdBillsJobData, stdBillsFeatureData);
  968. }
  969. }
  970. //更新清单备注
  971. function updateBillsComment(updateData, callback) {
  972. CommonAjax.post('/stdBillsEditor/updateBills', updateData, function () {
  973. if (callback) {
  974. callback();
  975. }
  976. });
  977. }
  978. //更新项目指引
  979. //@param {Array}updateDatas {Function}callback @return {void}
  980. function updateGuideItems(updateDatas, callback, errCB){
  981. CommonAjax.post('/billsGuidance/api/updateItems', {updateDatas: updateDatas}, function (rstData) {
  982. if(callback){
  983. callback(rstData);
  984. }
  985. }, function () {
  986. if(errCB) {
  987. errCB();
  988. }
  989. $.bootstrapLoading.end();
  990. });
  991. }
  992. //编辑后自动去除换行符回车符
  993. const deESC = /[\n]/g;
  994. //项目指引编辑
  995. //@param {Object}sheet {Array}cells
  996. function edit(sheet, cells){
  997. let updateDatas = [];
  998. //同步节点数据
  999. let syncDatas = [];
  1000. for(let cell of cells){
  1001. const field = guideItem.headers[cell.col].dataCode;
  1002. let node = bills.tree.selected.guidance.tree.items[cell.row];
  1003. if (field === 'name') {
  1004. let text = sheet.getValue(cell.row, cell.col);
  1005. text = text ? text.toString() : '';
  1006. text = text.replace(deESC, '');
  1007. sheet.setValue(cell.row, cell.col, text);
  1008. if(node.data.name != text){
  1009. syncDatas.push({node: node, text: text, field, cell});
  1010. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {name: text}});
  1011. }
  1012. } else if (field === 'outputItemCharacter' || field === 'required') {
  1013. const val = !sheet.getValue(cell.row, cell.col);
  1014. sheet.setValue(cell.row, cell.col, val);
  1015. syncDatas.push({node: node, text: val, field, cell });
  1016. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {[field]: val}});
  1017. }
  1018. }
  1019. if(updateDatas.length > 0){
  1020. updateGuideItems(updateDatas, function () {
  1021. for(let syncData of syncDatas){
  1022. syncData.node.data[syncData.field] = syncData.text;
  1023. }
  1024. }, function () {
  1025. //失败恢复
  1026. renderSheetFunc(sheet, function () {
  1027. for(let syncData of syncDatas){
  1028. sheet.setValue(syncData.node.serialNo(), syncData.cell.col, syncData.node.data[syncData.field] ? syncData.node.data[syncData.field] : '');
  1029. }
  1030. });
  1031. });
  1032. }
  1033. }
  1034. //项目指引插入,支持一次插入多条数据
  1035. //@param {Array}datas {Boolean}tobeChild(插入成为子项) {Function}callback @return {void}
  1036. function insert(datas, tobeChild, callback = null){
  1037. $.bootstrapLoading.start();
  1038. let sheet = guideItem.workBook.getActiveSheet();
  1039. let controller = bills.tree.selected.guidance.controller;
  1040. let selected = bills.tree.selected.guidance.tree.selected;
  1041. let updateDatas = [];
  1042. //建立数组下标索引
  1043. let newDataIndex = {};
  1044. for(let i = 0; i < datas.length; i++){
  1045. let newNodeData = {
  1046. libID: libID, ID: uuid.v1(), ParentID: selected ? selected.getParentID() : -1, NextSiblingID: selected ? selected.getNextSiblingID() : -1,
  1047. billsID: bills.tree.selected.getID()
  1048. };
  1049. //定额类型插入当前工作内容焦点行,
  1050. if(selected && ((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  1051. newNodeData.ParentID = selected.getID();
  1052. newNodeData.NextSiblingID = -1;
  1053. }
  1054. Object.assign(newNodeData, datas[i]);
  1055. newDataIndex[i] = newNodeData;
  1056. }
  1057. for(let i = 0; i < datas.length; i++){
  1058. //第一个节点
  1059. if(i === 0){
  1060. //非插入成子节点,更新选中节点NestSiblingID
  1061. if(selected && !((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  1062. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: newDataIndex[i].ID}});
  1063. }
  1064. }
  1065. //非最后一个节点
  1066. if(i !== datas.length - 1){
  1067. newDataIndex[i].NextSiblingID = newDataIndex[i + 1].ID;
  1068. }
  1069. updateDatas.push({updateType: updateType.create, updateData: newDataIndex[i]});
  1070. }
  1071. updateGuideItems(updateDatas, function () {
  1072. for(let updateData of updateDatas){
  1073. if(updateData.updateType === updateType.create){
  1074. let newNode = controller.insertByIDS(updateData.updateData.ID, updateData.updateData.ParentID, updateData.updateData.NextSiblingID);
  1075. //同步data
  1076. Object.assign(newNode.data, updateData.updateData);
  1077. const row = newNode.serialNo();
  1078. sheet.setValue(row, 0, newNode.data.name);
  1079. if (newNode.data.outputItemCharacter !== undefined) {
  1080. sheet.setValue(row, 1, newNode.data.outputItemCharacter);
  1081. }
  1082. showCheckBox(sheet, [newNode]);
  1083. refreshBtn(newNode);
  1084. }
  1085. }
  1086. if(callback){
  1087. callback();
  1088. }
  1089. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1090. guideItem.workBook.focus(true);
  1091. $.bootstrapLoading.end();
  1092. });
  1093. }
  1094. // 删除定额(嵌套删除自身及后代定额)
  1095. function delRations() {
  1096. const selected = bills.tree.selected.guidance.tree.selected;
  1097. if (!selected) {
  1098. return;
  1099. }
  1100. if (selected.data.type === itemType.ration) {
  1101. del({ row: selected.serialNo(), col: 0, rowCount: 1, colCount: 1 });
  1102. return;
  1103. }
  1104. const rations = selected.getPosterity().filter(item => item.data.type === itemType.ration);
  1105. if (!rations.length) {
  1106. return;
  1107. }
  1108. const updateDatas = rations.map(item => ({ updateType: updateType.del, findData: { ID: item.data.ID } }));
  1109. const rationIDs = rations.map(r => r.data.ID);
  1110. $.bootstrapLoading.start();
  1111. updateGuideItems(updateDatas, function () {
  1112. const guideSheet = guideItem.workBook.getSheet(0);
  1113. const treeNodes = bills.tree.selected.guidance.tree.items.filter(item => !rationIDs.includes(item.data.ID));
  1114. const state = bills.tree.selected.guidance.tree.getExpState(treeNodes);
  1115. const treeData = treeNodes.map(item => item.data);
  1116. initTree(bills.tree.selected.guidance, guideSheet, guideItem.treeSetting, treeData);
  1117. bills.tree.selected.guidance.tree.setExpandedByState(bills.tree.selected.guidance.tree.items, state);
  1118. renderSheetFunc(guideSheet, function () {
  1119. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.selected.guidance.tree.roots, guideSheet, true);
  1120. });
  1121. //设置底色
  1122. setNodesColor(guideSheet, bills.tree.selected.guidance.tree.items);
  1123. //项目指引初始焦点
  1124. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  1125. $.bootstrapLoading.end();
  1126. guideItem.workBook.focus(true)
  1127. });
  1128. }
  1129. //项目指引删除操作
  1130. //@return {void}
  1131. function del(selArea = null){
  1132. $.bootstrapLoading.start();
  1133. let controller = bills.tree.selected.guidance.controller;
  1134. let selNodes = [];
  1135. let sheet = guideItem.workBook.getSheet(0);
  1136. let sel = selArea ? selArea : sheet.getSelections()[0];
  1137. if(sel){
  1138. sel.row = sel.row === -1 ? 0 : sel.row;
  1139. for(let i = 0; i < sel.rowCount; i++){
  1140. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1141. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1142. }
  1143. }
  1144. }
  1145. //选中的块节点
  1146. let blockNodes = getBlockNodes(selNodes);
  1147. let updateDatas = [];
  1148. function getDelDatas(nodes){
  1149. for (let node of nodes) {
  1150. updateDatas.push({updateType: updateType.del, findData: {ID: node.getID()}});
  1151. if (node.children.length > 0) {
  1152. getDelDatas(node.children);
  1153. }
  1154. }
  1155. }
  1156. getDelDatas(blockNodes);
  1157. //更新相关的前节点
  1158. for (let node of blockNodes) {
  1159. if (node.preSibling && !blockNodes.includes(node.preSibling)) {
  1160. let next = node;
  1161. while (next.nextSibling && blockNodes.includes(next.nextSibling)) {
  1162. next = next.nextSibling;
  1163. }
  1164. updateDatas.push({updateType: updateType.update, findData: {ID: node.preSibling.getID()}, updateData: {NextSiblingID: next.getNextSiblingID()}});
  1165. }
  1166. }
  1167. updateGuideItems(updateDatas, function () {
  1168. console.log(blockNodes);
  1169. controller.m_delete(blockNodes);
  1170. guideItemInitSel(sheet.getActiveRowIndex());
  1171. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1172. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1173. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1174. $.bootstrapLoading.end();
  1175. guideItem.workBook.focus(true)
  1176. });
  1177. }
  1178. //项目指引升级
  1179. //@return {void}
  1180. function upLevel(){
  1181. $.bootstrapLoading.start();
  1182. let controller = bills.tree.selected.guidance.controller;
  1183. let selected = bills.tree.selected.guidance.tree.selected;
  1184. let updateDatas = [];
  1185. //更新父节点
  1186. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getParentID()}, updateData: {NextSiblingID: selected.getID()}});
  1187. //更新选中节点
  1188. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()},
  1189. updateData: {ParentID: selected.parent.getParentID(), NextSiblingID: selected.parent.getNextSiblingID()}});
  1190. if(selected.nextSibling && selected.children.length > 0){
  1191. //更新选中节点最末子节点
  1192. let lastChild = selected.children[selected.children.length - 1];
  1193. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: -1}});
  1194. }
  1195. //选中节点的所有后兄弟节点成为选中节点的子项
  1196. let selectedNextIDs = [];
  1197. let sNext = selected.nextSibling;
  1198. while(sNext){
  1199. selectedNextIDs.push(sNext.getID());
  1200. sNext = sNext.nextSibling;
  1201. }
  1202. for(let sID of selectedNextIDs){
  1203. updateDatas.push({updateType: updateType.update, findData: {ID: sID}, updateData: {ParentID: selected.getID()}});
  1204. }
  1205. updateGuideItems(updateDatas, function () {
  1206. controller.upLevel();
  1207. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1208. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1209. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1210. $.bootstrapLoading.end();
  1211. guideItem.workBook.focus(true)//31574
  1212. });
  1213. }
  1214. //项目指引降级
  1215. //@return {void}
  1216. function downLevel(){
  1217. $.bootstrapLoading.start();
  1218. let controller = bills.tree.selected.guidance.controller;
  1219. let selected = bills.tree.selected.guidance.tree.selected;
  1220. let updateDatas = [];
  1221. //更新前兄弟节点
  1222. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1223. //更新前兄弟节点最末子节点
  1224. if(selected.preSibling.children.length > 0){
  1225. let lastChild = selected.preSibling.children[selected.preSibling.children.length - 1];
  1226. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1227. }
  1228. //更新选中节点
  1229. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {ParentID: selected.preSibling.getID(), NextSiblingID: -1}});
  1230. updateGuideItems(updateDatas, function () {
  1231. controller.downLevel();
  1232. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1233. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1234. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1235. $.bootstrapLoading.end();
  1236. guideItem.workBook.focus(true)
  1237. });
  1238. }
  1239. //项目指引上移
  1240. //@return {void}
  1241. function upMove(){
  1242. $.bootstrapLoading.start();
  1243. let controller = bills.tree.selected.guidance.controller;
  1244. let selected = bills.tree.selected.guidance.tree.selected;
  1245. let updateDatas = [];
  1246. //更新前节点
  1247. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1248. //更新前前节点
  1249. if(selected.preSibling.preSibling){
  1250. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.preSibling.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1251. }
  1252. //更新选中节点
  1253. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.preSibling.getID()}});
  1254. updateGuideItems(updateDatas, function () {
  1255. controller.upMove();
  1256. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1257. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1258. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1259. $.bootstrapLoading.end();
  1260. guideItem.workBook.focus(true)
  1261. });
  1262. }
  1263. //项目指引下移
  1264. //@return {void}
  1265. function downMove(){
  1266. $.bootstrapLoading.start();
  1267. let controller = bills.tree.selected.guidance.controller;
  1268. let selected = bills.tree.selected.guidance.tree.selected;
  1269. let updateDatas = [];
  1270. //更新下节点
  1271. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getNextSiblingID()}, updateData: {NextSiblingID: selected.getID()}});
  1272. //更新前节点
  1273. if(selected.preSibling){
  1274. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1275. }
  1276. //更新选中节点
  1277. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.nextSibling.getNextSiblingID()}});
  1278. updateGuideItems(updateDatas, function () {
  1279. controller.downMove();
  1280. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1281. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1282. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1283. $.bootstrapLoading.end();
  1284. guideItem.workBook.focus(true)
  1285. });
  1286. }
  1287. //获取定额类型的项目指引名称,通过定额转换
  1288. //@param {Object}ration @return {String}
  1289. function getRationItemName(ration){
  1290. let arr = [];
  1291. arr.push(ration.code ? ration.code : '');
  1292. arr.push(ration.name ? ration.name : '');
  1293. arr.push(ration.basePrice ? ration.basePrice : '');
  1294. let rst = arr.join(' ');
  1295. rst += `/${ration.unit ? ration.unit : ''}`;
  1296. return rst;
  1297. }
  1298. //获取选中的定额表行
  1299. //@return {Array}
  1300. function getCheckedRationRows(all){
  1301. let rst = [];
  1302. let sheet = ration.workBook.getActiveSheet();
  1303. for(let i = 0; i < sheet.getRowCount(); i++){
  1304. // 全选
  1305. if (all) {
  1306. rst.push(i);
  1307. continue;
  1308. }
  1309. let checked = sheet.getValue(i, 0);
  1310. if(checked){
  1311. rst.push(i);
  1312. }
  1313. }
  1314. return rst;
  1315. }
  1316. //清空选中定额表行
  1317. //@param {Array}rows @return {void}
  1318. function clearCheckedRation(rows) {
  1319. let sheet = ration.workBook.getActiveSheet();
  1320. renderSheetFunc(sheet, function () {
  1321. for(let row of rows){
  1322. sheet.setValue(row, 0, 0);
  1323. }
  1324. });
  1325. }
  1326. //获取要插入的定额数据
  1327. //@param {Array}rows @return {Array}
  1328. function getInsertRations(rows){
  1329. let rst = [];
  1330. //当前已存在定额
  1331. let curRationIems = [];
  1332. let selected = bills.tree.selected.guidance.tree.selected;
  1333. if(selected){
  1334. if(selected.data.type === itemType.job){
  1335. curRationIems = selected.children;
  1336. }
  1337. else {
  1338. curRationIems = selected.parent ? selected.parent.children : selected.tree.roots;
  1339. }
  1340. }
  1341. for(let row of rows){
  1342. let selRation = ration.cache[row];
  1343. if(selRation){
  1344. //添加的定额是否已存在,不重复添加
  1345. let isExist = false;
  1346. for(let curRation of curRationIems){
  1347. if(curRation.data.rationID == selRation.ID){
  1348. isExist = true;
  1349. break;
  1350. }
  1351. }
  1352. if(!isExist){
  1353. rst.push({type: itemType.ration, name: getRationItemName(selRation), rationID: selRation.ID});
  1354. }
  1355. }
  1356. }
  1357. return rst;
  1358. }
  1359. //获取块节点父项不存在于选中节点中的节点
  1360. //@param {Array}nodes(选中的节点) @return {Array}
  1361. function getBlockNodes(nodes) {
  1362. let nodeMapping = {};
  1363. for(let node of nodes){
  1364. nodeMapping[node.data.ID] = node;
  1365. }
  1366. //块节点,父项不存在于选中节点中的节点
  1367. let blockNodes = [];
  1368. for(let node of nodes){
  1369. if(!nodeMapping[node.data.ParentID]){
  1370. blockNodes.push(node);
  1371. }
  1372. }
  1373. return blockNodes;
  1374. }
  1375. //允许复制整块,如果有多个块节点,且块节点的父项不同,则不可复制
  1376. //@param {Array}nodes(块节点) @return {Boolean}
  1377. function canCopyBlock(nodes) {
  1378. if(!nodes || nodes.length === 0){
  1379. return false;
  1380. }
  1381. let pID = nodes[0].data.ParentID;
  1382. for(let node of nodes){
  1383. if(node.data.ParentID !== pID){
  1384. return false;
  1385. }
  1386. }
  1387. return true;
  1388. }
  1389. //允许粘贴整块 有粘贴数据,节点存在,如果粘贴到的节点为定额数据,粘贴数据为全定额数据
  1390. //@param {Object}node(粘贴到的节点)
  1391. function canPasteBlock(node) {
  1392. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1393. if(!pasteDatas || pasteDatas.length === 0){
  1394. return false;
  1395. }
  1396. if(!node){
  1397. return false;
  1398. }
  1399. //若粘贴到定额节点,则数据须全为定额
  1400. if(node.data.type === itemType.ration){
  1401. for(let data of pasteDatas){
  1402. if(data.type !== itemType.ration){
  1403. return false;
  1404. }
  1405. }
  1406. }
  1407. //若粘贴到非定额节点,则粘贴的顶层数据须全为非定额
  1408. else {
  1409. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1410. for(let topData of topDatas){
  1411. if(topData.type === itemType.ration){
  1412. return false;
  1413. }
  1414. }
  1415. }
  1416. return true;
  1417. }
  1418. //复制整块,将块节点下所有节点数据复制一份,并且重新生成ID、ParentID、NextSiblingID,使用localStorage存储
  1419. //@param {Array}nodes(块节点) @return {void}
  1420. function copyBlocks(nodes) {
  1421. nodes = _.cloneDeep(nodes);
  1422. //将块节点的ParentID暂时设置为-1
  1423. for(let topNode of nodes){
  1424. topNode.data.ParentID = -1;
  1425. }
  1426. let copyDatas = [];
  1427. let copyNodes = [];
  1428. //获取块节点包含的所有节点(包括自己)
  1429. function containNodes(nodes) {
  1430. for(let node of nodes){
  1431. copyNodes.push(node);
  1432. if(node.children.length > 0){
  1433. containNodes(node.children);
  1434. }
  1435. }
  1436. }
  1437. containNodes(nodes);
  1438. for(let node of copyNodes){
  1439. copyDatas.push(node.data);
  1440. }
  1441. console.log(`copyDatas`);
  1442. console.log(copyDatas);
  1443. setLocalCache(itemCopyBlockKey, JSON.stringify(copyDatas));
  1444. }
  1445. //粘贴整块,整块数据粘贴到相关节点,并成为其后项
  1446. //@param {Object}node(粘贴到的节点) @return {void}
  1447. function pasteBlock(node) {
  1448. let itemObj = bills.tree.selected.guidance;
  1449. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1450. //整理ID
  1451. let IDMapping = {};
  1452. for(let data of pasteDatas){
  1453. data.newID = uuid.v1();
  1454. IDMapping[data.ID] = data;
  1455. }
  1456. for(let data of pasteDatas){
  1457. let nextData = IDMapping[data.NextSiblingID];
  1458. data.NextSiblingID = nextData ? nextData.newID : -1;
  1459. let parentData = IDMapping[data.ParentID];
  1460. data.ParentID = parentData ? parentData.newID : -1;
  1461. }
  1462. for(let data of pasteDatas){
  1463. data.ID = data.newID;
  1464. delete data.newID;
  1465. }
  1466. let updateDatas = [];
  1467. //将最顶层的块数据的ParentID设置成粘贴到节点的ParentID,并设置新的billsID
  1468. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1469. for(let topData of topDatas){
  1470. topData.ParentID = node.getParentID();
  1471. }
  1472. //更新数据
  1473. //更新插入的最末顶层数据NextSiblingID
  1474. if(node.nextSibling){
  1475. topDatas[topDatas.length - 1].NextSiblingID = node.getNextSiblingID();
  1476. }
  1477. //新建节点
  1478. for(let data of pasteDatas){
  1479. data.libID = libID;
  1480. data.billsID = node.data.billsID;
  1481. delete data._id;
  1482. updateDatas.push({updateType: updateType.create, updateData: data});
  1483. }
  1484. console.log(`pasteDatas`);
  1485. console.log(pasteDatas);
  1486. //更新粘贴到的节点的NextSiblingID
  1487. updateDatas.push({updateType: updateType.update, findData: {ID: node.data.ID}, updateData: {NextSiblingID: topDatas[0].ID}})
  1488. $.bootstrapLoading.start();
  1489. updateGuideItems(updateDatas, function (rstData) {
  1490. $.bootstrapLoading.end();
  1491. node.data.NextSiblingID = topDatas[0].ID;
  1492. let newNodes = itemObj.tree.insertDatasTo(node.data, pasteDatas);
  1493. cleanData(guideItem.workBook.getActiveSheet(), guideItem.headers, -1);
  1494. itemObj.controller.showTreeData();
  1495. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1496. showCheckBox(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1497. }, function () {
  1498. $.bootstrapLoading.end();
  1499. });
  1500. }
  1501. //初始化右键菜单
  1502. //@return {void}
  1503. function initContextMenu() {
  1504. $.contextMenu({
  1505. selector: '#guideItemSpread',
  1506. build: function($triggerElement, e){
  1507. //控制允许右键菜单在哪个位置出现
  1508. let sheet = guideItem.workBook.getSheet(0);
  1509. let offset = $("#guideItemSpread").offset(),
  1510. x = e.pageX - offset.left,
  1511. y = e.pageY - offset.top;
  1512. let target = sheet.hitTest(x, y);
  1513. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  1514. let sel = sheet.getSelections()[0];
  1515. if(sel && sel.rowCount === 1){
  1516. sheet.setActiveCell(target.row, target.col);
  1517. }
  1518. sel = sheet.getSelections()[0];
  1519. let selNodes = [];
  1520. if(sel){
  1521. sel.row = sel.row === -1 ? 0 : sel.row;
  1522. for(let i = 0; i < sel.rowCount; i++){
  1523. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1524. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1525. }
  1526. }
  1527. }
  1528. //块节点
  1529. let blockNodes = getBlockNodes(selNodes);
  1530. //右键在多选内则不重设焦点
  1531. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  1532. sheet.setActiveCell(target.row, target.col);
  1533. }
  1534. guideItemInitSel(target.row);
  1535. return {
  1536. callback: function(){},
  1537. items: {
  1538. "copy": {
  1539. name: "复制整块",
  1540. disabled: function () {
  1541. return locked || !canCopyBlock(blockNodes);
  1542. },
  1543. icon: "fa-copy",
  1544. callback: function (key, opt) {
  1545. copyBlocks(blockNodes);
  1546. }},
  1547. "paste": {
  1548. name: "粘贴整块",
  1549. disabled: function () {
  1550. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1551. return locked || !canPasteBlock(pasteNode);
  1552. },
  1553. icon: "fa-paste",
  1554. callback: function (key, opt) {
  1555. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1556. pasteBlock(pasteNode);
  1557. }},
  1558. "delRations": {
  1559. name: '删除定额',
  1560. disabled: function () {
  1561. let node = bills.tree.selected.guidance.tree.items[target.row];
  1562. return locked || !node
  1563. },
  1564. icon: "fa-remove",
  1565. callback: function (key, opt) {
  1566. $('#delRationAlert').modal('show');
  1567. }
  1568. },
  1569. "del": {
  1570. name: '删除',
  1571. disabled: function () {
  1572. let node = bills.tree.selected.guidance.tree.items[target.row];
  1573. return locked || !node
  1574. },
  1575. icon: "fa-remove",
  1576. callback: function (key, opt) {
  1577. $('#delAlert').modal('show');
  1578. }
  1579. },
  1580. "insertSibling": {
  1581. name: '插入行',
  1582. disabled: function () {
  1583. let node = bills.tree.selected.guidance.tree.items[target.row];
  1584. return locked || !node || node.data.type !== itemType.job;
  1585. },
  1586. icon: "fa-arrow-left",
  1587. callback: function (key, opt) {
  1588. insert([{type: itemType.job, name: ''}], false);
  1589. }
  1590. },
  1591. "insertChild": {
  1592. name: '插入子项',
  1593. disabled: function () {
  1594. let node = bills.tree.selected.guidance.tree.items[target.row];
  1595. return locked || !node || node.data.type !== itemType.job || !allJobChildren(node);
  1596. },
  1597. icon: 'fa-arrow-left',
  1598. callback: function (key, opt) {
  1599. insert([{type: itemType.job, name: ''}], true);
  1600. }
  1601. }
  1602. }
  1603. };
  1604. }
  1605. else{
  1606. return false;
  1607. }
  1608. }
  1609. });
  1610. }
  1611. //初始化个按钮点击
  1612. //@return {void}
  1613. function initBtn(){
  1614. $('#insert').click(function () {
  1615. insert([{type: itemType.job, name: '', outputItemCharacter: true }], false);
  1616. });
  1617. $('#delConfirm').click(function () {
  1618. del();
  1619. $('#delAlert').modal('hide');
  1620. });
  1621. $('#delRationConfirm').click(function () {
  1622. delRations();
  1623. $('#delRationAlert').modal('hide');
  1624. });
  1625. $('#del').click(function () {
  1626. $('#delAlert').modal('show');
  1627. });
  1628. $('#upLevel').click(function () {
  1629. upLevel();
  1630. });
  1631. $('#downLevel').click(function () {
  1632. downLevel();
  1633. });
  1634. $('#upMove').click(function () {
  1635. upMove();
  1636. });
  1637. $('#downMove').click(function () {
  1638. downMove();
  1639. });
  1640. //收起定额、展开全部
  1641. $('#expandContract').click(function () {
  1642. //目前状态时展开全部节点状态,点击则收起定额
  1643. let tree = bills.tree.selected.guidance.tree,
  1644. itemSheet = guideItem.workBook.getActiveSheet();
  1645. if(curExpandState === itemExpandState.expand){
  1646. curExpandState = itemExpandState.contract;
  1647. $(this).html('<i class="fa fa-plus-square-o" aria-hidden="true"></i> 展开全部');
  1648. setNodesExpandState(tree.items, itemExpandState.contract);
  1649. } else {
  1650. curExpandState = itemExpandState.expand;
  1651. $(this).html('<i class="fa fa-minus-square-o" aria-hidden="true"></i> 收起定额');
  1652. setNodesExpandState(tree.items, itemExpandState.expand);
  1653. }
  1654. renderSheetFunc(itemSheet, function () {
  1655. TREE_SHEET_HELPER.refreshNodesVisible(tree.roots, itemSheet, true);
  1656. });
  1657. });
  1658. // 插入选中定额
  1659. $('#insertRation').click(function () {
  1660. let checkedRows = getCheckedRationRows();
  1661. let insertDatas = getInsertRations(checkedRows);
  1662. if(insertDatas.length > 0){
  1663. insert(insertDatas, false, function () {
  1664. //清空选择
  1665. clearCheckedRation(checkedRows);
  1666. });
  1667. }
  1668. else {
  1669. clearCheckedRation(checkedRows);
  1670. }
  1671. });
  1672. // 插入全部定额
  1673. $('#insertAll').click(function () {
  1674. let isAll = true;
  1675. let checkedRows = getCheckedRationRows(isAll);
  1676. let insertDatas = getInsertRations(checkedRows);
  1677. if(insertDatas.length > 0){
  1678. insert(insertDatas, false);
  1679. }
  1680. });
  1681. //搜索定额
  1682. $('#searchBtn').click(function () {
  1683. let searchStr = $('#searchText').val();
  1684. if(!searchStr || searchStr === ''){
  1685. ration.cache = ration.datas;
  1686. }
  1687. else{
  1688. let reg = new RegExp(searchStr, 'i');
  1689. ration.cache = _.filter(ration.datas, function (data) {
  1690. return reg.test(data.code) || reg.test(data.name);
  1691. });
  1692. }
  1693. $('.top-content').hide();
  1694. $('#searchCount').text(`搜索结果: ${ration.cache.length}`);
  1695. $('#rationSearchResult').show();
  1696. autoFlashHeight();
  1697. ration.workBook.refresh();
  1698. let rationSheet = ration.workBook.getActiveSheet();
  1699. renderSheetFunc(rationSheet, function () {
  1700. clearCheckedRation(getCheckedRationRows());
  1701. showData(rationSheet, ration.headers, ration.cache);
  1702. })
  1703. });
  1704. //关闭搜索
  1705. $('#rationSearchResult a').click(function () {
  1706. $('.top-content').show();
  1707. $('#rationSearchResult').hide();
  1708. autoFlashHeight();
  1709. renderSheetFunc(ration.workBook.getActiveSheet(), function () {
  1710. clearCheckedRation(getCheckedRationRows());
  1711. });
  1712. section.workBook.refresh();
  1713. ration.workBook.refresh();
  1714. $('#searchText').val('');
  1715. //恢复章节树下的定额
  1716. sectionInitSel(section.workBook.getActiveSheet().getActiveRowIndex());
  1717. });
  1718. let keyupTime = 0,
  1719. delayTime = 500;
  1720. function delayKeyup(callback) {
  1721. let nowTime = Date.now();
  1722. keyupTime = nowTime;
  1723. setTimeout(function () {
  1724. if (nowTime - keyupTime == 0) {
  1725. callback();
  1726. }
  1727. }, delayTime);
  1728. }
  1729. //执行搜索
  1730. $('#searchText').keyup(function (e) {
  1731. delayKeyup(function () {
  1732. $('#searchBtn').click();
  1733. });
  1734. });
  1735. //编辑清单备注
  1736. $('.main-side-bottom').find('textarea').keyup(function () {
  1737. let me = this;
  1738. let node = bills.tree.selected;
  1739. let comment = $(me).val();
  1740. delayKeyup(function () {
  1741. if (node) {
  1742. let updateData = {lastOperator: userAccount, billsLibId: billsLibId, updateId: node.getID(), field: 'comment', data: comment};
  1743. updateBillsComment(updateData, function () {
  1744. node.data.comment = comment;
  1745. })
  1746. }
  1747. });
  1748. });
  1749. //编辑选项备注
  1750. $('.main-bottom-content').find('textarea').keyup(function () {
  1751. let me = this;
  1752. let node = bills.tree.selected.guidance.tree.selected;
  1753. let comment = $(me).val();
  1754. delayKeyup(function () {
  1755. if(node){
  1756. let updateDatas = [{updateType: updateType.update, findData: {ID: node.getID()}, updateData: {comment: comment}}];
  1757. updateGuideItems(updateDatas, function (rstData) {
  1758. node.data.comment = comment;
  1759. });
  1760. }
  1761. });
  1762. });
  1763. //定额高度拖动调整
  1764. let heightEleObj = {
  1765. module: moduleName,
  1766. resize: $('#deResize'),
  1767. top: $('#topContent'),
  1768. topSpread: $('#sectionSpread'),
  1769. bottom: $('#bottomContent'),
  1770. bottomSpread: $('#rationSpread')
  1771. },
  1772. heightLimit = {
  1773. min: 150,
  1774. max: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-150-10`,
  1775. notTopSpread: 0,
  1776. notBottomSpread: 0,
  1777. };
  1778. SlideResize.verticalSlide(heightEleObj, heightLimit, function () {
  1779. if(section.workBook){
  1780. section.workBook.refresh();
  1781. }
  1782. if(ration.workBook){
  1783. ration.workBook.refresh();
  1784. }
  1785. });
  1786. /*slideResize(rationLibResizeEles, {min: 147, max: 680}, 'height', function() {
  1787. //autoFlashHeight();
  1788. if(section.workBook){
  1789. section.workBook.refresh();
  1790. }
  1791. if(ration.workBook){
  1792. ration.workBook.refresh();
  1793. }
  1794. });*/
  1795. //左右拖动
  1796. //清单表与项目指引表
  1797. let leftElesObj = {};
  1798. leftElesObj.module = moduleName;
  1799. leftElesObj.resize = $('#slideResizeLeft');
  1800. leftElesObj.parent = $('#dataRow');
  1801. leftElesObj.left = $('#leftContent');
  1802. leftElesObj.right = $('#midContent');
  1803. SlideResize.horizontalSlide(leftElesObj, {min: 200, max: `$('#dataRow').width() - $('#rightContent').width() - 200`}, function () {
  1804. refreshALlWorkBook();
  1805. });
  1806. //人材机表与人材机组成物表
  1807. let rightElesObj = {};
  1808. rightElesObj.module = moduleName;
  1809. rightElesObj.resize = $('#slideResizeRight');
  1810. rightElesObj.parent = $('#dataRow');
  1811. rightElesObj.left = $('#midContent');
  1812. rightElesObj.right = $('#rightContent');
  1813. SlideResize.horizontalSlide(rightElesObj, {min: 200, max: `$('#dataRow').width() - $('#leftContent').width() - 200`}, function () {
  1814. refreshALlWorkBook();
  1815. });
  1816. }
  1817. //刷新全部工作簿
  1818. //@return {void}
  1819. function refreshALlWorkBook() {
  1820. if (bills.workBook) {
  1821. bills.workBook.refresh();
  1822. }
  1823. if (guideItem.workBook) {
  1824. guideItem.workBook.refresh();
  1825. }
  1826. if (section.workBook) {
  1827. section.workBook.refresh();
  1828. }
  1829. if (ration.workBook) {
  1830. ration.workBook.refresh();
  1831. }
  1832. $('.main-side-bottom').find('textarea').height($('.main-side-bottom').height() - 20);
  1833. $('.main-side-bottom').find('textarea').width($('.main-side-bottom').width() - 25);
  1834. $('.main-bottom-content').find('textarea').height($('.main-bottom-content').height() - 20);
  1835. $('.main-bottom-content').find('textarea').width($('.main-bottom-content').width() - 25);
  1836. }
  1837. //读取拖动相关
  1838. //@return {void}
  1839. function initSlideSize() {
  1840. //定额表上下
  1841. let heightEleObj = {
  1842. module: moduleName,
  1843. top: $('#topContent'),
  1844. topSpread: $('#sectionSpread'),
  1845. bottom: $('#bottomContent'),
  1846. bottomSpread: $('#rationSpread')
  1847. };
  1848. SlideResize.loadVerticalHeight(heightEleObj.module, heightEleObj,
  1849. {totalHeight: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-10`,
  1850. notTopSpread: 0, notBottomSpread: 0}, function () {
  1851. if(section.workBook){
  1852. section.workBook.refresh();
  1853. }
  1854. if(ration.workBook){
  1855. ration.workBook.refresh();
  1856. }
  1857. });
  1858. //水平
  1859. SlideResize.loadHorizonWidth(moduleName, [$('#slideResizeLeft'), $('#slideResizeRight')], [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
  1860. refreshALlWorkBook();
  1861. });
  1862. }
  1863. //初始化视图
  1864. //@param {void} @return {void}
  1865. function initViews(){
  1866. let modules = [bills, guideItem, section, ration];
  1867. initWorkBooks(modules);
  1868. lockUtil.lockTools($(document.body), locked);
  1869. getLibWithBills(libID);
  1870. initBtn();
  1871. initContextMenu();
  1872. initSlideSize();
  1873. }
  1874. return {initViews, initSlideSize};
  1875. })();
  1876. $(document).ready(function () {
  1877. billsGuidance.initViews();
  1878. });