pm_share.js 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  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. async function copyShareProject(selected, projID, engID){
  888. try {
  889. if(!engID || !selected){
  890. return;
  891. }
  892. let copyMap = {copy: null, update: null};
  893. let newName = getCopyName(selected);
  894. //获取单项工程的单位工程
  895. let tenderQuery = {$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], userID: userID, ParentID: engID};
  896. const rstData = await ajaxPost('/pm/api/getProjectsByQuery', {user_id: userID, query: tenderQuery, options: '-_id -property'}, false, 10000);
  897. let updateTender = null;
  898. for(let tender of rstData){
  899. if(tender.name === newName){
  900. $('#copyShare_name').text('已存在此单位工程。');
  901. $('#copyShare_name').addClass('text-danger');
  902. return;
  903. }
  904. if(tender.NextSiblingID == -1){
  905. updateTender = tender;
  906. }
  907. }
  908. //更新前节点
  909. if(updateTender){
  910. copyMap.update = {query: {ID: updateTender.ID}};
  911. }
  912. //拷贝
  913. let copyData = {
  914. userID: userID,
  915. ID: selected.data.actualTreeInfo.ID,
  916. NextSiblingID: -1,
  917. ParentID: engID,
  918. name: newName,
  919. shareInfo: [],
  920. compilation: selected.data.compilation,
  921. createDateTime: selected.data.createDateTime,
  922. fileVer: selected.data.fileVer ? selected.data.fileVer : '',
  923. projType: selected.data.projType,
  924. property: {},
  925. recentDateTime: selected.data.recentDateTime,
  926. fullFolder: selected.data.fullFolder
  927. };
  928. copyData.property.rootProjectID = projID;
  929. copyMap.copy = {document: copyData};
  930. $('#copyShare').modal('hide');
  931. $.bootstrapLoading.progressStart('拷贝项目', true);
  932. $("#progress_modal_body").text('正在拷贝项目,请稍候……');
  933. await ajaxPost('/pm/api/copyProjects', {projectMap: copyMap, user_id: userID, tenderCount: 1});
  934. importProcessChecking();
  935. } catch (err) {
  936. alert(err);
  937. }
  938. }
  939. //获取拷贝后的名称
  940. //@param {Object}node @return {String}
  941. function getCopyName(node) {
  942. //当前单位工程可能没有分享的用户信息,可能他人分享的是父级文件,userInfo在父级文件中
  943. let orgName = node.data.name,
  944. userInfo = node.data.userInfo;
  945. while (node && !userInfo) {
  946. node = node.parent;
  947. userInfo = node.data.userInfo;
  948. }
  949. return `${orgName} (${userInfo.name}分享拷贝)`;
  950. }
  951. //事件监听器
  952. //@return void
  953. function eventListener(){
  954. //tab
  955. $('#tab_pm_share').on('shown.bs.tab', function () {
  956. //侧滑隐藏
  957. $('.slide-sidebar').removeClass('open');
  958. $('.slide-sidebar').css('width', '0');
  959. projTreeObj.tree = null;
  960. if(projTreeObj.workBook){
  961. projTreeObj.workBook.destroy();
  962. projTreeObj.workBook = null;
  963. }
  964. gcTreeObj.tree = null;
  965. if(gcTreeObj.workBook){
  966. gcTreeObj.workBook.destroy();
  967. gcTreeObj.workBook = null;
  968. }
  969. initView();
  970. });
  971. //关闭拷贝工程
  972. $('#copyShare').on('hidden.bs.modal', function () {
  973. $('#copyShareProj-info').hide();
  974. $('#copyShareEng-info').hide();
  975. });
  976. //打开拷贝工程
  977. $('#copyShare').on('shown.bs.modal', function () {
  978. setCopyModal();
  979. //更改显示名称
  980. let newName = getCopyName(shareSeleted);
  981. $('#copyShare_name').html(`拷贝后,工程将重命名为 "<b>${newName}</b>"`);
  982. $('#copyShare_name').removeClass('text-danger');
  983. });
  984. //拷贝工程改变选择建设项目
  985. $('#copyShare_selectProj').change(function () {
  986. //更改显示名称
  987. let newName = getCopyName(shareSeleted);
  988. $('#copyShare_name').html(`拷贝后,工程将重命名为 "<b>${newName}</b>"`);
  989. $('#copyShare_name').removeClass('text-danger');
  990. $('#copyShareProj-info').hide();
  991. $('#copyShareEng-info').hide();
  992. let curSelID = $(this).select().val();
  993. setEng(parseInt(curSelID));
  994. });
  995. //拷贝工程改变选择单项工程
  996. $('#copyShare_selectEng').change(function () {
  997. //更改显示名称
  998. let newName = getCopyName(shareSeleted);
  999. $('#copyShare_name').html(`拷贝后,工程将重命名为 "<b>${newName}</b>"`);
  1000. $('#copyShare_name').removeClass('text-danger');
  1001. });
  1002. //确认拷贝
  1003. $('#copyShare_confirm').click(function () {
  1004. let selProj = $('#copyShare_selectProj').select().val();
  1005. if(!selProj){
  1006. $('#copyShareProj-info').show();
  1007. return;
  1008. }
  1009. //目标建设项目的计税方法与单位工程的一致时,才可拷贝
  1010. if (curCopySelTree) {
  1011. let projectNode = curCopySelTree.nodes[curCopySelTree.prefix + selProj];
  1012. if (!projectNode || !projectNode.data.property || projectNode.data.property.taxType != tree.selected.data.taxType){
  1013. alert('当前单位工程计税方法与目标建设项目不一致,不可复制。');
  1014. return;
  1015. }
  1016. }
  1017. let selEng = $('#copyShare_selectEng').select().val();
  1018. if(!selEng){
  1019. $('#copyShareEng-info').show();
  1020. return;
  1021. }
  1022. copyShareProject(tree.selected, parseInt(selProj), parseInt(selEng));
  1023. });
  1024. //清除分享
  1025. //清除了该节点后,可能还有该节点的数据在树上(树允许有重复数据),需要更新分享信息
  1026. function updateAfterCancel(userID, projectID) {
  1027. for (let item of tree.items) {
  1028. if (item.data.actualTreeInfo && item.data.actualTreeInfo.ID === projectID) {
  1029. _.remove(item.data.shareInfo, function (data) {
  1030. return data.userID === userID;
  1031. });
  1032. }
  1033. }
  1034. }
  1035. $('#cancelShareConfirm').click(function () {
  1036. $.bootstrapLoading.start();
  1037. let cancelProjID = tree.selected.data.actualTreeInfo.ID;
  1038. CommonAjax.post('/pm/api/share', {user_id: userID, type: oprType.cancel, projectID: cancelProjID, shareData:[{userID: userID}]}, function (rstData) {
  1039. tree.removeNode(tree.selected);
  1040. //更新与清除节点数据相同,且为被清除缓存分享信息
  1041. updateAfterCancel(userID, cancelProjID);
  1042. //重新设置actualIDShareInfo,以正确更新权限(清除了分享信息后,可能会导致权限变化 eg:清除了新的分享,则存留的分享项目采用旧的)
  1043. actualIDShareInfo = {};
  1044. let treeDatas = [];
  1045. for (let item of tree.items) {
  1046. treeDatas.push(item.data);
  1047. let actualTreeInfo = item.data.actualTreeInfo;
  1048. if (actualTreeInfo && !actualIDShareInfo[actualTreeInfo.ID]) {
  1049. actualIDShareInfo[actualTreeInfo.ID] = {
  1050. ID: actualTreeInfo.ID,
  1051. ParentID: actualTreeInfo.ParentID,
  1052. NextSiblingID: actualTreeInfo.NextSiblingID,
  1053. shareInfo: item.data.shareInfo
  1054. };
  1055. }
  1056. }
  1057. //重新设置权限
  1058. setPermissionsInfo(treeDatas);
  1059. showTreeData(tree.items, headers);
  1060. $.bootstrapLoading.end();
  1061. }, function () {
  1062. $.bootstrapLoading.end();
  1063. });
  1064. });
  1065. }
  1066. return {spreadObj, headers, initView, eventListener}
  1067. })();
  1068. $(document).ready(function () {
  1069. pmShare.eventListener();
  1070. });