pm_share.js 48 KB

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