billsGuidance.js 67 KB

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