pm_share.js 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  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 workImg = document.getElementById('work_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. let nowX = Math.floor(x) + textLength + 3,
  427. nowY = Math.floor((y + (y + h)) / 2) - 7;
  428. if (node.data.allowCooperate) {
  429. ctx.drawImage(workImg, nowX, nowY, workImgWidth, workImgHeight);
  430. nowX += workImgWidth;
  431. }
  432. if (node.data.allowCopy) {
  433. ctx.drawImage(copyImg, nowX, nowY, copyImgWidth, copyImgHeight);
  434. }
  435. }
  436. };
  437. InteractionCell.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  438. return {
  439. x: x,
  440. y: y,
  441. row: context.row,
  442. col: context.col,
  443. cellStyle: cellStyle,
  444. cellRect: cellRect,
  445. sheetArea: context.sheetArea,
  446. isReservedLocation: true
  447. };
  448. };
  449. InteractionCell.prototype.processMouseDown = function (hitinfo) {
  450. let dataCode = headers[hitinfo.col]['dataCode'];
  451. let node = tree.items[hitinfo.row];
  452. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  453. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  454. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  455. zoom = hitinfo.sheet.zoom();
  456. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  457. if(hitinfo.x - hitinfo.cellRect.x > 0 && hitinfo.x - hitinfo.cellRect.x < textLength){
  458. //由..分享,弹出分享者信息
  459. if(dataCode === 'from'){
  460. if(node.data.shareType === shareType.receive){
  461. $('#userinfo').find('h4').text(node.data.userInfo.name);
  462. $('#userinfo').find('h6').text(node.data.userInfo.company);
  463. let mobileHtml = `<i class="fa fa-tablet"> ${node.data.userInfo.mobile ? node.data.userInfo.mobile : ''}</i>`;
  464. $('#userinfo').find('li:first-child').html(mobileHtml);
  465. let emailHtml = `<i class="fa fa-envelope-o"> ${node.data.userInfo.email ? node.data.userInfo.email : ''}</i>`;
  466. $('#userinfo').find('li:last-child').html(emailHtml);
  467. $('#userinfo').modal('show');
  468. }
  469. }
  470. }
  471. };
  472. InteractionCell.prototype.processMouseMove = function (hitInfo) {
  473. let dataCode = headers[hitInfo.col]['dataCode'];
  474. let node = tree.items[hitInfo.row];
  475. let sheet = hitInfo.sheet;
  476. let div = sheet.getParent().getHost();
  477. let canvasId = div.id + "vp_vp";
  478. let canvas = $(`#${canvasId}`)[0];
  479. //改变鼠标图案
  480. let text = hitInfo.sheet.getText(hitInfo.row, hitInfo.col);
  481. let value = hitInfo.sheet.getValue(hitInfo.row, hitInfo.col);
  482. let acStyle = hitInfo.sheet.getActualStyle(hitInfo.row, hitInfo.col),
  483. zoom = hitInfo.sheet.zoom();
  484. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitInfo.sheet, row: hitInfo.row, col: hitInfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  485. if (sheet && hitInfo.x - hitInfo.cellRect.x > 0 && hitInfo.x - hitInfo.cellRect.x < textLength) {
  486. canvas.style.cursor='pointer';
  487. return true;
  488. }else{
  489. canvas.style.cursor='default';
  490. }
  491. return false;
  492. };
  493. return new InteractionCell();
  494. }
  495. //设置分享给界面数据
  496. //@param {Object}selected @return {void}
  497. function setShareToModal(selected){
  498. $('#shareToInfo').empty();
  499. if(!selected){
  500. return;
  501. }
  502. let userIDs = [];
  503. for(let user of selected.data.shareInfo){
  504. userIDs.push(user.userID);
  505. }
  506. CommonAjax.post('/user/getUsers', {userIDs: userIDs}, function (rstData) {
  507. for(let userInfo of rstData){
  508. for(let user of selected.data.shareInfo){
  509. if(user.userID === userInfo._id){
  510. user.name = userInfo.real_name;
  511. user.company = userInfo.company;
  512. user.mobile = userInfo.mobile;
  513. user.email = userInfo.email;
  514. }
  515. }
  516. }
  517. let infoArr = [];
  518. for(let user of selected.data.shareInfo){
  519. let infoHtml = `<tr>
  520. <td style="width: 106px;">${user.name}</td>
  521. <td style="width: 146px;">${user.company}</td>
  522. <td style="width: 146px;">${user.mobile}</td>
  523. <td style="width: 156px;">${user.email}</td>
  524. <td style="width: 70px;text-align: center"><input value="allowCopy" ${user.allowCopy ? 'checked' : ''} type="checkbox"></td>
  525. <td style="width: 70px;text-align: center"><input value="cancelShare" type="checkbox"></td>
  526. </tr>`;
  527. infoArr.push(infoHtml);
  528. }
  529. let infoHtml = infoArr.join('');
  530. $('#shareToInfo').html(infoHtml);
  531. });
  532. }
  533. //更新项目分享信息
  534. //@param {Object}selected
  535. function updateShareInfo(selected){
  536. if(!selected){
  537. return;
  538. }
  539. let usersTr = $('#shareToInfo').find('tr');
  540. let newShareInfo = [];
  541. for(let i = 0; i < usersTr.length; i++){
  542. let userTr = usersTr[i];
  543. let allowCopy = $(userTr).find('input:first').prop('checked');
  544. let cancelShare = $(userTr).find('input:last').prop('checked');
  545. selected.data.shareInfo[i].allowCopy = allowCopy;
  546. if(!cancelShare){
  547. newShareInfo.push(selected.data.shareInfo[i]);
  548. }
  549. }
  550. CommonAjax.post('/pm/api/updateProjects', {user_id: userID, updateData: [{updateType: 'update', updateData: {ID: selected.data.ID, shareInfo: newShareInfo}}]}, function () {
  551. selected.data.shareInfo = newShareInfo;
  552. if(newShareInfo.length === 0){
  553. renderSheetFunc(spreadObj.sheet, function () {
  554. let rIdx = selected.serialNo();
  555. tree.removeNode(selected);
  556. spreadObj.sheet.deleteRows(rIdx, 1);
  557. spreadObj.sheet.setRowCount(tree.items);
  558. initSelection({row: spreadObj.sheet.getActiveRowIndex(), rowCount: 1},null);
  559. });
  560. }
  561. });
  562. }
  563. const foreColor = '#007bff';
  564. const cancelForeColor = 'red';
  565. //显示树结构数据
  566. //@param {Array}nodes {Array}headers @return {void}
  567. function showTreeData(nodes, headers){
  568. let sheet = spreadObj.workBook.getActiveSheet();
  569. let fuc = function(){
  570. sheet.setRowCount(nodes.length);
  571. for(let i = 0; i < nodes.length; i++){
  572. let treeNodeCell = getTreeNodeCell(tree);
  573. sheet.getCell(i, treeCol).cellType(treeNodeCell);
  574. for(let j = 0; j < headers.length; j++){
  575. sheet.getRange(-1, j, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[j]['hAlign']]);
  576. sheet.getRange(-1, j, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[j]['vAlign']]);
  577. let dataCode = headers[j].dataCode;
  578. if(dataCode === 'from'){
  579. let style = new GC.Spread.Sheets.Style();
  580. style.foreColor = foreColor;
  581. sheet.setStyle(i, j, style);
  582. sheet.getCell(i, j).cellType(getInteractionCell());
  583. }
  584. sheet.setValue(i, j, nodes[i].data[dataCode] !== null && typeof nodes[i].data[dataCode] !== 'undefined' ? nodes[i].data[dataCode] : '');
  585. }
  586. }
  587. };
  588. renderSheetFunc(sheet, fuc);
  589. }
  590. //同一棵树,可能存在相同数据显示多条的问题(传入的datas中不存在相同数据)
  591. //将真实树结构数据存在actualTreeInfo中,外部树结构数据用uuid重置。
  592. //@param {Array}datas
  593. function setTreeInfo(datas) {
  594. let IDMapping = {};
  595. for (let data of datas) {
  596. //项目真实ID与项目分享信息映射,方便确定项目的权限
  597. if (!actualIDShareInfo[data.ID]) {
  598. actualIDShareInfo[data.ID] = {ID: data.ID, ParentID: data.ParentID, NextSiblingID: data.NextSiblingID, shareInfo: data.shareInfo};
  599. }
  600. IDMapping[data.ID] = uuid.v1();
  601. }
  602. for (let data of datas) {
  603. data.actualTreeInfo = {ID: data.ID, ParentID: data.ParentID, NextSiblingID: data.NextSiblingID};
  604. data.ID = IDMapping[data.ID];
  605. data.NextSiblingID = IDMapping[data.NextSiblingID] ? IDMapping[data.NextSiblingID] : -1;
  606. data.ParentID = IDMapping[data.ParentID] ? IDMapping[data.ParentID] : -1;
  607. }
  608. }
  609. //整理同层数据的NextSiblingID,ParentID
  610. //@param {Array}datas {Number || String}pid @return {void}
  611. function sortSameDepthData(datas, pid) {
  612. for (let i = 0; i < datas.length; i++) {
  613. let data = datas[i],
  614. nextData = datas[i + 1];
  615. data.NextSiblingID = nextData ? nextData.ID : -1;
  616. data.ParentID = pid;
  617. }
  618. }
  619. //给项目设置分享信息:由xx分享、分享时间、分享给我,含有userInfo信息的文件为他人直接分享的文件,他人分享父级文件,子文件不含有userInfo信息
  620. //@param {Array}datas @return {void}
  621. function setShareInfo(datas) {
  622. for (let data of datas) {
  623. if (data.userInfo) {
  624. //shareInfo中我的条目
  625. let selfInfo = _.find(data.shareInfo, {userID: userID});
  626. data.shareDate = selfInfo ? selfInfo.shareDate : ''
  627. data.from = data.userInfo.name;
  628. data.to = '分享给 我';
  629. data.cancel = '清除';
  630. }
  631. }
  632. }
  633. //给项目设置汇总信息
  634. //@param {Array}projs {Object}summaryInfo
  635. function setSummaryInfo(grouped, summaryInfo) {
  636. if (!summaryInfo) {
  637. return;
  638. }
  639. let allDatas = [];
  640. for (let data of grouped) {
  641. allDatas.push(data);
  642. if (data.children && data.children.length > 0) {
  643. allDatas = allDatas.concat(data.children);
  644. }
  645. }
  646. for(let proj of allDatas){
  647. let summaryProj = summaryInfo[proj.ID];
  648. if(summaryProj){
  649. proj.engineeringCost = summaryProj.engineeringCost;
  650. proj.subEngineering = summaryProj.subEngineering;
  651. proj.measure = summaryProj.measure;
  652. proj.safetyConstruction = summaryProj.safetyConstruction;
  653. proj.other = summaryProj.other;
  654. proj.charge = summaryProj.charge;
  655. proj.tax = summaryProj.tax;
  656. proj.rate = summaryProj.rate;
  657. proj.buildingArea = summaryProj.buildingArea;
  658. proj.perCost = summaryProj.perCost;
  659. }
  660. }
  661. }
  662. //从同层树数据获取第一个节点ID
  663. //@param {Array}treeDatas树的数据 @return {String}第一个节点的虚拟树ID
  664. function getFirstID(treeDatas) {
  665. let treeMapping = {};
  666. //建立ID索引
  667. for (let data of treeDatas) {
  668. //新建一个简单对象,防止污染treeDatas的数据
  669. treeMapping[data.ID] = {ID: data.ID, prev: null, next: null};
  670. }
  671. //绑定prev next
  672. for (let data of treeDatas) {
  673. let me = treeMapping[data.ID],
  674. next = treeMapping[data.NextSiblingID];
  675. if (next) {
  676. me.next = next;
  677. next.prev = me;
  678. }
  679. }
  680. //返回没有prev属性的数据
  681. let result = _.find(treeDatas, function (data) {
  682. return !treeMapping[data.ID].prev
  683. });
  684. return result ? result.ID : -1;
  685. }
  686. //获取可成树的数据
  687. //@param {Array}datas @return {Array}
  688. function getTreeDatas(groupedDatas, ungroupedDatas){
  689. //设置新的树结构数据
  690. for (let data of groupedDatas) {
  691. setTreeInfo([data].concat(data.children));
  692. }
  693. let engs = _.filter(ungroupedDatas, {projType: projectType.engineering}),
  694. tenders = _.filter(ungroupedDatas, {projType: projectType.tender});
  695. for (let data of engs) {
  696. setTreeInfo([data].concat(data.children));
  697. }
  698. setTreeInfo(tenders);
  699. let rst = [];
  700. //整理树结构
  701. sortSameDepthData(groupedDatas, -1);
  702. //第一个根节点数据
  703. let firstID = getFirstID(groupedDatas);
  704. //新建未分类建设项目及单项工程
  705. let ungroupedProj = {ID: uuid.v1(), ParentID: -1, NextSiblingID: firstID, name: '未分类建设项目', projType: projectType.project};
  706. let ungroupedEng = {ID: uuid.v1(), ParentID: ungroupedProj.ID, NextSiblingID: -1, name: '未分类单项工程', projType: projectType.engineering};
  707. //将未分类的数据归类
  708. sortSameDepthData(engs, ungroupedProj.ID);
  709. sortSameDepthData(tenders, ungroupedEng.ID);
  710. //未分类单项工程处于同层第一个节点
  711. ungroupedEng.NextSiblingID = engs[0] ? engs[0].ID : ungroupedEng.NextSiblingID;
  712. let allDatas = groupedDatas.concat(ungroupedDatas);
  713. //设置分享信息及操作信息
  714. setShareInfo(allDatas);
  715. for (let data of allDatas) {
  716. rst.push(data);
  717. if (data.children) {
  718. rst = rst.concat(data.children);
  719. }
  720. }
  721. rst.push(ungroupedProj);
  722. rst.push(ungroupedEng);
  723. return rst;
  724. }
  725. //按照时间排序
  726. //@param {Array}datas @return {void}
  727. function sortByDate(datas){
  728. datas.sort(function (a, b) {
  729. let shareInfoA = _.find(a.shareInfo, {userID}),
  730. shareInfoB = _.find(b.shareInfo, {userID});
  731. let aV = shareInfoA ? Date.parse(shareInfoA.shareDate) : 0,
  732. bV = shareInfoB ? Date.parse(shareInfoB.shareDate) : 0;
  733. //时间越晚越靠前
  734. if (aV > bV) {
  735. return -1;
  736. } else if (aV < bV) {
  737. return 1;
  738. }
  739. return 0;
  740. });
  741. }
  742. //设置节点数据权限
  743. //@param {Array}datas项目数据
  744. function setPermissionsInfo(datas) {
  745. //data.allowCopy与shareInfo里allowCopy的区别:
  746. //data.allowCopy为该单位实际的权限(跟着最新的分享信息走,可能随着父项)
  747. for (let data of datas) {
  748. if (data.projType === projectType.tender) {
  749. data.allowCopy = isAllowCopy(userID, data);
  750. data.allowCooperate = isAllowCoop(userID, data);
  751. }
  752. }
  753. }
  754. //建立树
  755. //@return void
  756. function initShareTree(){
  757. $.bootstrapLoading.start();
  758. //获取分享数据
  759. CommonAjax.post('/pm/api/receiveProjects', {user_id: userID}, function (rstData) {
  760. // 排序 --分享的文件按照时间先后顺序排序,分享文件下的子文件,按照原本树结构显示,不需要排序
  761. sortByDate(rstData.grouped);
  762. sortByDate(rstData.ungrouped);
  763. //设置汇总信息
  764. if (rstData.summaryInfo) {
  765. setSummaryInfo(rstData.grouped, rstData.summaryInfo.grouped);
  766. setSummaryInfo(rstData.ungrouped, rstData.summaryInfo.ungrouped);
  767. }
  768. let treeDatas = getTreeDatas(rstData.grouped, rstData.ungrouped);
  769. setPermissionsInfo(treeDatas);
  770. tree = pmTree.createNew(treeSetting, treeDatas);
  771. tree.selected = tree.items[0];
  772. showTreeData(tree.items, headers);
  773. //初始选择
  774. let initSel = spreadObj.sheet.getSelections()[0] ? spreadObj.sheet.getSelections()[0] : {row: 0, rowCount: 1};
  775. initSelection(initSel);
  776. autoFlashHeight();
  777. spreadObj.sheet.frozenColumnCount(4);
  778. spreadObj.workBook.refresh();
  779. $.bootstrapLoading.end();
  780. });
  781. }
  782. //初始化右键菜单
  783. function initContextMenu() {
  784. $.contextMenu({
  785. selector: '#shareSpread',
  786. build: function ($trigger, e) {
  787. let target = SheetDataHelper.safeRightClickSelection($trigger, e, spreadObj.workBook);
  788. initSelection({row: target.row, rowCount: 1}, preSelection ? preSelection : null, spreadObj.sheet);
  789. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  790. },
  791. items: {
  792. "copy": {
  793. name: "拷贝工程",
  794. icon: 'fa-copy',
  795. disabled: function () {
  796. let selected = tree.selected;
  797. return !(selected && selected.data.allowCopy);
  798. },
  799. callback: function (key, opt) {
  800. $('#copyShare').modal('show');
  801. }
  802. },
  803. "cancel": {
  804. name: "清除",
  805. icon: 'fa-remove',
  806. disabled: function () {
  807. let selected = tree.selected;
  808. return !(selected && selected.data.cancel && selected.data.cancel === '清除');
  809. },
  810. callback: function (key, opt) {
  811. let $p = $('<p>').text(`点“确定”按钮,确认清除分享文件 “${tree.selected.data.name}”。`);
  812. $('#cancelShare').find('.modal-body').empty();
  813. $('#cancelShare').find('.modal-body').append($p);
  814. $('#cancelShare').modal('show');
  815. }
  816. }
  817. }
  818. });
  819. }
  820. //初始化视图
  821. //@return void
  822. function initView(){
  823. if(tree){
  824. tree = null;
  825. }
  826. if(spreadObj.workBook){
  827. spreadObj.workBook.destroy();
  828. spreadObj.workBook = null;
  829. }
  830. initContextMenu();
  831. buildSheet();
  832. initShareTree();
  833. }
  834. //根据建设项目获取单项工程
  835. //@param {Number}projID @return {void}
  836. function setEng(projID){
  837. let engQuery = {$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], projType: projectType.engineering, userID: userID, ParentID: projID};
  838. CommonAjax.post('/pm/api/getProjectsByQuery', {user_id: userID, query: engQuery, options: '-_id -property'}, function (rstData) {
  839. $('#copyShare_selectEng').empty();
  840. for(let eng of rstData){
  841. let opt = $('<option>').val(eng.ID).text(eng.name);
  842. $('#copyShare_selectEng').append(opt);
  843. }
  844. });
  845. }
  846. //从其他建设项目中复制中,建设项目的文件层次结构名称和顺序
  847. //@param {Array}treeData @return {Array}
  848. function getFileHierarchyInfo(treeData){
  849. curCopySelTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
  850. curCopySelTree.loadDatas(treeData);
  851. let items = curCopySelTree.items;
  852. let rst = [];
  853. function getFileHierarchyName(node){
  854. let nodeName = node.data.name;
  855. let name = [];
  856. while (node.parent){
  857. name.push(node.parent.data.name ? node.parent.data.name : '');
  858. node = node.parent;
  859. }
  860. name = name.reverse();
  861. name.push(nodeName);
  862. return name.join('\\');
  863. }
  864. for(let node of items){
  865. if(node.children.length === 0 ){//project
  866. rst.push({ID: node.data.ID, fileHierarchyName: getFileHierarchyName(node)})
  867. }
  868. }
  869. return rst;
  870. }
  871. //设置拷贝工程下拉选择
  872. //@return {void}
  873. function setCopyModal(){
  874. //获取建设项目
  875. let projQuery = {$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], projType: {$in: [projectType.project, projectType.folder]}, userID: userID};
  876. CommonAjax.post('/pm/api/getProjectsByQuery', {user_id: userID, query: projQuery, options: '-_id'}, function (rstData) {
  877. let fileHierarchyData = getFileHierarchyInfo(rstData);
  878. $('#copyShare_selectProj').empty();
  879. for(let proj of fileHierarchyData){
  880. let opt = $('<option>').val(proj.ID).text(proj.fileHierarchyName);
  881. $('#copyShare_selectProj').append(opt);
  882. }
  883. //初始选择
  884. if(fileHierarchyData.length > 0){
  885. setEng(fileHierarchyData[0].ID);
  886. }
  887. });
  888. }
  889. //拷贝分享的工程
  890. //@param {Object}selected {Number}parentID @return {void}
  891. function copyShareProject(selected, projID, engID){
  892. if(!engID || !selected){
  893. return;
  894. }
  895. let copyMap = {copy: null, update: null};
  896. let newName = getCopyName(selected);
  897. //获取单项工程的单位工程
  898. let tenderQuery = {$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], userID: userID, ParentID: engID};
  899. CommonAjax.post('/pm/api/getProjectsByQuery', {user_id: userID, query: tenderQuery, options: '-_id -property'}, function (rstData) {
  900. let updateTender = null;
  901. for(let tender of rstData){
  902. if(tender.name === newName){
  903. $('#copyShare_name').text('已存在此单位工程。');
  904. $('#copyShare_name').addClass('text-danger');
  905. return;
  906. }
  907. if(tender.NextSiblingID == -1){
  908. updateTender = tender;
  909. }
  910. }
  911. //更新前节点
  912. if(updateTender){
  913. copyMap.update = {query: {ID: updateTender.ID}};
  914. }
  915. //拷贝
  916. let copyData = {
  917. userID: userID,
  918. ID: selected.data.actualTreeInfo.ID,
  919. NextSiblingID: -1,
  920. ParentID: engID,
  921. name: newName,
  922. shareInfo: [],
  923. compilation: selected.data.compilation,
  924. createDateTime: selected.data.createDateTime,
  925. fileVer: selected.data.fileVer ? selected.data.fileVer : '',
  926. projType: selected.data.projType,
  927. property: {},
  928. recentDateTime: selected.data.recentDateTime,
  929. fullFolder: selected.data.fullFolder
  930. };
  931. copyData.property.rootProjectID = projID;
  932. copyMap.copy = {document: copyData};
  933. $('#copyShare').modal('hide');
  934. $.bootstrapLoading.start();
  935. CommonAjax.post('/pm/api/copyProjects', {projectMap: copyMap, user_id: userID}, function (rstData) {
  936. $.bootstrapLoading.end();
  937. }, function () {
  938. $.bootstrapLoading.end();
  939. });
  940. });
  941. }
  942. //获取拷贝后的名称
  943. //@param {Object}node @return {String}
  944. function getCopyName(node) {
  945. //当前单位工程可能没有分享的用户信息,可能他人分享的是父级文件,userInfo在父级文件中
  946. let orgName = node.data.name,
  947. userInfo = node.data.userInfo;
  948. while (node && !userInfo) {
  949. node = node.parent;
  950. userInfo = node.data.userInfo;
  951. }
  952. return `${orgName} (${userInfo.name}分享拷贝)`;
  953. }
  954. //事件监听器
  955. //@return void
  956. function eventListener(){
  957. //tab
  958. $('#tab_pm_share').on('shown.bs.tab', function () {
  959. //侧滑隐藏
  960. $('.slide-sidebar').removeClass('open');
  961. $('.slide-sidebar').css('width', '0');
  962. projTreeObj.tree = null;
  963. if(projTreeObj.workBook){
  964. projTreeObj.workBook.destroy();
  965. projTreeObj.workBook = null;
  966. }
  967. gcTreeObj.tree = null;
  968. if(gcTreeObj.workBook){
  969. gcTreeObj.workBook.destroy();
  970. gcTreeObj.workBook = null;
  971. }
  972. initView();
  973. });
  974. //关闭拷贝工程
  975. $('#copyShare').on('hidden.bs.modal', function () {
  976. $('#copyShareProj-info').hide();
  977. $('#copyShareEng-info').hide();
  978. });
  979. //打开拷贝工程
  980. $('#copyShare').on('shown.bs.modal', function () {
  981. setCopyModal();
  982. //更改显示名称
  983. let newName = getCopyName(shareSeleted);
  984. $('#copyShare_name').html(`拷贝后,工程将重命名为 "<b>${newName}</b>"`);
  985. $('#copyShare_name').removeClass('text-danger');
  986. });
  987. //拷贝工程改变选择建设项目
  988. $('#copyShare_selectProj').change(function () {
  989. //更改显示名称
  990. let newName = getCopyName(shareSeleted);
  991. $('#copyShare_name').html(`拷贝后,工程将重命名为 "<b>${newName}</b>"`);
  992. $('#copyShare_name').removeClass('text-danger');
  993. $('#copyShareProj-info').hide();
  994. $('#copyShareEng-info').hide();
  995. let curSelID = $(this).select().val();
  996. setEng(parseInt(curSelID));
  997. });
  998. //拷贝工程改变选择单项工程
  999. $('#copyShare_selectEng').change(function () {
  1000. //更改显示名称
  1001. let newName = getCopyName(shareSeleted);
  1002. $('#copyShare_name').html(`拷贝后,工程将重命名为 "<b>${newName}</b>"`);
  1003. $('#copyShare_name').removeClass('text-danger');
  1004. });
  1005. //确认拷贝
  1006. $('#copyShare_confirm').click(function () {
  1007. let selProj = $('#copyShare_selectProj').select().val();
  1008. if(!selProj){
  1009. $('#copyShareProj-info').show();
  1010. return;
  1011. }
  1012. //目标建设项目的计税方法与单位工程的一致时,才可拷贝
  1013. if (curCopySelTree) {
  1014. let projectNode = curCopySelTree.nodes[curCopySelTree.prefix + selProj];
  1015. if (!projectNode || !projectNode.data.property || projectNode.data.property.taxType != tree.selected.data.taxType){
  1016. alert('当前单位工程计税方法与目标建设项目不一致,不可复制。');
  1017. return;
  1018. }
  1019. }
  1020. let selEng = $('#copyShare_selectEng').select().val();
  1021. if(!selEng){
  1022. $('#copyShareEng-info').show();
  1023. return;
  1024. }
  1025. copyShareProject(tree.selected, parseInt(selProj), parseInt(selEng));
  1026. });
  1027. //清除分享
  1028. //清除了该节点后,可能还有该节点的数据在树上(树允许有重复数据),需要更新分享信息
  1029. function updateAfterCancel(userID, projectID) {
  1030. for (let item of tree.items) {
  1031. if (item.data.actualTreeInfo && item.data.actualTreeInfo.ID === projectID) {
  1032. _.remove(item.data.shareInfo, function (data) {
  1033. return data.userID === userID;
  1034. });
  1035. }
  1036. }
  1037. }
  1038. $('#cancelShareConfirm').click(function () {
  1039. $.bootstrapLoading.start();
  1040. let cancelProjID = tree.selected.data.actualTreeInfo.ID;
  1041. CommonAjax.post('/pm/api/share', {user_id: userID, type: oprType.cancel, projectID: cancelProjID, shareData:[{userID: userID}]}, function (rstData) {
  1042. tree.removeNode(tree.selected);
  1043. //更新与清除节点数据相同,且为被清除缓存分享信息
  1044. updateAfterCancel(userID, cancelProjID);
  1045. //重新设置actualIDShareInfo,以正确更新权限(清除了分享信息后,可能会导致权限变化 eg:清除了新的分享,则存留的分享项目采用旧的)
  1046. actualIDShareInfo = {};
  1047. let treeDatas = [];
  1048. for (let item of tree.items) {
  1049. treeDatas.push(item.data);
  1050. let actualTreeInfo = item.data.actualTreeInfo;
  1051. if (actualTreeInfo && !actualIDShareInfo[actualTreeInfo.ID]) {
  1052. actualIDShareInfo[actualTreeInfo.ID] = {
  1053. ID: actualTreeInfo.ID,
  1054. ParentID: actualTreeInfo.ParentID,
  1055. NextSiblingID: actualTreeInfo.NextSiblingID,
  1056. shareInfo: item.data.shareInfo
  1057. };
  1058. }
  1059. }
  1060. //重新设置权限
  1061. setPermissionsInfo(treeDatas);
  1062. showTreeData(tree.items, headers);
  1063. $.bootstrapLoading.end();
  1064. }, function () {
  1065. $.bootstrapLoading.end();
  1066. });
  1067. });
  1068. }
  1069. return {spreadObj, headers, initView, eventListener}
  1070. })();
  1071. $(document).ready(function () {
  1072. pmShare.eventListener();
  1073. });