pm_share.js 51 KB

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