pm_share.js 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  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. debugger;
  756. // 排序 --分享的文件按照时间先后顺序排序,分享文件下的子文件,按照原本树结构显示,不需要排序
  757. sortByDate(rstData.grouped);
  758. sortByDate(rstData.ungrouped);
  759. //设置汇总信息
  760. if (rstData.summaryInfo) {
  761. setSummaryInfo(rstData.grouped, rstData.summaryInfo.grouped);
  762. setSummaryInfo(rstData.ungrouped, rstData.summaryInfo.ungrouped);
  763. }
  764. let treeDatas = getTreeDatas(rstData.grouped, rstData.ungrouped);
  765. setPermissionsInfo(treeDatas);
  766. tree = pmTree.createNew(treeSetting, treeDatas);
  767. tree.selected = tree.items[0];
  768. showTreeData(tree.items, headers);
  769. //初始选择
  770. let initSel = spreadObj.sheet.getSelections()[0] ? spreadObj.sheet.getSelections()[0] : {row: 0, rowCount: 1};
  771. initSelection(initSel);
  772. autoFlashHeight();
  773. spreadObj.sheet.frozenColumnCount(4);
  774. spreadObj.workBook.refresh();
  775. $.bootstrapLoading.end();
  776. });
  777. }
  778. //初始化右键菜单
  779. function initContextMenu() {
  780. $.contextMenu({
  781. selector: '#shareSpread',
  782. build: function ($trigger, e) {
  783. let target = SheetDataHelper.safeRightClickSelection($trigger, e, spreadObj.workBook);
  784. initSelection({row: target.row, rowCount: 1}, preSelection ? preSelection : null, spreadObj.sheet);
  785. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  786. },
  787. items: {
  788. "copy": {
  789. name: "拷贝工程",
  790. icon: 'fa-copy',
  791. disabled: function () {
  792. let selected = tree.selected;
  793. return !(selected && selected.data.allowCopy);
  794. },
  795. callback: function (key, opt) {
  796. $('#copyShare').modal('show');
  797. }
  798. },
  799. "cancel": {
  800. name: "清除",
  801. icon: 'fa-remove',
  802. disabled: function () {
  803. let selected = tree.selected;
  804. return !(selected && selected.data.cancel && selected.data.cancel === '清除');
  805. },
  806. callback: function (key, opt) {
  807. let $p = $('<p>').text(`点“确定”按钮,确认清除分享文件 “${tree.selected.data.name}”。`);
  808. $('#cancelShare').find('.modal-body').empty();
  809. $('#cancelShare').find('.modal-body').append($p);
  810. $('#cancelShare').modal('show');
  811. }
  812. }
  813. }
  814. });
  815. }
  816. //初始化视图
  817. //@return void
  818. function initView(){
  819. if(tree){
  820. tree = null;
  821. }
  822. if(spreadObj.workBook){
  823. spreadObj.workBook.destroy();
  824. spreadObj.workBook = null;
  825. }
  826. initContextMenu();
  827. buildSheet();
  828. initShareTree();
  829. }
  830. //根据建设项目获取单项工程
  831. //@param {Number}projID @return {void}
  832. function setEng(projID){
  833. let engQuery = {$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], projType: projectType.engineering, userID: userID, ParentID: projID};
  834. CommonAjax.post('/pm/api/getProjectsByQuery', {user_id: userID, query: engQuery, options: '-_id -property'}, function (rstData) {
  835. $('#copyShare_selectEng').empty();
  836. for(let eng of rstData){
  837. let opt = $('<option>').val(eng.ID).text(eng.name);
  838. $('#copyShare_selectEng').append(opt);
  839. }
  840. });
  841. }
  842. //从其他建设项目中复制中,建设项目的文件层次结构名称和顺序
  843. //@param {Array}treeData @return {Array}
  844. function getFileHierarchyInfo(treeData){
  845. curCopySelTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
  846. curCopySelTree.loadDatas(treeData);
  847. let items = curCopySelTree.items;
  848. let rst = [];
  849. function getFileHierarchyName(node){
  850. let nodeName = node.data.name;
  851. let name = [];
  852. while (node.parent){
  853. name.push(node.parent.data.name ? node.parent.data.name : '');
  854. node = node.parent;
  855. }
  856. name = name.reverse();
  857. name.push(nodeName);
  858. return name.join('\\');
  859. }
  860. for(let node of items){
  861. if(node.children.length === 0 ){//project
  862. rst.push({ID: node.data.ID, fileHierarchyName: getFileHierarchyName(node)})
  863. }
  864. }
  865. return rst;
  866. }
  867. //设置拷贝工程下拉选择
  868. //@return {void}
  869. function setCopyModal(){
  870. //获取建设项目
  871. let projQuery = {$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], projType: {$in: [projectType.project, projectType.folder]}, userID: userID};
  872. CommonAjax.post('/pm/api/getProjectsByQuery', {user_id: userID, query: projQuery, options: '-_id'}, function (rstData) {
  873. let fileHierarchyData = getFileHierarchyInfo(rstData);
  874. $('#copyShare_selectProj').empty();
  875. for(let proj of fileHierarchyData){
  876. let opt = $('<option>').val(proj.ID).text(proj.fileHierarchyName);
  877. $('#copyShare_selectProj').append(opt);
  878. }
  879. //初始选择
  880. if(fileHierarchyData.length > 0){
  881. setEng(fileHierarchyData[0].ID);
  882. }
  883. });
  884. }
  885. //拷贝分享的工程
  886. //@param {Object}selected {Number}parentID @return {void}
  887. function copyShareProject(selected, projID, engID){
  888. if(!engID || !selected){
  889. return;
  890. }
  891. let copyMap = {copy: null, update: null};
  892. let newName = getCopyName(selected);
  893. //获取单项工程的单位工程
  894. let tenderQuery = {$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], userID: userID, ParentID: engID};
  895. CommonAjax.post('/pm/api/getProjectsByQuery', {user_id: userID, query: tenderQuery, options: '-_id -property'}, function (rstData) {
  896. let updateTender = null;
  897. for(let tender of rstData){
  898. if(tender.name === newName){
  899. $('#copyShare_name').text('已存在此单位工程。');
  900. $('#copyShare_name').addClass('text-danger');
  901. return;
  902. }
  903. if(tender.NextSiblingID == -1){
  904. updateTender = tender;
  905. }
  906. }
  907. //更新前节点
  908. if(updateTender){
  909. copyMap.update = {query: {ID: updateTender.ID}};
  910. }
  911. //拷贝
  912. let copyData = {
  913. userID: userID,
  914. ID: selected.data.actualTreeInfo.ID,
  915. NextSiblingID: -1,
  916. ParentID: engID,
  917. name: newName,
  918. shareInfo: [],
  919. compilation: selected.data.compilation,
  920. createDateTime: selected.data.createDateTime,
  921. fileVer: selected.data.fileVer ? selected.data.fileVer : '',
  922. projType: selected.data.projType,
  923. property: {},
  924. recentDateTime: selected.data.recentDateTime,
  925. fullFolder: selected.data.fullFolder
  926. };
  927. copyData.property.rootProjectID = projID;
  928. copyMap.copy = {document: copyData};
  929. $('#copyShare').modal('hide');
  930. $.bootstrapLoading.start();
  931. CommonAjax.post('/pm/api/copyProjects', {projectMap: copyMap, user_id: userID, tenderCount: 1}, function (rstData) {
  932. $.bootstrapLoading.end();
  933. }, function () {
  934. $.bootstrapLoading.end();
  935. }, 1000 * 60 * 5);
  936. });
  937. }
  938. //获取拷贝后的名称
  939. //@param {Object}node @return {String}
  940. function getCopyName(node) {
  941. //当前单位工程可能没有分享的用户信息,可能他人分享的是父级文件,userInfo在父级文件中
  942. let orgName = node.data.name,
  943. userInfo = node.data.userInfo;
  944. while (node && !userInfo) {
  945. node = node.parent;
  946. userInfo = node.data.userInfo;
  947. }
  948. return `${orgName} (${userInfo.name}分享拷贝)`;
  949. }
  950. //事件监听器
  951. //@return void
  952. function eventListener(){
  953. //tab
  954. $('#tab_pm_share').on('shown.bs.tab', function () {
  955. //侧滑隐藏
  956. $('.slide-sidebar').removeClass('open');
  957. $('.slide-sidebar').css('width', '0');
  958. projTreeObj.tree = null;
  959. if(projTreeObj.workBook){
  960. projTreeObj.workBook.destroy();
  961. projTreeObj.workBook = null;
  962. }
  963. gcTreeObj.tree = null;
  964. if(gcTreeObj.workBook){
  965. gcTreeObj.workBook.destroy();
  966. gcTreeObj.workBook = null;
  967. }
  968. initView();
  969. });
  970. //关闭拷贝工程
  971. $('#copyShare').on('hidden.bs.modal', function () {
  972. $('#copyShareProj-info').hide();
  973. $('#copyShareEng-info').hide();
  974. });
  975. //打开拷贝工程
  976. $('#copyShare').on('shown.bs.modal', function () {
  977. setCopyModal();
  978. //更改显示名称
  979. let newName = getCopyName(shareSeleted);
  980. $('#copyShare_name').html(`拷贝后,工程将重命名为 "<b>${newName}</b>"`);
  981. $('#copyShare_name').removeClass('text-danger');
  982. });
  983. //拷贝工程改变选择建设项目
  984. $('#copyShare_selectProj').change(function () {
  985. //更改显示名称
  986. let newName = getCopyName(shareSeleted);
  987. $('#copyShare_name').html(`拷贝后,工程将重命名为 "<b>${newName}</b>"`);
  988. $('#copyShare_name').removeClass('text-danger');
  989. $('#copyShareProj-info').hide();
  990. $('#copyShareEng-info').hide();
  991. let curSelID = $(this).select().val();
  992. setEng(parseInt(curSelID));
  993. });
  994. //拷贝工程改变选择单项工程
  995. $('#copyShare_selectEng').change(function () {
  996. //更改显示名称
  997. let newName = getCopyName(shareSeleted);
  998. $('#copyShare_name').html(`拷贝后,工程将重命名为 "<b>${newName}</b>"`);
  999. $('#copyShare_name').removeClass('text-danger');
  1000. });
  1001. //确认拷贝
  1002. $('#copyShare_confirm').click(function () {
  1003. let selProj = $('#copyShare_selectProj').select().val();
  1004. if(!selProj){
  1005. $('#copyShareProj-info').show();
  1006. return;
  1007. }
  1008. //目标建设项目的计税方法与单位工程的一致时,才可拷贝
  1009. if (curCopySelTree) {
  1010. let projectNode = curCopySelTree.nodes[curCopySelTree.prefix + selProj];
  1011. if (!projectNode || !projectNode.data.property || projectNode.data.property.taxType != tree.selected.data.taxType){
  1012. alert('当前单位工程计税方法与目标建设项目不一致,不可复制。');
  1013. return;
  1014. }
  1015. }
  1016. let selEng = $('#copyShare_selectEng').select().val();
  1017. if(!selEng){
  1018. $('#copyShareEng-info').show();
  1019. return;
  1020. }
  1021. copyShareProject(tree.selected, parseInt(selProj), parseInt(selEng));
  1022. });
  1023. //清除分享
  1024. //清除了该节点后,可能还有该节点的数据在树上(树允许有重复数据),需要更新分享信息
  1025. function updateAfterCancel(userID, projectID) {
  1026. for (let item of tree.items) {
  1027. if (item.data.actualTreeInfo && item.data.actualTreeInfo.ID === projectID) {
  1028. _.remove(item.data.shareInfo, function (data) {
  1029. return data.userID === userID;
  1030. });
  1031. }
  1032. }
  1033. }
  1034. $('#cancelShareConfirm').click(function () {
  1035. $.bootstrapLoading.start();
  1036. let cancelProjID = tree.selected.data.actualTreeInfo.ID;
  1037. CommonAjax.post('/pm/api/share', {user_id: userID, type: oprType.cancel, projectID: cancelProjID, shareData:[{userID: userID}]}, function (rstData) {
  1038. tree.removeNode(tree.selected);
  1039. //更新与清除节点数据相同,且为被清除缓存分享信息
  1040. updateAfterCancel(userID, cancelProjID);
  1041. //重新设置actualIDShareInfo,以正确更新权限(清除了分享信息后,可能会导致权限变化 eg:清除了新的分享,则存留的分享项目采用旧的)
  1042. actualIDShareInfo = {};
  1043. let treeDatas = [];
  1044. for (let item of tree.items) {
  1045. treeDatas.push(item.data);
  1046. let actualTreeInfo = item.data.actualTreeInfo;
  1047. if (actualTreeInfo && !actualIDShareInfo[actualTreeInfo.ID]) {
  1048. actualIDShareInfo[actualTreeInfo.ID] = {
  1049. ID: actualTreeInfo.ID,
  1050. ParentID: actualTreeInfo.ParentID,
  1051. NextSiblingID: actualTreeInfo.NextSiblingID,
  1052. shareInfo: item.data.shareInfo
  1053. };
  1054. }
  1055. }
  1056. //重新设置权限
  1057. setPermissionsInfo(treeDatas);
  1058. showTreeData(tree.items, headers);
  1059. $.bootstrapLoading.end();
  1060. }, function () {
  1061. $.bootstrapLoading.end();
  1062. });
  1063. });
  1064. }
  1065. return {spreadObj, headers, initView, eventListener}
  1066. })();
  1067. $(document).ready(function () {
  1068. pmShare.eventListener();
  1069. });