billsGuidance.js 71 KB

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