pm_share.js 49 KB

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