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. frozenlineColor : '#ababab',
  58. protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
  59. clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
  60. }
  61. };
  62. const spreadEvents = {
  63. SelectionChanging: function (sender, info) {
  64. initSelection(info.newSelections[0], info.oldSelections[0]);
  65. }
  66. };
  67. //设置选中行底色
  68. //@param
  69. function setSelStyle(sel, backColor,sheet) {
  70. sel.row = sel.row === -1 ? 0 : sel.row;
  71. renderSheetFunc(sheet, function () {
  72. let style = projTreeObj.getSelStyle(backColor);
  73. for(let i = 0; i < sel.rowCount; i++){
  74. let row = i + sel.row;
  75. sheet.setStyle(row, -1, style);
  76. }
  77. });
  78. }
  79. //初始化焦点
  80. //@param {Object}newSel {Object}oldSel @return {void}
  81. function initSelection(newSel, oldSel = null) {
  82. let node = tree.items[newSel.row];
  83. tree.selected = node;
  84. shareSeleted = node;
  85. //恢复底色
  86. if(oldSel){
  87. setSelStyle(oldSel, projTreeObj.setting.style.defalutBackColor, spreadObj.sheet);
  88. }
  89. //设置选中行底色
  90. if(newSel){
  91. setSelStyle(newSel, projTreeObj.setting.style.selectedColor, spreadObj.sheet);
  92. }
  93. preSelection = newSel;
  94. }
  95. //渲染时方法,停止渲染
  96. //@param {Object}sheet {Function}func @return {void}
  97. function renderSheetFunc(sheet, func){
  98. sheet.suspendEvent();
  99. sheet.suspendPaint();
  100. if(func){
  101. func();
  102. }
  103. sheet.resumeEvent();
  104. sheet.resumePaint();
  105. }
  106. //设置表选项
  107. //@param {Object}workBook {Object}opts @return {void}
  108. function setSpreadOptions (workBook, opts) {
  109. for(let opt in opts.workBook){
  110. workBook.options[opt] = opts.workBook[opt];
  111. }
  112. for(let opt in opts.sheet){
  113. workBook.getActiveSheet().options[opt] = opts.sheet[opt];
  114. }
  115. }
  116. //建表头
  117. //@param {Object}sheet {Array}headers @return {void}
  118. function buildHeader(sheet, headers) {
  119. let fuc = function () {
  120. sheet.setColumnCount(headers.length);
  121. sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
  122. //let spreadWidth = getWorkBookWidth();
  123. for(let i = 0, len = headers.length; i < len; i++){
  124. sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
  125. if(headers[i].formatter){
  126. sheet.setFormatter(-1, i, headers[i].formatter);
  127. }
  128. sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
  129. sheet.getRange(-1, i, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[i]['hAlign']]);
  130. sheet.getRange(-1, i, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[i]['vAlign']]);
  131. }
  132. };
  133. renderSheetFunc(sheet, fuc);
  134. }
  135. //表监听事件
  136. //@param {Object}workBook @return {void}
  137. function bindEvent(workBook, events) {
  138. if(Object.keys(events).length === 0){
  139. return;
  140. }
  141. const Events = GC.Spread.Sheets.Events;
  142. for(let event in events){
  143. workBook.bind(Events[event], events[event]);
  144. }
  145. }
  146. //建表
  147. //@return {void}
  148. function buildSheet(){
  149. spreadObj.workBook = new GC.Spread.Sheets.Workbook(spreadDom[0], {sheetCount: 1});
  150. sheetCommonObj.spreadDefaultStyle(spreadObj.workBook);
  151. spreadObj.sheet = spreadObj.workBook.getActiveSheet();
  152. setSpreadOptions(spreadObj.workBook, spreadOpts);
  153. bindEvent(spreadObj.workBook, spreadEvents);
  154. buildHeader(spreadObj.sheet, headers);
  155. //全表不可编辑
  156. spreadObj.sheet.getRange(-1, -1, -1, -1).locked(true);
  157. }
  158. //此项目的分享权限信息(可能会被父级项目覆盖,以新为准)
  159. //@param {String}userID(本用户id) {Object}project(项目) @return {Object} || {Null}
  160. function getShareInfo(userID, project) {
  161. if (!project.actualTreeInfo) {
  162. return null;
  163. }
  164. //获取跟本用户和选中项目相关的分享信息
  165. let shareList = [];
  166. let actualID = project.actualTreeInfo.ID,
  167. actualData = actualIDShareInfo[actualID];
  168. while (actualData) {
  169. for (let data of actualData.shareInfo) {
  170. if (data.userID === userID) {
  171. shareList.push(data);
  172. break;
  173. }
  174. }
  175. actualData = actualIDShareInfo[actualData.ParentID];
  176. }
  177. //获取最新分享
  178. shareList.sort(function (a, b) {
  179. //return Date.parse(b.shareDate) - Date.parse(a.shareDate)
  180. return Date.parse(b.updateDate) - Date.parse(a.updateDate);
  181. });
  182. return shareList[0] || null;
  183. }
  184. //此项目是否可以拷贝
  185. //@param {String}userID {Object}project @return {Boolean}
  186. function isAllowCopy(userID, project){
  187. let myShareInfo = getShareInfo(userID, project);
  188. if (!myShareInfo) {
  189. return false;
  190. }
  191. return !!myShareInfo.allowCopy;
  192. }
  193. //此项目是否可以协作
  194. //@param {String}userID {Object}project @return {Boolean}
  195. function isAllowCoop(userID, project) {
  196. let myShareInfo = getShareInfo(userID, project);
  197. if (!myShareInfo) {
  198. return false;
  199. }
  200. return !!myShareInfo.allowCooperate;
  201. }
  202. //获取树节点
  203. //@param {Object}tree @return {Object}
  204. function getTreeNodeCell(tree){
  205. let indent = 20;
  206. let levelIndent = -5;
  207. let halfBoxLength = 5;
  208. let halfExpandLength = 3;
  209. let imgWidth = 18;
  210. let imgHeight = 14;
  211. let TreeNodeCellType = function () {
  212. };
  213. TreeNodeCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  214. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  215. if (style.backColor) {
  216. ctx.save();
  217. ctx.fillStyle = style.backColor;
  218. ctx.fillRect(x, y, w, h);
  219. ctx.restore();
  220. } else {
  221. ctx.clearRect(x, y, w, h);
  222. }
  223. let drawLine = function (canvas, x1, y1, x2, y2, color) {
  224. ctx.save();
  225. ctx.translate(0.5, 0.5);
  226. ctx.beginPath();
  227. ctx.moveTo(x1, y1);
  228. ctx.lineTo(x2, y2);
  229. ctx.strokeStyle = color;
  230. ctx.stroke();
  231. ctx.restore();
  232. };
  233. let drawExpandBox = function (ctx, x, y, w, h, centerX, centerY, expanded) {
  234. let rect = {}, h1, h2, offset = 1;
  235. rect.top = centerY - halfBoxLength;
  236. rect.bottom = centerY + halfBoxLength;
  237. rect.left = centerX - halfBoxLength;
  238. rect.right = centerX + halfBoxLength;
  239. if (rect.left < x + w) {
  240. rect.right = Math.min(rect.right, x + w);
  241. ctx.save();
  242. ctx.translate(0.5, 0.5);
  243. ctx.strokeStyle = 'black';
  244. ctx.beginPath();
  245. ctx.moveTo(rect.left, rect.top);
  246. ctx.lineTo(rect.left, rect.bottom);
  247. ctx.lineTo(rect.right, rect.bottom);
  248. ctx.lineTo(rect.right, rect.top);
  249. ctx.lineTo(rect.left, rect.top);
  250. ctx.stroke();
  251. ctx.fillStyle = 'white';
  252. ctx.fill();
  253. ctx.restore();
  254. // Draw Horizontal Line
  255. h1 = centerX - halfExpandLength;
  256. h2 = Math.min(centerX + halfExpandLength, x + w);
  257. if (h2 > h1) {
  258. drawLine(ctx, h1, centerY, h2, centerY, 'black');
  259. }
  260. // Draw Vertical Line
  261. if (!expanded && (centerX < x + w)) {
  262. drawLine(ctx, centerX, centerY - halfExpandLength, centerX, centerY + halfExpandLength, 'black');
  263. }
  264. }
  265. }
  266. let node = tree.items[options.row];
  267. let showTreeLine = true;
  268. if (!node) { return; }
  269. let centerX = Math.floor(x) + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  270. let x1 = centerX + indent / 2;
  271. let centerY = Math.floor((y + (y + h)) / 2);
  272. let y1;
  273. // Draw Sibling Line
  274. if (showTreeLine) {
  275. // Draw Horizontal Line
  276. if (centerX < x + w) {
  277. drawLine(ctx, centerX, centerY, Math.min(x1, x + w), centerY, 'gray');
  278. let img;
  279. if(node.data.projType === projectType.folder){
  280. img = document.getElementById('folder_open_pic');
  281. imgWidth = 15;
  282. }
  283. else if(node.data.projType === projectType.project){
  284. img = document.getElementById('proj_pic');
  285. imgWidth = 18;
  286. }
  287. else if(node.data.projType === projectType.engineering){
  288. img = document.getElementById('eng_pic');
  289. imgWidth = 14;
  290. }
  291. else if(node.data.projType === projectType.tender){
  292. img = document.getElementById('tender_pic');
  293. imgWidth = 14;
  294. }
  295. ctx.drawImage(img, centerX+indent/2+3, centerY - 7, imgWidth,imgHeight);
  296. }
  297. // Draw Vertical Line
  298. if (centerX < x + w) {
  299. y1 = node.isLast() ? centerY : y + h;
  300. if (node.isFirst() && !node.parent.parent) {
  301. drawLine(ctx, centerX, centerY, centerX, y1, 'gray');
  302. } else {
  303. drawLine(ctx, centerX, y, centerX, y1, 'gray');
  304. }
  305. }
  306. }
  307. // Draw Expand Box
  308. if (node.children.length > 0) {
  309. drawExpandBox(ctx, x, y, w, h, centerX, centerY, node.expanded);
  310. }
  311. // Draw Parent Line
  312. if (showTreeLine) {
  313. var parent = node.parent, parentCenterX = centerX - indent - levelIndent;
  314. while (parent.parent) {
  315. if (!parent.isLast()) {
  316. if (parentCenterX < x + w) {
  317. drawLine(ctx, parentCenterX, y, parentCenterX, y + h, 'gray');
  318. }
  319. }
  320. parent = parent.parent;
  321. parentCenterX -= (indent + levelIndent);
  322. }
  323. };
  324. // Draw Text
  325. arguments[2] = x + (node.depth() + 1) * indent + node.depth() * levelIndent + imgWidth + 3;
  326. arguments[4] = w - (node.depth() + 1) * indent - node.depth() * levelIndent - imgWidth - 3;
  327. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  328. };
  329. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  330. let info = {x: x, y: y, row: context.row, col: context.col, cellStyle: cellStyle, cellRect: cellRect, sheetArea: context.sheetArea};
  331. let node = tree.items[info.row];
  332. if (node && node.data.projType === projectType.tender) {
  333. info.isReservedLocation = true;
  334. }
  335. return info;
  336. };
  337. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  338. let offset = -1;
  339. let node = tree.items[hitinfo.row];
  340. let centerX = hitinfo.cellRect.x + offset + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  341. let centerY = (hitinfo.cellRect.y + offset + (hitinfo.cellRect.y + offset + hitinfo.cellRect.height)) / 2;
  342. //点击单位工程
  343. if(node.data.projType === projectType.tender){
  344. let thisClick = Date.now(),
  345. open = false;
  346. if (this.preNode === node && this.preClick && thisClick - this.preClick <= 300) {
  347. open = true;
  348. projTreeObj.openTender(node.data.actualTreeInfo.ID, node.parent, 200);
  349. }
  350. this.preClick = open ? null : thisClick;
  351. this.preNode = open ? null : node;
  352. }
  353. if (!node || node.children.length === 0) {
  354. return;
  355. }
  356. if (hitinfo.x >= centerX - halfBoxLength - 2 && hitinfo.x <= centerX + halfBoxLength + 2 &&
  357. hitinfo.y >= centerY - halfBoxLength - 2 && hitinfo.y <= centerY + halfBoxLength + 2) {
  358. node.setExpanded(!node.expanded);
  359. TREE_SHEET_HELPER.massOperationSheet(hitinfo.sheet, function () {
  360. let iCount = node.posterityCount(), i, child;
  361. for (i = 0; i < iCount; i++) {
  362. child = tree.items[hitinfo.row + i + 1];
  363. hitinfo.sheet.setRowVisible(hitinfo.row + i + 1, child.visible, hitinfo.sheetArea);
  364. }
  365. hitinfo.sheet.invalidateLayout();
  366. });
  367. hitinfo.sheet.repaint();
  368. }
  369. };
  370. TreeNodeCellType.prototype.processMouseEnter = function (hitinfo) {
  371. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  372. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  373. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  374. zoom = hitinfo.sheet.zoom();
  375. let node = tree.items[hitinfo.row];
  376. let nodeIndent = node ? (node.depth() + 1) * indent + node.depth() * levelIndent + imgWidth + 3 : 0;
  377. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  378. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  379. if(textLength > cellWidth - nodeIndent){
  380. TREE_SHEET_HELPER.showTipsDiv(text,{pos: {}},hitinfo);
  381. }
  382. };
  383. TreeNodeCellType.prototype.processMouseLeave = function (hitinfo) {
  384. TREE_SHEET_HELPER.tipDiv = 'hide';
  385. if (TREE_SHEET_HELPER._toolTipElement) {
  386. $(TREE_SHEET_HELPER._toolTipElement).hide();
  387. TREE_SHEET_HELPER._toolTipElement = null;
  388. };
  389. TREE_SHEET_HELPER.tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  390. }
  391. return new TreeNodeCellType();
  392. }
  393. //互动单元格
  394. function getInteractionCell() {
  395. let editImg = document.getElementById('edit_pic'),
  396. workImgWidth = 13,
  397. workImgHeight = 13,
  398. copyImg = document.getElementById('copy_pic'),
  399. copyImgWidth = 13,
  400. copyImgHeight = 13;
  401. let InteractionCell = function () {
  402. };
  403. InteractionCell.prototype = new GC.Spread.Sheets.CellTypes.Text();
  404. InteractionCell.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  405. if (style.backColor) {
  406. ctx.save();
  407. ctx.fillStyle = style.backColor;
  408. ctx.fillRect(x, y, w, h);
  409. ctx.restore();
  410. } else {
  411. ctx.clearRect(x, y, w, h);
  412. }
  413. let node = tree.items[options.row];
  414. // Draw Text
  415. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  416. if (node && node.data.projType === projectType.tender) {
  417. let text = options.sheet.getText(options.row, options.col);
  418. let acStyle = options.sheet.getActualStyle(options.row, options.col),
  419. zoom = options.sheet.zoom();
  420. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: options.sheet, row: options.row, col: options.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  421. const imgIndent = 5;
  422. let nowX = Math.floor(x) + textLength + imgIndent,
  423. nowY = Math.floor((y + (y + h)) / 2) - 7;
  424. if (node.data.allowCooperate) {
  425. ctx.drawImage(editImg, nowX, nowY, workImgWidth, workImgHeight);
  426. nowX += workImgWidth;
  427. }
  428. if (node.data.allowCopy) {
  429. ctx.drawImage(copyImg, nowX, nowY, copyImgWidth, copyImgHeight);
  430. }
  431. }
  432. };
  433. InteractionCell.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  434. return {
  435. x: x,
  436. y: y,
  437. row: context.row,
  438. col: context.col,
  439. cellStyle: cellStyle,
  440. cellRect: cellRect,
  441. sheetArea: context.sheetArea,
  442. isReservedLocation: true
  443. };
  444. };
  445. InteractionCell.prototype.processMouseDown = function (hitinfo) {
  446. let dataCode = headers[hitinfo.col]['dataCode'];
  447. let node = tree.items[hitinfo.row];
  448. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  449. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  450. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  451. zoom = hitinfo.sheet.zoom();
  452. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  453. if(hitinfo.x - hitinfo.cellRect.x > 0 && hitinfo.x - hitinfo.cellRect.x < textLength){
  454. //由..分享,弹出分享者信息
  455. if(dataCode === 'from'){
  456. if(node.data.shareType === shareType.receive){
  457. $('#userinfo').find('h4').text(node.data.userInfo.name);
  458. $('#userinfo').find('h6').text(node.data.userInfo.company);
  459. let mobileHtml = `<i class="fa fa-tablet"> ${node.data.userInfo.mobile ? node.data.userInfo.mobile : ''}</i>`;
  460. $('#userinfo').find('li:first-child').html(mobileHtml);
  461. let emailHtml = `<i class="fa fa-envelope-o"> ${node.data.userInfo.email ? node.data.userInfo.email : ''}</i>`;
  462. $('#userinfo').find('li:last-child').html(emailHtml);
  463. $('#userinfo').modal('show');
  464. }
  465. }
  466. }
  467. };
  468. InteractionCell.prototype.processMouseMove = function (hitInfo) {
  469. let dataCode = headers[hitInfo.col]['dataCode'];
  470. let node = tree.items[hitInfo.row];
  471. let sheet = hitInfo.sheet;
  472. let div = sheet.getParent().getHost();
  473. let canvasId = div.id + "vp_vp";
  474. let canvas = $(`#${canvasId}`)[0];
  475. //改变鼠标图案
  476. let text = hitInfo.sheet.getText(hitInfo.row, hitInfo.col);
  477. let value = hitInfo.sheet.getValue(hitInfo.row, hitInfo.col);
  478. let acStyle = hitInfo.sheet.getActualStyle(hitInfo.row, hitInfo.col),
  479. zoom = hitInfo.sheet.zoom();
  480. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitInfo.sheet, row: hitInfo.row, col: hitInfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  481. if (sheet && hitInfo.x - hitInfo.cellRect.x > 0 && hitInfo.x - hitInfo.cellRect.x < textLength) {
  482. canvas.style.cursor='pointer';
  483. return true;
  484. }else{
  485. canvas.style.cursor='default';
  486. }
  487. return false;
  488. };
  489. return new InteractionCell();
  490. }
  491. //设置分享给界面数据
  492. //@param {Object}selected @return {void}
  493. function setShareToModal(selected){
  494. $('#shareToInfo').empty();
  495. if(!selected){
  496. return;
  497. }
  498. let userIDs = [];
  499. for(let user of selected.data.shareInfo){
  500. userIDs.push(user.userID);
  501. }
  502. CommonAjax.post('/user/getUsers', {userIDs: userIDs}, function (rstData) {
  503. for(let userInfo of rstData){
  504. for(let user of selected.data.shareInfo){
  505. if(user.userID === userInfo._id){
  506. user.name = userInfo.real_name;
  507. user.company = userInfo.company;
  508. user.mobile = userInfo.mobile;
  509. user.email = userInfo.email;
  510. }
  511. }
  512. }
  513. let infoArr = [];
  514. for(let user of selected.data.shareInfo){
  515. let infoHtml = `<tr>
  516. <td style="width: 106px;">${user.name}</td>
  517. <td style="width: 146px;">${user.company}</td>
  518. <td style="width: 146px;">${user.mobile}</td>
  519. <td style="width: 156px;">${user.email}</td>
  520. <td style="width: 70px;text-align: center"><input value="allowCopy" ${user.allowCopy ? 'checked' : ''} type="checkbox"></td>
  521. <td style="width: 70px;text-align: center"><input value="cancelShare" type="checkbox"></td>
  522. </tr>`;
  523. infoArr.push(infoHtml);
  524. }
  525. let infoHtml = infoArr.join('');
  526. $('#shareToInfo').html(infoHtml);
  527. });
  528. }
  529. //更新项目分享信息
  530. //@param {Object}selected
  531. function updateShareInfo(selected){
  532. if(!selected){
  533. return;
  534. }
  535. let usersTr = $('#shareToInfo').find('tr');
  536. let newShareInfo = [];
  537. for(let i = 0; i < usersTr.length; i++){
  538. let userTr = usersTr[i];
  539. let allowCopy = $(userTr).find('input:first').prop('checked');
  540. let cancelShare = $(userTr).find('input:last').prop('checked');
  541. selected.data.shareInfo[i].allowCopy = allowCopy;
  542. if(!cancelShare){
  543. newShareInfo.push(selected.data.shareInfo[i]);
  544. }
  545. }
  546. CommonAjax.post('/pm/api/updateProjects', {user_id: userID, updateData: [{updateType: 'update', updateData: {ID: selected.data.ID, shareInfo: newShareInfo}}]}, function () {
  547. selected.data.shareInfo = newShareInfo;
  548. if(newShareInfo.length === 0){
  549. renderSheetFunc(spreadObj.sheet, function () {
  550. let rIdx = selected.serialNo();
  551. tree.removeNode(selected);
  552. spreadObj.sheet.deleteRows(rIdx, 1);
  553. spreadObj.sheet.setRowCount(tree.items);
  554. initSelection({row: spreadObj.sheet.getActiveRowIndex(), rowCount: 1},null);
  555. });
  556. }
  557. });
  558. }
  559. const foreColor = '#007bff';
  560. const cancelForeColor = 'red';
  561. //显示树结构数据
  562. //@param {Array}nodes {Array}headers @return {void}
  563. function showTreeData(nodes, headers){
  564. let sheet = spreadObj.workBook.getActiveSheet();
  565. let fuc = function(){
  566. sheet.setRowCount(nodes.length);
  567. for(let i = 0; i < nodes.length; i++){
  568. let treeNodeCell = getTreeNodeCell(tree);
  569. sheet.getCell(i, treeCol).cellType(treeNodeCell);
  570. for(let j = 0; j < headers.length; j++){
  571. sheet.getRange(-1, j, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[j]['hAlign']]);
  572. sheet.getRange(-1, j, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[j]['vAlign']]);
  573. let dataCode = headers[j].dataCode;
  574. if(dataCode === 'from'){
  575. let style = new GC.Spread.Sheets.Style();
  576. style.foreColor = foreColor;
  577. sheet.setStyle(i, j, style);
  578. sheet.getCell(i, j).cellType(getInteractionCell());
  579. }
  580. sheet.setValue(i, j, nodes[i].data[dataCode] !== null && typeof nodes[i].data[dataCode] !== 'undefined' ? nodes[i].data[dataCode] : '');
  581. }
  582. }
  583. };
  584. renderSheetFunc(sheet, fuc);
  585. }
  586. //同一棵树,可能存在相同数据显示多条的问题(传入的datas中不存在相同数据)
  587. //将真实树结构数据存在actualTreeInfo中,外部树结构数据用uuid重置。
  588. //@param {Array}datas
  589. function setTreeInfo(datas) {
  590. let IDMapping = {};
  591. for (let data of datas) {
  592. //项目真实ID与项目分享信息映射,方便确定项目的权限
  593. if (!actualIDShareInfo[data.ID]) {
  594. actualIDShareInfo[data.ID] = {ID: data.ID, ParentID: data.ParentID, NextSiblingID: data.NextSiblingID, shareInfo: data.shareInfo};
  595. }
  596. IDMapping[data.ID] = uuid.v1();
  597. }
  598. for (let data of datas) {
  599. data.actualTreeInfo = {ID: data.ID, ParentID: data.ParentID, NextSiblingID: data.NextSiblingID};
  600. data.ID = IDMapping[data.ID];
  601. data.NextSiblingID = IDMapping[data.NextSiblingID] ? IDMapping[data.NextSiblingID] : -1;
  602. data.ParentID = IDMapping[data.ParentID] ? IDMapping[data.ParentID] : -1;
  603. }
  604. }
  605. //整理同层数据的NextSiblingID,ParentID
  606. //@param {Array}datas {Number || String}pid @return {void}
  607. function sortSameDepthData(datas, pid) {
  608. for (let i = 0; i < datas.length; i++) {
  609. let data = datas[i],
  610. nextData = datas[i + 1];
  611. data.NextSiblingID = nextData ? nextData.ID : -1;
  612. data.ParentID = pid;
  613. }
  614. }
  615. //给项目设置分享信息:由xx分享、分享时间、分享给我,含有userInfo信息的文件为他人直接分享的文件,他人分享父级文件,子文件不含有userInfo信息
  616. //@param {Array}datas @return {void}
  617. function setShareInfo(datas) {
  618. for (let data of datas) {
  619. if (data.userInfo) {
  620. //shareInfo中我的条目
  621. let selfInfo = _.find(data.shareInfo, {userID: userID});
  622. data.shareDate = selfInfo ? selfInfo.shareDate : ''
  623. data.from = data.userInfo.name;
  624. data.to = '分享给 我';
  625. data.cancel = '清除';
  626. }
  627. }
  628. }
  629. //给项目设置汇总信息
  630. //@param {Array}projs {Object}summaryInfo
  631. function setSummaryInfo(grouped, summaryInfo) {
  632. if (!summaryInfo) {
  633. return;
  634. }
  635. let allDatas = [];
  636. for (let data of grouped) {
  637. allDatas.push(data);
  638. if (data.children && data.children.length > 0) {
  639. allDatas = allDatas.concat(data.children);
  640. }
  641. }
  642. for(let proj of allDatas){
  643. let summaryProj = summaryInfo[proj.ID];
  644. if(summaryProj){
  645. proj.engineeringCost = summaryProj.engineeringCost;
  646. proj.subEngineering = summaryProj.subEngineering;
  647. proj.measure = summaryProj.measure;
  648. proj.safetyConstruction = summaryProj.safetyConstruction;
  649. proj.other = summaryProj.other;
  650. proj.charge = summaryProj.charge;
  651. proj.tax = summaryProj.tax;
  652. proj.rate = summaryProj.rate;
  653. proj.buildingArea = summaryProj.buildingArea;
  654. proj.perCost = summaryProj.perCost;
  655. }
  656. }
  657. }
  658. //从同层树数据获取第一个节点ID
  659. //@param {Array}treeDatas树的数据 @return {String}第一个节点的虚拟树ID
  660. function getFirstID(treeDatas) {
  661. let treeMapping = {};
  662. //建立ID索引
  663. for (let data of treeDatas) {
  664. //新建一个简单对象,防止污染treeDatas的数据
  665. treeMapping[data.ID] = {ID: data.ID, prev: null, next: null};
  666. }
  667. //绑定prev next
  668. for (let data of treeDatas) {
  669. let me = treeMapping[data.ID],
  670. next = treeMapping[data.NextSiblingID];
  671. if (next) {
  672. me.next = next;
  673. next.prev = me;
  674. }
  675. }
  676. //返回没有prev属性的数据
  677. let result = _.find(treeDatas, function (data) {
  678. return !treeMapping[data.ID].prev
  679. });
  680. return result ? result.ID : -1;
  681. }
  682. //获取可成树的数据
  683. //@param {Array}datas @return {Array}
  684. function getTreeDatas(groupedDatas, ungroupedDatas){
  685. //设置新的树结构数据
  686. for (let data of groupedDatas) {
  687. setTreeInfo([data].concat(data.children));
  688. }
  689. let engs = _.filter(ungroupedDatas, {projType: projectType.engineering}),
  690. tenders = _.filter(ungroupedDatas, {projType: projectType.tender});
  691. for (let data of engs) {
  692. setTreeInfo([data].concat(data.children));
  693. }
  694. setTreeInfo(tenders);
  695. let rst = [];
  696. //整理树结构
  697. sortSameDepthData(groupedDatas, -1);
  698. //第一个根节点数据
  699. let firstID = getFirstID(groupedDatas);
  700. //新建未分类建设项目及单项工程
  701. let ungroupedProj = {ID: uuid.v1(), ParentID: -1, NextSiblingID: firstID, name: '未分类建设项目', projType: projectType.project};
  702. let ungroupedEng = {ID: uuid.v1(), ParentID: ungroupedProj.ID, NextSiblingID: -1, name: '未分类单项工程', projType: projectType.engineering};
  703. //将未分类的数据归类
  704. sortSameDepthData(engs, ungroupedProj.ID);
  705. sortSameDepthData(tenders, ungroupedEng.ID);
  706. //未分类单项工程处于同层第一个节点
  707. ungroupedEng.NextSiblingID = engs[0] ? engs[0].ID : ungroupedEng.NextSiblingID;
  708. let allDatas = groupedDatas.concat(ungroupedDatas);
  709. //设置分享信息及操作信息
  710. setShareInfo(allDatas);
  711. for (let data of allDatas) {
  712. rst.push(data);
  713. if (data.children) {
  714. rst = rst.concat(data.children);
  715. }
  716. }
  717. rst.push(ungroupedProj);
  718. rst.push(ungroupedEng);
  719. return rst;
  720. }
  721. //按照时间排序
  722. //@param {Array}datas @return {void}
  723. function sortByDate(datas){
  724. datas.sort(function (a, b) {
  725. let shareInfoA = _.find(a.shareInfo, {userID}),
  726. shareInfoB = _.find(b.shareInfo, {userID});
  727. let aV = shareInfoA ? Date.parse(shareInfoA.shareDate) : 0,
  728. bV = shareInfoB ? Date.parse(shareInfoB.shareDate) : 0;
  729. //时间越晚越靠前
  730. if (aV > bV) {
  731. return -1;
  732. } else if (aV < bV) {
  733. return 1;
  734. }
  735. return 0;
  736. });
  737. }
  738. //设置节点数据权限
  739. //@param {Array}datas项目数据
  740. function setPermissionsInfo(datas) {
  741. //data.allowCopy与shareInfo里allowCopy的区别:
  742. //data.allowCopy为该单位实际的权限(跟着最新的分享信息走,可能随着父项)
  743. for (let data of datas) {
  744. if (data.projType === projectType.tender) {
  745. data.allowCopy = isAllowCopy(userID, data);
  746. data.allowCooperate = isAllowCoop(userID, data);
  747. }
  748. }
  749. }
  750. //建立树
  751. //@return void
  752. function initShareTree(){
  753. $.bootstrapLoading.start();
  754. //获取分享数据
  755. CommonAjax.post('/pm/api/receiveProjects', {user_id: userID}, function (rstData) {
  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. });