billsGuidance.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2018/6/1
  7. * @version
  8. */
  9. const billsGuidance = (function () {
  10. //自执行函数全局变量定义
  11. const libID = getQueryString('libID');
  12. const bills = {
  13. dom: $('#billsSpread'),
  14. workBook: null,
  15. cache: [],
  16. tree: null,
  17. controller: null,
  18. treeSetting: {
  19. treeCol: 0,
  20. emptyRows: 0,
  21. headRows: 1,
  22. headRowHeight: [40],
  23. defaultRowHeight: 21,
  24. cols: [{
  25. width: 200,
  26. readOnly: true,
  27. head: {
  28. titleNames: ["项目编码"],
  29. spanCols: [1],
  30. spanRows: [1],
  31. vAlign: [1],
  32. hAlign: [1],
  33. font: ["Arial"]
  34. },
  35. data: {
  36. field: "code",
  37. vAlign: 1,
  38. hAlign: 0,
  39. font: "Arial"
  40. }
  41. }, {
  42. width: 200,
  43. readOnly: true,
  44. head: {
  45. titleNames: ["项目名称"],
  46. spanCols: [1],
  47. spanRows: [1],
  48. vAlign: [1],
  49. hAlign: [1],
  50. font: ["Arial"]
  51. },
  52. data: {
  53. field: "name",
  54. vAlign: 1,
  55. hAlign: 0,
  56. font: "Arial"
  57. }
  58. }]
  59. },
  60. headers: [
  61. {name: '项目编码', dataCode: 'code', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'},
  62. {name: '项目名称', dataCode: 'name', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'}
  63. ],
  64. events: {
  65. SelectionChanged: function (sender, info) {
  66. billsInitSel(info.newSelections[0].row);
  67. }
  68. }
  69. };
  70. //项目指引类型
  71. const itemType = {
  72. job: 0,
  73. ration: 1
  74. };
  75. const updateType = {
  76. create: 'create',
  77. update: 'update'
  78. };
  79. const guideItem = {
  80. dom: $('#guideItemSpread'),
  81. workBook: null,
  82. tree: null,
  83. controller: null,
  84. treeSetting: {
  85. treeCol: 0,
  86. emptyRows: 0,
  87. headRows: 1,
  88. headRowHeight: [40],
  89. defaultRowHeight: 21,
  90. cols: [{
  91. width: 400,
  92. readOnly: false,
  93. head: {
  94. titleNames: ["项目指引"],
  95. spanCols: [1],
  96. spanRows: [1],
  97. vAlign: [1],
  98. hAlign: [1],
  99. font: ["Arial"]
  100. },
  101. data: {
  102. field: "name",
  103. vAlign: 1,
  104. hAlign: 0,
  105. font: "Arial"
  106. }
  107. }]
  108. },
  109. headers: [
  110. {name: '项目指引', dataCode: 'name', width: 400, vAlign: 'center', hAlign: 'left', formatter: '@'},
  111. ],
  112. events: {
  113. SelectionChanged: function (sender, info) {
  114. guideItemInitSel(info.newSelections[0].row)
  115. },
  116. EditEnded: function (sender, args) {
  117. edit(args.sheet, [{row: args.row, col: args.col}]);
  118. },
  119. RangeChanged: function (sender, args) {
  120. edit(args.sheet, args.changedCells);
  121. }
  122. }
  123. };
  124. const ration = {
  125. dom: $('#rationSpread'),
  126. workBook: null,
  127. cache: [],
  128. headers: [
  129. {name: '选择', dataCode: 'select', width: 50, vAlign: 'center', hAlign: 'center'},
  130. {name: '编码', dataCode: 'code', width: 110, vAlign: 'center', hAlign: 'left', formatter: '@'},
  131. {name: '名称', dataCode: 'name', width: 250, vAlign: 'center', hAlign: 'left', formatter: '@'},
  132. {name: '单位', dataCode: 'unit', width: 100, vAlign: 'center', hAlign: 'left', formatter: '@'}
  133. ],
  134. events: {
  135. ButtonClicked: function (sender, args) {
  136. if(args.sheet.isEditing()){
  137. args.sheet.endEdit(true);
  138. }
  139. },
  140. CellDoubleClick: function (sender, args) {
  141. if(ration.headers[args.col].dataCode === 'name'){
  142. let insertDatas = getInsertRations([args.row]);
  143. if(insertDatas.length > 0){
  144. insert(insertDatas);
  145. }
  146. }
  147. }
  148. }
  149. };
  150. const options = {
  151. workBook: {
  152. tabStripVisible: false,
  153. allowContextMenu: false,
  154. allowCopyPasteExcelStyle : false,
  155. allowExtendPasteRange: false,
  156. allowUserDragDrop : false,
  157. allowUserDragFill: false,
  158. scrollbarMaxAlign : true
  159. },
  160. sheet: {
  161. protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
  162. clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
  163. }
  164. };
  165. //渲染时方法,停止渲染
  166. //@param {Object}sheet {Function}func @return {void}
  167. function renderSheetFunc(sheet, func){
  168. sheet.suspendEvent();
  169. sheet.suspendPaint();
  170. if(func){
  171. func();
  172. }
  173. sheet.resumeEvent();
  174. sheet.resumePaint();
  175. }
  176. //设置表选项
  177. //@param {Object}workBook {Object}opts @return {void}
  178. function setOptions (workBook, opts) {
  179. for(let opt in opts.workBook){
  180. workBook.options[opt] = opts.workBook[opt];
  181. }
  182. for(let opt in opts.sheet){
  183. workBook.getActiveSheet().options[opt] = opts.sheet[opt];
  184. }
  185. }
  186. //建表头
  187. //@param {Object}sheet {Array}headers @return {void}
  188. function buildHeader(sheet, headers) {
  189. let fuc = function () {
  190. sheet.setColumnCount(headers.length);
  191. sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
  192. for(let i = 0, len = headers.length; i < len; i++){
  193. sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
  194. sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
  195. if(headers[i].formatter){
  196. sheet.setFormatter(-1, i, headers[i].formatter);
  197. }
  198. sheet.getRange(-1, i, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[i]['hAlign']]);
  199. sheet.getRange(-1, i, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[i]['vAlign']]);
  200. }
  201. };
  202. renderSheetFunc(sheet, fuc);
  203. }
  204. //表监听事件
  205. //@param {Object}workBook @return {void}
  206. function bindEvent(workBook, events) {
  207. if(Object.keys(events).length === 0){
  208. return;
  209. }
  210. const Events = GC.Spread.Sheets.Events;
  211. let sheet = workBook.getActiveSheet();
  212. for(let event in events){
  213. workBook.bind(Events[event], events[event]);
  214. }
  215. }
  216. //建表
  217. //@param {Object}module @return {void}
  218. function buildSheet(module) {
  219. if(!module.workBook){
  220. module.workBook = new GC.Spread.Sheets.Workbook(module.dom[0], {sheetCount: 1});
  221. let sheet = module.workBook.getActiveSheet();
  222. if(module === bills){
  223. //默认初始可控制焦点在清单表中
  224. module.workBook.focus();
  225. sheet.options.isProtected = true;
  226. }
  227. if(module === ration){
  228. sheet.options.isProtected = true;
  229. sheet.getRange(-1, 0, -1, 1).locked(false);
  230. sheet.getRange(-1, 1, -1, -1).locked(true);
  231. }
  232. setOptions(module.workBook, options);
  233. buildHeader(module.workBook.getActiveSheet(), module.headers);
  234. bindEvent(module.workBook, module.events);
  235. }
  236. }
  237. //清空表数据
  238. //@param {Object}sheet {Array}headers {Number}rowCount @return {void}
  239. function cleanData(sheet, headers, rowCount){
  240. renderSheetFunc(sheet, function () {
  241. sheet.clear(-1, 0, -1, headers.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  242. if (rowCount > 0) {
  243. sheet.setRowCount(rowCount);
  244. }
  245. });
  246. }
  247. //根据清单获取项目指引
  248. //@param {String}guidanceLibID {Number}billsID {Function}callback @return {void}
  249. function getItemsByBills(guidanceLibID, billsID, callback){
  250. CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: guidanceLibID, billsID: billsID}, function (rstData) {
  251. if(callback){
  252. callback(rstData);
  253. }
  254. });
  255. }
  256. //清单表焦点控制
  257. //@param {Number}row @return {void}
  258. function billsInitSel(row){
  259. let guideSheet = guideItem.workBook.getActiveSheet();
  260. cleanData(guideSheet, guideItem.headers, -1);
  261. let node = bills.tree.items[row];
  262. if(!node){
  263. return;
  264. }
  265. bills.tree.selected = node;
  266. if(!node.guidance.tree){
  267. getItemsByBills(libID, node.data.ID, function (rstData) {
  268. initTree(node.guidance, guideSheet, guideItem.treeSetting, rstData);
  269. //项目指引初始焦点
  270. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  271. });
  272. }
  273. else{
  274. node.guidance.controller.showTreeData();
  275. //项目指引初始焦点
  276. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  277. }
  278. }
  279. //节点子项是否全是工作内容
  280. //@param {Object}node @return {Boolean}
  281. function allJobChildren(node){
  282. for(let c of node.children){
  283. if(c.data.type === itemType.ration){
  284. return false;
  285. }
  286. }
  287. return true;
  288. }
  289. //节点子项是否全是定额
  290. //@param {Object}node @return {Boolean}
  291. function allRationChildren(node){
  292. for(let c of node.children){
  293. if(c.data.type === itemType.job){
  294. return false;
  295. }
  296. }
  297. return true;
  298. }
  299. //刷新按钮有效性
  300. //@param {Object}node @return {void}
  301. function refreshBtn(node){
  302. //全部设为无效
  303. $('.tools-btn').children().addClass('disabled');
  304. $('#insertRation').addClass('disabled');
  305. //插入
  306. if(bills.tree.selected && bills.tree.selected.guidance.tree){
  307. $('#insert').removeClass('disabled');
  308. if(node && node.data.type === itemType.ration){
  309. $('#insert').addClass('disabled');
  310. }
  311. }
  312. //删除
  313. if(node){
  314. $('#del').removeClass('disabled');
  315. }
  316. if(node && node.data.type === itemType.job){
  317. //升级
  318. if(node.parent){
  319. $('#upLevel').removeClass('disabled');
  320. if(node.nextSibling && node.children.length > 0 && !allJobChildren(node)){
  321. $('#upLevel').addClass('disabled');
  322. }
  323. }
  324. //降级
  325. if(node.preSibling){
  326. $('#downLevel').removeClass('disabled');
  327. if(node.preSibling.children.length > 0 && !allJobChildren(node.preSibling)){
  328. $('#downLevel').addClass('disabled');
  329. }
  330. }
  331. }
  332. //上移
  333. if(node && node.preSibling){
  334. $('#upMove').removeClass('disabled')
  335. }
  336. //下移
  337. if(node && node.nextSibling){
  338. $('#downMove').removeClass('disabled');
  339. }
  340. //插入定额
  341. if(node && (node.children.length === 0 || allRationChildren(node))){
  342. $('#insertRation').removeClass('disabled');
  343. }
  344. }
  345. //项目指引表焦点控制
  346. //@param {Number}row @return {void}
  347. function guideItemInitSel(row){
  348. let billsNode = bills.tree.selected;
  349. let node = null;
  350. if(billsNode && billsNode.guidance.tree){
  351. node = billsNode.guidance.tree.items[row];
  352. if(node){
  353. billsNode.guidance.tree.selected = node;
  354. }
  355. }
  356. refreshBtn(node);
  357. }
  358. //初始化当前库名
  359. //@param {String} @return {void}
  360. function initLibName(libName) {
  361. $('#libName')[0].outerHTML = $('#libName')[0].outerHTML.replace("XXX清单指引", libName);
  362. }
  363. //初始化各工作表
  364. //@param {Array}modules @return {void}
  365. function initWorkBooks(modules){
  366. for(let module of modules){
  367. buildSheet(module);
  368. }
  369. }
  370. //输出表数据(定额表)
  371. //@param {Object}sheet {Array}headers {Array}datas @return {void}
  372. function showData(sheet, headers, datas){
  373. let fuc = function () {
  374. sheet.setRowCount(datas.length);
  375. //复选框
  376. let checkBoxType = new GC.Spread.Sheets.CellTypes.CheckBox();
  377. sheet.setCellType(-1, 0, checkBoxType);
  378. for(let col = 0, cLen = headers.length; col < cLen; col++){
  379. for(let row = 0, rLen = datas.length; row < rLen; row++){
  380. sheet.setValue(row, col, datas[row][headers[col]['dataCode']]);
  381. }
  382. }
  383. };
  384. renderSheetFunc(sheet, fuc);
  385. }
  386. //初始化定额条目
  387. //@param {Number}rationLibId @return {void}
  388. function initRationItems(rationLibId){
  389. $.bootstrapLoading.start();
  390. CommonAjax.post('/rationRepository/api/getRationItemsByLib', {rationLibId: rationLibId}, function (rstData) {
  391. rstData.sort(function (a, b) {
  392. let rst = 0;
  393. if(a.code > b.code){
  394. rst = 1;
  395. }
  396. else if(a.code < b.code){
  397. rst = -1;
  398. }
  399. return rst;
  400. });
  401. ration.cache = rstData;
  402. showData(ration.workBook.getActiveSheet(), ration.headers, rstData);
  403. $.bootstrapLoading.end();
  404. });
  405. }
  406. //初始化定额库选择
  407. //@param {String}compilationId @return {void}
  408. function initRationLibs(compilationId){
  409. CommonAjax.post('/rationRepository/api/getRationLibsByCompilation', {compilationId: compilationId}, function (rstData) {
  410. $('#rationLibSel').empty();
  411. for(let rationLib of rstData){
  412. let opt = `<option value="${rationLib.ID}">${rationLib.dispName}</option>`;
  413. $('#rationLibSel').append(opt);
  414. }
  415. //初始选择
  416. initRationItems(parseInt($('#rationLibSel').select().val()));
  417. $('#rationLibSel').change(function () {
  418. let rationLibId = parseInt($(this).select().val());
  419. initRationItems(rationLibId);
  420. })
  421. });
  422. }
  423. //获取指引库信息及关联的清单
  424. //@param {Number}libID {Function}callback @return {Object}
  425. function getLibWithBills(libID, callback){
  426. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function (rstData) {
  427. initRationLibs(rstData.guidanceLib.compilationId);
  428. bills.cache = rstData.bills;
  429. initLibName(rstData.guidanceLib.name);
  430. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  431. //每一棵项目指引树挂在清单节点上
  432. for(let node of bills.tree.items){
  433. node.guidance = {tree: null, controller: null};
  434. }
  435. //默认初始节点
  436. billsInitSel(0);
  437. if(callback){
  438. callback(rstData);
  439. }
  440. }, function (msg) {
  441. window.location.href = '/billsGuidance/main';
  442. });
  443. }
  444. //初始化并输出树
  445. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  446. function initTree(module, sheet, treeSetting, datas){
  447. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  448. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  449. module.tree.loadDatas(datas);
  450. module.controller.showTreeData();
  451. }
  452. //更新项目指引
  453. //@param {Array}updateDatas {Function}callback @return {void}
  454. function updateGuideItems(updateDatas, callback){
  455. CommonAjax.post('/billsGuidance/api/updateItems', {updateDatas: updateDatas}, function (rstData) {
  456. if(callback){
  457. callback(rstData);
  458. }
  459. });
  460. }
  461. //项目指引编辑
  462. //@param {Object}sheet {Array}cells
  463. function edit(sheet, cells){
  464. let updateDatas = [];
  465. //同步节点数据
  466. let syncDatas = [];
  467. for(let cell of cells){
  468. let text = sheet.getValue(cell.row, cell.col);
  469. text = text ? text : '';
  470. let node = bills.tree.selected.guidance.tree.items[cell.row];
  471. if(node.data.name != text){
  472. syncDatas.push({node: node, text: text});
  473. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {name: text}});
  474. }
  475. }
  476. if(updateDatas.length > 0){
  477. updateGuideItems(updateDatas, function () {
  478. for(let syncData of syncDatas){
  479. syncData.node.data.name = syncData.text;
  480. }
  481. }, function () {
  482. //失败恢复
  483. renderSheetFunc(sheet, function () {
  484. for(let syncData of syncDatas){
  485. sheet.setValue(syncData.node.serialNo(), 0, syncData.node.data.name ? syncData.node.data.name : '');
  486. }
  487. });
  488. });
  489. }
  490. }
  491. //项目指引插入,支持一次插入多条数据
  492. //@param {Array}datas {Function}callback @return {void}
  493. function insert(datas, callback = null){
  494. $.bootstrapLoading.start();
  495. let sheet = guideItem.workBook.getActiveSheet();
  496. let controller = bills.tree.selected.guidance.controller;
  497. let selected = bills.tree.selected.guidance.tree.selected;
  498. let updateDatas = [];
  499. //建立数组下标索引
  500. let newDataIndex = {};
  501. for(let i = 0; i < datas.length; i++){
  502. let newNodeData = {
  503. libID: libID, ID: uuid.v1(), ParentID: selected ? selected.getParentID() : -1, NextSiblingID: selected ? selected.getNextSiblingID() : -1,
  504. billsID: bills.tree.selected.getID()
  505. };
  506. //定额类型插入当前工作内容焦点行,
  507. if(selected && selected.data.type === itemType.job && datas[i].type === itemType.ration){
  508. newNodeData.ParentID = selected.getID();
  509. newNodeData.NextSiblingID = -1;
  510. }
  511. Object.assign(newNodeData, datas[i]);
  512. newDataIndex[i] = newNodeData;
  513. }
  514. for(let i = 0; i < datas.length; i++){
  515. //第一个节点
  516. if(i === 0){
  517. //非插入成子节点,更新选中节点NestSiblingID
  518. if(selected && !(selected.data.type === itemType.job && datas[i].type === itemType.ration)){
  519. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: newDataIndex[i].ID}});
  520. }
  521. }
  522. //非最后一个节点
  523. if(i !== datas.length - 1){
  524. newDataIndex[i].NextSiblingID = newDataIndex[i + 1].ID;
  525. }
  526. updateDatas.push({updateType: updateType.create, updateData: newDataIndex[i]});
  527. }
  528. updateGuideItems(updateDatas, function () {
  529. for(let updateData of updateDatas){
  530. if(updateData.updateType === updateType.create){
  531. let newNode = controller.insertByIDS(updateData.updateData.ID, updateData.updateData.ParentID, updateData.updateData.NextSiblingID);
  532. //同步data
  533. Object.assign(newNode.data, updateData.updateData);
  534. sheet.setValue(newNode.serialNo(), 0, newNode.data.name);
  535. refreshBtn(newNode);
  536. }
  537. }
  538. if(callback){
  539. callback();
  540. }
  541. $.bootstrapLoading.end();
  542. });
  543. }
  544. //项目指引删除操作
  545. //@return {void}
  546. function del(){
  547. $.bootstrapLoading.start();
  548. let controller = bills.tree.selected.guidance.controller;
  549. let selected = bills.tree.selected.guidance.tree.selected;
  550. let updateDatas = [];
  551. function getDelDatas(node){
  552. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {deleted: true}});
  553. if(node.children.length > 0){
  554. for(let c of node.children){
  555. getDelDatas(c);
  556. }
  557. }
  558. }
  559. getDelDatas(selected);
  560. updateGuideItems(updateDatas, function () {
  561. controller.delete();
  562. refreshBtn(bills.tree.selected.guidance.tree.selected);
  563. $.bootstrapLoading.end();
  564. });
  565. }
  566. //项目指引升级
  567. //@return {void}
  568. function upLevel(){
  569. $.bootstrapLoading.start();
  570. let controller = bills.tree.selected.guidance.controller;
  571. let selected = bills.tree.selected.guidance.tree.selected;
  572. let updateDatas = [];
  573. //更新父节点
  574. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getParentID()}, updateData: {NextSiblingID: selected.getID()}});
  575. //更新选中节点
  576. updateDatas.push({udpateType: updateType.update, findData: {ID: selected.getID()},
  577. updateData: {ParentID: selected.parent.getParentID(), NextSiblingID: selected.parent.getNextSiblingID()}});
  578. if(selected.nextSibling && selected.children.length > 0){
  579. //更新选中节点最末子节点
  580. let lastChild = selected.children[selected.children.length - 1];
  581. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  582. }
  583. updateGuideItems(updateDatas, function () {
  584. controller.upLevel();
  585. refreshBtn(bills.tree.selected.guidance.tree.selected);
  586. $.bootstrapLoading.end();
  587. });
  588. }
  589. //项目指引降级
  590. //@return {void}
  591. function downLevel(){
  592. $.bootstrapLoading.start();
  593. let controller = bills.tree.selected.guidance.controller;
  594. let selected = bills.tree.selected.guidance.tree.selected;
  595. let updateDatas = [];
  596. //更新前兄弟节点
  597. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  598. //更新前兄弟节点最末子节点
  599. if(selected.preSibling.children.length > 0){
  600. let lastChild = selected.preSibling.children[selected.preSibling.children.length - 1];
  601. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: selected.getID()}});
  602. }
  603. //更新选中节点
  604. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {ParentID: selected.preSibling.getID(), NextSiblingID: -1}});
  605. updateGuideItems(updateDatas, function () {
  606. controller.downLevel();
  607. refreshBtn(bills.tree.selected.guidance.tree.selected);
  608. $.bootstrapLoading.end();
  609. });
  610. }
  611. //项目指引上移
  612. //@return {void}
  613. function upMove(){
  614. $.bootstrapLoading.start();
  615. let controller = bills.tree.selected.guidance.controller;
  616. let selected = bills.tree.selected.guidance.tree.selected;
  617. let updateDatas = [];
  618. //更新前节点
  619. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  620. //更新前前节点
  621. if(selected.preSibling.preSibling){
  622. updateDatas.push({udpateType: updateType.update, findData: {ID: selected.preSibling.preSibling.getID()}, updateData: {NextSiblingID: selected.getID()}});
  623. }
  624. //更新选中节点
  625. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.preSibling.getID()}});
  626. updateGuideItems(updateDatas, function () {
  627. controller.upMove();
  628. refreshBtn(bills.tree.selected.guidance.tree.selected);
  629. $.bootstrapLoading.end();
  630. });
  631. }
  632. //项目指引下移
  633. //@return {void}
  634. function downMove(){
  635. $.bootstrapLoading.start();
  636. let controller = bills.tree.selected.guidance.controller;
  637. let selected = bills.tree.selected.guidance.tree.selected;
  638. let updateDatas = [];
  639. //更新下节点
  640. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getNextSiblingID()}, updateData: {NextSiblingID: selected.getID()}});
  641. //更新前节点
  642. if(selected.preSibling){
  643. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  644. }
  645. //更新选中节点
  646. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.nextSibling.getNextSiblingID()}});
  647. updateGuideItems(updateDatas, function () {
  648. controller.downMove();
  649. refreshBtn(bills.tree.selected.guidance.tree.selected);
  650. $.bootstrapLoading.end();
  651. });
  652. }
  653. //获取定额类型的项目指引名称,通过定额转换
  654. //@param {Object}ration @return {String}
  655. function getRationItemName(ration){
  656. let arr = [];
  657. arr.push(ration.code ? ration.code : '');
  658. arr.push(ration.name ? ration.name : '');
  659. arr.push(ration.basePrice ? ration.basePrice : '');
  660. let rst = arr.join(' ');
  661. rst += `/${ration.unit ? ration.unit : ''}`;
  662. return rst;
  663. }
  664. //获取选中的定额表行
  665. //@return {Array}
  666. function getCheckedRationRows(){
  667. let rst = [];
  668. let sheet = ration.workBook.getActiveSheet();
  669. for(let i = 0; i < sheet.getRowCount(); i++){
  670. let checked = sheet.getValue(i, 0);
  671. if(checked){
  672. rst.push(i);
  673. }
  674. }
  675. return rst;
  676. }
  677. //清空选中定额表行
  678. //@param {Array}rows @return {void}
  679. function clearCheckedRation(rows) {
  680. let sheet = ration.workBook.getActiveSheet();
  681. renderSheetFunc(sheet, function () {
  682. for(let row of rows){
  683. sheet.setValue(row, 0, 0);
  684. }
  685. });
  686. }
  687. //获取要插入的定额数据
  688. //@param {Array}rows @return {Array}
  689. function getInsertRations(rows){
  690. let rst = [];
  691. //当前已存在定额
  692. let curRationIems = [];
  693. let selected = bills.tree.selected.guidance.tree.selected;
  694. if(selected){
  695. if(selected.data.type === itemType.job){
  696. curRationIems = selected.children;
  697. }
  698. else {
  699. curRationIems = selected.parent ? selected.parent.children : selected.tree.roots;
  700. }
  701. }
  702. for(let row of rows){
  703. let selRation = ration.cache[row];
  704. if(selRation){
  705. //添加的定额是否已存在,不重复添加
  706. let isExist = false;
  707. for(let curRation of curRationIems){
  708. if(curRation.data.rationID == selRation.ID){
  709. isExist = true;
  710. break;
  711. }
  712. }
  713. if(!isExist){
  714. rst.push({type: itemType.ration, name: getRationItemName(selRation), rationID: selRation.ID});
  715. }
  716. }
  717. }
  718. return rst;
  719. }
  720. //初始化个按钮点击
  721. //@return {void}
  722. function initBtn(){
  723. $('#insert').click(function () {
  724. insert([{type: itemType.job, name: ''}]);
  725. });
  726. $('#del').click(function () {
  727. del();
  728. });
  729. $('#upLevel').click(function () {
  730. upLevel();
  731. });
  732. $('#downLevel').click(function () {
  733. downLevel();
  734. });
  735. $('#upMove').click(function () {
  736. upMove();
  737. });
  738. $('#downMove').click(function () {
  739. downMove();
  740. });
  741. $('#insertRation').click(function () {
  742. let checkedRows = getCheckedRationRows();
  743. let insertDatas = getInsertRations(checkedRows);
  744. if(insertDatas.length > 0){
  745. insert(insertDatas, function () {
  746. //清空选择
  747. clearCheckedRation(checkedRows);
  748. });
  749. }
  750. else {
  751. clearCheckedRation(checkedRows);
  752. }
  753. });
  754. }
  755. //初始化视图
  756. //@param {void} @return {void}
  757. function initViews(){
  758. let modules = [bills, guideItem, ration];
  759. initWorkBooks(modules);
  760. getLibWithBills(libID);
  761. initBtn();
  762. }
  763. return {initViews};
  764. })();
  765. $(document).ready(function () {
  766. billsGuidance.initViews();
  767. });