pm_share.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2018/6/28
  7. * @version
  8. */
  9. const pmShare = (function () {
  10. const spreadDom = $('#shareSpread');
  11. let spreadObj = {workBook: null, sheet: null};
  12. let preSelection = null;
  13. //项目分享类型,由别人分享给自己的,和自己分享给别人的
  14. const shareType = {receive: 'receive', shareTo: 'shareTo'};
  15. //操作类型
  16. const oprType = {copy: 'copy', cancel: 'cancel'};
  17. let tree = null,
  18. actualIDShareInfo = {};//项目真实树ID与项目分享信息映射
  19. let curCopySelTree = null; //拷贝工程建设项目选项树
  20. const treeCol = 0;
  21. const treeSetting = {
  22. tree: {
  23. id: 'ID',
  24. pid: 'ParentID',
  25. nid: 'NextSiblingID',
  26. rootId: -1,
  27. autoUpdate: false
  28. }
  29. };
  30. const headers = [
  31. {name: '工程列表', dataCode: 'name', width: 300, rateWidth: 0.55, vAlign: 'center', hAlign: 'left'},
  32. {name: '来自', dataCode: 'from', width: 80, rateWidth: 0.15, vAlign: 'center', hAlign: 'left'},
  33. {name: '分享时间', dataCode: 'shareDate', width: 140, rateWidth: 0.15, vAlign: 'center', hAlign: 'left'},
  34. {name: '工程造价', dataCode: 'engineeringCost', width: 100, vAlign: 'center', hAlign: 'right', formatter: '0.00'},
  35. {name: '分部分项合计', dataCode: 'subEngineering', width: 100, vAlign: 'center', hAlign: 'right', formatter: '0.00'},
  36. {name: '措施项目合计', dataCode: 'measure', width: 100, vAlign: 'center', hAlign: 'right', formatter: '0.00'},
  37. {name: '其他项目合计', dataCode: 'other', width: 100, vAlign: 'center', hAlign: 'right', formatter: '0.00'},
  38. {name: '规费', dataCode: 'charge', width: 100, vAlign: 'center', hAlign: 'right', formatter: '0.00'},
  39. {name: '税金', dataCode: 'tax', width: 100, vAlign: 'center', hAlign: 'right', formatter: '0.00'},
  40. {name: '占造价比例(%)', dataCode: 'rate', width: 100, vAlign: 'center', hAlign: 'right', formatter: '0.00'},
  41. {name: '建筑面积', dataCode: 'buildingArea', width: 100, vAlign: 'center', hAlign: 'right', formatter: '0.00'},
  42. {name: '单方造价', dataCode: 'perCost', width: 100, vAlign: 'center', hAlign: 'right', formatter: '0.00'},
  43. {name: '工程专业', dataCode: 'feeStandardName', width: 100, vAlign: 'center', hAlign: 'left'},
  44. ];
  45. const spreadOpts = {
  46. workBook: {
  47. tabStripVisible: false,
  48. allowContextMenu: false,
  49. allowCopyPasteExcelStyle : false,
  50. allowExtendPasteRange: false,
  51. allowUserDragDrop : false,
  52. allowUserDragFill: false,
  53. scrollbarMaxAlign : true
  54. },
  55. sheet: {
  56. isProtected: true,
  57. protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
  58. clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
  59. }
  60. };
  61. const spreadEvents = {
  62. SelectionChanging: function (sender, info) {
  63. initSelection(info.newSelections[0], info.oldSelections[0]);
  64. }
  65. };
  66. //设置选中行底色
  67. //@param
  68. function setSelStyle(sel, backColor,sheet) {
  69. sel.row = sel.row === -1 ? 0 : sel.row;
  70. renderSheetFunc(sheet, function () {
  71. let style = projTreeObj.getSelStyle(backColor);
  72. for(let i = 0; i < sel.rowCount; i++){
  73. let row = i + sel.row;
  74. sheet.setStyle(row, -1, style);
  75. }
  76. });
  77. }
  78. //初始化焦点
  79. //@param {Object}newSel {Object}oldSel @return {void}
  80. function initSelection(newSel, oldSel = null) {
  81. let node = tree.items[newSel.row];
  82. tree.selected = node;
  83. shareSeleted = node;
  84. //恢复底色
  85. if(oldSel){
  86. setSelStyle(oldSel, projTreeObj.setting.style.defalutBackColor, spreadObj.sheet);
  87. }
  88. //设置选中行底色
  89. if(newSel){
  90. setSelStyle(newSel, projTreeObj.setting.style.selectedColor, spreadObj.sheet);
  91. }
  92. preSelection = newSel;
  93. }
  94. //渲染时方法,停止渲染
  95. //@param {Object}sheet {Function}func @return {void}
  96. function renderSheetFunc(sheet, func){
  97. sheet.suspendEvent();
  98. sheet.suspendPaint();
  99. if(func){
  100. func();
  101. }
  102. sheet.resumeEvent();
  103. sheet.resumePaint();
  104. }
  105. //设置表选项
  106. //@param {Object}workBook {Object}opts @return {void}
  107. function setSpreadOptions (workBook, opts) {
  108. for(let opt in opts.workBook){
  109. workBook.options[opt] = opts.workBook[opt];
  110. }
  111. for(let opt in opts.sheet){
  112. workBook.getActiveSheet().options[opt] = opts.sheet[opt];
  113. }
  114. }
  115. //建表头
  116. //@param {Object}sheet {Array}headers @return {void}
  117. function buildHeader(sheet, headers) {
  118. let fuc = function () {
  119. sheet.setColumnCount(headers.length);
  120. sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
  121. //let spreadWidth = getWorkBookWidth();
  122. for(let i = 0, len = headers.length; i < len; i++){
  123. sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
  124. if(headers[i].formatter){
  125. sheet.setFormatter(-1, i, headers[i].formatter);
  126. }
  127. sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
  128. sheet.getRange(-1, i, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[i]['hAlign']]);
  129. sheet.getRange(-1, i, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[i]['vAlign']]);
  130. }
  131. };
  132. renderSheetFunc(sheet, fuc);
  133. }
  134. //表监听事件
  135. //@param {Object}workBook @return {void}
  136. function bindEvent(workBook, events) {
  137. if(Object.keys(events).length === 0){
  138. return;
  139. }
  140. const Events = GC.Spread.Sheets.Events;
  141. for(let event in events){
  142. workBook.bind(Events[event], events[event]);
  143. }
  144. }
  145. //建表
  146. //@return {void}
  147. function buildSheet(){
  148. spreadObj.workBook = new GC.Spread.Sheets.Workbook(spreadDom[0], {sheetCount: 1});
  149. sheetCommonObj.spreadDefaultStyle(spreadObj.workBook);
  150. spreadObj.sheet = spreadObj.workBook.getActiveSheet();
  151. setSpreadOptions(spreadObj.workBook, spreadOpts);
  152. bindEvent(spreadObj.workBook, spreadEvents);
  153. buildHeader(spreadObj.sheet, headers);
  154. //全表不可编辑
  155. spreadObj.sheet.getRange(-1, -1, -1, -1).locked(true);
  156. }
  157. //此项目的分享权限信息(可能会被父级项目覆盖,以新为准)
  158. //@param {String}userID(本用户id) {Object}project(项目) @return {Object} || {Null}
  159. function getShareInfo(userID, project) {
  160. if (!project.actualTreeInfo) {
  161. return null;
  162. }
  163. //获取跟本用户和选中项目相关的分享信息
  164. let shareList = [];
  165. let actualID = project.actualTreeInfo.ID,
  166. actualData = actualIDShareInfo[actualID];
  167. while (actualData) {
  168. for (let data of actualData.shareInfo) {
  169. if (data.userID === userID) {
  170. shareList.push(data);
  171. break;
  172. }
  173. }
  174. actualData = actualIDShareInfo[actualData.ParentID];
  175. }
  176. //获取最新分享
  177. shareList.sort(function (a, b) {
  178. let aV = Date.parse(a.shareDate),
  179. bV = Date.parse(b.shareDate);
  180. if (aV > bV) {
  181. return -1;
  182. } else if (aV < bV) {
  183. return 1;
  184. }
  185. return 0;
  186. });
  187. return shareList[0] || null;
  188. }
  189. //此项目是否可以拷贝
  190. //@param {String}userID {Object}project @return {Boolean}
  191. function isAllowCopy(userID, project){
  192. let myShareInfo = getShareInfo(userID, project);
  193. if (!myShareInfo) {
  194. return false;
  195. }
  196. return !!myShareInfo.allowCopy;
  197. }
  198. //此项目是否可以协作
  199. //@param {String}userID {Object}project @return {Boolean}
  200. function isAllowCoop(userID, project) {
  201. let myShareInfo = getShareInfo(userID, project);
  202. if (!myShareInfo) {
  203. return false;
  204. }
  205. return !!myShareInfo.allowCooperate;
  206. }
  207. //获取树节点
  208. //@param {Object}tree @return {Object}
  209. function getTreeNodeCell(tree){
  210. let indent = 20;
  211. let levelIndent = -5;
  212. let halfBoxLength = 5;
  213. let halfExpandLength = 3;
  214. let imgWidth = 18;
  215. let imgHeight = 14;
  216. let TreeNodeCellType = function () {
  217. };
  218. TreeNodeCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  219. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  220. if (style.backColor) {
  221. ctx.save();
  222. ctx.fillStyle = style.backColor;
  223. ctx.fillRect(x, y, w, h);
  224. ctx.restore();
  225. } else {
  226. ctx.clearRect(x, y, w, h);
  227. }
  228. let drawLine = function (canvas, x1, y1, x2, y2, color) {
  229. ctx.save();
  230. ctx.translate(0.5, 0.5);
  231. ctx.beginPath();
  232. ctx.moveTo(x1, y1);
  233. ctx.lineTo(x2, y2);
  234. ctx.strokeStyle = color;
  235. ctx.stroke();
  236. ctx.restore();
  237. };
  238. let drawExpandBox = function (ctx, x, y, w, h, centerX, centerY, expanded) {
  239. let rect = {}, h1, h2, offset = 1;
  240. rect.top = centerY - halfBoxLength;
  241. rect.bottom = centerY + halfBoxLength;
  242. rect.left = centerX - halfBoxLength;
  243. rect.right = centerX + halfBoxLength;
  244. if (rect.left < x + w) {
  245. rect.right = Math.min(rect.right, x + w);
  246. ctx.save();
  247. ctx.translate(0.5, 0.5);
  248. ctx.strokeStyle = 'black';
  249. ctx.beginPath();
  250. ctx.moveTo(rect.left, rect.top);
  251. ctx.lineTo(rect.left, rect.bottom);
  252. ctx.lineTo(rect.right, rect.bottom);
  253. ctx.lineTo(rect.right, rect.top);
  254. ctx.lineTo(rect.left, rect.top);
  255. ctx.stroke();
  256. ctx.fillStyle = 'white';
  257. ctx.fill();
  258. ctx.restore();
  259. // Draw Horizontal Line
  260. h1 = centerX - halfExpandLength;
  261. h2 = Math.min(centerX + halfExpandLength, x + w);
  262. if (h2 > h1) {
  263. drawLine(ctx, h1, centerY, h2, centerY, 'black');
  264. }
  265. // Draw Vertical Line
  266. if (!expanded && (centerX < x + w)) {
  267. drawLine(ctx, centerX, centerY - halfExpandLength, centerX, centerY + halfExpandLength, 'black');
  268. }
  269. }
  270. }
  271. let node = tree.items[options.row];
  272. let showTreeLine = true;
  273. if (!node) { return; }
  274. let centerX = Math.floor(x) + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  275. let x1 = centerX + indent / 2;
  276. let centerY = Math.floor((y + (y + h)) / 2);
  277. let y1;
  278. // Draw Sibling Line
  279. if (showTreeLine) {
  280. // Draw Horizontal Line
  281. if (centerX < x + w) {
  282. drawLine(ctx, centerX, centerY, Math.min(x1, x + w), centerY, 'gray');
  283. let img;
  284. if(node.data.projType === projectType.folder){
  285. img = document.getElementById('folder_open_pic');
  286. imgWidth = 15;
  287. }
  288. else if(node.data.projType === projectType.project){
  289. img = document.getElementById('proj_pic');
  290. imgWidth = 18;
  291. }
  292. else if(node.data.projType === projectType.engineering){
  293. img = document.getElementById('eng_pic');
  294. imgWidth = 14;
  295. }
  296. else if(node.data.projType === projectType.tender){
  297. img = document.getElementById('tender_pic');
  298. imgWidth = 14;
  299. }
  300. ctx.drawImage(img, centerX+indent/2+3, centerY - 7, imgWidth,imgHeight);
  301. }
  302. // Draw Vertical Line
  303. if (centerX < x + w) {
  304. y1 = node.isLast() ? centerY : y + h;
  305. if (node.isFirst() && !node.parent.parent) {
  306. drawLine(ctx, centerX, centerY, centerX, y1, 'gray');
  307. } else {
  308. drawLine(ctx, centerX, y, centerX, y1, 'gray');
  309. }
  310. }
  311. }
  312. // Draw Expand Box
  313. if (node.children.length > 0) {
  314. drawExpandBox(ctx, x, y, w, h, centerX, centerY, node.expanded);
  315. }
  316. // Draw Parent Line
  317. if (showTreeLine) {
  318. var parent = node.parent, parentCenterX = centerX - indent - levelIndent;
  319. while (parent.parent) {
  320. if (!parent.isLast()) {
  321. if (parentCenterX < x + w) {
  322. drawLine(ctx, parentCenterX, y, parentCenterX, y + h, 'gray');
  323. }
  324. }
  325. parent = parent.parent;
  326. parentCenterX -= (indent + levelIndent);
  327. }
  328. };
  329. // Draw Text
  330. arguments[2] = x + (node.depth() + 1) * indent + node.depth() * levelIndent + imgWidth + 3;
  331. arguments[4] = w - (node.depth() + 1) * indent - node.depth() * levelIndent - imgWidth - 3;
  332. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  333. };
  334. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  335. let info = {x: x, y: y, row: context.row, col: context.col, cellStyle: cellStyle, cellRect: cellRect, sheetArea: context.sheetArea};
  336. let node = tree.items[info.row];
  337. if (node && node.data.projType === projectType.tender) {
  338. info.isReservedLocation = true;
  339. }
  340. return info;
  341. };
  342. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  343. let offset = -1;
  344. let node = tree.items[hitinfo.row];
  345. let centerX = hitinfo.cellRect.x + offset + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  346. let centerY = (hitinfo.cellRect.y + offset + (hitinfo.cellRect.y + offset + hitinfo.cellRect.height)) / 2;
  347. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  348. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  349. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  350. zoom = hitinfo.sheet.zoom();
  351. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  352. //(图标+名字)区域
  353. function withingClickArea(){
  354. return hitinfo.x > centerX + halfBoxLength && hitinfo.x < centerX + halfBoxLength + imgWidth + indent/2+3 + textLength;
  355. }
  356. //点击单位工程
  357. if(node.data.projType === projectType.tender){
  358. /*let newTab = window.open('about:blank');
  359. //打开项目的实际ID
  360. BeforeOpenProject(node.data.actualTreeInfo.ID, {'fullFolder': GetFullFolder(node.parent)}, function () {
  361. let mainUrl = `/main?project=${node.data.actualTreeInfo.ID}`;
  362. CommonAjax.get(mainUrl, [], function () {
  363. newTab.location.href = mainUrl;
  364. });
  365. });*/
  366. let thisClick = Date.now(),
  367. open = false;
  368. if (this.preNode === node && this.preClick && thisClick - this.preClick <= 300) {
  369. open = true;
  370. projTreeObj.openTender(node.data.actualTreeInfo.ID, node.parent, 200);
  371. }
  372. this.preClick = open ? null : thisClick;
  373. this.preNode = open ? null : node;
  374. }
  375. if (!node || node.children.length === 0) {
  376. return;
  377. }
  378. if (hitinfo.x >= centerX - halfBoxLength - 2 && hitinfo.x <= centerX + halfBoxLength + 2 &&
  379. hitinfo.y >= centerY - halfBoxLength - 2 && hitinfo.y <= centerY + halfBoxLength + 2) {
  380. node.setExpanded(!node.expanded);
  381. TREE_SHEET_HELPER.massOperationSheet(hitinfo.sheet, function () {
  382. let iCount = node.posterityCount(), i, child;
  383. for (i = 0; i < iCount; i++) {
  384. child = tree.items[hitinfo.row + i + 1];
  385. hitinfo.sheet.setRowVisible(hitinfo.row + i + 1, child.visible, hitinfo.sheetArea);
  386. }
  387. hitinfo.sheet.invalidateLayout();
  388. });
  389. hitinfo.sheet.repaint();
  390. }
  391. };
  392. /*TreeNodeCellType.prototype.processMouseMove = function (hitInfo) {
  393. let sheet = hitInfo.sheet;
  394. let div = sheet.getParent().getHost();
  395. let canvasId = div.id + "vp_vp";
  396. let canvas = $(`#${canvasId}`)[0];
  397. //改变鼠标图案
  398. if (sheet && hitInfo.isReservedLocation) {
  399. canvas.style.cursor='pointer';
  400. return true;
  401. }else{
  402. canvas.style.cursor='default';
  403. }
  404. return false;
  405. };*/
  406. TreeNodeCellType.prototype.processMouseEnter = function (hitinfo) {
  407. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  408. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  409. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  410. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  411. zoom = hitinfo.sheet.zoom();
  412. let node = tree.items[hitinfo.row];
  413. let nodeIndent = node ? (node.depth() + 1) * indent + node.depth() * levelIndent + imgWidth + 3 : 0;
  414. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  415. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  416. if(textLength > cellWidth - nodeIndent){
  417. TREE_SHEET_HELPER.showTipsDiv(text,{pos: {}},hitinfo);
  418. }
  419. };
  420. TreeNodeCellType.prototype.processMouseLeave = function (hitinfo) {
  421. TREE_SHEET_HELPER.tipDiv = 'hide';
  422. if (TREE_SHEET_HELPER._toolTipElement) {
  423. $(TREE_SHEET_HELPER._toolTipElement).hide();
  424. TREE_SHEET_HELPER._toolTipElement = null;
  425. };
  426. TREE_SHEET_HELPER.tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  427. }
  428. return new TreeNodeCellType();
  429. }
  430. //互动单元格
  431. function getInteractionCell() {
  432. let workImg = document.getElementById('work_pic'),
  433. workImgWidth = 13,
  434. workImgHeight = 13,
  435. copyImg = document.getElementById('copy_pic'),
  436. copyImgWidth = 13,
  437. copyImgHeight = 13;
  438. let InteractionCell = function () {
  439. };
  440. InteractionCell.prototype = new GC.Spread.Sheets.CellTypes.Text();
  441. InteractionCell.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  442. if (style.backColor) {
  443. ctx.save();
  444. ctx.fillStyle = style.backColor;
  445. ctx.fillRect(x, y, w, h);
  446. ctx.restore();
  447. } else {
  448. ctx.clearRect(x, y, w, h);
  449. }
  450. let node = tree.items[options.row];
  451. // Draw Text
  452. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  453. if (node && node.data.projType === projectType.tender) {
  454. let text = options.sheet.getText(options.row, options.col);
  455. let acStyle = options.sheet.getActualStyle(options.row, options.col),
  456. zoom = options.sheet.zoom();
  457. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: options.sheet, row: options.row, col: options.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  458. let nowX = Math.floor(x) + textLength + 3,
  459. nowY = Math.floor((y + (y + h)) / 2) - 7;
  460. if (node.data.allowCooperate) {
  461. ctx.drawImage(workImg, nowX, nowY, workImgWidth, workImgHeight);
  462. nowX += workImgWidth;
  463. }
  464. if (node.data.allowCopy) {
  465. ctx.drawImage(copyImg, nowX, nowY, copyImgWidth, copyImgHeight);
  466. }
  467. }
  468. };
  469. InteractionCell.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  470. return {
  471. x: x,
  472. y: y,
  473. row: context.row,
  474. col: context.col,
  475. cellStyle: cellStyle,
  476. cellRect: cellRect,
  477. sheetArea: context.sheetArea,
  478. isReservedLocation: true
  479. };
  480. };
  481. InteractionCell.prototype.processMouseDown = function (hitinfo) {
  482. let dataCode = headers[hitinfo.col]['dataCode'];
  483. let node = tree.items[hitinfo.row];
  484. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  485. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  486. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  487. zoom = hitinfo.sheet.zoom();
  488. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  489. if(hitinfo.x - hitinfo.cellRect.x > 0 && hitinfo.x - hitinfo.cellRect.x < textLength){
  490. //由..分享,弹出分享者信息
  491. if(dataCode === 'from'){
  492. if(node.data.shareType === shareType.receive){
  493. $('#userinfo').find('h4').text(node.data.userInfo.name);
  494. $('#userinfo').find('h6').text(node.data.userInfo.company);
  495. let mobileHtml = `<i class="fa fa-tablet"> ${node.data.userInfo.mobile ? node.data.userInfo.mobile : ''}</i>`;
  496. $('#userinfo').find('li:first-child').html(mobileHtml);
  497. let emailHtml = `<i class="fa fa-envelope-o"> ${node.data.userInfo.email ? node.data.userInfo.email : ''}</i>`;
  498. $('#userinfo').find('li:last-child').html(emailHtml);
  499. $('#userinfo').modal('show');
  500. }
  501. }
  502. }
  503. };
  504. InteractionCell.prototype.processMouseMove = function (hitInfo) {
  505. let dataCode = headers[hitInfo.col]['dataCode'];
  506. let node = tree.items[hitInfo.row];
  507. let sheet = hitInfo.sheet;
  508. let div = sheet.getParent().getHost();
  509. let canvasId = div.id + "vp_vp";
  510. let canvas = $(`#${canvasId}`)[0];
  511. //改变鼠标图案
  512. let text = hitInfo.sheet.getText(hitInfo.row, hitInfo.col);
  513. let value = hitInfo.sheet.getValue(hitInfo.row, hitInfo.col);
  514. let acStyle = hitInfo.sheet.getActualStyle(hitInfo.row, hitInfo.col),
  515. zoom = hitInfo.sheet.zoom();
  516. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitInfo.sheet, row: hitInfo.row, col: hitInfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  517. if (sheet && hitInfo.x - hitInfo.cellRect.x > 0 && hitInfo.x - hitInfo.cellRect.x < textLength) {
  518. canvas.style.cursor='pointer';
  519. return true;
  520. }else{
  521. canvas.style.cursor='default';
  522. }
  523. return false;
  524. };
  525. return new InteractionCell();
  526. }
  527. //设置分享给界面数据
  528. //@param {Object}selected @return {void}
  529. function setShareToModal(selected){
  530. $('#shareToInfo').empty();
  531. if(!selected){
  532. return;
  533. }
  534. let userIDs = [];
  535. for(let user of selected.data.shareInfo){
  536. userIDs.push(user.userID);
  537. }
  538. CommonAjax.post('/user/getUsers', {userIDs: userIDs}, function (rstData) {
  539. for(let userInfo of rstData){
  540. for(let user of selected.data.shareInfo){
  541. if(user.userID === userInfo._id){
  542. user.name = userInfo.real_name;
  543. user.company = userInfo.company;
  544. user.mobile = userInfo.mobile;
  545. user.email = userInfo.email;
  546. }
  547. }
  548. }
  549. let infoArr = [];
  550. for(let user of selected.data.shareInfo){
  551. let infoHtml = `<tr>
  552. <td style="width: 106px;">${user.name}</td>
  553. <td style="width: 146px;">${user.company}</td>
  554. <td style="width: 146px;">${user.mobile}</td>
  555. <td style="width: 156px;">${user.email}</td>
  556. <td style="width: 70px;text-align: center"><input value="allowCopy" ${user.allowCopy ? 'checked' : ''} type="checkbox"></td>
  557. <td style="width: 70px;text-align: center"><input value="cancelShare" type="checkbox"></td>
  558. </tr>`;
  559. infoArr.push(infoHtml);
  560. }
  561. let infoHtml = infoArr.join('');
  562. $('#shareToInfo').html(infoHtml);
  563. });
  564. }
  565. //更新项目分享信息
  566. //@param {Object}selected
  567. function updateShareInfo(selected){
  568. if(!selected){
  569. return;
  570. }
  571. let usersTr = $('#shareToInfo').find('tr');
  572. let newShareInfo = [];
  573. for(let i = 0; i < usersTr.length; i++){
  574. let userTr = usersTr[i];
  575. let allowCopy = $(userTr).find('input:first').prop('checked');
  576. let cancelShare = $(userTr).find('input:last').prop('checked');
  577. selected.data.shareInfo[i].allowCopy = allowCopy;
  578. if(!cancelShare){
  579. newShareInfo.push(selected.data.shareInfo[i]);
  580. }
  581. }
  582. CommonAjax.post('/pm/api/updateProjects', {user_id: userID, updateData: [{updateType: 'update', updateData: {ID: selected.data.ID, shareInfo: newShareInfo}}]}, function () {
  583. selected.data.shareInfo = newShareInfo;
  584. if(newShareInfo.length === 0){
  585. renderSheetFunc(spreadObj.sheet, function () {
  586. let rIdx = selected.serialNo();
  587. tree.removeNode(selected);
  588. spreadObj.sheet.deleteRows(rIdx, 1);
  589. spreadObj.sheet.setRowCount(tree.items);
  590. initSelection({row: spreadObj.sheet.getActiveRowIndex(), rowCount: 1},null);
  591. });
  592. }
  593. });
  594. }
  595. const foreColor = '#007bff';
  596. const cancelForeColor = 'red';
  597. //显示树结构数据
  598. //@param {Array}nodes {Array}headers @return {void}
  599. function showTreeData(nodes, headers){
  600. let sheet = spreadObj.workBook.getActiveSheet();
  601. let fuc = function(){
  602. sheet.setRowCount(nodes.length);
  603. for(let i = 0; i < nodes.length; i++){
  604. let treeNodeCell = getTreeNodeCell(tree);
  605. sheet.getCell(i, treeCol).cellType(treeNodeCell);
  606. for(let j = 0; j < headers.length; j++){
  607. sheet.getRange(-1, j, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[j]['hAlign']]);
  608. sheet.getRange(-1, j, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[j]['vAlign']]);
  609. let dataCode = headers[j].dataCode;
  610. if(dataCode === 'from'){
  611. let style = new GC.Spread.Sheets.Style();
  612. style.foreColor = foreColor;
  613. sheet.setStyle(i, j, style);
  614. sheet.getCell(i, j).cellType(getInteractionCell());
  615. }
  616. sheet.setValue(i, j, nodes[i].data[dataCode] !== null && typeof nodes[i].data[dataCode] !== 'undefined' ? nodes[i].data[dataCode] : '');
  617. }
  618. }
  619. };
  620. renderSheetFunc(sheet, fuc);
  621. }
  622. //同一棵树,可能存在相同数据显示多条的问题(传入的datas中不存在相同数据)
  623. //将真实树结构数据存在actualTreeInfo中,外部树结构数据用uuid重置。
  624. //@param {Array}datas
  625. function setTreeInfo(datas) {
  626. let IDMapping = {};
  627. for (let data of datas) {
  628. //项目真实ID与项目分享信息映射,方便确定项目的权限
  629. if (!actualIDShareInfo[data.ID]) {
  630. actualIDShareInfo[data.ID] = {ID: data.ID, ParentID: data.ParentID, NextSiblingID: data.NextSiblingID, shareInfo: data.shareInfo};
  631. }
  632. IDMapping[data.ID] = uuid.v1();
  633. }
  634. for (let data of datas) {
  635. data.actualTreeInfo = {ID: data.ID, ParentID: data.ParentID, NextSiblingID: data.NextSiblingID};
  636. data.ID = IDMapping[data.ID];
  637. data.NextSiblingID = IDMapping[data.NextSiblingID] ? IDMapping[data.NextSiblingID] : -1;
  638. data.ParentID = IDMapping[data.ParentID] ? IDMapping[data.ParentID] : -1;
  639. }
  640. }
  641. //整理同层数据的NextSiblingID,ParentID
  642. //@param {Array}datas {Number || String}pid @return {void}
  643. function sortSameDepthData(datas, pid) {
  644. for (let i = 0; i < datas.length; i++) {
  645. let data = datas[i],
  646. nextData = datas[i + 1];
  647. data.NextSiblingID = nextData ? nextData.ID : -1;
  648. data.ParentID = pid;
  649. }
  650. }
  651. //给项目设置分享信息:由xx分享、分享时间、分享给我,含有userInfo信息的文件为他人直接分享的文件,他人分享父级文件,子文件不含有userInfo信息
  652. //@param {Array}datas @return {void}
  653. function setShareInfo(datas) {
  654. for (let data of datas) {
  655. if (data.userInfo) {
  656. //shareInfo中我的条目
  657. let selfInfo = _.find(data.shareInfo, {userID: userID});
  658. data.shareDate = selfInfo ? selfInfo.shareDate : ''
  659. data.from = data.userInfo.name;
  660. data.to = '分享给 我';
  661. data.cancel = '清除';
  662. }
  663. }
  664. }
  665. //给项目设置汇总信息
  666. //@param {Array}projs {Object}summaryInfo
  667. function setSummaryInfo(grouped, summaryInfo) {
  668. if (!summaryInfo) {
  669. return;
  670. }
  671. let allDatas = [];
  672. for (let data of grouped) {
  673. allDatas.push(data);
  674. if (data.children && data.children.length > 0) {
  675. allDatas = allDatas.concat(data.children);
  676. }
  677. }
  678. for(let proj of allDatas){
  679. let summaryProj = summaryInfo[proj.ID];
  680. if(summaryProj){
  681. proj.engineeringCost = summaryProj.engineeringCost;
  682. proj.subEngineering = summaryProj.subEngineering;
  683. proj.measure = summaryProj.measure;
  684. proj.safetyConstruction = summaryProj.safetyConstruction;
  685. proj.other = summaryProj.other;
  686. proj.charge = summaryProj.charge;
  687. proj.tax = summaryProj.tax;
  688. proj.rate = summaryProj.rate;
  689. proj.buildingArea = summaryProj.buildingArea;
  690. proj.perCost = summaryProj.perCost;
  691. }
  692. }
  693. }
  694. //从同层树数据获取第一个节点ID
  695. //@param {Array}treeDatas树的数据 @return {String}第一个节点的虚拟树ID
  696. function getFirstID(treeDatas) {
  697. let treeMapping = {};
  698. //建立ID索引
  699. for (let data of treeDatas) {
  700. //新建一个简单对象,防止污染treeDatas的数据
  701. treeMapping[data.ID] = {ID: data.ID, prev: null, next: null};
  702. }
  703. //绑定prev next
  704. for (let data of treeDatas) {
  705. let me = treeMapping[data.ID],
  706. next = treeMapping[data.NextSiblingID];
  707. if (next) {
  708. me.next = next;
  709. next.prev = me;
  710. }
  711. }
  712. //返回没有prev属性的数据
  713. let result = _.find(treeDatas, function (data) {
  714. return !treeMapping[data.ID].prev
  715. });
  716. return result ? result.ID : -1;
  717. }
  718. //获取可成树的数据
  719. //@param {Array}datas @return {Array}
  720. function getTreeDatas(groupedDatas, ungroupedDatas){
  721. //设置新的树结构数据
  722. for (let data of groupedDatas) {
  723. setTreeInfo([data].concat(data.children));
  724. }
  725. let engs = _.filter(ungroupedDatas, {projType: projectType.engineering}),
  726. tenders = _.filter(ungroupedDatas, {projType: projectType.tender});
  727. for (let data of engs) {
  728. setTreeInfo([data].concat(data.children));
  729. }
  730. setTreeInfo(tenders);
  731. let rst = [];
  732. //整理树结构
  733. sortSameDepthData(groupedDatas, -1);
  734. //第一个根节点数据
  735. let firstID = getFirstID(groupedDatas);
  736. //新建未分类建设项目及单项工程
  737. let ungroupedProj = {ID: uuid.v1(), ParentID: -1, NextSiblingID: firstID, name: '未分类建设项目', projType: projectType.project};
  738. let ungroupedEng = {ID: uuid.v1(), ParentID: ungroupedProj.ID, NextSiblingID: -1, name: '未分类单项工程', projType: projectType.engineering};
  739. /*if (groupedDatas.length > 0) {
  740. groupedDatas[groupedDatas.length - 1].NextSiblingID = ungroupedProj.ID;
  741. }*/
  742. //将未分类的数据归类
  743. sortSameDepthData(engs, ungroupedProj.ID);
  744. sortSameDepthData(tenders, ungroupedEng.ID);
  745. //未分类单项工程处于同层第一个节点
  746. ungroupedEng.NextSiblingID = engs[0] ? engs[0].ID : ungroupedEng.NextSiblingID;
  747. let allDatas = groupedDatas.concat(ungroupedDatas);
  748. //设置分享信息及操作信息
  749. setShareInfo(allDatas);
  750. for (let data of allDatas) {
  751. rst.push(data);
  752. if (data.children) {
  753. rst = rst.concat(data.children);
  754. }
  755. }
  756. rst.push(ungroupedProj);
  757. rst.push(ungroupedEng);
  758. return rst;
  759. }
  760. //按照时间排序
  761. //@param {Array}datas @return {void}
  762. function sortByDate(datas){
  763. datas.sort(function (a, b) {
  764. let shareInfoA = _.find(a.shareInfo, {userID}),
  765. shareInfoB = _.find(b.shareInfo, {userID});
  766. let aV = shareInfoA ? Date.parse(shareInfoA.shareDate) : 0,
  767. bV = shareInfoB ? Date.parse(shareInfoB.shareDate) : 0;
  768. //时间越晚越靠前
  769. if (aV > bV) {
  770. return -1;
  771. } else if (aV < bV) {
  772. return 1;
  773. }
  774. return 0;
  775. });
  776. }
  777. //设置节点数据权限
  778. //@param {Array}datas项目数据
  779. function setPermissionsInfo(datas) {
  780. //data.allowCopy与shareInfo里allowCopy的区别:
  781. //data.allowCopy为该单位实际的权限(跟着最新的分享信息走,可能随着父项)
  782. for (let data of datas) {
  783. if (data.projType === projectType.tender) {
  784. data.allowCopy = isAllowCopy(userID, data);
  785. data.allowCooperate = isAllowCoop(userID, data);
  786. }
  787. }
  788. }
  789. //建立树
  790. //@return void
  791. function initShareTree(){
  792. $.bootstrapLoading.start();
  793. //获取分享数据
  794. CommonAjax.post('/pm/api/receiveProjects', {user_id: userID}, function (rstData) {
  795. // 排序 --分享的文件按照时间先后顺序排序,分享文件下的子文件,按照原本树结构显示,不需要排序
  796. sortByDate(rstData.grouped);
  797. sortByDate(rstData.ungrouped);
  798. //设置汇总信息
  799. if (rstData.summaryInfo) {
  800. setSummaryInfo(rstData.grouped, rstData.summaryInfo.grouped);
  801. setSummaryInfo(rstData.ungrouped, rstData.summaryInfo.ungrouped);
  802. }
  803. let treeDatas = getTreeDatas(rstData.grouped, rstData.ungrouped);
  804. setPermissionsInfo(treeDatas);
  805. tree = pmTree.createNew(treeSetting, treeDatas);
  806. tree.selected = tree.items[0];
  807. showTreeData(tree.items, headers);
  808. //初始选择
  809. let initSel = spreadObj.sheet.getSelections()[0] ? spreadObj.sheet.getSelections()[0] : {row: 0, rowCount: 1};
  810. initSelection(initSel);
  811. autoFlashHeight();
  812. spreadObj.sheet.frozenColumnCount(4);
  813. spreadObj.workBook.refresh();
  814. $.bootstrapLoading.end();
  815. });
  816. }
  817. //初始化右键菜单
  818. function initContextMenu() {
  819. $.contextMenu({
  820. selector: '#shareSpread',
  821. build: function ($trigger, e) {
  822. let target = SheetDataHelper.safeRightClickSelection($trigger, e, spreadObj.workBook);
  823. initSelection({row: target.row, rowCount: 1}, preSelection ? preSelection : null, spreadObj.sheet);
  824. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  825. },
  826. items: {
  827. "copy": {
  828. name: "拷贝工程",
  829. icon: 'fa-copy',
  830. disabled: function () {
  831. let selected = tree.selected;
  832. return !(selected && selected.data.allowCopy);
  833. },
  834. callback: function (key, opt) {
  835. $('#copyShare').modal('show');
  836. }
  837. },
  838. "cancel": {
  839. name: "清除",
  840. icon: 'fa-remove',
  841. disabled: function () {
  842. let selected = tree.selected;
  843. return !(selected && selected.data.cancel && selected.data.cancel === '清除');
  844. },
  845. callback: function (key, opt) {
  846. let $p = $('<p>').text(`点“确定”按钮,确认清除分享文件 “${tree.selected.data.name}”。`);
  847. $('#cancelShare').find('.modal-body').empty();
  848. $('#cancelShare').find('.modal-body').append($p);
  849. $('#cancelShare').modal('show');
  850. }
  851. }
  852. }
  853. });
  854. }
  855. //初始化视图
  856. //@return void
  857. function initView(){
  858. if(tree){
  859. tree = null;
  860. }
  861. if(spreadObj.workBook){
  862. spreadObj.workBook.destroy();
  863. spreadObj.workBook = null;
  864. }
  865. initContextMenu();
  866. buildSheet();
  867. initShareTree();
  868. }
  869. //根据建设项目获取单项工程
  870. //@param {Number}projID @return {void}
  871. function setEng(projID){
  872. let engQuery = {$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], projType: projectType.engineering, userID: userID, ParentID: projID};
  873. CommonAjax.post('/pm/api/getProjectsByQuery', {user_id: userID, query: engQuery, options: '-_id -property'}, function (rstData) {
  874. $('#copyShare_selectEng').empty();
  875. for(let eng of rstData){
  876. let opt = $('<option>').val(eng.ID).text(eng.name);
  877. $('#copyShare_selectEng').append(opt);
  878. }
  879. });
  880. }
  881. //从其他建设项目中复制中,建设项目的文件层次结构名称和顺序
  882. //@param {Array}treeData @return {Array}
  883. function getFileHierarchyInfo(treeData){
  884. curCopySelTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
  885. curCopySelTree.loadDatas(treeData);
  886. let items = curCopySelTree.items;
  887. let rst = [];
  888. function getFileHierarchyName(node){
  889. let nodeName = node.data.name;
  890. let name = [];
  891. while (node.parent){
  892. name.push(node.parent.data.name ? node.parent.data.name : '');
  893. node = node.parent;
  894. }
  895. name = name.reverse();
  896. name.push(nodeName);
  897. return name.join('\\');
  898. }
  899. for(let node of items){
  900. if(node.children.length === 0 ){//project
  901. rst.push({ID: node.data.ID, fileHierarchyName: getFileHierarchyName(node)})
  902. }
  903. }
  904. return rst;
  905. }
  906. //设置拷贝工程下拉选择
  907. //@return {void}
  908. function setCopyModal(){
  909. //获取建设项目
  910. let projQuery = {$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], projType: {$in: [projectType.project, projectType.folder]}, userID: userID};
  911. CommonAjax.post('/pm/api/getProjectsByQuery', {user_id: userID, query: projQuery, options: '-_id'}, function (rstData) {
  912. let fileHierarchyData = getFileHierarchyInfo(rstData);
  913. $('#copyShare_selectProj').empty();
  914. for(let proj of fileHierarchyData){
  915. let opt = $('<option>').val(proj.ID).text(proj.fileHierarchyName);
  916. $('#copyShare_selectProj').append(opt);
  917. }
  918. //初始选择
  919. if(fileHierarchyData.length > 0){
  920. setEng(fileHierarchyData[0].ID);
  921. }
  922. });
  923. }
  924. //拷贝分享的工程
  925. //@param {Object}selected {Number}parentID @return {void}
  926. function copyShareProject(selected, projID, engID){
  927. if(!engID || !selected){
  928. return;
  929. }
  930. let copyMap = {copy: null, update: null};
  931. let newName = getCopyName(selected);
  932. //获取单项工程的单位工程
  933. let tenderQuery = {$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], userID: userID, ParentID: engID};
  934. CommonAjax.post('/pm/api/getProjectsByQuery', {user_id: userID, query: tenderQuery, options: '-_id -property'}, function (rstData) {
  935. let updateTender = null;
  936. for(let tender of rstData){
  937. if(tender.name === newName){
  938. $('#copyShare_name').text('已存在此单位工程。');
  939. $('#copyShare_name').addClass('text-danger');
  940. return;
  941. }
  942. if(tender.NextSiblingID == -1){
  943. updateTender = tender;
  944. }
  945. }
  946. //更新前节点
  947. if(updateTender){
  948. copyMap.update = {query: {ID: updateTender.ID}};
  949. }
  950. //拷贝
  951. let copyData = {
  952. userID: userID,
  953. ID: selected.data.actualTreeInfo.ID,
  954. NextSiblingID: -1,
  955. ParentID: engID,
  956. name: newName,
  957. shareInfo: [],
  958. compilation: selected.data.compilation,
  959. createDateTime: selected.data.createDateTime,
  960. fileVer: selected.data.fileVer ? selected.data.fileVer : '',
  961. projType: selected.data.projType,
  962. property: {},
  963. recentDateTime: selected.data.recentDateTime,
  964. fullFolder: selected.data.fullFolder
  965. };
  966. copyData.property.rootProjectID = projID;
  967. copyMap.copy = {document: copyData};
  968. $('#copyShare').modal('hide');
  969. $.bootstrapLoading.start();
  970. CommonAjax.post('/pm/api/copyProjects', {projectMap: copyMap, user_id: userID}, function (rstData) {
  971. $.bootstrapLoading.end();
  972. }, function () {
  973. $.bootstrapLoading.end();
  974. });
  975. });
  976. }
  977. //获取拷贝后的名称
  978. //@param {Object}node @return {String}
  979. function getCopyName(node) {
  980. //当前单位工程可能没有分享的用户信息,可能他人分享的是父级文件,userInfo在父级文件中
  981. let orgName = node.data.name,
  982. userInfo = node.data.userInfo;
  983. while (node && !userInfo) {
  984. node = node.parent;
  985. userInfo = node.data.userInfo;
  986. }
  987. return `${orgName} (${userInfo.name}分享拷贝)`;
  988. }
  989. //事件监听器
  990. //@return void
  991. function eventListener(){
  992. //tab
  993. $('#tab_pm_share').on('shown.bs.tab', function () {
  994. //侧滑隐藏
  995. $('.slide-sidebar').removeClass('open');
  996. $('.slide-sidebar').css('width', '0');
  997. projTreeObj.tree = null;
  998. if(projTreeObj.workBook){
  999. projTreeObj.workBook.destroy();
  1000. projTreeObj.workBook = null;
  1001. }
  1002. gcTreeObj.tree = null;
  1003. if(gcTreeObj.workBook){
  1004. gcTreeObj.workBook.destroy();
  1005. gcTreeObj.workBook = null;
  1006. }
  1007. initView();
  1008. });
  1009. //关闭拷贝工程
  1010. $('#copyShare').on('hidden.bs.modal', function () {
  1011. $('#copyShareProj-info').hide();
  1012. $('#copyShareEng-info').hide();
  1013. });
  1014. //打开拷贝工程
  1015. $('#copyShare').on('shown.bs.modal', function () {
  1016. setCopyModal();
  1017. //更改显示名称
  1018. let newName = getCopyName(shareSeleted);
  1019. $('#copyShare_name').html(`拷贝后,工程将重命名为 "<b>${newName}</b>"`);
  1020. $('#copyShare_name').removeClass('text-danger');
  1021. });
  1022. //拷贝工程改变选择建设项目
  1023. $('#copyShare_selectProj').change(function () {
  1024. //更改显示名称
  1025. let newName = getCopyName(shareSeleted);
  1026. $('#copyShare_name').html(`拷贝后,工程将重命名为 "<b>${newName}</b>"`);
  1027. $('#copyShare_name').removeClass('text-danger');
  1028. $('#copyShareProj-info').hide();
  1029. $('#copyShareEng-info').hide();
  1030. let curSelID = $(this).select().val();
  1031. setEng(parseInt(curSelID));
  1032. });
  1033. //拷贝工程改变选择单项工程
  1034. $('#copyShare_selectEng').change(function () {
  1035. //更改显示名称
  1036. let newName = getCopyName(shareSeleted);
  1037. $('#copyShare_name').html(`拷贝后,工程将重命名为 "<b>${newName}</b>"`);
  1038. $('#copyShare_name').removeClass('text-danger');
  1039. });
  1040. //确认拷贝
  1041. $('#copyShare_confirm').click(function () {
  1042. let selProj = $('#copyShare_selectProj').select().val();
  1043. if(!selProj){
  1044. $('#copyShareProj-info').show();
  1045. return;
  1046. }
  1047. //目标建设项目的计税方法与单位工程的一致时,才可拷贝
  1048. if (curCopySelTree) {
  1049. let projectNode = curCopySelTree.nodes[curCopySelTree.prefix + selProj];
  1050. if (!projectNode || !projectNode.data.property || projectNode.data.property.taxType != tree.selected.data.taxType){
  1051. alert('当前单位工程计税方法与目标建设项目不一致,不可复制。');
  1052. return;
  1053. }
  1054. }
  1055. let selEng = $('#copyShare_selectEng').select().val();
  1056. if(!selEng){
  1057. $('#copyShareEng-info').show();
  1058. return;
  1059. }
  1060. copyShareProject(tree.selected, parseInt(selProj), parseInt(selEng));
  1061. });
  1062. //清除分享
  1063. //清除了该节点后,可能还有该节点的数据在树上(树允许有重复数据),需要更新分享信息
  1064. function updateAfterCancel(userID, projectID) {
  1065. for (let item of tree.items) {
  1066. if (item.data.actualTreeInfo && item.data.actualTreeInfo.ID === projectID) {
  1067. _.remove(item.data.shareInfo, function (data) {
  1068. return data.userID === userID;
  1069. });
  1070. }
  1071. }
  1072. }
  1073. $('#cancelShareConfirm').click(function () {
  1074. $.bootstrapLoading.start();
  1075. let cancelProjID = tree.selected.data.actualTreeInfo.ID;
  1076. CommonAjax.post('/pm/api/share', {user_id: userID, type: oprType.cancel, projectID: cancelProjID, shareData:[{userID: userID}]}, function (rstData) {
  1077. tree.removeNode(tree.selected);
  1078. //更新与清除节点数据相同,且为被清除缓存分享信息
  1079. updateAfterCancel(userID, cancelProjID);
  1080. //重新设置actualIDShareInfo,以正确更新权限(清除了分享信息后,可能会导致权限变化 eg:清除了新的分享,则存留的分享项目采用旧的)
  1081. actualIDShareInfo = {};
  1082. let treeDatas = [];
  1083. for (let item of tree.items) {
  1084. treeDatas.push(item.data);
  1085. let actualTreeInfo = item.data.actualTreeInfo;
  1086. if (actualTreeInfo && !actualIDShareInfo[actualTreeInfo.ID]) {
  1087. actualIDShareInfo[actualTreeInfo.ID] = {
  1088. ID: actualTreeInfo.ID,
  1089. ParentID: actualTreeInfo.ParentID,
  1090. NextSiblingID: actualTreeInfo.NextSiblingID,
  1091. shareInfo: item.data.shareInfo
  1092. };
  1093. }
  1094. }
  1095. //重新设置权限
  1096. setPermissionsInfo(treeDatas);
  1097. showTreeData(tree.items, headers);
  1098. $.bootstrapLoading.end();
  1099. }, function () {
  1100. $.bootstrapLoading.end();
  1101. });
  1102. });
  1103. }
  1104. return {spreadObj, headers, initView, eventListener}
  1105. })();
  1106. $(document).ready(function () {
  1107. pmShare.eventListener();
  1108. });