billsGuidance.js 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716
  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. if (setting.pos && text && text !== '') {
  551. //固定不显示的div,存储文本获取固定div宽度,toolTipElement由于显示和隐藏,获取宽度不正确
  552. if(!this._fixedTipElement){
  553. let div = $('#fixedTip1')[0];
  554. if (!div) {
  555. div = document.createElement("div");
  556. $(div).css("padding", 5)
  557. .attr("id", 'fixedTip');
  558. $(div).hide();
  559. document.body.insertBefore(div, null);
  560. }
  561. this._fixedTipElement = div;
  562. }
  563. $(this._fixedTipElement).width('');
  564. $(this._fixedTipElement).html(text);
  565. if (!this._toolTipElement) {
  566. let div = $('#autoTip1')[0];
  567. if (!div) {
  568. div = document.createElement("div");
  569. $(div).css("position", "absolute")
  570. .css("border", "1px #C0C0C0 solid")
  571. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  572. .css("font", "0.9rem Calibri")
  573. .css("background", "white")
  574. .css("padding", 5)
  575. .attr("id", 'autoTip1');
  576. $(div).hide();
  577. document.body.insertBefore(div, null);
  578. }
  579. this._toolTipElement = div;
  580. $(this._toolTipElement).width('');
  581. //实时读取位置信息
  582. if(hitinfo.sheet && hitinfo.sheet.getParent().qo){
  583. setting.pos = SheetDataHelper.getObjPos(hitinfo.sheet.getParent().qo);
  584. }
  585. $(this._toolTipElement).html(text);
  586. //定额库定额特殊处理
  587. if($(hitinfo.sheet.getParent().qo).attr('id') === 'rationSpread'){
  588. let divWidth = $(this._fixedTipElement).width(),
  589. divHeight = $(this._fixedTipElement).height();
  590. if(divWidth > 600){
  591. divWidth = 590;
  592. $(this._toolTipElement).width(divWidth);
  593. }
  594. let top = setting.pos.y + hitinfo.y - divHeight < 0 ? 0 : setting.pos.y + hitinfo.cellRect.y - divHeight;
  595. $(this._toolTipElement).css("top", top).css("left", setting.pos.x - divWidth);
  596. }
  597. else{
  598. $(this._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  599. }
  600. //名称
  601. if(hitinfo.col === 2){
  602. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  603. zoom = hitinfo.sheet.zoom();
  604. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  605. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  606. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  607. if(textLength > cellWidth){
  608. $(this._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  609. $(this._toolTipElement).show("fast");
  610. ration.tipDiv = 'show';//做个标记
  611. }
  612. }
  613. else {
  614. $(this._toolTipElement).show("fast");
  615. ration.tipDiv = 'show';//做个标记
  616. }
  617. }
  618. }
  619. };
  620. TipCellType.prototype.processMouseLeave = function (hininfo) {
  621. ration.tipDiv = 'hide';
  622. if (this._toolTipElement) {
  623. $(this._toolTipElement).hide();
  624. this._toolTipElement = null;
  625. }
  626. tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  627. }
  628. return new TipCellType();
  629. }
  630. //输出表数据(定额表)
  631. //@param {Object}sheet {Array}headers {Array}datas @return {void}
  632. function showData(sheet, headers, datas){
  633. let fuc = function () {
  634. sheet.setRowCount(datas.length);
  635. //复选框
  636. let checkBoxType = new GC.Spread.Sheets.CellTypes.CheckBox();
  637. let tipCellType = getTipCellType(sheet);
  638. sheet.setCellType(-1, 0, checkBoxType);
  639. for(let col = 0, cLen = headers.length; col < cLen; col++){
  640. for(let row = 0, rLen = datas.length; row < rLen; row++){
  641. sheet.setValue(row, col, datas[row][headers[col]['dataCode']]);
  642. if(col === 1){
  643. sheet.setTag(row, col, datas[row]['hint']);
  644. }
  645. }
  646. }
  647. sheet.setCellType(-1, 1, tipCellType);
  648. sheet.setCellType(-1, 2, tipCellType);
  649. };
  650. renderSheetFunc(sheet, fuc);
  651. }
  652. //根据定额章节树ID获取定额(从数据缓存中获取,定额数据一开始一次性拉取)
  653. //@param {Number}sectionId {Array}rations @return {Array}
  654. function getRationsBySectionId(sectionId, rations) {
  655. if(!sectionId || !rations){
  656. return [];
  657. }
  658. return _.filter(rations, {sectionId});
  659. }
  660. //定额章节树焦点控制
  661. //@param {Number}row @return {void}
  662. function sectionInitSel(row) {
  663. let rationSheet = ration.workBook.getActiveSheet();
  664. let sectionNode = section.tree ? section.tree.items[row] : null;
  665. if(sectionNode && sectionNode.children.length === 0){
  666. let sectionRations = getRationsBySectionId(sectionNode.data.ID, ration.datas);
  667. ration.cache = sectionRations;
  668. showData(rationSheet, ration.headers, sectionRations);
  669. }
  670. else {
  671. cleanData(rationSheet, ration.headers, 0);
  672. }
  673. }
  674. //初始化定额条目
  675. //@param {Number}rationLibId @return {void}
  676. function initRationItems(rationLibId){
  677. $.bootstrapLoading.start();
  678. //获取定额章节树
  679. let sectionSheet = section.workBook.getActiveSheet();
  680. CommonAjax.post('/rationRepository/api/getRationTree', {rationLibId: rationLibId}, function (sectionDatas) {
  681. //获取所有定额数据
  682. let reqEntity = {rationLibId: rationLibId, showHint: true, returnFields: '-_id code ID sectionId name unit basePrice rationGljList jobContent annotation'};
  683. CommonAjax.post('/rationRepository/api/getRationItemsByLib', reqEntity, function (rstData) {
  684. section.cache = sectionDatas;
  685. initTree(section, section.workBook.getActiveSheet(), section.treeSetting, sectionDatas);
  686. //初始焦点在第一行(切换库)
  687. sectionSheet.setActiveCell(0, 0);
  688. rstData.sort(function (a, b) {
  689. let rst = 0;
  690. if(a.code > b.code){
  691. rst = 1;
  692. }
  693. else if(a.code < b.code){
  694. rst = -1;
  695. }
  696. return rst;
  697. });
  698. ration.datas = rstData;
  699. sectionInitSel(0);
  700. $.bootstrapLoading.end();
  701. }, function () {
  702. $.bootstrapLoading.end();
  703. });
  704. }, function () {
  705. $.bootstrapLoading.end();
  706. });
  707. }
  708. //初始化定额库选择
  709. //@param {String}compilationId @return {void}
  710. function initRationLibs(compilationId){
  711. CommonAjax.post('/rationRepository/api/getRationLibsByCompilation', {compilationId: compilationId}, function (rstData) {
  712. $('#rationLibSel').empty();
  713. for(let rationLib of rstData){
  714. let opt = `<option value="${rationLib.ID}">${rationLib.dispName}</option>`;
  715. $('#rationLibSel').append(opt);
  716. }
  717. //初始选择
  718. initRationItems(parseInt($('#rationLibSel').select().val()));
  719. $('#rationLibSel').change(function () {
  720. let rationLibId = parseInt($(this).select().val());
  721. initRationItems(rationLibId);
  722. })
  723. });
  724. }
  725. //清单设置悬浮提示信息
  726. //@param {Array}billsNodes(清单节点) {Array}jobs(总的工作内容数据) {Array}items(总的项目特征数据)
  727. function setBillsHint(billsNodes, jobs, items) {
  728. let jobsMapping = {},
  729. itemsMapping = {};
  730. for(let job of jobs){
  731. jobsMapping[job.id] = job;
  732. }
  733. for(let item of items){
  734. itemsMapping[item.id] = item;
  735. }
  736. let tagInfo = [];
  737. for(let billsNode of billsNodes){
  738. let hintArr = [];
  739. let billsItems = billsNode.data.items;
  740. if(billsItems.length > 0){
  741. //项目特征
  742. hintArr.push('项目特征:');
  743. }
  744. let itemCount = 1,
  745. jobCount = 1;
  746. for(let billsItem of billsItems){
  747. let itemData = itemsMapping[billsItem.id];
  748. if(itemData){
  749. //特征值
  750. let eigens = [];
  751. for(let eigen of itemData.itemValue){
  752. eigens.push(eigen.value);
  753. }
  754. eigens = eigens.join(';');
  755. hintArr.push(`${itemCount}.${itemData.content}${eigens === '' ? '' : ': ' + eigens}`);
  756. itemCount ++;
  757. }
  758. }
  759. //工作内容
  760. let billsJobs = billsNode.data.jobs;
  761. if(billsJobs.length > 0){
  762. hintArr.push('工作内容:');
  763. }
  764. for(let billsJob of billsJobs){
  765. let jobData = jobsMapping[billsJob.id];
  766. if(jobData){
  767. hintArr.push(`${jobCount}.${jobData.content}`);
  768. jobCount ++;
  769. }
  770. }
  771. /*if(billsNode.data.ruleText && billsNode.data.ruleText !== ''){
  772. hintArr.push('工程量计算规则:');
  773. hintArr.push(billsNode.data.ruleText);
  774. }
  775. if(billsNode.data.recharge && billsNode.data.recharge !== ''){
  776. hintArr.push('补注:');
  777. hintArr.push(billsNode.data.recharge);
  778. }*/
  779. if(hintArr.length > 0){
  780. tagInfo.push({row: billsNode.serialNo(), value: hintArr.join('\n')});
  781. }
  782. }
  783. let sheet = bills.workBook.getActiveSheet();
  784. renderSheetFunc(sheet, function () {
  785. for(let tagI of tagInfo){
  786. sheet.setTag(tagI.row, 0, tagI.value);
  787. }
  788. });
  789. }
  790. //初始化清单的工作内容和项目特征
  791. //@param {Number}billsLibId {Function}callback @return {void}
  792. function initJobAndCharacter(billsLibId, callback){
  793. CommonAjax.post('/stdBillsEditor/getJobContent', {billsLibId: billsLibId}, function (datas) {
  794. stdBillsJobData = datas;
  795. CommonAjax.post('/stdBillsEditor/getItemCharacter', {billsLibId: billsLibId}, function (datas) {
  796. stdBillsFeatureData = datas;
  797. if(callback){
  798. callback();
  799. }
  800. });
  801. });
  802. }
  803. //获取指引库信息及关联的清单
  804. //@param {Number}libID {Function}callback @return {Object}
  805. function getLibWithBills(libID, callback){
  806. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function (rstData) {
  807. initRationLibs(rstData.guidanceLib.compilationId);
  808. bills.cache = rstData.bills;
  809. initLibName(rstData.guidanceLib.name);
  810. /*initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  811. //每一棵项目指引树挂在清单节点上
  812. for(let node of bills.tree.items){
  813. node.guidance = {tree: null, controller: null};
  814. }
  815. //默认初始节点
  816. billsInitSel(0);
  817. if(callback){
  818. callback(rstData);
  819. }*/
  820. let initDataCallback = function () {
  821. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  822. //每一棵项目指引树挂在清单节点上
  823. for(let node of bills.tree.items){
  824. node.guidance = {tree: null, controller: null};
  825. }
  826. //默认初始节点
  827. billsInitSel(0);
  828. if(callback){
  829. callback(rstData);
  830. }
  831. };
  832. initJobAndCharacter(rstData.guidanceLib.billsLibId, initDataCallback);
  833. }, function (msg) {
  834. window.location.href = '/billsGuidance/main';
  835. });
  836. }
  837. //初始化并输出树
  838. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  839. function initTree(module, sheet, treeSetting, datas){
  840. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  841. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  842. module.tree.loadDatas(datas);
  843. module.controller.showTreeData();
  844. if(module === bills){
  845. setBillsHint(bills.tree.items, stdBillsJobData, stdBillsFeatureData);
  846. }
  847. }
  848. //更新项目指引
  849. //@param {Array}updateDatas {Function}callback @return {void}
  850. function updateGuideItems(updateDatas, callback){
  851. CommonAjax.post('/billsGuidance/api/updateItems', {updateDatas: updateDatas}, function (rstData) {
  852. if(callback){
  853. callback(rstData);
  854. }
  855. });
  856. }
  857. //项目指引编辑
  858. //@param {Object}sheet {Array}cells
  859. function edit(sheet, cells){
  860. let updateDatas = [];
  861. //同步节点数据
  862. let syncDatas = [];
  863. for(let cell of cells){
  864. let text = sheet.getValue(cell.row, cell.col);
  865. text = text ? text : '';
  866. let node = bills.tree.selected.guidance.tree.items[cell.row];
  867. if(node.data.name != text){
  868. syncDatas.push({node: node, text: text});
  869. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {name: text}});
  870. }
  871. }
  872. if(updateDatas.length > 0){
  873. updateGuideItems(updateDatas, function () {
  874. for(let syncData of syncDatas){
  875. syncData.node.data.name = syncData.text;
  876. }
  877. }, function () {
  878. //失败恢复
  879. renderSheetFunc(sheet, function () {
  880. for(let syncData of syncDatas){
  881. sheet.setValue(syncData.node.serialNo(), 0, syncData.node.data.name ? syncData.node.data.name : '');
  882. }
  883. });
  884. });
  885. }
  886. }
  887. //项目指引插入,支持一次插入多条数据
  888. //@param {Array}datas {Boolean}tobeChild(插入成为子项) {Function}callback @return {void}
  889. function insert(datas, tobeChild, callback = null){
  890. $.bootstrapLoading.start();
  891. let sheet = guideItem.workBook.getActiveSheet();
  892. let controller = bills.tree.selected.guidance.controller;
  893. let selected = bills.tree.selected.guidance.tree.selected;
  894. let updateDatas = [];
  895. //建立数组下标索引
  896. let newDataIndex = {};
  897. for(let i = 0; i < datas.length; i++){
  898. let newNodeData = {
  899. libID: libID, ID: uuid.v1(), ParentID: selected ? selected.getParentID() : -1, NextSiblingID: selected ? selected.getNextSiblingID() : -1,
  900. billsID: bills.tree.selected.getID()
  901. };
  902. //定额类型插入当前工作内容焦点行,
  903. if(selected && ((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  904. newNodeData.ParentID = selected.getID();
  905. newNodeData.NextSiblingID = -1;
  906. }
  907. Object.assign(newNodeData, datas[i]);
  908. newDataIndex[i] = newNodeData;
  909. }
  910. for(let i = 0; i < datas.length; i++){
  911. //第一个节点
  912. if(i === 0){
  913. //非插入成子节点,更新选中节点NestSiblingID
  914. if(selected && !((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  915. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: newDataIndex[i].ID}});
  916. }
  917. }
  918. //非最后一个节点
  919. if(i !== datas.length - 1){
  920. newDataIndex[i].NextSiblingID = newDataIndex[i + 1].ID;
  921. }
  922. updateDatas.push({updateType: updateType.create, updateData: newDataIndex[i]});
  923. }
  924. updateGuideItems(updateDatas, function () {
  925. for(let updateData of updateDatas){
  926. if(updateData.updateType === updateType.create){
  927. let newNode = controller.insertByIDS(updateData.updateData.ID, updateData.updateData.ParentID, updateData.updateData.NextSiblingID);
  928. //同步data
  929. Object.assign(newNode.data, updateData.updateData);
  930. sheet.setValue(newNode.serialNo(), 0, newNode.data.name);
  931. refreshBtn(newNode);
  932. }
  933. }
  934. if(callback){
  935. callback();
  936. }
  937. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  938. guideItem.workBook.focus(true);
  939. $.bootstrapLoading.end();
  940. });
  941. }
  942. //项目指引删除操作
  943. //@return {void}
  944. function del(){
  945. $.bootstrapLoading.start();
  946. let controller = bills.tree.selected.guidance.controller;
  947. let selected = bills.tree.selected.guidance.tree.selected;
  948. let updateDatas = [];
  949. function getDelDatas(node){
  950. updateDatas.push({updateType: updateType.del, findData: {ID: node.getID()}, updateData: {deleted: true}});
  951. if(node.children.length > 0){
  952. for(let c of node.children){
  953. getDelDatas(c);
  954. }
  955. }
  956. }
  957. getDelDatas(selected);
  958. if(selected.preSibling) {
  959. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  960. }
  961. updateGuideItems(updateDatas, function () {
  962. controller.delete();
  963. refreshBtn(bills.tree.selected.guidance.tree.selected);
  964. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  965. $.bootstrapLoading.end();
  966. guideItem.workBook.focus(true)
  967. });
  968. }
  969. //项目指引升级
  970. //@return {void}
  971. function upLevel(){
  972. $.bootstrapLoading.start();
  973. let controller = bills.tree.selected.guidance.controller;
  974. let selected = bills.tree.selected.guidance.tree.selected;
  975. let updateDatas = [];
  976. //更新父节点
  977. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getParentID()}, updateData: {NextSiblingID: selected.getID()}});
  978. //更新选中节点
  979. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()},
  980. updateData: {ParentID: selected.parent.getParentID(), NextSiblingID: selected.parent.getNextSiblingID()}});
  981. if(selected.nextSibling && selected.children.length > 0){
  982. //更新选中节点最末子节点
  983. let lastChild = selected.children[selected.children.length - 1];
  984. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: -1}});
  985. }
  986. //选中节点的所有后兄弟节点成为选中节点的子项
  987. let selectedNextIDs = [];
  988. let sNext = selected.nextSibling;
  989. while(sNext){
  990. selectedNextIDs.push(sNext.getID());
  991. sNext = sNext.nextSibling;
  992. }
  993. for(let sID of selectedNextIDs){
  994. updateDatas.push({updateType: updateType.update, findData: {ID: sID}, updateData: {ParentID: selected.getID()}});
  995. }
  996. updateGuideItems(updateDatas, function () {
  997. controller.upLevel();
  998. refreshBtn(bills.tree.selected.guidance.tree.selected);
  999. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1000. $.bootstrapLoading.end();
  1001. guideItem.workBook.focus(true)//31574
  1002. });
  1003. }
  1004. //项目指引降级
  1005. //@return {void}
  1006. function downLevel(){
  1007. $.bootstrapLoading.start();
  1008. let controller = bills.tree.selected.guidance.controller;
  1009. let selected = bills.tree.selected.guidance.tree.selected;
  1010. let updateDatas = [];
  1011. //更新前兄弟节点
  1012. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1013. //更新前兄弟节点最末子节点
  1014. if(selected.preSibling.children.length > 0){
  1015. let lastChild = selected.preSibling.children[selected.preSibling.children.length - 1];
  1016. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1017. }
  1018. //更新选中节点
  1019. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {ParentID: selected.preSibling.getID(), NextSiblingID: -1}});
  1020. updateGuideItems(updateDatas, function () {
  1021. controller.downLevel();
  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. //@return {void}
  1030. function upMove(){
  1031. $.bootstrapLoading.start();
  1032. let controller = bills.tree.selected.guidance.controller;
  1033. let selected = bills.tree.selected.guidance.tree.selected;
  1034. let updateDatas = [];
  1035. //更新前节点
  1036. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1037. //更新前前节点
  1038. if(selected.preSibling.preSibling){
  1039. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.preSibling.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1040. }
  1041. //更新选中节点
  1042. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.preSibling.getID()}});
  1043. updateGuideItems(updateDatas, function () {
  1044. controller.upMove();
  1045. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1046. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1047. $.bootstrapLoading.end();
  1048. guideItem.workBook.focus(true)
  1049. });
  1050. }
  1051. //项目指引下移
  1052. //@return {void}
  1053. function downMove(){
  1054. $.bootstrapLoading.start();
  1055. let controller = bills.tree.selected.guidance.controller;
  1056. let selected = bills.tree.selected.guidance.tree.selected;
  1057. let updateDatas = [];
  1058. //更新下节点
  1059. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getNextSiblingID()}, updateData: {NextSiblingID: selected.getID()}});
  1060. //更新前节点
  1061. if(selected.preSibling){
  1062. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1063. }
  1064. //更新选中节点
  1065. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.nextSibling.getNextSiblingID()}});
  1066. updateGuideItems(updateDatas, function () {
  1067. controller.downMove();
  1068. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1069. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1070. $.bootstrapLoading.end();
  1071. guideItem.workBook.focus(true)
  1072. });
  1073. }
  1074. //获取定额类型的项目指引名称,通过定额转换
  1075. //@param {Object}ration @return {String}
  1076. function getRationItemName(ration){
  1077. let arr = [];
  1078. arr.push(ration.code ? ration.code : '');
  1079. arr.push(ration.name ? ration.name : '');
  1080. arr.push(ration.basePrice ? ration.basePrice : '');
  1081. let rst = arr.join(' ');
  1082. rst += `/${ration.unit ? ration.unit : ''}`;
  1083. return rst;
  1084. }
  1085. //获取选中的定额表行
  1086. //@return {Array}
  1087. function getCheckedRationRows(){
  1088. let rst = [];
  1089. let sheet = ration.workBook.getActiveSheet();
  1090. for(let i = 0; i < sheet.getRowCount(); i++){
  1091. let checked = sheet.getValue(i, 0);
  1092. if(checked){
  1093. rst.push(i);
  1094. }
  1095. }
  1096. return rst;
  1097. }
  1098. //清空选中定额表行
  1099. //@param {Array}rows @return {void}
  1100. function clearCheckedRation(rows) {
  1101. let sheet = ration.workBook.getActiveSheet();
  1102. renderSheetFunc(sheet, function () {
  1103. for(let row of rows){
  1104. sheet.setValue(row, 0, 0);
  1105. }
  1106. });
  1107. }
  1108. //获取要插入的定额数据
  1109. //@param {Array}rows @return {Array}
  1110. function getInsertRations(rows){
  1111. let rst = [];
  1112. //当前已存在定额
  1113. let curRationIems = [];
  1114. let selected = bills.tree.selected.guidance.tree.selected;
  1115. if(selected){
  1116. if(selected.data.type === itemType.job){
  1117. curRationIems = selected.children;
  1118. }
  1119. else {
  1120. curRationIems = selected.parent ? selected.parent.children : selected.tree.roots;
  1121. }
  1122. }
  1123. for(let row of rows){
  1124. let selRation = ration.cache[row];
  1125. if(selRation){
  1126. //添加的定额是否已存在,不重复添加
  1127. let isExist = false;
  1128. for(let curRation of curRationIems){
  1129. if(curRation.data.rationID == selRation.ID){
  1130. isExist = true;
  1131. break;
  1132. }
  1133. }
  1134. if(!isExist){
  1135. rst.push({type: itemType.ration, name: getRationItemName(selRation), rationID: selRation.ID});
  1136. }
  1137. }
  1138. }
  1139. return rst;
  1140. }
  1141. //获取块节点父项不存在于选中节点中的节点
  1142. //@param {Array}nodes(选中的节点) @return {Array}
  1143. function getBlockNodes(nodes) {
  1144. let nodeMapping = {};
  1145. for(let node of nodes){
  1146. nodeMapping[node.data.ID] = node;
  1147. }
  1148. //块节点,父项不存在于选中节点中的节点
  1149. let blockNodes = [];
  1150. for(let node of nodes){
  1151. if(!nodeMapping[node.data.ParentID]){
  1152. blockNodes.push(node);
  1153. }
  1154. }
  1155. return blockNodes;
  1156. }
  1157. //允许复制整块,如果有多个块节点,且块节点的父项不同,则不可复制
  1158. //@param {Array}nodes(块节点) @return {Boolean}
  1159. function canCopyBlock(nodes) {
  1160. if(!nodes || nodes.length === 0){
  1161. return false;
  1162. }
  1163. let pID = nodes[0].data.ParentID;
  1164. for(let node of nodes){
  1165. if(node.data.ParentID !== pID){
  1166. return false;
  1167. }
  1168. }
  1169. return true;
  1170. }
  1171. //允许粘贴整块 有粘贴数据,节点存在,如果粘贴到的节点为定额数据,粘贴数据为全定额数据
  1172. //@param {Object}node(粘贴到的节点)
  1173. function canPasteBlock(node) {
  1174. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1175. if(!pasteDatas || pasteDatas.length === 0){
  1176. return false;
  1177. }
  1178. if(!node){
  1179. return false;
  1180. }
  1181. //若粘贴到定额节点,则数据须全为定额
  1182. if(node.data.type === itemType.ration){
  1183. for(let data of pasteDatas){
  1184. if(data.type !== itemType.ration){
  1185. return false;
  1186. }
  1187. }
  1188. }
  1189. //若粘贴到非定额节点,则粘贴的顶层数据须全为非定额
  1190. else {
  1191. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1192. for(let topData of topDatas){
  1193. if(topData.type === itemType.ration){
  1194. return false;
  1195. }
  1196. }
  1197. }
  1198. return true;
  1199. }
  1200. //复制整块,将块节点下所有节点数据复制一份,并且重新生成ID、ParentID、NextSiblingID,使用localStorage存储
  1201. //@param {Array}nodes(块节点) @return {void}
  1202. function copyBlocks(nodes) {
  1203. nodes = _.cloneDeep(nodes);
  1204. //将块节点的ParentID暂时设置为-1
  1205. for(let topNode of nodes){
  1206. topNode.data.ParentID = -1;
  1207. }
  1208. let copyDatas = [];
  1209. let copyNodes = [];
  1210. //获取块节点包含的所有节点(包括自己)
  1211. function containNodes(nodes) {
  1212. for(let node of nodes){
  1213. copyNodes.push(node);
  1214. if(node.children.length > 0){
  1215. containNodes(node.children);
  1216. }
  1217. }
  1218. }
  1219. containNodes(nodes);
  1220. for(let node of copyNodes){
  1221. copyDatas.push(node.data);
  1222. }
  1223. console.log(`copyDatas`);
  1224. console.log(copyDatas);
  1225. setLocalCache(itemCopyBlockKey, JSON.stringify(copyDatas));
  1226. }
  1227. //粘贴整块,整块数据粘贴到相关节点,并成为其后项
  1228. //@param {Object}node(粘贴到的节点) @return {void}
  1229. function pasteBlock(node) {
  1230. let itemObj = bills.tree.selected.guidance;
  1231. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1232. //整理ID
  1233. let IDMapping = {};
  1234. for(let data of pasteDatas){
  1235. data.newID = uuid.v1();
  1236. IDMapping[data.ID] = data;
  1237. }
  1238. for(let data of pasteDatas){
  1239. let nextData = IDMapping[data.NextSiblingID];
  1240. data.NextSiblingID = nextData ? nextData.newID : -1;
  1241. let parentData = IDMapping[data.ParentID];
  1242. data.ParentID = parentData ? parentData.newID : -1;
  1243. }
  1244. for(let data of pasteDatas){
  1245. data.ID = data.newID;
  1246. delete data.newID;
  1247. }
  1248. let updateDatas = [];
  1249. //将最顶层的块数据的ParentID设置成粘贴到节点的ParentID,并设置新的billsID
  1250. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1251. for(let topData of topDatas){
  1252. topData.ParentID = node.getParentID();
  1253. }
  1254. //更新数据
  1255. //更新插入的最末顶层数据NextSiblingID
  1256. if(node.nextSibling){
  1257. topDatas[topDatas.length - 1].NextSiblingID = node.getNextSiblingID();
  1258. }
  1259. //新建节点
  1260. for(let data of pasteDatas){
  1261. data.libID = libID;
  1262. data.billsID = node.data.billsID;
  1263. delete data._id;
  1264. updateDatas.push({updateType: updateType.create, updateData: data});
  1265. }
  1266. console.log(`node`);
  1267. console.log(node);
  1268. console.log(`pasteDatas`);
  1269. console.log(pasteDatas);
  1270. //更新粘贴到的节点的NextSiblingID
  1271. updateDatas.push({updateType: updateType.update, findData: {ID: node.data.ID}, updateData: {NextSiblingID: topDatas[0].ID}})
  1272. $.bootstrapLoading.start();
  1273. updateGuideItems(updateDatas, function (rstData) {
  1274. $.bootstrapLoading.end();
  1275. node.data.NextSiblingID = topDatas[0].ID;
  1276. let newNodes = itemObj.tree.insertDatasTo(node.data, pasteDatas);
  1277. cleanData(guideItem.workBook.getActiveSheet(), guideItem.headers, -1);
  1278. itemObj.controller.showTreeData();
  1279. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1280. }, function () {
  1281. $.bootstrapLoading.end();
  1282. });
  1283. }
  1284. //初始化右键菜单
  1285. //@return {void}
  1286. function initContextMenu() {
  1287. $.contextMenu({
  1288. selector: '#guideItemSpread',
  1289. build: function($triggerElement, e){
  1290. //控制允许右键菜单在哪个位置出现
  1291. let sheet = guideItem.workBook.getSheet(0);
  1292. let offset = $("#guideItemSpread").offset(),
  1293. x = e.pageX - offset.left,
  1294. y = e.pageY - offset.top;
  1295. let target = sheet.hitTest(x, y);
  1296. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  1297. let sel = sheet.getSelections()[0];
  1298. if(sel && sel.rowCount === 1){
  1299. sheet.setActiveCell(target.row, target.col);
  1300. }
  1301. sel = sheet.getSelections()[0];
  1302. let selNodes = [];
  1303. if(sel){
  1304. sel.row = sel.row === -1 ? 0 : sel.row;
  1305. for(let i = 0; i < sel.rowCount; i++){
  1306. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1307. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1308. }
  1309. }
  1310. }
  1311. //块节点
  1312. let blockNodes = getBlockNodes(selNodes);
  1313. //右键在多选内则不重设焦点
  1314. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  1315. sheet.setActiveCell(target.row, target.col);
  1316. }
  1317. guideItemInitSel(target.row);
  1318. return {
  1319. callback: function(){},
  1320. items: {
  1321. "copy": {
  1322. name: "复制整块",
  1323. disabled: function () {
  1324. return !canCopyBlock(blockNodes);
  1325. },
  1326. icon: "fa-copy",
  1327. callback: function (key, opt) {
  1328. copyBlocks(blockNodes);
  1329. }},
  1330. "paste": {
  1331. name: "粘贴整块",
  1332. disabled: function () {
  1333. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1334. return !canPasteBlock(pasteNode);
  1335. },
  1336. icon: "fa-paste",
  1337. callback: function (key, opt) {
  1338. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1339. pasteBlock(pasteNode);
  1340. }},
  1341. "insertSibling": {
  1342. name: '插入行',
  1343. disabled: function () {
  1344. let node = bills.tree.selected.guidance.tree.items[target.row];
  1345. return !node || node.data.type !== itemType.job;
  1346. },
  1347. icon: "fa-arrow-left",
  1348. callback: function (key, opt) {
  1349. insert([{type: itemType.job, name: ''}], false);
  1350. }
  1351. },
  1352. "insertChild": {
  1353. name: '插入子项',
  1354. disabled: function () {
  1355. let node = bills.tree.selected.guidance.tree.items[target.row];
  1356. return !node || node.data.type !== itemType.job || !allJobChildren(node);
  1357. },
  1358. icon: 'fa-arrow-left',
  1359. callback: function (key, opt) {
  1360. insert([{type: itemType.job, name: ''}], true);
  1361. }
  1362. }
  1363. }
  1364. };
  1365. }
  1366. else{
  1367. return false;
  1368. }
  1369. }
  1370. });
  1371. }
  1372. //拖动相关
  1373. let mouseMoveCount = 0;
  1374. let rationLibResizeEles = {};
  1375. rationLibResizeEles.id = '#de';
  1376. rationLibResizeEles.resize = $('#deResize');
  1377. rationLibResizeEles.nearElement = $('#de').find('.top-content');
  1378. rationLibResizeEles.nearSpread = $('#sectionSpread');
  1379. rationLibResizeEles.farElement = $('#de').find('.bottom-content');
  1380. rationLibResizeEles.farSpread = $('#rationSpread');
  1381. rationLibResizeEles.nav = null;
  1382. function setDefaultSize(tag,eles,type) {
  1383. let o_nearSize = 5;
  1384. let o_farSize = 2;
  1385. if(type == 'height'){
  1386. let headerHeight = $(".header").height();
  1387. let toolsbarHeight = $(".sidebar-tools-bar").height();
  1388. let resizeHeight = 6;
  1389. let totalHeight = $(window).height() - headerHeight - toolsbarHeight - resizeHeight;
  1390. const navSize = eles.nav ? eles.nav[type]() + 4 : 0;
  1391. totalHeight = totalHeight - navSize;
  1392. let nearSize = (o_nearSize/(o_nearSize + o_farSize))* totalHeight;
  1393. eles.nearSpread[type](nearSize);
  1394. eles.nearElement[type](nearSize);
  1395. eles.farSpread[type](totalHeight - nearSize);
  1396. eles.farElement[type](totalHeight - nearSize);
  1397. }
  1398. }
  1399. function setSizeWithPercent(tag,eles,nearSize,farSize,type) {
  1400. nearSize = parseFloat(nearSize);
  1401. farSize = parseFloat(farSize);
  1402. if(type !== 'width') {
  1403. let headerHeight = $(".header").height();
  1404. let toolsbarHeight = $(".sidebar-tools-bar").height();
  1405. let resizeHeight = 6;
  1406. let totalHeight = $(window).height() - headerHeight - toolsbarHeight - resizeHeight;
  1407. const navSize = eles.nav ? eles.nav[type]() + 4 : 0;
  1408. totalHeight = totalHeight - navSize;
  1409. nearSize = (nearSize/(nearSize + farSize))* totalHeight;
  1410. eles.nearSpread[type](nearSize);
  1411. eles.nearElement[type](nearSize);
  1412. eles.farSpread[type](totalHeight - nearSize);
  1413. eles.farElement[type](totalHeight - nearSize);
  1414. }
  1415. }
  1416. /**
  1417. * 读取设置的高度
  1418. *
  1419. * @param {String} tag - 顶层div的id
  1420. * @param {function} callback - 回调函数
  1421. * @return {void}
  1422. */
  1423. function loadSize(eles, type, callback) {
  1424. let tag = eles.id;
  1425. if (tag === '') {
  1426. return;
  1427. }
  1428. if(type !== 'height' && type !== 'width'){
  1429. return;
  1430. }
  1431. let o_nearSize = eles.nearSpread[type]();
  1432. let o_farSize = eles.farSpread[type]();
  1433. let nearSize = getLocalCache(`near${type}:${tag}`);
  1434. let farSize = getLocalCache(`far${type}:${tag}`);
  1435. if (nearSize === null || farSize === null) {
  1436. setDefaultSize(tag,eles,type);
  1437. }else {
  1438. setSizeWithPercent(tag,eles,nearSize,farSize,type)//zhang 2018-06-04 改成按百分比设置
  1439. }
  1440. callback();
  1441. }
  1442. /**
  1443. * 拖动更改div大小
  1444. *
  1445. * @param {Object} eles - id:存储本地的标记 resize:拖动条 nearElement:左上外层div nearSpread:左上spread farElement:右下外层div evFixedSize:造价书左右拖动用
  1446. * @param {Object} limit - min/max
  1447. * @param {String} type - height/width
  1448. * @param {function} callback - 成功后执行
  1449. * @return {void}
  1450. */
  1451. function slideResize(eles, limit, type, callback) {
  1452. if(type !== 'height' && type !== 'width'){
  1453. return;
  1454. }
  1455. //nearElement:左上, farElement:右下
  1456. let startP = 0;
  1457. let drag = false;
  1458. const resizeElement = eles.resize;
  1459. const nElement = eles.nearElement;
  1460. const fElement = eles.farElement;
  1461. const navContentEle = eles.nav ? eles.nav : null;
  1462. let nEleSize = 0;
  1463. let fEleSize = 0;
  1464. let navSize = 0;
  1465. let nEleChangeSize = 0;
  1466. let fEleChangeSize = 0;
  1467. // 鼠标点下时
  1468. resizeElement.mousedown(function(e) {
  1469. drag = true;
  1470. startP = type === 'height' ? e.clientY : e.clientX;
  1471. // 获取左(上)部分的宽度(高度)
  1472. nEleSize = nElement[type]();
  1473. // 获取右(下)部分的宽度(高度)
  1474. fEleSize = fElement[type]();
  1475. // nav宽(高度)部分
  1476. if(navContentEle){
  1477. navSize = navContentEle[type]() + 4;
  1478. }
  1479. resizeElement.tooltip('hide');
  1480. });
  1481. // 鼠标移动
  1482. $("body").mousemove(function(e) {
  1483. if (drag) {
  1484. let moveSize = type === 'height' ? e.clientY - startP : e.clientX - startP;
  1485. // 判断拖动范围不能超出
  1486. nEleChangeSize = nEleSize + moveSize;
  1487. nEleChangeSize = nEleChangeSize < limit.min ? limit.min : nEleChangeSize;
  1488. nEleChangeSize = nEleChangeSize > limit.max ? limit.max + 9 : nEleChangeSize;
  1489. fEleChangeSize = fEleSize - moveSize;
  1490. fEleChangeSize = fEleChangeSize < limit.min ? limit.min : fEleChangeSize;
  1491. fEleChangeSize = fEleChangeSize > limit.max ? limit.max + 9 : fEleChangeSize;
  1492. if(type === 'width'){
  1493. let rePercent = getResizeWidthPercent(nEleChangeSize, fEleChangeSize);
  1494. eles.nearElement.css(type, rePercent.nearPercent);
  1495. eles.farElement.css(type, rePercent.farPercent);
  1496. }
  1497. else{
  1498. eles.nearSpread[type](nEleChangeSize);
  1499. eles.nearElement[type](nEleChangeSize);
  1500. eles.farSpread[type](fEleChangeSize - navSize);
  1501. eles.farElement[type](fEleChangeSize - navSize);
  1502. }
  1503. //实时刷新页面
  1504. mouseMoveCount+=Math.abs(moveSize);//取移动的决对值
  1505. if(mouseMoveCount >=5){//当累计移动超过5个像素时,才刷新,减少刷新次数
  1506. if(callback) callback();
  1507. mouseMoveCount = 0;
  1508. }
  1509. }
  1510. });
  1511. // 鼠标弹起
  1512. $("body").mouseup(function(e) {
  1513. if (drag) {
  1514. callback();
  1515. drag = false;
  1516. // 存入本地缓存
  1517. const id = eles.id;
  1518. nEleChangeSize = nEleChangeSize >= limit.max ? limit.max + 9 : nEleChangeSize;
  1519. fEleChangeSize = fEleChangeSize >= limit.max ? limit.max + 9 : fEleChangeSize;
  1520. setLocalCache(`near${type}:${id}`, nEleChangeSize);
  1521. setLocalCache(`far${type}:${id}`, fEleChangeSize);
  1522. }
  1523. });
  1524. }
  1525. /**
  1526. * 读取设置的高度
  1527. *
  1528. * @param {String} tag - 顶层div的id
  1529. * @param {function} callback - 回调函数
  1530. * @return {void}
  1531. */
  1532. function loadSize(eles, type, callback) {
  1533. let tag = eles.id;
  1534. if (tag === '') {
  1535. return;
  1536. }
  1537. if(type !== 'height' && type !== 'width'){
  1538. return;
  1539. }
  1540. let o_nearSize = eles.nearSpread[type]();
  1541. let o_farSize = eles.farSpread[type]();
  1542. let nearSize = getLocalCache(`near${type}:${tag}`);
  1543. let farSize = getLocalCache(`far${type}:${tag}`);
  1544. if (nearSize === null || farSize === null) {
  1545. setDefaultSize(tag,eles,type);//zhang 2018-05-21
  1546. /* eles.nearSpread[type](o_nearSize);
  1547. eles.farSpread[type](o_farSize);*/
  1548. }else {
  1549. setSizeWithPercent(tag,eles,nearSize,farSize,type)//zhang 2018-06-04 改成按百分比设置
  1550. }
  1551. if(type === 'width'){//使用百分比
  1552. let rePercent = getResizeWidthPercent(nearSize ? nearSize : o_nearSize, farSize ? farSize : o_farSize);
  1553. eles.nearElement.css(type, rePercent.nearPercent);
  1554. eles.farElement.css(type, rePercent.farPercent);
  1555. }
  1556. callback();
  1557. }
  1558. //初始化个按钮点击
  1559. //@return {void}
  1560. function initBtn(){
  1561. $('#insert').click(function () {
  1562. insert([{type: itemType.job, name: ''}], false);
  1563. });
  1564. $('#delConfirm').click(function () {
  1565. del();
  1566. $('#delAlert').modal('hide');
  1567. });
  1568. $('#del').click(function () {
  1569. $('#delAlert').modal('show');
  1570. });
  1571. $('#upLevel').click(function () {
  1572. upLevel();
  1573. });
  1574. $('#downLevel').click(function () {
  1575. downLevel();
  1576. });
  1577. $('#upMove').click(function () {
  1578. upMove();
  1579. });
  1580. $('#downMove').click(function () {
  1581. downMove();
  1582. });
  1583. //收起定额、展开全部
  1584. $('#expandContract').click(function () {
  1585. //目前状态时展开全部节点状态,点击则收起定额
  1586. let tree = bills.tree.selected.guidance.tree,
  1587. itemSheet = guideItem.workBook.getActiveSheet();
  1588. if(curExpandState === itemExpandState.expand){
  1589. curExpandState = itemExpandState.contract;
  1590. $(this).html('<i class="fa fa-plus-square-o" aria-hidden="true"></i> 展开全部');
  1591. setNodesExpandState(tree.items, itemExpandState.contract);
  1592. } else {
  1593. curExpandState = itemExpandState.expand;
  1594. $(this).html('<i class="fa fa-minus-square-o" aria-hidden="true"></i> 收起定额');
  1595. setNodesExpandState(tree.items, itemExpandState.expand);
  1596. }
  1597. renderSheetFunc(itemSheet, function () {
  1598. TREE_SHEET_HELPER.refreshNodesVisible(tree.roots, itemSheet, true);
  1599. });
  1600. });
  1601. $('#insertRation').click(function () {
  1602. let checkedRows = getCheckedRationRows();
  1603. let insertDatas = getInsertRations(checkedRows);
  1604. if(insertDatas.length > 0){
  1605. insert(insertDatas, false, function () {
  1606. //清空选择
  1607. clearCheckedRation(checkedRows);
  1608. });
  1609. }
  1610. else {
  1611. clearCheckedRation(checkedRows);
  1612. }
  1613. });
  1614. //搜索定额
  1615. $('#searchBtn').click(function () {
  1616. let searchStr = $('#searchText').val();
  1617. if(!searchStr || searchStr === ''){
  1618. ration.cache = ration.datas;
  1619. }
  1620. else{
  1621. let reg = new RegExp(searchStr, 'i');
  1622. ration.cache = _.filter(ration.datas, function (data) {
  1623. return reg.test(data.code) || reg.test(data.name);
  1624. });
  1625. }
  1626. $('.top-content').hide();
  1627. $('#searchCount').text(`搜索结果: ${ration.cache.length}`);
  1628. $('#rationSearchResult').show();
  1629. autoFlashHeight();
  1630. ration.workBook.refresh();
  1631. let rationSheet = ration.workBook.getActiveSheet();
  1632. renderSheetFunc(rationSheet, function () {
  1633. clearCheckedRation(getCheckedRationRows());
  1634. showData(rationSheet, ration.headers, ration.cache);
  1635. })
  1636. });
  1637. //关闭搜索
  1638. $('#rationSearchResult a').click(function () {
  1639. $('.top-content').show();
  1640. $('#rationSearchResult').hide();
  1641. autoFlashHeight();
  1642. renderSheetFunc(ration.workBook.getActiveSheet(), function () {
  1643. clearCheckedRation(getCheckedRationRows());
  1644. });
  1645. section.workBook.refresh();
  1646. ration.workBook.refresh();
  1647. $('#searchText').val('');
  1648. //恢复章节树下的定额
  1649. sectionInitSel(section.workBook.getActiveSheet().getActiveRowIndex());
  1650. });
  1651. //执行搜索
  1652. $('#searchText').keyup(function (e) {
  1653. $('#searchBtn').click();
  1654. });
  1655. //编辑备注
  1656. $('.main-bottom-content').find('textarea').keyup(function () {
  1657. let node = bills.tree.selected.guidance.tree.selected;
  1658. if(node){
  1659. let comment = $(this).val();
  1660. let updateDatas = [{updateType: updateType.update, findData: {ID: node.getID()}, updateData: {comment: comment}}];
  1661. updateGuideItems(updateDatas, function (rstData) {
  1662. node.data.comment = comment;
  1663. });
  1664. }
  1665. });
  1666. //定额高度拖动调整
  1667. slideResize(rationLibResizeEles, {min: 147, max: 680}, 'height', function() {
  1668. //autoFlashHeight();
  1669. if(section.workBook){
  1670. section.workBook.refresh();
  1671. }
  1672. if(ration.workBook){
  1673. ration.workBook.refresh();
  1674. }
  1675. });
  1676. }
  1677. //初始化视图
  1678. //@param {void} @return {void}
  1679. function initViews(){
  1680. let modules = [bills, guideItem, section, ration];
  1681. initWorkBooks(modules);
  1682. getLibWithBills(libID);
  1683. initBtn();
  1684. initContextMenu();
  1685. loadSize(rationLibResizeEles, 'height', function () {
  1686. if(section.workBook){
  1687. section.workBook.refresh();
  1688. }
  1689. if(ration.workBook){
  1690. ration.workBook.refresh();
  1691. }
  1692. });
  1693. }
  1694. return {initViews};
  1695. })();
  1696. $(document).ready(function () {
  1697. billsGuidance.initViews();
  1698. CommonAjax.post('/billsGuidance/api/testItems', {libID: getQueryString('libID')}, function (rstData) {
  1699. console.log(rstData);
  1700. });
  1701. });