pm_share.js 50 KB

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