pm_share.js 48 KB

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