pm_newMain.js 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229
  1. /**
  2. * 项目管理相关js
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/8/22
  6. * @version
  7. */
  8. let Tree = null;//
  9. let movetoZTree = null;
  10. let copytoZTree = null;
  11. let engineering = [];
  12. let feeRateData = [];
  13. let isSaving = false;
  14. let projectProperty = [];
  15. let fileDelObj = null;
  16. let projectType = {
  17. folder: 'Folder',
  18. tender: 'Tender',
  19. project: 'Project',
  20. engineering: 'Engineering'
  21. };
  22. let fileType = {
  23. unitPriceFile: 'UnitPriceFile',
  24. feeRateFile: 'FeeRateFile'
  25. };
  26. const projTreeObj = {
  27. tree: null,
  28. workBook: null,
  29. setting: {
  30. tree: {
  31. id: 'ID',
  32. pid: 'ParentID',
  33. nid: 'NextSiblingID',
  34. rootId: -1,
  35. autoUpdate: false
  36. },
  37. header: [
  38. {name: '工程列表', dataCode: 'name', width: 800, vAlign: 'center', hAlign: 'left'},
  39. {name: '工程造价', dataCode: 'engineeringCost', width: 170, vAlign: 'center', hAlign: 'right'},
  40. {name: '单价文件', dataCode: 'unitPriceFile', width: 250, vAlign: 'center', hAlign: 'left'},
  41. {name: '费率文件', dataCode: 'feeRateFile', width: 250, vAlign: 'center', hAlign: 'left'},
  42. {name: '创建日期', dataCode: 'createDateTime', width: 170, vAlign: 'center', hAlign: 'left'}
  43. ],
  44. options: {
  45. tabStripVisible: false,
  46. allowCopyPasteExcelStyle : false,
  47. allowExtendPasteRange: false,
  48. allowUserDragDrop : false,
  49. allowUserDragFill: false,
  50. scrollbarMaxAlign : true
  51. }
  52. },
  53. renderSheetFuc: function (sheet, fuc) {
  54. sheet.suspendPaint();
  55. sheet.suspendEvent();
  56. fuc();
  57. sheet.resumePaint();
  58. sheet.resumeEvent();
  59. },
  60. setOptions: function (workbook, opts) {
  61. for(let opt in opts){
  62. workbook.options[opt] = opts[opt];
  63. }
  64. },
  65. bindEvent: function (workBook) {
  66. const _events = GC.Spread.Sheets.Events;
  67. let sheet = workBook.getActiveSheet();
  68. //改变选中节点set selected
  69. sheet.bind(_events.SelectionChanging, this.onSelectionChanging);
  70. },
  71. buildHeader: function (sheet, headers) {
  72. let me = this;
  73. let fuc = function () {
  74. sheet.options.isProtected = true;
  75. sheet.options.protectionOptions = {
  76. allowResizeRows: true,
  77. allowResizeColumns: true
  78. };
  79. sheet.setColumnCount(headers.length);
  80. sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
  81. for(let i = 0, len = headers.length; i < len; i++){
  82. sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
  83. sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
  84. }
  85. };
  86. me.renderSheetFuc(sheet, fuc);
  87. },
  88. buildSheet: function () {
  89. if(!this.workBook){
  90. this.workBook = new GC.Spread.Sheets.Workbook($('#projSpread')[0], {sheetCount: 1});
  91. this.setOptions(this.workBook, this.setting.options);
  92. this.buildHeader(this.workBook.getActiveSheet(), this.setting.header);
  93. this.bindEvent(this.workBook);
  94. }
  95. },
  96. initSelection: function (row) {
  97. let me = this;
  98. let node = me.tree.items[row];
  99. me.tree.selected = node;
  100. $(".tools-btn > a").not(".disabled").addClass("disabled");
  101. $("#add-engineering-btn").addClass("disabled");
  102. $('#add-tender-btn').removeClass('disabled');
  103. if(node){
  104. switch(node.data.projType) {
  105. case projectType.project:
  106. $("#del-btn").removeClass("disabled");
  107. $("#add-engineering-btn").removeClass("disabled");
  108. break;
  109. case projectType.folder:
  110. if(!node.children || node.children.length === 0){
  111. $("#del-btn").removeClass("disabled");
  112. }
  113. break;
  114. case projectType.engineering:
  115. $("#del-btn").removeClass("disabled");
  116. $("#add-engineering-btn").removeClass("disabled");
  117. break;
  118. case projectType.tender:
  119. $("#add-engineering-btn").removeClass("disabled");
  120. $("#move-to-btn").removeClass("disabled");
  121. $("#copy-to-btn").removeClass("disabled");
  122. $("#share-btn").removeClass("disabled");
  123. $("#cooperate-btn").removeClass("disabled");
  124. $("#del-btn").removeClass("disabled");
  125. break;
  126. }
  127. $("#rename-btn").removeClass("disabled");
  128. }
  129. },
  130. onSelectionChanging: function (sender, args) {
  131. let me = projTreeObj;
  132. me.initSelection(args.newSelections[0].row);
  133. },
  134. getShowData: function (datas) {
  135. for(let data of datas){
  136. data.name = data.name ? data.name : '';
  137. if(data.projType !== projectType.tender){
  138. data.engineeringCost = '';
  139. data.unitPriceFile = '';
  140. data.feeRateFile = '';
  141. data.createDateTime = '';
  142. }
  143. else{
  144. data.engineeringCost = data.engineeringCost ? data.engineeringCost : 0;
  145. data.unitPriceFile = data.property && data.property.unitPriceFile && data.property.unitPriceFile.name ? data.property.unitPriceFile.name : '';
  146. data.feeRateFile = data.property && data.property.feeFile && data.property.feeFile.name ? data.property.feeFile.name : '';
  147. data.createDateTime = data.createDateTime ? new Date(data.createDateTime).Format('yyyy-MM-dd') : '';
  148. }
  149. }
  150. },
  151. getTreeNodeCell: function (tree) {
  152. let indent = 20;
  153. let levelIndent = -5;
  154. let halfBoxLength = 5;
  155. let halfExpandLength = 3;
  156. let imgWidth = 18;
  157. let imgHeight = 14;
  158. let TreeNodeCellType = function () {
  159. };
  160. TreeNodeCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  161. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  162. if (style.backColor) {
  163. ctx.save();
  164. ctx.fillStyle = style.backColor;
  165. ctx.fillRect(x, y, w, h);
  166. ctx.restore();
  167. } else {
  168. ctx.clearRect(x, y, w, h);
  169. }
  170. let drawLine = function (canvas, x1, y1, x2, y2, color) {
  171. ctx.save();
  172. ctx.translate(0.5, 0.5);
  173. ctx.beginPath();
  174. ctx.moveTo(x1, y1);
  175. ctx.lineTo(x2, y2);
  176. ctx.strokeStyle = color;
  177. ctx.stroke();
  178. ctx.restore();
  179. };
  180. let drawExpandBox = function (ctx, x, y, w, h, centerX, centerY, expanded) {
  181. let rect = {}, h1, h2, offset = 1;
  182. rect.top = centerY - halfBoxLength;
  183. rect.bottom = centerY + halfBoxLength;
  184. rect.left = centerX - halfBoxLength;
  185. rect.right = centerX + halfBoxLength;
  186. if (rect.left < x + w) {
  187. rect.right = Math.min(rect.right, x + w);
  188. ctx.save();
  189. ctx.translate(0.5, 0.5);
  190. ctx.strokeStyle = 'black';
  191. ctx.beginPath();
  192. ctx.moveTo(rect.left, rect.top);
  193. ctx.lineTo(rect.left, rect.bottom);
  194. ctx.lineTo(rect.right, rect.bottom);
  195. ctx.lineTo(rect.right, rect.top);
  196. ctx.lineTo(rect.left, rect.top);
  197. ctx.stroke();
  198. ctx.fillStyle = 'white';
  199. ctx.fill();
  200. ctx.restore();
  201. // Draw Horizontal Line
  202. h1 = centerX - halfExpandLength;
  203. h2 = Math.min(centerX + halfExpandLength, x + w);
  204. if (h2 > h1) {
  205. drawLine(ctx, h1, centerY, h2, centerY, 'black');
  206. }
  207. // Draw Vertical Line
  208. if (!expanded && (centerX < x + w)) {
  209. drawLine(ctx, centerX, centerY - halfExpandLength, centerX, centerY + halfExpandLength, 'black');
  210. }
  211. }
  212. }
  213. let node = tree.items[options.row];
  214. let showTreeLine = true;
  215. if (!node) { return; }
  216. let centerX = Math.floor(x) + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  217. let x1 = centerX + indent / 2;
  218. let centerY = Math.floor((y + (y + h)) / 2);
  219. let y1;
  220. // Draw Sibling Line
  221. if (showTreeLine) {
  222. // Draw Horizontal Line
  223. if (centerX < x + w) {
  224. drawLine(ctx, centerX, centerY, Math.min(x1, x + w), centerY, 'gray');
  225. let img;
  226. if(node.data.projType === projectType.folder){
  227. img = document.getElementById('folder_open_pic');
  228. imgWidth = 15;
  229. }
  230. else if(node.data.projType === projectType.project){
  231. img = document.getElementById('proj_pic');
  232. imgWidth = 18;
  233. }
  234. else if(node.data.projType === projectType.engineering){
  235. img = document.getElementById('eng_pic');
  236. imgWidth = 14;
  237. }
  238. else if(node.data.projType === projectType.tender){
  239. img = document.getElementById('tender_pic');
  240. imgWidth = 14;
  241. }
  242. ctx.drawImage(img, centerX+indent/2+3, centerY - 7, imgWidth,imgHeight);
  243. }
  244. // Draw Vertical Line
  245. if (centerX < x + w) {
  246. y1 = node.isLast() ? centerY : y + h;
  247. if (node.isFirst() && !node.parent.parent) {
  248. drawLine(ctx, centerX, centerY, centerX, y1, 'gray');
  249. } else {
  250. drawLine(ctx, centerX, y, centerX, y1, 'gray');
  251. }
  252. }
  253. }
  254. // Draw Expand Box
  255. if (node.children.length > 0) {
  256. drawExpandBox(ctx, x, y, w, h, centerX, centerY, node.expanded);
  257. }
  258. // Draw Parent Line
  259. if (showTreeLine) {
  260. var parent = node.parent, parentCenterX = centerX - indent - levelIndent;
  261. while (parent.parent) {
  262. if (!parent.isLast()) {
  263. if (parentCenterX < x + w) {
  264. drawLine(ctx, parentCenterX, y, parentCenterX, y + h, 'gray');
  265. }
  266. }
  267. parent = parent.parent;
  268. parentCenterX -= (indent + levelIndent);
  269. }
  270. };
  271. // Draw Text
  272. //x = x + (node.depth() + 1) * indent + node.depth() * levelIndent;
  273. x = x + (node.depth() + 1) * indent + node.depth() * levelIndent + imgWidth + 3;
  274. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  275. };
  276. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  277. return {
  278. x: x,
  279. y: y,
  280. row: context.row,
  281. col: context.col,
  282. cellStyle: cellStyle,
  283. cellRect: cellRect,
  284. sheetArea: context.sheetArea,
  285. isReservedLocation: true
  286. };
  287. };
  288. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  289. let offset = -1;
  290. let node = tree.items[hitinfo.row];
  291. tree.selected = node;
  292. let centerX = hitinfo.cellRect.x + offset + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  293. let centerY = (hitinfo.cellRect.y + offset + (hitinfo.cellRect.y + offset + hitinfo.cellRect.height)) / 2;
  294. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  295. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  296. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  297. zoom = hitinfo.sheet.zoom();
  298. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  299. //(图标+名字)区域
  300. function withingClickArea(){
  301. return hitinfo.x > centerX + halfBoxLength && hitinfo.x < centerX + halfBoxLength + imgWidth + indent/2+3 + textLength;
  302. }
  303. //建设项目,侧滑汇总
  304. if(node.data.projType === projectType.project && withingClickArea()){
  305. setDataToSideBar();
  306. $(".slide-sidebar").animate({width:"800"}).addClass("open");
  307. $('body').unbind('click');
  308. setTimeout(function () {
  309. $("body").bind('click', function (event) {
  310. var e = event || window.event; //浏览器兼容性
  311. if (!$(event.target).is('a')) {
  312. var elem = event.target || e.srcElement;
  313. while (elem) { //循环判断至跟节点,防止点击的是div子元素
  314. if (elem.className == "open-sidebar" || elem.className == 'slide-sidebar open') {
  315. return false;
  316. }
  317. elem = elem.parentNode;
  318. }
  319. $(".slide-sidebar").animate({width: "0"}).removeClass("open")// 关闭处理
  320. }
  321. });
  322. }, 100);
  323. }
  324. //单项文件,进入造价书界面
  325. else if(node.data.projType === projectType.tender && withingClickArea()){
  326. let newTab = window.open('about:blank');
  327. BeforeOpenProject(node.data.ID, {'fullFolder': GetFullFolder(node.parent)}, function () {
  328. let mainUrl = `/main?project=${node.data.ID}`;
  329. CommonAjax.get(mainUrl, [], function () {
  330. newTab.location.href = mainUrl;
  331. });
  332. });
  333. return;
  334. }
  335. if (!node || node.children.length === 0) { return; }
  336. if (hitinfo.x > centerX - halfBoxLength && hitinfo.x < centerX + halfBoxLength && hitinfo.y > centerY - halfBoxLength && hitinfo.y < centerY + halfBoxLength) {
  337. node.setExpanded(!node.expanded);
  338. TREE_SHEET_HELPER.massOperationSheet(hitinfo.sheet, function () {
  339. let iCount = node.posterityCount(), i, child;
  340. for (i = 0; i < iCount; i++) {
  341. child = tree.items[hitinfo.row + i + 1];
  342. hitinfo.sheet.setRowVisible(hitinfo.row + i + 1, child.visible, hitinfo.sheetArea);
  343. }
  344. hitinfo.sheet.invalidateLayout();
  345. });
  346. hitinfo.sheet.repaint();
  347. }
  348. };
  349. TreeNodeCellType.prototype.processMouseMove = function (hitInfo) {
  350. let sheet = hitInfo.sheet;
  351. let div = sheet.getParent().getHost();
  352. let canvasId = div.id + "vp_vp";
  353. let canvas = $(`#${canvasId}`)[0];
  354. //改变鼠标图案
  355. let node = tree.items[hitInfo.row];
  356. let offset = -1;
  357. let centerX = hitInfo.cellRect.x + offset + node.depth() * indent + node.depth() * levelIndent + indent / 2;
  358. let text = hitInfo.sheet.getText(hitInfo.row, hitInfo.col);
  359. let value = hitInfo.sheet.getValue(hitInfo.row, hitInfo.col);
  360. let acStyle = hitInfo.sheet.getActualStyle(hitInfo.row, hitInfo.col),
  361. zoom = hitInfo.sheet.zoom();
  362. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitInfo.sheet, row: hitInfo.row, col: hitInfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  363. if (sheet && hitInfo.x > centerX + halfBoxLength && hitInfo.x < centerX + halfBoxLength + imgWidth + indent/2+3 + textLength) {
  364. canvas.style.cursor='pointer';
  365. return true;
  366. }else{
  367. canvas.style.cursor='default';
  368. }
  369. return false;
  370. };
  371. return new TreeNodeCellType();
  372. },
  373. showTreeData: function (nodes, headers) {
  374. let me = this;
  375. let sheet = me.workBook.getActiveSheet();
  376. let fuc = function(){
  377. sheet.setRowCount(nodes.length);
  378. for(let i = 0; i < nodes.length; i++){
  379. let treeNodeCell = me.getTreeNodeCell(me.tree);
  380. sheet.getCell(i, 0).cellType(treeNodeCell);
  381. for(let j = 0; j < headers.length; j++){
  382. sheet.getRange(-1, j, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[j]['hAlign']]);
  383. sheet.getRange(-1, j, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[j]['vAlign']]);
  384. let dataCode = headers[j].dataCode;
  385. sheet.setValue(i, j, nodes[i]['data'][dataCode]);
  386. }
  387. }
  388. };
  389. me.renderSheetFuc(sheet, fuc);
  390. },
  391. addRow: function (node) {
  392. const sheet = this.workBook.getActiveSheet();
  393. const items = this.tree.items;
  394. const rIdx = items.indexOf(node);
  395. const cIdx = sheet.getActiveColumnIndex();
  396. sheet.addRows(rIdx, 1);
  397. //set selection selected
  398. sheet.setSelection(rIdx, cIdx, 1, 1);
  399. this.tree.selected = node;
  400. //父节点收起时添加子节点,子节点添加完后隐藏
  401. if(node.parent && !node.parent.expanded){
  402. sheet.setRowVisible(rIdx, false);
  403. }
  404. sheet.getCell(rIdx, 0).cellType(this.getTreeNodeCell(this.tree));
  405. this.refreshNodeData(sheet, node);
  406. },
  407. refreshNodeData: function (sheet, node) {
  408. let me = this;
  409. //解决字段名不同
  410. if(node.data.projType !== projectType.tender){
  411. node.data.engineeringCost = '';
  412. node.data.unitPriceFile = '';
  413. node.data.feeRateFile = '';
  414. node.data.createDateTime = '';
  415. }
  416. else{
  417. node.data.engineeringCost = node.data.engineeringCost ? node.data.engineeringCost : 0;
  418. node.data.unitPriceFile = node.data.property && node.data.property.unitPriceFile && node.data.property.unitPriceFile.name ? node.data.property.unitPriceFile.name : '';
  419. node.data.feeRateFile = node.data.property && node.data.property.feeFile && node.data.property.feeFile.name ? node.data.property.feeFile.name : '';
  420. node.data.createDateTime = node.data.createDateTime ? new Date(node.data.createDateTime).Format('yyyy-MM-dd') : '';
  421. }
  422. this.renderSheetFuc(sheet, function () {
  423. let rIdx = me.tree.items.indexOf(node);
  424. for(let col = 0; col < me.setting.header.length; col++){
  425. let dataCode = me.setting.header[col]['dataCode'];
  426. sheet.setValue(rIdx, col, node.data[dataCode]);
  427. }
  428. });
  429. },
  430. insert: function (data, parent, next) {
  431. let node = this.tree.addNodeData(data, parent, next);
  432. this.addRow(node);
  433. return node;
  434. },
  435. };
  436. $(document).ready(function() {
  437. init();
  438. $('#tab_pm_all').on('show.bs.tab', function () {
  439. gcTree = null;
  440. init();
  441. });
  442. // 侧滑数据
  443. /* $(".poj-list").on('click', ".open-sidebar", function() {
  444. setDataToSideBar();
  445. $(".slide-sidebar").animate({width:"800"}).addClass("open");
  446. });*/
  447. //单价、费率文件删除确认
  448. $('#fileDelConfirm').click(function () {
  449. if(fileDelObj && fileDelObj.id){
  450. let updateObj = Object.create(null);
  451. updateObj.updateType = 'delete';
  452. updateObj.updateData = Object.create(null);
  453. if(fileDelObj.fileType === fileType.unitPriceFile){
  454. updateObj.updateData.id = fileDelObj.id;
  455. }
  456. else if(fileDelObj.fileType === fileType.feeRateFile){
  457. updateObj.updateData.ID = fileDelObj.id;
  458. }
  459. updateObj.fileType = fileDelObj.fileType;
  460. a_updateFiles([updateObj], function () {
  461. fileDelObj = null;
  462. $('#fileDelCancel').click();
  463. //refresh front?
  464. });
  465. }
  466. });
  467. //绑定新建建设项目、新建单项工程、新建文件夹、重命名Enter键事件
  468. bindInputs($('#project-name'), $('#engineering-name'), $('#folder-name'), $('#rename-name'));
  469. //绑定新建建设项目、新建单项工程、新建文件夹、重命名弹窗隐藏事件
  470. bindModalsHidden($('#add-project-dialog'), $('#add-engineering-dialog'), $('#add-folder-dialog'), $('#rename-dialog'));
  471. // 新增建设项目点击
  472. $('#add-project-btn').click(function () {
  473. let selectedItem = projTreeObj.tree.selected;
  474. $('#add-project-dialog').modal('show');
  475. });
  476. // 新增建设项目操作
  477. $('#addProjOk').click(function () {
  478. AddProject();
  479. });
  480. // 选择计价方式
  481. $("input[name='valuation_type']").click(function() {
  482. let type = $(this).val();
  483. let targetData = type === 'bill' ? JSON.parse(billValuation) : JSON.parse(rationValuation);
  484. let html = '<option value="">请选择计价规则</option>';
  485. for(let valuation of targetData) {
  486. if (valuation === null) {
  487. continue;
  488. }
  489. html += '<option value="'+ valuation._id +'">'+ valuation.name +'</option>';
  490. }
  491. $("#valuation").html(html);
  492. $("#tender-engineering").html('<option value="">请选择对应的工程专业</option>');
  493. });
  494. //选择计价规则
  495. $("#valuation").change(function () {
  496. let engineeringList = getEngineeringList();
  497. let engineeringHtml = getEngineeringHtml(engineeringList);
  498. $("#tender-engineering").html(engineeringHtml);
  499. $('#valuation-info').hide();
  500. });
  501. // 新增单项项目点击
  502. $("#add-engineering-btn").click(function() {
  503. let selectedItem = projTreeObj.tree.selected;
  504. try {
  505. if(selectedItem !== null && selectedItem.data.projType !== projectType.folder){
  506. $("#add-engineering-dialog").modal("show");
  507. }
  508. } catch (error) {
  509. alert(error);
  510. }
  511. });
  512. // 新增单项工程操作
  513. $("#add-engineering-confirm").click(function() {
  514. AddEngineering();
  515. });
  516. // 新增单位工程点击
  517. $("#add-tender-btn").click(function() {
  518. let selectedItem = projTreeObj.tree.selected;
  519. $("#add-tender-dialog").modal("show");
  520. });
  521. //新建单位工程-建设项目提示
  522. $('#poj-name').change(function () {
  523. let pojName = $('#poj-name').val().trim();
  524. let nameList = getNameList($('#poj-name-list').children());
  525. let isExist = hasListName(nameList, pojName);
  526. if(!isExist){
  527. if(pojName !== ''){
  528. replaceClass($('#poj-name-info'), 'text-danger', 'text-info');
  529. setDangerInfo($('#poj-name-info'), `新建“${pojName}”`);
  530. }
  531. //清空单项工程下拉和文件下拉
  532. setEngOptions(null);
  533. setFileOptions(null);
  534. }
  535. else {
  536. $('#poj-name-info').hide();
  537. }
  538. });
  539. //新建单位工程-单项工程提示
  540. $('#eng-name').change(function () {
  541. let engName = $('#eng-name').val().trim();
  542. let nameList = getNameList($('#eng-name-list').children());
  543. let isExist = hasListName(nameList, engName);
  544. if(!isExist){
  545. if(engName !== ''){
  546. replaceClass($('#eng-name-info'), 'text-danger', 'text-info');
  547. setDangerInfo($('#eng-name-info'), `新建“${engName}”`);
  548. }
  549. }
  550. else {
  551. $('#eng-name-info').hide();
  552. }
  553. });
  554. //新建单位工程-单位工程提示
  555. $('#tender-name').change(function () {
  556. let selected = projTreeObj.tree.selected;
  557. let pojName = $('#poj-name').val().trim();
  558. let engName = $('#eng-name').val().trim();
  559. let tenderName = $('#tender-name').val().trim();
  560. let isExist = hasTender(selected, pojName, engName, tenderName);
  561. if(isExist){
  562. if(tenderName !== '')
  563. setDangerInfo($('#tender-name-info'), `已存在“${tenderName}”`);
  564. }
  565. else {
  566. $('#tender-name-info').hide();
  567. }
  568. });
  569. //下拉是否含有输入的名字
  570. function hasListName(nameList, name){
  571. for(let i = 0, len = nameList.length; i < len; i++){
  572. if(nameList[i] === name){
  573. return true;
  574. }
  575. }
  576. return false;
  577. }
  578. function getNameList(list){
  579. let rst = [];
  580. for(let i = 0, len = list.length; i < len; i++){
  581. rst.push($(list[i]).text());
  582. }
  583. return rst;
  584. }
  585. // 新增单位工程弹层改变
  586. $('#add-tender-dialog').on('show.bs.modal', function() {
  587. //clear info
  588. $('#poj-name-info').hide();
  589. $('#eng-name-info').hide();
  590. $('#tender-name-info').hide();
  591. $('#tender-name').val('');
  592. $('#valuation-info').hide();
  593. $('#engineering-info').hide();
  594. //获取建设项目
  595. let selected = projTreeObj.tree.selected;
  596. let projs = getProjs(selected);
  597. setProjOptions(projs, selected);
  598. $($("input[name='valuation_type']")[0]).click();
  599. });
  600. // 新增单位工程
  601. $("#add-tender-confirm").click(function() {
  602. AddTender();
  603. });
  604. // 新增文件夹按钮点击
  605. $("#add-folder-btn").click(function() {
  606. $("#add-folder-dialog").modal("show");
  607. });
  608. // 新增文件夹操作
  609. $("#add-folder-confirm").click(function() {
  610. AddFolder();
  611. });
  612. // 删除按钮点击
  613. $('#del-btn').click(function() {
  614. if (projTreeObj.tree && projTreeObj.tree.selected) {
  615. $('#del').modal('show');
  616. }
  617. });
  618. // 删除时文字替换
  619. $('#del').on('show.bs.modal', function() {
  620. let hasTenderChild = function (children) {
  621. for (let i = 0; i < children.length; i++) {
  622. if (children[i].children.length === 0) {
  623. if (children[i].data.projType === 'Tender') {
  624. return true;
  625. }
  626. } else if (hasTenderChild(children[i].children)) {
  627. return true;
  628. }
  629. }
  630. return false;
  631. };
  632. // 显示内容
  633. let tenderHintElement = $('#tenderHint');
  634. let folderHintElement = $('#folderHint');
  635. if (projTreeObj.tree.selected.children.length === 0) {
  636. tenderHintElement.show();
  637. tenderHintElement.text('删除 "' + projTreeObj.tree.selected.data.name +'" ?');
  638. folderHintElement.hide();
  639. } else {
  640. tenderHintElement.hide();
  641. folderHintElement.show();
  642. folderHintElement.text('删除 "'+ projTreeObj.tree.selected.data.name +'" 以及它包含的子项?');
  643. }
  644. // 显示是否可以找回
  645. if (hasTenderChild([projTreeObj.tree.selected])) {
  646. $('#restoreHint').show();
  647. } else {
  648. $('#restoreHint').hide();
  649. }
  650. });
  651. // 删除操作
  652. $('#delete-confirm').click(function () {
  653. let updateData = null;
  654. let dialog = $('#del');
  655. if (projTreeObj.tree) {
  656. updateData = GetDeleteUpdateData(projTreeObj.tree.selected);
  657. UpdateProjectData(updateData, function () {
  658. dialog.modal('hide');
  659. projTreeObj.tree.removeNode(projTreeObj.tree.selected);
  660. });
  661. }
  662. });
  663. // 重命名按钮点击
  664. $('#rename-btn').click(function() {
  665. if (!projTreeObj.tree) {
  666. return false;
  667. }
  668. if (!projTreeObj.tree.selected) {
  669. alert('请选择需要重命名的数据');
  670. return false;
  671. }
  672. $('#rename-dialog').modal('show');
  673. });
  674. // 重命名操作
  675. $("#rename-confirm").click(function() {
  676. let select = projTreeObj.tree.selected;
  677. let newName = $('#rename-name').val();
  678. let dialog = $('#rename-dialog');
  679. if (newName === '') {
  680. setDangerInfo($('#rename-name-info'), '请输入重命名');
  681. return false;
  682. }
  683. if (newName === select.data.name) {
  684. dialog.modal('hide');
  685. return false;
  686. }
  687. RenameProject(select.id(), newName, select.data.ParentID, function () {
  688. setDangerInfo($('#rename-name-info'), '', false);
  689. dialog.modal('hide');
  690. select.data.name = newName;
  691. let sheet = projTreeObj.workBook.getActiveSheet();
  692. sheet.setValue(sheet.getActiveRowIndex(), 0, newName);
  693. });
  694. });
  695. // 移动到按钮点击
  696. $('#move-to-btn').click(function () {
  697. if (Tree && Tree.selected()) {
  698. $('#move-to-dialog').modal('show');
  699. }
  700. });
  701. // 移动到窗口内容重组
  702. $('#move-to-dialog').on('show.bs.modal', function () {
  703. movetoZTree = ConvertTreeToZtree(Tree, $('#treeDemo'), Tree.selected());
  704. });
  705. // 移动到操作
  706. $('#move-to-confirm').click(function () {
  707. let updateData = null;
  708. let dialog = $('#move-to-dialog');
  709. let target = GetTargetTreeNode($.fn.zTree.getZTreeObj('treeDemo'));
  710. let cur = Tree.selected();
  711. if (!target) {
  712. dialog.modal('hide');
  713. return false;
  714. }
  715. if (target.data.projType !== projectType.engineering) {
  716. alert("请移动到单项工程中!");
  717. return false;
  718. }
  719. // 判断同级是否有同名
  720. if (target.children.length > 0) {
  721. for (let tmp in target.children) {
  722. if (tmp === 0) {
  723. continue;
  724. }
  725. if (target.children[tmp].data.name === cur.data.name) {
  726. alert("对应单项工程中存在同名数据!");
  727. return false;
  728. }
  729. }
  730. }
  731. let parent = target;
  732. let next = target.firstChild();
  733. if (parent !== cur.parent || (next !== cur && next !== cur.nextSibling)){
  734. let typeInfo = {
  735. updateType: 'update',
  736. projectType: null
  737. };
  738. updateData = GetUpdateData(null, parent, next, '', null, Tree.selected().id(), typeInfo);
  739. UpdateProjectData(updateData, function (data) {
  740. dialog.modal('hide');
  741. Tree.move(Tree.selected(), parent, next);
  742. });
  743. } else {
  744. dialog.modal('hide');
  745. }
  746. });
  747. // 复制到按钮点击
  748. $('#copy-to-btn').click(function () {
  749. let selectedItem = Tree.selected();
  750. try {
  751. let selectedType = selectedItem !== null && selectedItem.data !== undefined ?
  752. selectedItem.data.projType : '';
  753. if (selectedType !== projectType.tender) {
  754. throw '请选择单位工程进行复制';
  755. }
  756. } catch (error) {
  757. alert(error);
  758. return false;
  759. }
  760. $('#copy-to-dialog').modal('show');
  761. });
  762. // 复制到弹层替换
  763. $('#copy-to-dialog').on('show.bs.modal', function () {
  764. copytoZTree = ConvertTreeToZtree(Tree, $('#treeDemo2'), null);
  765. });
  766. // 复制到操作
  767. $("#copy-to-confirm").click(function() {
  768. let dialog = $('#copy-to-dialog');
  769. let target = GetTargetTreeNode($.fn.zTree.getZTreeObj('treeDemo2'));
  770. let parent = null;
  771. let next = null;
  772. let pre = null;
  773. let cur = Tree.selected();
  774. if (!target) {
  775. return false;
  776. }
  777. if (target.data.projType !== projectType.engineering) {
  778. alert("请移动到单项工程中!");
  779. return false;
  780. }
  781. if (target.data.projType !== projectType.tender && target.children.length !== 0 &&
  782. target.firstChild().data.projType !== projectType.tender) {
  783. dialog.modal('hide');
  784. }
  785. // 判断同级是否有同名
  786. if (target.children.length > 0) {
  787. for (let tmp in target.children) {
  788. if (tmp === 0) {
  789. continue;
  790. }
  791. if (target.children[tmp].data.name === cur.data.name) {
  792. alert("对应单项工程中存在同名数据!");
  793. return false;
  794. }
  795. }
  796. }
  797. if (target.data.projType === projectType.tender) {
  798. parent = target.parent;
  799. next = target.nextSibling;
  800. } else {
  801. parent = target;
  802. next = target.firstChild();
  803. }
  804. if (parent !== cur.parent || (next !== cur && next !== cur.nextSibling)){
  805. CommonAjax.post('/pm/api/getNewProjectID', {count: 1, user_id: userID}, function (IDs) {
  806. let typeInfo = {
  807. updateType: 'copy',
  808. projType: cur.data.projectType
  809. };
  810. let updateData = GetUpdateData(null, parent, next, cur.data.name, cur.data.property, IDs.lowID, typeInfo);
  811. updateData.forEach(function (data) {
  812. if (data.updateType === 'copy') {
  813. data['srcProjectId'] = cur.id();
  814. }
  815. });
  816. pre = GetNeedUpdatePreNode(parent, next);
  817. if (pre) {
  818. updateData = {};
  819. updateData['updateType'] = 'update';
  820. updateData['updateData'] = {};
  821. updateData['updateData'][Tree.setting.tree.id] = pre.id();
  822. updateData['updateData'][Tree.setting.tree.nid] = node.tree.maxNodeId() + 1;
  823. }
  824. Tree.maxNodeId(IDs.lowID - 1);
  825. CommonAjax.post('/pm/api/copyProjects', {updateData: updateData, user_id: userID}, function (data) {
  826. dialog.modal('hide');
  827. data.forEach(function (nodeData) {
  828. if (nodeData.updateType === 'copy') {
  829. Tree.addNodeData(nodeData.updateData, parent, next);
  830. }
  831. });
  832. }, function () {
  833. dialog.modal('hide');
  834. });
  835. });
  836. }
  837. });
  838. // 选择工程专业后动态更改费率文件等数据
  839. $("#tender-engineering").change(function() {
  840. $('#engineering-info').hide();
  841. let engineeringList = getEngineeringList();
  842. if(engineeringList.length === 0){
  843. return false;
  844. }
  845. let selectedEngineering = $(this).val();
  846. selectedEngineering = parseInt(selectedEngineering);
  847. let currentLib = {};
  848. for(let engineering of engineeringList) {
  849. if (engineering.engineering === selectedEngineering) {
  850. currentLib = engineering.lib;
  851. }
  852. }
  853. if (Object.keys(currentLib).length <= 0) {
  854. return false;
  855. }
  856. // 输出数据到页面
  857. if (currentLib.fee_lib !== undefined && currentLib.fee_lib.length > 0) {
  858. $("#tender-fee-rate").children("option").first().val("newFeeRate-"+currentLib.fee_lib[0].id);
  859. }
  860. $(this).parent().siblings('.hidden-area').slideDown('fast');
  861. });
  862. });
  863. /**
  864. * 初始化数据
  865. *
  866. * @return {void}
  867. */
  868. function init() {
  869. billValuation = billValuation.replace(/\n/g, '\\n');
  870. rationValuation = rationValuation.replace(/\n/g, '\\n');
  871. //init spread and pmTree
  872. GetAllProjectData(function (datas) {
  873. projTreeObj.getShowData(datas);
  874. projTreeObj.tree = pmTree.createNew(projTreeObj.setting, datas);
  875. projTreeObj.tree.selected = projTreeObj.tree.items[0];
  876. projTreeObj.buildSheet();
  877. projTreeObj.showTreeData(projTreeObj.tree.items, projTreeObj.setting.header);
  878. //初始选择
  879. projTreeObj.initSelection(0);
  880. });
  881. engineering = engineeringList !== null && engineeringList !== undefined ? JSON.parse(engineeringList) : [];
  882. }
  883. /**
  884. * 新增建设项目
  885. *
  886. * @return {boolean}
  887. */
  888. function AddProject() {
  889. let name = $('#project-name').val().trim();
  890. if (name === '') {
  891. setDangerInfo($('#project-name-info'), '请填写建设项目名称');
  892. return false;
  893. }
  894. let existCallback = function () {
  895. setDangerInfo($('#project-name-info'), `已存在“${$("#project-name").val()}”`);
  896. };
  897. let sucCallback = function () {
  898. $('#add-project-dialog').modal('hide');
  899. $('#project-name').val('');
  900. setDangerInfo($('#project-name-info'), '', false);
  901. };
  902. let selectedItem = projTreeObj.tree.selected;
  903. /*
  904. * (1)、当前没有焦点行,新建建设项目为第一个节点。
  905. (2)、当前定位在文件夹,新建建设项目为文件夹的最后一个子节点。
  906. (3)、当前定位在建设项目,新建建设项目为其后兄弟。
  907. (4)、当前定位在单项工程或单位工程,新建项目为当前所属建设项目的后兄弟。
  908. * */
  909. if(!selectedItem){
  910. AddSiblingsItem(selectedItem, name, null, projectType.project, existCallback, sucCallback);
  911. }
  912. else {
  913. if(selectedItem.data.projType === projectType.project){
  914. AddSiblingsItem(selectedItem, name, null, projectType.project, existCallback, sucCallback);
  915. }
  916. else if(selectedItem.data.projType === projectType.engineering || selectedItem.data.projType === projectType.tender){
  917. let proj = selectedItem.parent.data.projType === projectType.project ? selectedItem.parent : selectedItem.parent.parent;
  918. AddSiblingsItem(proj, name, null, projectType.project, existCallback, sucCallback);
  919. }
  920. else if(selectedItem.data.projType === projectType.folder){
  921. AddChildrenItem(selectedItem, name, null, projectType.project, existCallback, sucCallback);
  922. }
  923. }
  924. }
  925. //新建建设项目、新建单项工程、新建文件夹、重命名弹窗隐藏事件
  926. function bindModalsHidden(projDialog, engDialog, folderDialog, renameDialog){
  927. projDialog.on('hidden.bs.modal', function () {
  928. setDangerInfo($('#project-name-info'), '', false);
  929. $('#project-name').val('');
  930. });
  931. engDialog.on('hidden.bs.modal', function () {
  932. setDangerInfo($('#engineering-name-info'), '', false);
  933. $('#engineering-name').val('');
  934. });
  935. folderDialog.on('hidden.bs.modal', function () {
  936. setDangerInfo($('#folder-name-info'), '', false);
  937. $('#folder-name').val('');
  938. });
  939. renameDialog.on('hidden.bs.modal', function () {
  940. setDangerInfo($('#rename-name-info'), '', false);
  941. $('#rename-name').val('');
  942. });
  943. }
  944. //绑定新建建设项目、新建单项工程、新建文件夹、重命名回车键功能
  945. function bindInputs(projInput, engInput, foldInput, renameInput){
  946. projInput.bind('keypress', function (event) {
  947. if(event.keyCode === 13){
  948. $('#addProjOk').click();
  949. return false;
  950. }
  951. });
  952. engInput.bind('keypress', function (event) {
  953. if(event.keyCode === 13){
  954. $('#add-engineering-confirm').click();
  955. return false;
  956. }
  957. });
  958. foldInput.bind('keypress', function (event) {
  959. if(event.keyCode === 13){
  960. $('#add-folder-confirm').click();
  961. return false;
  962. }
  963. });
  964. renameInput.bind('keypress', function (event) {
  965. if(event.keyCode === 13){
  966. $('#rename-confirm').click();
  967. return false;
  968. }
  969. });
  970. }
  971. //新建建设项目、单项工程、文件夹、重命名提示(文本改变,暂时不需要)
  972. function getChangedFunc(input, nameInfo){
  973. return function () {
  974. let selected = Tree.selected();
  975. let parent = selected ? selected.parent : Tree._root;
  976. let name = input.val();
  977. if(existName(name, parent.children)){
  978. nameInfo.text(`已存在“${name}”`);
  979. nameInfo.show();
  980. }
  981. else {
  982. nameInfo.text('');
  983. nameInfo.hide();
  984. }
  985. }
  986. }
  987. function AddTenderItems(selected, projName, engName, tenderName, property, callback){
  988. const addPath = {p_e_t: 'p_e_t', e_t: 'e_t', t: 't'};
  989. let path, updateDatas = [];
  990. let tempProjs = getProjs(selected);
  991. let tempProj = getNodeByName(projName, tempProjs);
  992. let tempEng;
  993. if(tempProj){
  994. tempEng = getNodeByName(engName, tempProj.children);
  995. if(tempEng){
  996. path = addPath.t;
  997. }
  998. else {
  999. path = addPath.e_t
  1000. }
  1001. }
  1002. else {
  1003. path = addPath.p_e_t;
  1004. }
  1005. if(path === addPath.p_e_t){
  1006. let parent, pre, next;
  1007. GetNewProjectId(3, function (IDs) {
  1008. let projID = IDs.lowID, engID = IDs.lowID + 1, tenderID = IDs.lowID + 2;
  1009. if(!selected || selected.data.projType === projectType.project){
  1010. parent = selected ? selected.parent : Tree._root;
  1011. pre = selected;
  1012. next = selected ? selected.nextSibling : Tree.firstNode();
  1013. }
  1014. else if(selected.data.projType === projectType.folder){
  1015. parent = selected ? selected : Tree._root;
  1016. pre = selected ? selected.lastChild() : Tree.firstNode();
  1017. next = null;
  1018. }
  1019. else if(selected.data.projType === projectType.engineering || selected.data.projType === projectType.tender){
  1020. let selectedProj = selected.parent.data.projType === projectType.project ? selected.parent : selected.parent.parent;
  1021. parent = selectedProj ? selectedProj.parent : Tree._root;
  1022. pre = selectedProj;
  1023. next = selectedProj ? selectedProj.nextSibling : Tree.firstNode();
  1024. }
  1025. let updateProjs = GetUpdateData(pre, parent, next, projName, null, projID, {updateType: 'new', projectType: projectType.project});
  1026. let updateEng = {updateType: 'new', updateData: {ID: engID, ParentID: projID, NextSiblingID: -1, name: engName, projType: projectType.engineering}};
  1027. property.rootProjectID = projID;
  1028. let updateTender = {updateType: 'new', updateData: {ID: tenderID, ParentID: engID, NextSiblingID: -1, name: tenderName, projType: projectType.tender, property: property}};
  1029. updateDatas = updateDatas.concat(updateProjs);
  1030. updateDatas.push(updateEng);
  1031. updateDatas.push(updateTender);
  1032. UpdateProjectData(updateDatas, function(datas){
  1033. let projData, engData, tenderData;
  1034. datas.forEach(function (data) {
  1035. if (data.updateType === 'new') {
  1036. if(data.updateData.projType === projectType.project){
  1037. projData = data.updateData;
  1038. }
  1039. else if(data.updateData.projType === projectType.engineering){
  1040. engData = data.updateData;
  1041. }
  1042. else if(data.updateData.projType === projectType.tender){
  1043. tenderData = data.updateData;
  1044. }
  1045. }
  1046. });
  1047. let pojNode = projTreeObj.insert(projData, parent, next);
  1048. let engNode = projTreeObj.insert(engData, pojNode, null);
  1049. projTreeObj.insert(tenderData, engNode, null);
  1050. callback();
  1051. });
  1052. });
  1053. }
  1054. else if(path === addPath.e_t){
  1055. GetNewProjectId(2, function (IDs) {
  1056. let engID = IDs.lowID, tenderID = IDs.lowID + 1;
  1057. let pre = tempProj.lastChild();
  1058. let next = null;
  1059. let updateEng = {updateType: 'new', updateData: {ID: engID, ParentID: tempProj.data.ID, NextSiblingID: -1, name: engName, projType: projectType.engineering}};
  1060. property.rootProjectID = tempProj.data.ID;
  1061. let updateTender = {updateType: 'new', updateData: {ID: tenderID, ParentID: engID, NextSiblingID: -1, name: tenderName, projType: projectType.tender, property: property}};
  1062. if(selected && selected.data.projType === projectType.engineering && selected.parent === tempProj){
  1063. pre = selected;
  1064. next = selected.nextSibling;
  1065. updateEng.updateData.NextSiblingID = pre.data.NextSiblingID;
  1066. }
  1067. updateDatas.push(updateEng);
  1068. updateDatas.push(updateTender);
  1069. if(pre){
  1070. updateDatas.push({updateType: 'update', updateData: {ID: pre.id(), NextSiblingID: engID}});
  1071. }
  1072. UpdateProjectData(updateDatas, function (datas) {
  1073. let engData, tenderData;
  1074. datas.forEach(function (data) {
  1075. if (data.updateType === 'new') {
  1076. if(data.updateData.projType === projectType.engineering){
  1077. engData = data.updateData;
  1078. }
  1079. else if(data.updateData.projType === projectType.tender){
  1080. tenderData = data.updateData;
  1081. }
  1082. }
  1083. });
  1084. let engNode = projTreeObj.insert(engData, tempProj, next);
  1085. projTreeObj.insert(tenderData, engNode, null);
  1086. callback();
  1087. });
  1088. });
  1089. }
  1090. else if(path === addPath.t){
  1091. GetNewProjectId(1, function (IDs) {
  1092. let tenderID = IDs.lowID;
  1093. let pre = tempEng.lastChild();
  1094. property.rootProjectID = tempProj.data.ID;
  1095. let updateTender = {updateType: 'new', updateData: {ID: tenderID, ParentID: tempEng.id(), NextSiblingID: -1, name: tenderName, projType: projectType.tender, property: property}};
  1096. updateDatas.push(updateTender);
  1097. if(pre){
  1098. updateDatas.push({updateType: 'update', updateData: {ID: pre.id(), NextSiblingID: tenderID}});
  1099. }
  1100. UpdateProjectData(updateDatas, function (datas) {
  1101. datas.forEach(function (data) {
  1102. if(data.updateType === 'new') {
  1103. projTreeObj.insert(data.updateData, tempEng, null);
  1104. }
  1105. });
  1106. callback();
  1107. })
  1108. });
  1109. }
  1110. }
  1111. /**
  1112. * 新增子元素
  1113. *
  1114. * @param {String} name
  1115. * @param {String} type
  1116. * @param {function} callback
  1117. * @return {void}
  1118. */
  1119. function AddChildrenItem(selected, name, property, type, existCallback, sucCallback) {
  1120. if(!selected){
  1121. selected = projTreeObj.tree.selected;
  1122. }
  1123. let parent = selected ? selected : projTreeObj.tree._root;
  1124. let pre = selected ? selected.lastChild() : projTreeObj.tree.firstNode();
  1125. if(existName(name, parent.children)){
  1126. //alert('同级目录已存在相同名称数据.');
  1127. existCallback();
  1128. }
  1129. else {
  1130. GetNewProjectId(1, function(IDs) {
  1131. let typeInfo = {
  1132. updateType: 'new',
  1133. projectType: type
  1134. };
  1135. let updateData = GetUpdateData(pre, parent, null, name, property, IDs.lowID, typeInfo);
  1136. projTreeObj.tree.maxNodeId(IDs.lowID - 1);
  1137. UpdateProjectData(updateData, function(datas){
  1138. datas.forEach(function (data) {
  1139. if (data.updateType === 'new') {
  1140. projTreeObj.insert(data.updateData, parent, null);
  1141. }
  1142. });
  1143. sucCallback();
  1144. });
  1145. });
  1146. }
  1147. }
  1148. /**
  1149. * 新增同级元素
  1150. *
  1151. * @param {String} name
  1152. * @param {String} type
  1153. * @param {function} callback
  1154. * @return {void}
  1155. */
  1156. function AddSiblingsItem(selected, name, property, type, existCallback, sucCallback) {
  1157. if(!selected){
  1158. selected = projTreeObj.tree.selected;
  1159. }
  1160. let parent = selected ? selected.parent : projTreeObj.tree._root;
  1161. let next = selected ? selected.nextSibling : projTreeObj.tree.firstNode();
  1162. if(existName(name, parent.children)){
  1163. //alert('同级目录已存在相同名称数据.');
  1164. existCallback();
  1165. }
  1166. else {
  1167. GetNewProjectId(1, function(IDs) {
  1168. let typeInfo = {
  1169. updateType: 'new',
  1170. projectType: type
  1171. };
  1172. let updateData = GetUpdateData(selected, parent, next, name, property, IDs.lowID, typeInfo);
  1173. projTreeObj.tree.maxNodeId(IDs.lowID - 1);
  1174. UpdateProjectData(updateData, function(datas){
  1175. datas.forEach(function (data) {
  1176. if (data.updateType === 'new') {
  1177. projTreeObj.insert(data.updateData, parent, next);
  1178. }
  1179. });
  1180. sucCallback();
  1181. });
  1182. });
  1183. }
  1184. }
  1185. function getEngineeringList(){
  1186. let valuation = $("#valuation").val();
  1187. let valuationType = $("input[name='valuation_type']:checked").val();
  1188. let valuationData = valuationType === 'bill' ? JSON.parse(billValuation) : JSON.parse(rationValuation);
  1189. let engineeringList = [];
  1190. for(let tmp of valuationData) {
  1191. if (tmp._id === valuation) {
  1192. engineeringList = tmp.engineering_list;
  1193. break;
  1194. }
  1195. }
  1196. return engineeringList;
  1197. }
  1198. function getNodeByName(name, nodes){
  1199. for(let i = 0, len = nodes.length; i < len; i++){
  1200. if(name === nodes[i].data.name){
  1201. return nodes[i];
  1202. }
  1203. }
  1204. return null;
  1205. }
  1206. //同级是否重名
  1207. function existName(name , nodes){
  1208. for(let i = 0, len = nodes.length; i < len; i++){
  1209. if(name === nodes[i].data.name){
  1210. return true;
  1211. }
  1212. }
  1213. return false;
  1214. }
  1215. //获取新建单位工程时的建设项目数据
  1216. function getProjs(selected){
  1217. let rst = [];
  1218. let temp;
  1219. let firstNode;
  1220. if(!selected){
  1221. temp = projTreeObj.tree.roots;
  1222. firstNode = temp.children[0];
  1223. }
  1224. else if(selected.data.projType === projectType.folder){
  1225. temp = selected;
  1226. firstNode = temp.children[0];
  1227. }
  1228. else if(selected.data.projType === projectType.project){
  1229. temp = selected.parent;
  1230. firstNode = temp.children[0];
  1231. }
  1232. else if(selected.data.projType === projectType.engineering || selected.data.projType === projectType.tender){
  1233. let proj = selected.parent.data.projType === projectType.project ? selected.parent : selected.parent.parent;
  1234. temp = proj.parent;
  1235. firstNode = proj;
  1236. }
  1237. for(let childNode of temp.children){
  1238. if(childNode.data.projType === projectType.project){
  1239. rst.push(childNode);
  1240. }
  1241. }
  1242. //firstNode to first place
  1243. let index = null;
  1244. for(let i = 0, len = rst.length; i < len; i++){
  1245. if(rst[i].data.ID === firstNode.data.ID){
  1246. index = i;
  1247. break;
  1248. }
  1249. }
  1250. if(index){
  1251. rst.splice(index, 1);
  1252. rst.splice(0, 0, firstNode);
  1253. }
  1254. return rst;
  1255. }
  1256. function setFileOptions(projID){
  1257. // 获取单价文件数据
  1258. if(!projID){
  1259. $("#unit-price").children("option:not(':first')").remove();
  1260. let first = $("#tender-fee-rate").children("option").first();
  1261. $("#tender-fee-rate").empty();
  1262. $("#tender-fee-rate").append(first);
  1263. }
  1264. else {
  1265. getUnitFile(projID, function (response) {
  1266. $("#unit-price").children("option:not(':first')").remove();
  1267. if (response.data.length <= 0) {
  1268. return false;
  1269. }
  1270. let unitFileHtml = '';
  1271. for(let tmp of response.data) {
  1272. unitFileHtml += '<option value="'+ tmp.id +'">'+ tmp.name +'</option>';
  1273. }
  1274. $("#unit-price").children("option").first().after(unitFileHtml);
  1275. });
  1276. // 获取费率文件数据
  1277. getFeeRateFile(projID, function (response) {
  1278. let first = $("#tender-fee-rate").children("option").first();
  1279. $("#tender-fee-rate").empty();
  1280. $("#tender-fee-rate").append(first);
  1281. if (response.data.length <= 0) {
  1282. return false;
  1283. }
  1284. for(let tmp of response.data) {
  1285. let option = $("<option>").val(tmp.ID).text(tmp.name);
  1286. $("#tender-fee-rate").append(option);
  1287. }
  1288. });
  1289. }
  1290. }
  1291. //建设项目下拉框
  1292. function setProjOptions(projs, selected){
  1293. $("#poj-name-list").empty();
  1294. $("#poj-name").val("");
  1295. if(projs.length > 0){
  1296. let firstProj = selected && selected.data.projType === projectType.project ? selected: projs[0];
  1297. $("#poj-name").val(firstProj.data.name);
  1298. setFileOptions(firstProj.data.ID);
  1299. setEngOptions(firstProj.data.ID);
  1300. for(let i = 0, len = projs.length; i < len; i++){
  1301. let proj = $("<button>").val(projs[i].data.ID).text(projs[i].data.name);
  1302. proj.addClass("dropdown-item");
  1303. proj.attr("type", "button");
  1304. proj.click(function () {
  1305. $("#poj-name").val(projs[i].data.name);
  1306. setFileOptions(projs[i].data.ID);
  1307. setEngOptions(projs[i].data.ID);
  1308. });
  1309. $("#poj-name-list").append(proj);
  1310. }
  1311. }
  1312. else {
  1313. setFileOptions(null);
  1314. setEngOptions(null);
  1315. }
  1316. }
  1317. //单项工程下拉框
  1318. function setEngOptions(projID){
  1319. let proj = projTreeObj.tree.findNode(projID) || null;
  1320. $("#eng-name-list").empty();
  1321. $("#eng-name").val("");
  1322. if(proj){
  1323. let engineerings = [].concat(proj.children);
  1324. //set selected engineering to first place
  1325. let selected = projTreeObj.tree.selected;
  1326. let firstNode = null;
  1327. if(selected && (selected.data.projType === projectType.engineering || selected.data.projType === projectType.tender)){
  1328. firstNode = selected.data.projType === projectType.engineering ? selected : selected.parent;
  1329. }
  1330. if(firstNode){
  1331. let index = null;
  1332. for(let i = 0, len = engineerings.length; i < len; i++){
  1333. if(firstNode.data.ID === engineerings[i].data.ID){
  1334. index = i;
  1335. }
  1336. }
  1337. if(index){
  1338. engineerings.splice(index, 1);
  1339. engineerings.splice(0, 0, firstNode);
  1340. }
  1341. }
  1342. if(engineerings.length > 0){
  1343. $("#eng-name").val(engineerings[0].data.name);
  1344. for(let i = 0, len = engineerings.length; i < len; i++){
  1345. let eng = $("<button>").val(engineerings[i].data.ID).text(engineerings[i].data.name);
  1346. eng.addClass("dropdown-item");
  1347. eng.attr("type", "button");
  1348. eng.click(function () {
  1349. $("#eng-name").val(engineerings[i].data.name);
  1350. });
  1351. $("#eng-name-list").append(eng);
  1352. }
  1353. }
  1354. }
  1355. }
  1356. function hasTender(selected, pojName, engName, tenderName){
  1357. let isExist = false;
  1358. let tempProjs = getProjs(selected);
  1359. if(pojName !== ''){
  1360. let tempProj = getNodeByName(pojName, tempProjs);
  1361. if(tempProj){
  1362. if(engName !== ''){
  1363. let tempEng = getNodeByName(engName, tempProj.children);
  1364. if(tempEng){
  1365. let tempTender = getNodeByName(tenderName, tempEng.children);
  1366. if(tempTender){
  1367. isExist = true;
  1368. }
  1369. }
  1370. }
  1371. }
  1372. }
  1373. return isExist;
  1374. }
  1375. //替换class
  1376. function replaceClass(selector, orgClass, newClass){
  1377. selector.removeClass(orgClass);
  1378. selector.addClass(newClass);
  1379. }
  1380. //设置提示信息
  1381. function setDangerInfo(area, info, show = true){
  1382. area.text(info);
  1383. if(show)
  1384. area.show();
  1385. else
  1386. area.hide();
  1387. }
  1388. /**
  1389. * 新增单项工程
  1390. *
  1391. * @return {boolean}
  1392. */
  1393. function AddEngineering() {
  1394. let name = $('#engineering-name').val().trim();
  1395. if (name === '') {
  1396. setDangerInfo($('#engineering-name-info'), '请填写单项工程名称');
  1397. return false;
  1398. }
  1399. let existCallback = function () {
  1400. setDangerInfo($('#engineering-name-info'), `已存在“${$("#engineering-name").val()}”`);
  1401. };
  1402. let sucCallback = function () {
  1403. $('#add-engineering-dialog').modal('hide');
  1404. $('#engineering-name').val('');
  1405. setDangerInfo($('#engineering-name-info'), '', false);
  1406. };
  1407. let selectedItem = projTreeObj.tree.selected;
  1408. // 如果选择的是单项工程则新增同级数据
  1409. if(selectedItem){
  1410. if(selectedItem.data.projType === projectType.project){
  1411. AddChildrenItem(selectedItem, name, null, projectType.engineering, existCallback, sucCallback);
  1412. }
  1413. else if(selectedItem.data.projType === projectType.engineering){
  1414. AddSiblingsItem(selectedItem, name, null, projectType.engineering, existCallback, sucCallback);
  1415. }
  1416. else if(selectedItem.data.projType === projectType.tender){
  1417. let proj = selectedItem.parent;
  1418. AddSiblingsItem(proj, name, null, projectType.engineering, existCallback, sucCallback);
  1419. }
  1420. }
  1421. }
  1422. /**
  1423. * 新增单位工程
  1424. *
  1425. * @return {boolean}
  1426. */
  1427. function AddTender() {
  1428. try {
  1429. let projName = $("#poj-name").val().trim();
  1430. if(projName === ''){
  1431. replaceClass($('#poj-name-info'), 'text-info', 'text-danger');
  1432. setDangerInfo($('#poj-name-info'), '请填写建设项目名称');
  1433. return false;
  1434. }
  1435. let engName = $("#eng-name").val().trim();
  1436. if(engName === ''){
  1437. replaceClass($('#eng-name-info'), 'text-info', 'text-danger');
  1438. setDangerInfo($('#eng-name-info'), '请填写单项工程名称');
  1439. return false;
  1440. }
  1441. let tenderName = $('#tender-name').val();
  1442. if (tenderName === '') {
  1443. setDangerInfo($('#tender-name-info'), '请填写单位工程名称');
  1444. return false;
  1445. }
  1446. if(hasTender(projTreeObj.tree.selected, projName, engName, tenderName)){
  1447. return false;
  1448. }
  1449. let unitPriceFile = $("#unit-price").val();
  1450. let unitPriceName = unitPriceFile !== '' ? $("#unit-price").children("option:selected").text() : tenderName;
  1451. let feeFile = $("#tender-fee-rate").val();
  1452. let feeFileName = $("#tender-fee-rate").children("option:selected").text();
  1453. let valuation = $("#valuation").val();
  1454. if(valuation === ''){
  1455. setDangerInfo($('#valuation-info'), '请选择计价规则');
  1456. return false;
  1457. }
  1458. let engineering = $("#tender-engineering").val();
  1459. if (engineering === '') {
  1460. setDangerInfo($('#engineering-info'), '请选择工程专业');
  1461. return false;
  1462. }
  1463. let valuationName = $("#valuation").children("option:selected").text();
  1464. let valuationType = $("input[name='valuation_type']:checked").val();
  1465. let engineering_id = undefined;
  1466. let valuationData = valuationType === 'bill' ? JSON.parse(billValuation) : JSON.parse(rationValuation);
  1467. let engineeringList = [];
  1468. for(let tmp of valuationData) {
  1469. if (tmp._id === valuation) {
  1470. engineeringList = tmp.engineering_list;
  1471. break;
  1472. }
  1473. }
  1474. let libs = null;
  1475. for(let tmp of engineeringList) {
  1476. if (tmp.engineering == engineering) {
  1477. engineering_id = tmp.engineering_id;
  1478. libs = tmp.lib;
  1479. break;
  1480. }
  1481. }
  1482. // 一个项目里面,这两个文件必须得有,而界面又没有像费率、单价文件那样给出可选项。所以这里给出提示。
  1483. if (!libs.artificial_lib) throw '编办没有绑定人工系数标准文件';
  1484. if (!libs.program_lib) throw '编办没有绑定计算程序标准文件';
  1485. let engineeringName = $('#tender-engineering').children("option:selected").text();
  1486. let callback = function() {
  1487. $("#add-tender-dialog").modal("hide");
  1488. $('#tender-name').val('');
  1489. $("#tender-fee-rate").children("option").removeAttr("selected");
  1490. $("#tender-engineering").children("option").removeAttr("selected");
  1491. $("#poj-name").val('');
  1492. $("#poj-name-info").hide();
  1493. $("#eng-name").val('');
  1494. $("#eng-name-info").hide();
  1495. };
  1496. let selectedItem = projTreeObj.tree.selected;
  1497. let tenderInfo = {
  1498. valuation: valuation,
  1499. valuationType: valuationType,
  1500. valuationName: valuationName,
  1501. engineering: engineering,
  1502. engineering_id: engineering_id,
  1503. engineeringName: engineeringName,
  1504. unitPriceFile: {name: unitPriceName, id: unitPriceFile},
  1505. feeFile: {name: feeFileName, id: feeFile}
  1506. };
  1507. AddTenderItems(selectedItem, projName, engName, tenderName, tenderInfo, callback);
  1508. } catch (error) {
  1509. alert(error);
  1510. }
  1511. }
  1512. /**
  1513. * 新增文件夹
  1514. *
  1515. * @return {boolean}
  1516. */
  1517. function AddFolder() {
  1518. let name = $('#folder-name').val().trim();
  1519. if (name === '') {
  1520. setDangerInfo($('#folder-name-info'), '请填写文件夹名称');
  1521. return false;
  1522. }
  1523. let selectedItem = projTreeObj.tree.selected;
  1524. let existCallback = function () {
  1525. setDangerInfo($('#folder-name-info'), `已存在“${$("#folder-name").val()}”`);
  1526. };
  1527. let sucCallback = function () {
  1528. $('#add-folder-dialog').modal('hide');
  1529. $('#folder-name').val('');
  1530. setDangerInfo($('#folder-name-info'), '', false);
  1531. };
  1532. if (selectedItem !== null) {
  1533. // 判断是否超过3层
  1534. if(!withinTreble(selectedItem)){
  1535. alert("文件夹不能超过3层");
  1536. return false;
  1537. }
  1538. if(selectedItem.data.projType === projectType.folder || selectedItem.data.projType === projectType.project){
  1539. AddSiblingsItem(null, name, null, projectType.folder, existCallback, sucCallback);
  1540. }
  1541. else if(selectedItem.data.projType === projectType.engineering || selectedItem.data.projType === projectType.tender){
  1542. let proj = selectedItem.parent.data.projType === projectType.project ? selectedItem.parent : selectedItem.parent.parent;
  1543. AddSiblingsItem(proj, name, null, projectType.folder, existCallback, sucCallback);
  1544. }
  1545. } else {
  1546. AddSiblingsItem(null, name, null, projectType.folder, existCallback, sucCallback);
  1547. }
  1548. }
  1549. //判断是否是三层文件夹以内
  1550. function withinTreble(selectedItem){
  1551. let rst;
  1552. if(selectedItem.data.projType === projectType.engineering || selectedItem.data.projType === projectType.tender){
  1553. selectedItem = selectedItem.parent.data.projType === projectType.project ? selectedItem.parent : selectedItem.parent.parent;
  1554. }
  1555. if(selectedItem.parent.parent && hasFolder(selectedItem.parent.parent.children) && selectedItem.parent.parent.parent && hasFolder(selectedItem.parent.parent.parent.children)
  1556. && selectedItem.parent.parent.parent.parent && hasFolder(selectedItem.parent.parent.parent.parent.children)){
  1557. return false;
  1558. }
  1559. return true;
  1560. function hasFolder(items){
  1561. for(let i = 0, len = items.length; i < len; i++){
  1562. if(items[i].data.projType === projectType.folder){
  1563. return true;
  1564. }
  1565. }
  1566. return false;
  1567. }
  1568. }
  1569. /**
  1570. * 组织更新数据
  1571. *
  1572. * @param {Object} parent
  1573. * @param {Object} next
  1574. * @param {String} name
  1575. * @param {Object} type
  1576. * @return {Object}
  1577. */
  1578. function GetUpdateData(pre, parent, next, name, property, newId, type) {
  1579. let data = [];
  1580. let updateData = {};
  1581. let rootProjectID = -1;
  1582. if(type.projectType === projectType.tender){
  1583. let rootProject = parent ? parent.parent : projTreeObj.tree._root;
  1584. rootProjectID = rootProject ? rootProject.id() : -1;
  1585. if(property){
  1586. property.rootProjectID=rootProjectID;
  1587. }
  1588. }
  1589. updateData['updateType'] = type.updateType === undefined ? 'new' : type.updateType;
  1590. updateData['updateData'] = {};
  1591. if (newId !== '') {
  1592. updateData['updateData'][projTreeObj.tree.setting.tree.id] = newId;
  1593. }
  1594. updateData['updateData'][projTreeObj.tree.setting.tree.pid] = parent ? parent.id() : -1;
  1595. updateData['updateData'][projTreeObj.tree.setting.tree.nid] = next ? next.id() : -1;
  1596. if (name !== '') {
  1597. updateData['updateData']['name'] = name;
  1598. }
  1599. if (property !== null && property !== undefined) {
  1600. updateData['updateData']['property'] = property;
  1601. }
  1602. if (type !== null && type.projectType !== null) {
  1603. updateData['updateData']['projType'] = type.projectType !== undefined ? type.projectType : 'Tender';
  1604. }
  1605. if(pre){//维护preNode
  1606. let updateObj = Object.create(null);
  1607. updateObj.updateData = Object.create(null);
  1608. updateObj.updateType = 'update';
  1609. updateObj.updateData.ID = pre.id();
  1610. updateObj.updateData.NextSiblingID = newId;
  1611. data.push(updateObj);
  1612. }
  1613. data.push(updateData);
  1614. return data;
  1615. }
  1616. /**
  1617. * 获取删除数据
  1618. *
  1619. * @return {Object} node
  1620. * @return {Object}
  1621. */
  1622. function GetDeleteUpdateData(node) {
  1623. let datas = [], updateData,
  1624. pre = node.preSibling(),
  1625. deleteNodeData = function (node) {
  1626. var data = Object.create(null);
  1627. data['updateType'] = 'delete';
  1628. //data['NextSiblingID'] = node.data.NextSiblingID;
  1629. data['updateData'] = Object.create(null);
  1630. data['updateData'][projTreeObj.tree.setting.tree.id] = node.id();
  1631. data['updateData']['projType'] = node.data.projType;
  1632. if (node.data.projType === 'Tender') {
  1633. data['updateData']['FullFolder'] = GetFullFolder(node.parent);
  1634. }
  1635. return data;
  1636. },
  1637. addDeleteChildren = function (children) {
  1638. children.forEach(function(child){
  1639. datas.push(deleteNodeData(child));
  1640. addDeleteChildren(child.children);
  1641. });
  1642. };
  1643. if (pre && pre.id() !== -1) {
  1644. updateData = {};
  1645. updateData['updateType'] = 'update';
  1646. updateData['updateData'] = {};
  1647. updateData['updateData'][projTreeObj.tree.setting.tree.id] = pre.id();
  1648. updateData['updateData'][projTreeObj.tree.setting.tree.nid] = node ? node.nid() : -1;
  1649. datas.push(updateData);
  1650. }
  1651. datas.push(deleteNodeData(node));
  1652. addDeleteChildren(node.children);
  1653. return datas;
  1654. };
  1655. /**
  1656. * 获取父级所有名称
  1657. *
  1658. * @return {Array}
  1659. */
  1660. function GetFullFolder (node) {
  1661. let fullFolder = [];
  1662. let cur = node;
  1663. while (cur && cur.data) {
  1664. fullFolder.unshift(cur.data.name);
  1665. cur = cur.parent;
  1666. }
  1667. return fullFolder;
  1668. }
  1669. /**
  1670. * 获取需要更新的前节点
  1671. *
  1672. * @param {Object} parent
  1673. * @param {Object} next
  1674. * @return {Object}
  1675. */
  1676. function GetNeedUpdatePreNode(parent, next) {
  1677. if (next) {
  1678. return next.preSibling();
  1679. } else if (parent) {
  1680. return parent.firstChild();
  1681. } else {
  1682. return null;
  1683. }
  1684. }
  1685. /**
  1686. * 获取最新id
  1687. *
  1688. * @param {function} callback
  1689. * @return {void}
  1690. */
  1691. function GetNewProjectId(count, callback) {
  1692. CommonAjax.post('/pm/api/getNewProjectID', {count: count}, function(data) {
  1693. callback(data);
  1694. });
  1695. }
  1696. /**
  1697. * 重命名项目
  1698. *
  1699. * @param {Number} projectId
  1700. * @param {String} newName
  1701. * @param {Number} parentID
  1702. * @param {function} callback
  1703. * @return {void}
  1704. */
  1705. function RenameProject(projectId, newName, parentID, callback) {
  1706. $.ajax({
  1707. type: "POST",
  1708. url: '/pm/api/renameProject',
  1709. data: {'data': JSON.stringify({"user_id": userID, "id": projectId, "newName": newName, "parentID": parentID})},
  1710. dataType: 'json',
  1711. cache: false,
  1712. timeout: 5000,
  1713. success: function(result){
  1714. if (result.error === 0) {
  1715. callback();
  1716. } else {
  1717. if(result.message === '同级目录已存在相同名称数据'){
  1718. setDangerInfo($('#rename-name-info'), `已存在“${newName}”`);
  1719. }
  1720. }
  1721. },
  1722. error: function(iqXHR, textStatus, errorThrown){
  1723. alert('error ' + textStatus + " " + errorThrown)
  1724. }
  1725. });
  1726. }
  1727. /**
  1728. * 转换当前树结构为zTree结构
  1729. *
  1730. * @param {Object} Tree
  1731. * @param {Object} zTreeObj
  1732. * @param {Object} filterNode
  1733. * @return {Mixed}
  1734. */
  1735. function ConvertTreeToZtree(Tree, zTreeObj, filterNode) {
  1736. let setting = {
  1737. data: {
  1738. simpleData: {
  1739. enable:true,
  1740. idKey: "id",
  1741. pIdKey: "pId",
  1742. rootPId: "-1"
  1743. }
  1744. }};
  1745. let zTreeData = [],
  1746. exportNodesData = function (nodes) {
  1747. nodes.forEach(function (node) {
  1748. if (node !== filterNode) {
  1749. var data = {};
  1750. data['id'] = node.data[Tree.setting.tree.id];
  1751. data['pId'] = node.pid();
  1752. data['name'] = node.data['name'];
  1753. data['isParent'] = node.data.projType === 'Folder';//(node.data.projType === 'Folder' && node.children.length === 0);
  1754. data['open'] = node.data.projType === 'Folder';//node.children.length !== 0;
  1755. zTreeData.push(data);
  1756. exportNodesData(node.children);
  1757. }
  1758. })
  1759. };
  1760. exportNodesData(Tree._root.children);
  1761. return $.fn.zTree.init(zTreeObj, setting, zTreeData);
  1762. }
  1763. /**
  1764. * 获取指定zTree节点
  1765. *
  1766. * @param {Object} zTreeObj
  1767. * @return {object}
  1768. */
  1769. function GetTargetTreeNode(zTreeObj) {
  1770. if (!zTreeObj || !Tree) {
  1771. return null;
  1772. }
  1773. let ztree_selected = zTreeObj.getSelectedNodes().length === 0 ? null : zTreeObj.getSelectedNodes()[0];
  1774. return ztree_selected ? Tree.findNode(ztree_selected.id) : null;
  1775. }
  1776. /**
  1777. * 根据指定id获取对应的工程专业
  1778. *
  1779. * @param {Array} engineeringList
  1780. * @return {String}
  1781. */
  1782. function getEngineeringHtml(engineeringList) {
  1783. let result = '<option value="">请选择对应的工程专业</option>';
  1784. if (engineeringList.length <= 0) {
  1785. return result;
  1786. }
  1787. let engineeringObject = {};
  1788. for(let tmp of engineering) {
  1789. engineeringObject[tmp.value] = tmp.name;
  1790. }
  1791. for(let tmp of engineeringList) {
  1792. if (engineeringObject[tmp.engineering] !== undefined) {
  1793. result += '<option value="'+ tmp.engineering +'">'+ engineeringObject[tmp.engineering] +'</option>';
  1794. }
  1795. }
  1796. return result;
  1797. }
  1798. /**
  1799. * 远程获取项目属性数据
  1800. *
  1801. * @param {Object} projectInfo
  1802. * @return {void}
  1803. */
  1804. function getProperty(projectInfo) {
  1805. if (projectInfo.property === undefined) {
  1806. return;
  1807. }
  1808. projectProperty = projectInfo.property;
  1809. // 写入专业工程相关
  1810. let engineeringHtml = getEngineeringHtml(projectProperty.engineeringList);
  1811. $("#tender-engineering").html(engineeringHtml);
  1812. // 填入计价规则
  1813. let valuationHtml = '<option value="'+ projectProperty.valuation +'">'+ projectProperty.valuationName +'</option>';
  1814. $("#tender-valuation").html(valuationHtml);
  1815. // 选中计价方式
  1816. $("input[name='tender_valuation_type']").attr('disabled', 'disabled').removeAttr('checked', 'checked');
  1817. $("input[name='tender_valuation_type'][value='"+ projectProperty.valuationType +"']")
  1818. .attr("checked", "checked").removeAttr('disabled', 'disabled');
  1819. }
  1820. /**
  1821. * 获取单价文件
  1822. *
  1823. * @param {Number} parentID
  1824. * @return {void}
  1825. */
  1826. function getUnitFile(parentID, callback) {
  1827. parentID = parseInt(parentID);
  1828. if (isNaN(parentID) && parentID <= 0) {
  1829. return;
  1830. }
  1831. $.ajax({
  1832. url: '/pm/api/getUnitFile',
  1833. type: 'post',
  1834. data: {'data': JSON.stringify({"user_id": userID, "parentID": parentID})},
  1835. dataType: 'json',
  1836. error: function() {
  1837. alert('数据传输错误!');
  1838. },
  1839. beforeSend: function() {
  1840. },
  1841. success: function(response) {
  1842. if (response.error === 1) {
  1843. alert('获取失败!');
  1844. } else {
  1845. if(callback){
  1846. callback(response);
  1847. }
  1848. }
  1849. }
  1850. });
  1851. }
  1852. /**
  1853. * 获取费率文件
  1854. *
  1855. * @param {Number} parentID
  1856. * @return {void}
  1857. */
  1858. function getFeeRateFile(parentID, callback) {
  1859. parentID = parseInt(parentID);
  1860. if (isNaN(parentID) && parentID <= 0) {
  1861. return;
  1862. }
  1863. $.ajax({
  1864. url: '/pm/api/getFeeRateFile',
  1865. type: 'post',
  1866. data: {'data': JSON.stringify({"user_id": userID, "parentID": parentID})},
  1867. dataType: 'json',
  1868. error: function() {
  1869. alert('数据传输错误!');
  1870. },
  1871. beforeSend: function() {
  1872. },
  1873. success: function(response) {
  1874. if (response.error === 1) {
  1875. alert('获取失败!');
  1876. } else {
  1877. if(callback){
  1878. callback(response);
  1879. }
  1880. }
  1881. }
  1882. });
  1883. }
  1884. /**
  1885. * 加载数据到侧边栏
  1886. *
  1887. * @return {void}
  1888. */
  1889. function setDataToSideBar() {
  1890. // 获取当前点击的数据
  1891. let that = projTreeObj;
  1892. let selectedItem = that.tree.selected;
  1893. let name = selectedItem.data.name;
  1894. let target = selectedItem.data.projType === projectType.project ? '#summary-project' : '#summary-engineering';
  1895. $(".side-content .p-3").hide();
  1896. $(target).show();
  1897. // 加载单价文件与费率文件
  1898. if (selectedItem.data.projType === projectType.project) {
  1899. let engineeringData = selectedItem.children !== null && selectedItem.children.children !== null ?
  1900. selectedItem.children : [];
  1901. /*if (engineeringData.length <= 0) {
  1902. return;
  1903. }*/
  1904. let unitPriceFileList = [];
  1905. let feeFileList = [];
  1906. let poj_tenders = getProjTenders(selectedItem);
  1907. getUnitFile(selectedItem.data.ID, function (response) {
  1908. unitPriceFileList = unitPriceFileList.concat(response.data);
  1909. $(target + '-unit-price-table tbody').empty();
  1910. set_file_table(target, poj_tenders, unitPriceFileList, fileType.unitPriceFile);
  1911. });
  1912. getFeeRateFile(selectedItem.data.ID, function (response) {
  1913. feeFileList = feeFileList.concat(response.data);
  1914. $(target + '-fee-table tbody').empty();
  1915. set_file_table(target, poj_tenders, feeFileList, fileType.feeRateFile);
  1916. });
  1917. }
  1918. }
  1919. //获取建设项目的全部单位工程
  1920. function getProjTenders(proj) {
  1921. let rst = [];
  1922. let engineerings = proj.children || null;
  1923. if (engineerings) {
  1924. for (let i = 0, len = engineerings.length; i < len; i++) {
  1925. let e_tenders = engineerings[i].children || null;
  1926. if (e_tenders && e_tenders.length > 0) {
  1927. rst = rst.concat(e_tenders);
  1928. }
  1929. }
  1930. }
  1931. return rst;
  1932. }
  1933. //单价、费率文件汇总信息的使用次数、使用该文件的单位工程
  1934. function getUsedObj(tenders, fileId, type){
  1935. let rst = Object.create(null), usedCount = 0, usedInfo = '';
  1936. rst.usedCount = 0;
  1937. rst.usedInfo = null;
  1938. for(let i = 0, len = tenders.length; i < len; i++){
  1939. if(tenders[i].data.property){
  1940. let theFile = type === fileType.unitPriceFile ? tenders[i].data.property.unitPriceFile || null : tenders[i].data.property.feeFile || null;
  1941. if(theFile && theFile.id == fileId){
  1942. usedCount ++;
  1943. usedInfo += tenders[i].data.name + '<br>';
  1944. }
  1945. }
  1946. }
  1947. if(usedCount > 0){
  1948. usedInfo = usedInfo.slice(0, usedInfo.length - 4);
  1949. rst.usedCount = usedCount;
  1950. rst.usedInfo = usedInfo;
  1951. }
  1952. return rst;
  1953. }
  1954. //单价、费率文件汇总界面交互
  1955. function bindEvents_file_table(jqS, usedObj, targetBody, type){
  1956. //悬浮显示删除和重命名按钮
  1957. $(jqS).hover(function(){
  1958. $('p',this).show();
  1959. },function(){
  1960. $('p', this).hide();
  1961. });
  1962. //删除
  1963. if(usedObj.usedCount > 0){//不可删除
  1964. $(jqS + ' p a:eq(0)').addClass('disabled');
  1965. $(jqS + ' p a:eq(0)').removeAttr('data-target');
  1966. }
  1967. else {
  1968. $(jqS + ' p a:eq(0)').on('click', function () {
  1969. let dispName = $(jqS + ' div:eq(0)')[0].childNodes[0].textContent;
  1970. //刷新删除弹出框内容
  1971. let delData = '删除"' + dispName + '"?';
  1972. $('#del-wj .modal-body h5').text(delData);
  1973. let attrId = $(jqS).attr('id');
  1974. let id = attrId.slice(5, attrId.length);
  1975. if(type === fileType.unitPriceFile){
  1976. id = parseInt(id);
  1977. }
  1978. let obj = Object.create(null);
  1979. obj.fileType = type;
  1980. obj.id = id;
  1981. fileDelObj = obj;
  1982. });
  1983. }
  1984. //重命名
  1985. $(jqS + ' p a:eq(1)').on('click', function () {
  1986. let fileObjs = getFileObj(targetBody, type);
  1987. let orgDispName = $(jqS + ' div:eq(0)')[0].childNodes[0].textContent;
  1988. let postFix = orgDispName.slice(orgDispName.length - 4, orgDispName.length);
  1989. let orgName = orgDispName.slice(0, orgDispName.length - 4);
  1990. $(jqS + ' input').val(orgName);
  1991. $(jqS + ' div:eq(0)').hide();
  1992. $(jqS + ' div:eq(1)').show();
  1993. //确认重命名
  1994. $(jqS + ' .btn-success').on('click', function () {
  1995. let attrId = $(jqS).attr('id');
  1996. let id = attrId.slice(5, attrId.length);
  1997. let newName = $(jqS + ' input').val().trim();
  1998. if(newName !== orgName){
  1999. if(hasThisFileName(fileObjs, newName)){
  2000. alert('本建设项目已存在该文件名,请重新输入!');
  2001. $(jqS + ' input').val(orgName);
  2002. return;
  2003. }
  2004. if(newName.trim().length === 0){
  2005. alert('文件名不可为空!');
  2006. $(jqS + ' input').val(orgName);
  2007. return;
  2008. }
  2009. //ajax
  2010. let updateObj = Object.create(null);
  2011. updateObj.fileType = type;
  2012. updateObj.updateType = 'update';
  2013. updateObj.updateData = Object.create(null);
  2014. if(type === fileType.unitPriceFile){
  2015. updateObj.updateData.id = parseInt(id);
  2016. //updateObj.updateData.id = id;
  2017. }
  2018. else if(type === fileType.feeRateFile){
  2019. updateObj.updateData.ID = id;
  2020. }
  2021. updateObj.updateData.name = newName;
  2022. a_updateFiles([updateObj], function () {
  2023. let newDispName = newName + postFix;
  2024. $(jqS + ' div:eq(0)')[0].childNodes[0].textContent = newDispName;
  2025. $(jqS + ' div:eq(0)').show();
  2026. $(jqS + ' div:eq(1)').hide();
  2027. });
  2028. }
  2029. let newDispName = newName + postFix;
  2030. $(jqS + ' div:eq(0)')[0].childNodes[0].textContent = newDispName;
  2031. $(jqS + ' div:eq(0)').show();
  2032. $(jqS + ' div:eq(1)').hide();
  2033. });
  2034. //取消重命名
  2035. $(jqS + ' .btn-secondary').on('click', function () {
  2036. $(jqS + ' div:eq(0)').show();
  2037. $(jqS + ' div:eq(1)').hide();
  2038. });
  2039. });
  2040. //悬浮框显示使用该文件的单位工程
  2041. $($(jqS)[0].nextSibling).popover({
  2042. placement:"bottom",
  2043. html:true,
  2044. trigger:"hover", //| focus
  2045. content: usedObj.usedInfo ? usedObj.usedInfo : ''
  2046. }
  2047. );
  2048. }
  2049. //更新单价、费率文件(删除、重命名)
  2050. function a_updateFiles(updateDatas, callback){
  2051. $.ajax({
  2052. type: 'post',
  2053. url: '/pm/api/updateFiles',
  2054. data: {data: JSON.stringify({user_id: userID, updateDatas: updateDatas})},
  2055. dataType: 'json',
  2056. success: function (result){
  2057. if(!result.error && callback){
  2058. callback();
  2059. }
  2060. }
  2061. })
  2062. }
  2063. function set_file_table(target, poj_tenders, fileList, type){
  2064. let fileCounter = 1;
  2065. for(let i = 0, len = fileList.length; i < len; i++){
  2066. let fileId = type === fileType.unitPriceFile ? fileList[i].id : fileList[i].ID;
  2067. let usedObj = getUsedObj(poj_tenders, fileId, type);
  2068. let usedHtml = usedObj.usedCount > 0 ? '<td class="text-center"><a href="javascript:void(0);">' + usedObj.usedCount + '</a></td>' : '<td class="text-center">' + usedObj.usedCount + '</td>';
  2069. let hoverHtml = '<p style="display: none"><a class="btn btn-sm" href="javascript:void(0);" data-toggle="modal" data-target="#del-wj">删除</a><a class="btn btn-sm" href="javascript:void(0);">重命名</a></p></div>';
  2070. let renHtml = '<div class="input-group" style="display: none;">'
  2071. + '<input class="form-control form-control-sm" value="">'
  2072. + '<span class="input-group-btn">'
  2073. + '<button class="btn btn-success btn-sm" type="button"><i class="fa fa-check"></i></button>'
  2074. + '</span>'
  2075. + '<span class="input-group-btn">'
  2076. + '<button class="btn btn-secondary btn-sm" type="button"><i class="fa fa-remove"></i></button>'
  2077. + '</span>'
  2078. + '</div></td>';
  2079. let fileTypeStr = type === fileType.unitPriceFile ? '单价文件' : '费率文件';
  2080. let fileHtml = '<tr><td>' + fileCounter + '</td><td id="file_' + fileId + '"><div>' + fileList[i].name + hoverHtml + renHtml + usedHtml + '</tr>';
  2081. fileCounter++;
  2082. let targetBody = type === fileType.unitPriceFile ? target + '-unit-price-table tbody' : target + '-fee-table tbody';
  2083. $(targetBody).append(fileHtml);
  2084. let jqS = '#file_' + fileId;
  2085. bindEvents_file_table(jqS, usedObj, targetBody, type);
  2086. }
  2087. }
  2088. function getFileObj(jqS, type){
  2089. let rst = [];
  2090. let trs = $('tr', jqS);
  2091. for(let i = 0, len = trs.length; i < len; i++){
  2092. let td = $('td:eq(1)', trs[i])[0];
  2093. let dispName = td.childNodes[0].childNodes[0].textContent;
  2094. let name = dispName.slice(0, dispName.length - 4);
  2095. let attrId = $(td).attr('id');
  2096. let id = attrId.slice(5, attrId.length);
  2097. if(type === fileType.unitPriceFile){
  2098. id = parseInt(id);
  2099. }
  2100. let obj = Object.create(null);
  2101. obj.id = id;
  2102. obj.name = name;
  2103. rst.push(obj);
  2104. }
  2105. return rst;
  2106. //let orgDispName = $(jqS + ' div:eq(0)')[0].childNodes[0].textContent;
  2107. }
  2108. function hasThisFileName(fileObjs, name){
  2109. for(let i = 0, len = fileObjs.length; i < len; i++){
  2110. if(fileObjs[i].name === name){
  2111. return true;
  2112. }
  2113. }
  2114. return false;
  2115. }