billsGuidance.js 67 KB

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