glj_view.js 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  1. /**
  2. * Created by CSL on 2017-05-12.
  3. */
  4. var gljOprObj = {
  5. sheet: null,
  6. libID: null,
  7. ration: null,
  8. sheetData: [],
  9. checkb: null,
  10. mainTreeSelectedChange:false,
  11. detailSheet: null,
  12. detailData: [],
  13. GLJSelection: [],
  14. selectedGLJClass: null,
  15. parentNodeIds: {},
  16. activeTab: '#linkGLJ',
  17. setting: {},
  18. detailSetting: {
  19. header: [
  20. {headerName: "名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  21. {headerName: "计算式", headerWidth: 120, dataCode: "regex", dataType: "String"},
  22. {headerName: "结果(C)", headerWidth: 120, dataCode: "result", dataType: "Number", decimalField: "quantity_detail"},
  23. {headerName: "累加", headerWidth: 120, dataCode: "isSummation", dataType: "String", cellType: "checkBox"}
  24. ],
  25. view: {
  26. lockColumns: [2, 3]
  27. }
  28. },
  29. gljTreeSetting: {
  30. view: {
  31. expandSpeed: "",
  32. selectedMulti: false
  33. },
  34. edit: {
  35. enable: false,
  36. editNameSelectAll: true,
  37. showRemoveBtn: true,
  38. showRenameBtn: true,
  39. removeTitle: "删除节点",
  40. renameTitle: "更改名称"
  41. },
  42. data: {
  43. keep: {
  44. parent: true,
  45. leaf: true
  46. },
  47. key: {
  48. children: "items",
  49. name: "Name"
  50. },
  51. simpleData: {
  52. enable: false,
  53. idKey: "ID",
  54. pIdKey: "ParentID",
  55. rootPId: -1
  56. }
  57. },
  58. callback: {
  59. onClick: function (event, treeId, treeNode) {
  60. if (treeId == 'gljTree') {
  61. let me = gljOprObj, gljTypeId = treeNode.ID;
  62. if (treeNode.ID) {
  63. me.gljCurTypeId = treeNode.ID;
  64. me.filterLibGLJSheetData();
  65. me.showLibGLJSheetData();
  66. }
  67. } else {
  68. if (treeNode.isParent) {
  69. $('#class_selected_conf').attr("disabled", "disabled");
  70. $('#selected_class').val("");
  71. } else {
  72. $('#class_selected_conf').removeAttr("disabled");
  73. $('#selected_class').val(treeNode.ID);
  74. }
  75. }
  76. }
  77. }
  78. },
  79. gljLibSheetSetting: {
  80. owner: 'gljTree',
  81. header: [
  82. {headerName: "选择", headerWidth: 40, dataCode: "select", hAlign: "center", vAlign: "center", cellType: "checkBox"},
  83. {headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
  84. {headerName: "名称", headerWidth: 220, dataCode: "name", dataType: "String", hAlign: "left", vAlign: "center"},
  85. {headerName: "规格型号", headerWidth: 185, dataCode: "specs", dataType: "String", hAlign: "left", vAlign: "center"},
  86. {headerName: "单位", headerWidth: 40, dataCode: "unit", dataType: "String", hAlign: "center", vAlign: "center"},
  87. {headerName: "单价", headerWidth: 55, dataCode: "basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
  88. {headerName: "类型", headerWidth: 60, dataCode: "gljType", dataType: "String", hAlign: "center", vAlign: "center"},
  89. {headerName: "新增", headerWidth: 40, dataCode: "isComplementary", dataType: "String", hAlign: "center", vAlign: "center", cellType: "checkBox"}
  90. ],
  91. view: {
  92. lockColumns: [0, 1, 2, 3, 4, 5, 6]
  93. }
  94. },
  95. gljLibSheet: null,
  96. initSheet: function (sheet) {
  97. var me = this;
  98. me.sheet = sheet;
  99. sheetCommonObj.initSheet(me.sheet, me.setting, 30);
  100. sheet.name('ration_glj');
  101. me.bindSheetEvent(sheet);
  102. sheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, me.onCellDoubleClick);
  103. sheet.bind(GC.Spread.Sheets.Events.ClipboardChanged, me.onClipboardChanged);
  104. subSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClick);
  105. if(!projectReadOnly){
  106. gljContextMenu.loadGLJSpreadContextMenu();
  107. }
  108. sheet.bind(GC.Spread.Sheets.Events.SelectionChanged,function (sender,args) {
  109. let selected = args.newSelections[0] ? args.newSelections[0] : {row: 0, col: 0};
  110. me.sheetInitSelection(selected);
  111. });
  112. },
  113. sheetInitSelection: function (selected) {
  114. let me = gljOprObj;
  115. if(selected.row < me.sheetData.length){
  116. me.sheet.setStyle(selected.row, -1, me.getSelStyle(true));
  117. }
  118. me.sheet.repaint();
  119. if(me.preGljSelection && me.preGljSelection.row !== selected.row){
  120. me.sheet.setStyle(me.preGljSelection.row, -1, me.getSelStyle(false));
  121. }
  122. me.preGljSelection = selected;
  123. },
  124. initDetailSheet: function (sheet) {
  125. var me = this;
  126. me.detailSheet = sheet;
  127. sheetCommonObj.initSheet(me.detailSheet, me.detailSetting, 30);
  128. // me.detailSheet.selectionUnit(0);//0 cell,1 row,2 col;
  129. sheet.name('quantity_detail');
  130. me.bindSheetEvent(sheet);
  131. },
  132. detailSheetReadonly:function () {
  133. let selected = projectObj.project.mainTree.selected;
  134. let Bills = projectObj.project.Bills;
  135. if(selected) {
  136. //清单锁定时只读
  137. if(selected.sourceType == ModuleNames.bills && projectObj.project.isBillsLocked() && projectObj.project.withinBillsLocked(selected)){
  138. return true;
  139. }
  140. //大项费用、分部节点层次时,工程量明细只读。
  141. if(indicativeInfoObj.isDXFY(selected) || indicativeInfoObj.isFB(selected)){
  142. return true;
  143. }
  144. //是主材或者是设备时只读
  145. if(selected.sourceType == ModuleNames.ration_glj){
  146. return true;
  147. }else if(gljOprObj.isInstallationNode(selected)){//是补项或者是安装类型的定额时只读
  148. return true;
  149. }
  150. return false;
  151. }
  152. return true;
  153. },
  154. bindSheetEvent: function (sheet) {
  155. var me = this;
  156. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  157. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  158. sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  159. sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
  160. sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.startEditChecking);
  161. // sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  162. },
  163. onClipboardPasting: function (sender, args) {
  164. var me = gljOprObj;
  165. if(args.sheetName!="quantity_detail"&&(args.cellRange.rowCount!=1||args.cellRange.colCount!=1)){//工程量明细做特殊处理
  166. args.cancel = true;
  167. }
  168. },
  169. onClipboardPasted: function (e, info) {
  170. var me = gljOprObj;
  171. console.log('past');
  172. // if (!me.ration) {return;};
  173. // your code...
  174. },
  175. startEditChecking:function (sender,args) {
  176. let me = gljOprObj;
  177. let selected = projectObj.project.mainTree.selected;
  178. if(selected){
  179. if(me.isInstallationNode(selected)==true){
  180. args.cancel = true;
  181. }else {
  182. if(args.sheetName == 'quantity_detail'){//工程量明细表
  183. if(me.detailSheetReadonly()){
  184. args.cancel = true;
  185. }else {
  186. if(args.sheet.getValue(args.row,args.col)==null){//这里是为了解决当单元格里的值是null的时候,在单元格里输入数据,按键盘箭头移动光标的时候,会直接结束编辑,跳到另外的单元格。
  187. args.sheet.setValue(args.row,args.col,"");
  188. }
  189. }
  190. }
  191. if(args.sheetName == 'ration_glj'){//定额工料机表
  192. if(!me.rationGLJEditCheck(args)) args.cancel = true;
  193. }
  194. }
  195. }else {
  196. args.cancel = true;
  197. }
  198. },
  199. isInstallationNode:function(node){
  200. if(node.sourceType == ModuleNames.ration&&node.data.type == rationType.install){//是定额安装费类型时只读,原先是补项的时候也是控制只读的||(node.sourceType == ModuleNames.bills&&node.data.type==billType.BX)){//是定额安装费类型或者补项
  201. return true;
  202. }
  203. return false
  204. },
  205. onEditEnded: function (sender, args) {
  206. var me = gljOprObj;
  207. if (args.sheetName == 'ration_glj') {
  208. me.onEditGLJSheet(args)
  209. }
  210. if (args.sheetName == 'quantity_detail') {
  211. me.onEditDetailSheet(args);
  212. }
  213. },
  214. onEditDetailSheet: function (args,callback) {
  215. var me = gljOprObj;
  216. if (args.row > me.detailData.length) {
  217. return;
  218. }
  219. if (args.row == me.detailData.length && args.editingText == null) {
  220. return;
  221. }
  222. var selected = projectObj.project.mainTree.selected;//因为使用了延时方法,所以要先取得选中行;
  223. var detailList = me.detailData;
  224. if(args.editingText){
  225. args.editingText = args.editingText.replace(/(/g, "(");//替换中文左右括号;
  226. args.editingText = args.editingText.replace(/)/g, ")");
  227. }
  228. if (args.row == detailList.length) {
  229. projectObj.project.quantity_detail.saveQuantityDetail(args, me.detailSetting.header[args.col].dataCode, selected,callback);
  230. }
  231. if (args.row < detailList.length) {
  232. projectObj.project.quantity_detail.updateQuantityDetail(args, me.detailSetting.header[args.col].dataCode, detailList[args.row], selected,callback);
  233. }
  234. },
  235. onEditGLJSheet: function (args) {
  236. var me = gljOprObj;
  237. if (args.row >= me.sheetData.length) {
  238. me.sheet.getCell(args.row, args.col).value(null);
  239. return;
  240. }
  241. me.updateRationGLJ(args);
  242. },
  243. onSelectionChanged: function (sender, args) {
  244. let me = gljOprObj;
  245. me.initSelection(args.newSelections.length > 0 ? {row: args.newSelections[0].row} : {row: 0});
  246. },
  247. getSelStyle: function (selected) {
  248. let style = new GC.Spread.Sheets.Style();
  249. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  250. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  251. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  252. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  253. let colorOpts = optionsOprObj.getOption(optionsOprObj.optionsTypes.COLOROPTS);
  254. let selectedColor = colorOpts.SELECTED.backColor,
  255. recColor = 'White';
  256. style.backColor = selected ? selectedColor : recColor;
  257. return style;
  258. },
  259. initSelection: function (sel) {
  260. let me = gljOprObj;
  261. if(sel){
  262. me.gljLibSheet.setStyle(sel.row, -1, me.getSelStyle(true));
  263. }
  264. if(me.preGljLibSelection && me.preGljLibSelection.row !== sel.row){
  265. me.gljLibSheet.setStyle(me.preGljLibSelection.row, -1, me.getSelStyle(false));
  266. }
  267. me.preGljLibSelection = sel;
  268. },
  269. onButtonClick: function (sender, args) {
  270. if(args.sheet.isEditing()){
  271. args.sheet.endEdit();
  272. }
  273. var me = gljOprObj;
  274. var sheet = args.sheet, row = args.row, col = args.col;
  275. var cellType = sheet.getCellType(row, col);
  276. if (cellType instanceof GC.Spread.Sheets.CellTypes.Button) {
  277. if(args.sheetName == 'rationInstallSheet'){
  278. installationFeeObj.onPositionButtonClick(sender,args);
  279. }
  280. } else {
  281. me.onCheckBoxClick(sender, args)
  282. }
  283. },
  284. onCheckBoxClick: function (sender, args) {
  285. let selected = projectObj.project.mainTree.selected;
  286. if(selected.sourceType == ModuleNames.ration_glj){//选中的是工料机时不可编辑
  287. return ;
  288. }
  289. let checkboxValue = args.sheet.getCell(args.row, args.col).value();
  290. if(args.sheetName == 'rationInstallSheet' && checkboxValue){
  291. return;
  292. }
  293. if(gljOprObj.isInstallationNode(selected)==true){
  294. return;
  295. }
  296. let newval = 0;
  297. if (checkboxValue) {
  298. newval = 0;
  299. args.sheet.getCell(args.row, args.col).value(newval);
  300. } else {
  301. newval = 1;
  302. args.sheet.getCell(args.row, args.col).value(newval);
  303. }
  304. if (args.sheetName == 'ration_glj') {
  305. gljOprObj.updateIsEstimate(args,newval);
  306. } else if (args.sheetName == 'quantity_detail') {
  307. projectObj.project.quantity_detail.isSummationUpdate(args, gljOprObj.detailData, newval);
  308. } else if (args.sheetName == 'glj_lib') {
  309. if(gljOprObj.gljLibSheetSetting.header[args.col].dataCode === 'select'){
  310. gljOprObj.setGLJSelection(args, newval);
  311. }
  312. }else if(args.sheetName == 'rationInstallSheet'){
  313. args.newValue = newval;
  314. installationFeeObj.onRationInstallValueChange(sender,args);
  315. }
  316. },
  317. onCellDoubleClick:function (sender, args) {
  318. var me = gljOprObj;
  319. var header = me.setting.header;
  320. if (args.row >= me.sheetData.length) {
  321. return;
  322. }
  323. if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
  324. if(me.hasComposition(me.sheetData[args.row])){
  325. alert("当前工料机的市场价由组成物计算得出,不可直接修改。");
  326. }
  327. }
  328. if (header[args.col] && header[args.col].dataCode == 'basePrice') {
  329. var isAdd = me.sheetData[args.row].isAdd;
  330. if(isAdd==1){//是新增但没有组成物时允许修改定额价
  331. if(me.hasComposition(me.sheetData[args.row])){//如果有组成物,不可修改
  332. alert("当前工料机的定额价由组成物计算得出,不可直接修改。");
  333. }
  334. }
  335. }
  336. },
  337. onClipboardChanged: function (sender, info) {
  338. let cDatas = sheetCommonObj.getTableData(info.sheet, null);
  339. sheetCommonObj.copyTextToClipboard(cDatas);
  340. return;
  341. },
  342. rationGLJEditCheck:function (args) {//true 可以编辑,false 不能编辑
  343. var me = gljOprObj;
  344. var header = me.setting.header;
  345. if (_.includes(me.setting.view.lockColumns, args.col)) return false;//如果是锁定的列,不能编辑
  346. if(me.sheetData[args.row] != undefined){
  347. if(me.sheetData[args.row].isMixRatio){//对于组成物列
  348. return header[args.col].dataCode == 'marketPrice'//允许修改组成物市单价,其它的不可以
  349. }else {
  350. if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
  351. return !me.marketPriceReadOnly({data:me.sheetData[args.row]});
  352. }
  353. if (header[args.col] && header[args.col].dataCode == 'basePrice') {
  354. var isAdd = me.sheetData[args.row].isAdd;
  355. if(isAdd==1){//是新增但没有组成物时允许修改定额价
  356. return !me.marketPriceReadOnly({data:me.sheetData[args.row]});//如果有组成物,不可修改
  357. } else {
  358. return false;
  359. }
  360. }
  361. return true;
  362. }
  363. }else {
  364. return false
  365. }
  366. }
  367. ,
  368. hasComposition:function (ration_glj,isRationType) {//判断是否有组成物,有则返回true 现在主材类型的工料机也有可能有组成物。
  369. let type = isRationType==true? ration_glj.subType:ration_glj.type;
  370. if(notEditType.indexOf(type)!=-1||type==gljType.MAIN_MATERIAL){
  371. let keyArray = isRationType==true? rationKeyArray:gljKeyArray;
  372. let con_key = this.getIndex(ration_glj,keyArray);
  373. var mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  374. if(mixRatioMap[con_key]&&mixRatioMap[con_key].length>0){
  375. return true;
  376. }
  377. }
  378. return false;
  379. },
  380. onRangeChanged: function (sender, args) {
  381. var me = gljOprObj;
  382. if(args.sheetName == 'quantity_detail'){
  383. me.batchUpdateQuantityDetail(args);
  384. }else {
  385. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  386. args.editingText = null;
  387. }else if(args.action == GC.Spread.Sheets.RangeChangedAction.paste){
  388. args.editingText = args.sheet.getCell(args.row,args.col).value();
  389. }else {
  390. return;
  391. }
  392. if (args.sheetName == 'ration_glj') {
  393. me.onEditGLJSheet(args);
  394. }
  395. }
  396. },
  397. batchUpdateQuantityDetail:function (args) {
  398. let me = gljOprObj;
  399. let updateArray = [];
  400. for(let i =0;i<args.changedCells.length;i++){
  401. let c = args.changedCells[i];
  402. let tem = {
  403. row:c.row,
  404. col:c.col,
  405. editingText:args.sheet.getCell(c.row,c.col).text(),
  406. sheet:args.sheet,
  407. sheetName:args.sheetName,
  408. index:i
  409. };
  410. updateArray.push(tem);
  411. }
  412. if(updateArray.length>0){
  413. updateArray.length == 1?me.onEditDetailSheet(updateArray[0]):me.onEditDetailSheet(updateArray[0],updateCallback);
  414. }
  415. function updateCallback(i_args) {
  416. let index = i_args.index;
  417. if(index < updateArray.length-1){
  418. let nextIndex = index+1;
  419. updateArray[nextIndex].replace = i_args.replace;
  420. if(nextIndex == updateArray.length-1){//是最后一个,则不用调callback了
  421. me.onEditDetailSheet(updateArray[nextIndex]);
  422. }else {
  423. me.onEditDetailSheet(updateArray[nextIndex],updateCallback);
  424. }
  425. }
  426. }
  427. },
  428. showDataIfRationSelect: function (node,selectedNodeId) {
  429. var isShow = false;
  430. //恢复底色
  431. this.sheet.setStyle(this.sheet.getActiveRowIndex(), -1, this.getSelStyle(false));
  432. if(projectReadOnly && this.setting.view.lockColumns){
  433. this.setting.view.lockColumns = null;
  434. }
  435. if(selectedNodeId){
  436. this.selectedNodeId = selectedNodeId;
  437. }
  438. if (node) {
  439. if (this.selectedNodeId && this.selectedNodeId == node.getID()) {
  440. return;
  441. } else {
  442. this.selectedNodeId = node.getID();
  443. }
  444. if (node.sourceType == "ration") {
  445. if(node.data.type==rationType.gljRation){
  446. if($('#linkGLJ').hasClass('active')){
  447. this.showMixRatio(node);
  448. }
  449. }else {
  450. if($('#linkGLJ').hasClass('active')){
  451. this.showRationGLJData(node);
  452. }
  453. if($('#linkAZZJF').hasClass('active')){
  454. installationFeeObj.showRationInstallationData(node);
  455. }
  456. }
  457. isShow = true;
  458. }
  459. if(node.sourceType == ModuleNames.ration_glj){
  460. if($('#linkGLJ').hasClass('active')) {
  461. this.showMixRatio(node);
  462. }
  463. isShow = true;
  464. }
  465. if($('#linkGCLMX').hasClass('active')){
  466. this.showQuantityDetailData(node);
  467. }
  468. } else {
  469. this.selectedNodeId = null;
  470. }
  471. if (!isShow) {
  472. this.clearSheetData();
  473. }
  474. //子目换算
  475. zmhs_obj.showZMHSData(node);
  476. // $('#dropdown').hide();
  477. },
  478. showMixRatio:function (node) {//显示组成物到定额工料机
  479. let mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  480. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  481. let indexArray =node.sourceType==ModuleNames.ration?rationKeyArray:gljKeyArray;
  482. let connect_index = this.getIndex(node.data,indexArray);
  483. let gljList=[];
  484. if(mixRatioMap[connect_index]){ //说明是有组成物的类型
  485. gljList = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  486. }
  487. if(gljList.length>0){//计算总消耗量
  488. if(node.sourceType==ModuleNames.ration){
  489. this.calcMixRationTotalQuantity(gljList,node.data.quantity);
  490. }else {
  491. let totalQuantity = this.getTotalQuantity(node.data);
  492. this.calcMixRationTotalQuantity(gljList,totalQuantity)
  493. }
  494. }
  495. this.sheetData = gljList;
  496. this.sheet.setRowCount(0);
  497. this.sheetData = sortRationGLJ(this.sheetData);
  498. this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType([]));
  499. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  500. //初始选择
  501. this.preGljSelection = null;
  502. this.sheetInitSelection({row: this.sheet.getActiveRowIndex(), col: 0});
  503. this.sheet.getRange(-1, 0, -1, this.setting.header.length).locked(true);//锁住定额工料机的所有列
  504. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);//锁住工程量明细的所有列
  505. },
  506. showRationGLJData: function (node) {
  507. var gljList = [];
  508. var ration_glj = projectObj.project.ration_glj;
  509. node = node ? node : projectObj.project.mainTree.selected;
  510. if (node.sourceType == ModuleNames.ration) {
  511. if(node.data.type==rationType.gljRation){
  512. this.showMixRatio(node);
  513. }else {
  514. let ration = node.data;
  515. gljList = this.filterGljByRation(ration, ration_glj.datas);
  516. this.showInSheet(gljList);
  517. }
  518. }else if(node.sourceType == ModuleNames.ration_glj){
  519. this.showMixRatio(node);
  520. }
  521. },
  522. showRationGLJSheetData: function (init) {
  523. let selected = this.sheet.getSelections();
  524. this.combineWithProjectGlj(this.sheetData);
  525. this.sheet.setRowCount(0);
  526. this.sheetData = sortRationGLJ(this.sheetData);
  527. this.sumQuantity();//计算总消耗量
  528. this.addMixRatioToShow();//显示组成物信息
  529. this.initRationTree(init,this.getUnitPriceCodeMap());
  530. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  531. if(this.mainTreeSelectedChange == true){
  532. this.sheet.setSelection(0,1,1,1);//默认选中第一行,第二列(名称列)
  533. this.mainTreeSelectedChange = false;
  534. }else if(selected){//定位光标到之前的位置
  535. this.sheet.setSelection(selected[0].row,selected[0].col,selected[0].rowCount,selected[0].colCount);
  536. }
  537. //初始选择
  538. this.preGljSelection = null;
  539. this.sheetInitSelection({row: this.sheet.getActiveRowIndex(), col: this.sheet.getActiveColumnIndex()});
  540. },
  541. getUnitPriceCodeMap : function () {//取单价文件中,编码前缀一样的映射表
  542. let codeMap = {};
  543. let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;
  544. if(priceMap){
  545. for(let connectKey in priceMap){
  546. let code = priceMap[connectKey].code;
  547. let name = priceMap[connectKey].name;
  548. let specs = priceMap[connectKey].specs;
  549. if(code){
  550. let displayText = code +" "+name +" "+specs;
  551. let preCode = code.split("-")[0];
  552. if(codeMap[preCode]) {
  553. codeMap[preCode].push({text:displayText,value:connectKey});
  554. }else {
  555. codeMap[preCode]=[{text:displayText ,value:connectKey}];
  556. }
  557. }
  558. }
  559. }
  560. return codeMap;
  561. },
  562. initRationTree: function (init,codeMap) {
  563. this.sheet.suspendPaint();
  564. this.sheet.suspendEvent();
  565. this.sheet.setRowCount(this.sheetData.length >30?this.sheetData.length:30);
  566. for (var i = 0; i < this.sheetData.length; i++) {
  567. let options = this.getCodeOptions(this.sheetData[i],codeMap);
  568. this.sheet.setCellType(i, 0,this.getTreeNodeCellType(this.sheetData,options),GC.Spread.Sheets.SheetArea.viewport);
  569. if (this.sheetData[i].hasOwnProperty('subList')) {
  570. var collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
  571. if (collapsed == true) {
  572. this.sheet.getRange(i + 1, -1, this.sheetData[i].subList.length, -1).visible(false);
  573. }
  574. }
  575. }
  576. this.sheet.resumeEvent();
  577. this.sheet.resumePaint();
  578. },
  579. getCodeOptions:function (recode,codeMap) {
  580. let options = [];
  581. if(recode.isMixRatio ===true){
  582. return null;
  583. }
  584. let code = recode.code;
  585. if(code) {
  586. let preCode = code.split("-")[0];
  587. if( codeMap[preCode]) options = codeMap[preCode];
  588. if(options.length>0) _.remove(options,{'value':gljOprObj.getIndex(recode, gljKeyArray)})//去掉本身
  589. }
  590. return options;
  591. },
  592. filterGljByRation: function (ration, datas) {
  593. var gljList = [];
  594. if (datas && datas.length > 0) {
  595. gljList = _.filter(datas, {'rationID': ration.ID})
  596. }
  597. return gljList;
  598. },
  599. showInSheet: function (gljList) {
  600. this.sheetData = gljList;
  601. this.showRationGLJSheetData(true);
  602. },
  603. sumQuantity: function (node) {
  604. if (this.sheetData.length > 0) {
  605. node = node ? node : projectObj.project.mainTree.selected;
  606. let ration = node.data;
  607. let quantity = ration.quantity;
  608. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  609. for (let glj of this.sheetData) {
  610. glj.totalQuantity= this.getTotalQuantity(glj,ration);
  611. }
  612. }
  613. },
  614. getTotalQuantity:function(glj,ration){
  615. ration=ration?ration: _.find(projectObj.project.Ration.datas,{"ID":glj.rationID});
  616. if(ration){
  617. let quantity = ration.quantity;
  618. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  619. if (glj.isMixRatio == true) {//如果是用于显示的组成物,则不用计算,跳过
  620. return;
  621. }
  622. quantity = scMathUtil.roundForObj(quantity, getDecimal("ration.quantity"));//计算前进行4舍5入
  623. glj.quantity = scMathUtil.roundForObj(glj.quantity, getDecimal("glj.quantity"));
  624. glj.totalQuantity = scMathUtil.roundToString(quantity * glj.quantity, getDecimal("glj.quantity"));
  625. if (glj.hasOwnProperty('subList')) {//需要计算glj下挂的组成物的总消耗量
  626. this.calcMixRationTotalQuantity(glj.subList,glj.totalQuantity);
  627. }
  628. return glj.totalQuantity;
  629. }
  630. },
  631. calcMixRationTotalQuantity(mList,pTotal){ //计算组成物的总消耗量
  632. for (let subG of mList) {
  633. subG.rationItemQuantity = scMathUtil.roundForObj(subG.rationItemQuantity, getDecimal("glj.quantity"));
  634. subG.totalQuantity = scMathUtil.roundToString(subG.rationItemQuantity * pTotal, getDecimal("glj.quantity"));
  635. }
  636. },
  637. addMixRatioToShow: function () {
  638. var newList = [];
  639. _.remove(this.sheetData, {'isMixRatio': true});
  640. for (var i = 0; i < this.sheetData.length; i++) {
  641. newList.push(this.sheetData[i]);
  642. if (this.sheetData[i].hasOwnProperty('subList')) {
  643. newList = newList.concat(this.sheetData[i].subList);
  644. }
  645. }
  646. this.sheetData = newList;
  647. },
  648. combineWithProjectGlj: function (ration_gljs,needRatio=true) {
  649. var projectGLJData = projectObj.project.projectGLJ.datas;
  650. var projectGljs = projectGLJData.gljList;
  651. var mixRatioMap = projectGLJData.mixRatioMap;
  652. if (ration_gljs && ration_gljs.length > 0 && projectGljs && projectGljs.length > 0) {
  653. for (var i = 0; i < ration_gljs.length; i++) {
  654. var glj = _.find(projectGljs, {'id': ration_gljs[i].projectGLJID});
  655. if (glj) {
  656. if(projectObj.project.projectGLJ.isEstimateType(ration_gljs[i].type )){
  657. ration_gljs[i].isEstimate = glj.is_evaluate;
  658. }
  659. ration_gljs[i].shortName =projectObj.project.projectGLJ.getShortNameByID(ration_gljs[i].type);
  660. ration_gljs[i].isAdd = glj.unit_price.is_add;
  661. ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
  662. var connect_index = this.getIndex(glj, gljKeyArray);
  663. if (needRatio==true&&mixRatioMap.hasOwnProperty(connect_index)) {
  664. var mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  665. ration_gljs[i].subList = mixRatios;
  666. }
  667. }
  668. }
  669. }
  670. return ration_gljs;
  671. },
  672. setGLJPrice:function (data,glj,isRadio = false) {//isRadio 标记是否算组成物的价格
  673. let proGLJ = projectObj.project.projectGLJ;
  674. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  675. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  676. let labourCoeDatas = projectObj.project.labourCoe.datas;
  677. glj = glj?glj:_.find(proGLJ.datas.gljList, {'id': data.projectGLJID});
  678. let result = gljUtil.getGLJPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  679. data.marketPrice = result.marketPrice;
  680. data.basePrice = result.basePrice;
  681. data.adjustPrice = result.adjustPrice;
  682. data.marketUnitFee = data.marketPrice;//更新树节点市场单价列的值
  683. return data;
  684. },
  685. getBasePrice:function (treeNode) {//造价书中的工料机修改的节点要用到
  686. let proGLJ = projectObj.project.projectGLJ;
  687. let glj =_.find(proGLJ.datas.gljList, {'id': treeNode.data.projectGLJID});
  688. if(this.calcPriceDiff(glj)==true){
  689. return proGLJ.getBasePrice(glj);
  690. }else {
  691. return scMathUtil.roundForObj(treeNode.data.marketUnitFee,getDecimal("glj.unitPrice"));
  692. }
  693. },
  694. calcPriceDiff:function (glj) {
  695. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  696. return gljUtil.calcPriceDiff(glj,calcOptions);
  697. },
  698. getIndex(obj, pops){
  699. let t_index = '';
  700. let k_arr = [];
  701. for (let p of pops) {
  702. let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
  703. k_arr.push(tmpK);
  704. }
  705. t_index = k_arr.join("|-|");
  706. return t_index;
  707. },
  708. getConditionByKey(conKey){//将连接字符串转换成对象
  709. let valueArray = conKey.split("|-|");
  710. let obj ={};
  711. for(let i = 0;i<valueArray.length;i++){
  712. if(valueArray[i]!='null'){
  713. if(gljKeyArray[i]=='type'){
  714. valueArray[i] = parseInt(valueArray[i]);
  715. }
  716. obj[gljKeyArray[i]]=valueArray[i];
  717. }
  718. }
  719. return obj;
  720. },
  721. getMixRationShowDatas: function (mixRatioList, projectGljs) {
  722. var temRationGLJs = [];
  723. for (var i = 0; i < mixRatioList.length; i++) {
  724. var pg = _.find(projectGljs, {
  725. 'code': mixRatioList[i].code,
  726. 'name': mixRatioList[i].name,
  727. 'specs': mixRatioList[i].specs,
  728. 'type': mixRatioList[i].type,
  729. 'unit': mixRatioList[i].unit
  730. });//改关联关系
  731. var tem = {
  732. projectGLJID: pg.id,
  733. code: pg.code,
  734. name: pg.name,
  735. specs: pg.specs,
  736. unit: pg.unit,
  737. type:mixRatioList[i].type,
  738. shortName: projectObj.project.projectGLJ.getShortNameByID(mixRatioList[i].type),
  739. consumption:mixRatioList[i].consumption,
  740. rationItemQuantity: mixRatioList[i].consumption,
  741. // quantity:mixRatioList[i].consumption,
  742. /* basePrice: pg.unit_price.base_price,
  743. marketPrice: pg.unit_price.market_price,
  744. adjustPrice: pg.adjust_price,*/
  745. //isEstimate: pg.is_evaluate,
  746. isMixRatio: true,
  747. isAdd: pg.unit_price.is_add,
  748. GLJID: pg.glj_id
  749. };
  750. if(projectObj.project.projectGLJ.isEstimateType(pg.type)){
  751. tem.isEstimate = pg.is_evaluate;
  752. }
  753. this.setGLJPrice(tem,pg);
  754. temRationGLJs.push(tem);
  755. }
  756. temRationGLJs = _.sortBy(temRationGLJs, 'code');
  757. return temRationGLJs;
  758. },
  759. showQuantityDetailData: function (node) {
  760. node = node ? node : projectObj.project.mainTree.selected;
  761. var quantity_detail = projectObj.project.quantity_detail;
  762. let field = node.sourceType == ModuleNames.ration?'rationID':'billID';
  763. let details = quantity_detail.getListByID(node.data.ID,field);
  764. sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
  765. this.detailData = details;
  766. if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
  767. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
  768. }
  769. },
  770. clearSheetData: function () {
  771. if($('#linkGLJ').hasClass('active')){
  772. sheetCommonObj.showData(this.sheet, this.setting, []);
  773. }
  774. if($('#linkAZZJF').hasClass('active')){
  775. installationFeeObj.rationInstallSheet.setRowCount(0);//清除combobox cell
  776. sheetCommonObj.showData(installationFeeObj.rationInstallSheet, installationFeeObj.rationInstallSetting, []);
  777. }
  778. // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
  779. this.sheetData = [];
  780. installationFeeObj.rationInstallData = [];
  781. //this.detailData=[];
  782. },
  783. updateRationGLJ: function (args) {
  784. var me = this;
  785. var updateField = me.setting.header[args.col].dataCode;
  786. var recode = me.sheetData[args.row];
  787. var newval;
  788. if(!me.rationGLJEditCheck(args)){
  789. recode? me.sheet.getCell(args.row, args.col).value(recode[updateField]): me.sheet.getCell(args.row, args.col).value(null);
  790. return;
  791. }
  792. if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
  793. if (args.editingText == null) {
  794. updateField == 'marketPrice' ? newval = 0 : newval = "";
  795. } else {
  796. var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : 6;//对于市场价和定额价,这里只是中间的小数位数,后面更新前会根据有没有组成物再取值
  797. newval = number_util.checkNumberValue(args.editingText, decimal);
  798. if (newval == null) {
  799. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  800. return;
  801. }
  802. }
  803. } else {
  804. if (updateField == 'name' || updateField == 'unit') {
  805. if (args.editingText === null) {
  806. alert(me.setting.header[args.col].headerName + '不能为空!');
  807. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  808. return;
  809. }
  810. }
  811. if(updateField == 'code'){
  812. if (!gljUtil.isDef(args.editingText)||args.editingText==''||args.editingText.indexOf('|-|') === -1||this.isRationGLJExit(args.editingText)) {//说明是选中自已,或者是已存在的工料机
  813. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  814. return;
  815. }
  816. }
  817. newval = args.editingText == null ? "" : args.editingText;
  818. }
  819. if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
  820. return
  821. }
  822. if (updateField == 'marketPrice' || updateField == 'basePrice') {
  823. projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
  824. }else if(updateField == 'code'){//替换单价文件中已经有的工料机
  825. projectObj.project.ration_glj.updateRationGLJByChangeCode(recode, updateField, newval);
  826. } else {
  827. projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
  828. }
  829. },
  830. isRationGLJExit:function (connectKey) {
  831. for(let rg of gljOprObj.sheetData){
  832. if(rg.isMixRatio == true){
  833. continue;
  834. }
  835. if(gljOprObj.getIndex(rg, gljKeyArray) == connectKey){//存在一样的工料机
  836. return true;
  837. }
  838. }
  839. return false;
  840. },
  841. updateRationTypeGLJ: function (value, node, fieldName,editingText) {
  842. let newval;
  843. let updatePrice = false;
  844. if (fieldName == "marketUnitFee") {
  845. updatePrice = true;
  846. if (value == null) {
  847. newval = 0;
  848. } else {
  849. var decimal = getDecimal("glj.unitPrice");
  850. newval = number_util.checkNumberValue(value, decimal);
  851. }
  852. } else {
  853. if (value != null) {
  854. projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value,editingText);
  855. return;
  856. //update
  857. }
  858. }
  859. if (newval && updatePrice == true) {
  860. projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
  861. return
  862. }
  863. projectObj.mainController.refreshTreeNode([node]);
  864. },
  865. updateIsEstimate:function (args, newval) {
  866. var me = gljOprObj;
  867. if(me.setting.header[args.col].dataCode=="isEstimate"){
  868. var pspread= new ProjectGLJSpread();
  869. var recode = me.sheetData[args.row];
  870. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  871. let glj = _.find(projectGljs, {'id': recode.projectGLJID});
  872. if(glj){
  873. glj["is_evaluate"]=newval;
  874. args.fromRG=true;
  875. pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
  876. }
  877. }
  878. },
  879. showLibGLJSheetData: function () {
  880. this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
  881. sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
  882. this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
  883. },
  884. filterLibGLJSheetData: function () {
  885. let me = this;
  886. let val = $("input[name='glj']:checked").val();
  887. if (val == 'allGljs') {
  888. me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
  889. } else {
  890. me.gljLibSheetData = me[val];
  891. }
  892. if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
  893. me.filterLibGLJByType();
  894. }else if($('#actionType').val() == 'addMix'){
  895. projectGljObject.filterLibGLJForMixRatio();
  896. }
  897. //文本筛选
  898. let searchStr = $('#gljSearchKeyword').val();
  899. if(searchStr && searchStr.trim() != ''){
  900. let reg = new RegExp(searchStr);
  901. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  902. return reg.test(data.code) || reg.test(data.name);
  903. });
  904. }
  905. if (me.gljCurTypeId == undefined) {
  906. return;
  907. }
  908. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  909. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  910. return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
  911. });
  912. } else {
  913. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
  914. }
  915. },
  916. setGLJSelection: function (args, newVal) {
  917. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert'|| $('#actionType').val() == 'addMix') {
  918. this.addGLJsSelection(args, newVal);
  919. } else {
  920. this.replaceGLJSelection(args, newVal);
  921. }
  922. },
  923. addGLJsSelection: function (args, newVal) {
  924. var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
  925. if (newVal == 1) {
  926. this.GLJSelection.push(con_key);
  927. this.gljLibSheetData[args.row].select = 1;
  928. } else if (newVal == 0) {
  929. _.pull(this.GLJSelection, con_key);
  930. this.gljLibSheetData[args.row].select = 0;
  931. }
  932. },
  933. replaceGLJSelection: function (args, newVal) {
  934. var me = this;
  935. var oldSelection = this.GLJSelection[0];
  936. if (newVal == 0) {
  937. args.sheet.getCell(args.row, args.col).value(1);
  938. return;
  939. }
  940. this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
  941. this.gljLibSheetData[args.row].select = 1;
  942. var oindex = _.findIndex(this.gljLibSheetData, function (item) {
  943. var i_key = me.getIndex(item, gljLibKeyArray);
  944. return oldSelection == i_key;
  945. });
  946. if (oindex != -1) {
  947. args.sheet.getCell(oindex, args.col).value(0);
  948. this.gljLibSheetData[oindex].select = 0;
  949. } else {
  950. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  951. var i_key = me.getIndex(item, gljLibKeyArray);
  952. return oldSelection == i_key;
  953. });
  954. oldData ? oldData.select = 0 : "";
  955. }
  956. },
  957. filterLibGLJByType: function () {
  958. var me = this;
  959. var selected = me.sheetData[gljContextMenu.selectedRow];
  960. //当前人材机类型是“混凝土、砂浆、配合比、商品混凝土、商品砂浆”时,筛选的可替换的人材机类型应是“混凝土、或砂浆、或配合比、或商品混凝土、或商品砂浆”。
  961. let materialTypes = [202, 203, 204, 205, 206];//除了普通材料
  962. let filterTypes = materialTypes.includes(selected.type) ? materialTypes : [selected.type];
  963. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  964. return filterTypes.includes(data.gljType);
  965. });
  966. //me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljType': selected.type});
  967. },
  968. getComboData: function (gljDistType) {
  969. let me = this;
  970. let distType;
  971. let distTypeTree = {
  972. prefix: 'gljType',
  973. distTypes: {},
  974. comboDatas: [],
  975. distTypesArr: []
  976. };
  977. gljDistType.forEach(function (typeData) {
  978. let typeObj = {
  979. data: typeData,
  980. children: [],
  981. parent: null
  982. }
  983. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  984. distTypeTree.distTypesArr.push(typeObj);
  985. });
  986. gljDistType.forEach(function (typeData) {
  987. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  988. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  989. if (parent) {
  990. distType.parent = parent;
  991. parent.children.push(distType);
  992. }
  993. });
  994. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  995. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  996. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  997. }
  998. });
  999. return distTypeTree;
  1000. },
  1001. doInsertGLJ: function () {
  1002. var me = this;
  1003. var selected = projectObj.project.mainTree.selected;
  1004. var project = projectObj.project;
  1005. if (me.GLJSelection.length <= 0) {
  1006. return;
  1007. }
  1008. $("#glj_tree_div").modal('hide');
  1009. $.bootstrapLoading.start();
  1010. project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (parentNodeID,nextNodeID,data) {
  1011. let newNode=null;
  1012. for (let r_glj of data) {
  1013. r_glj.quantity = r_glj.quantity + "";
  1014. project.Ration.datas.push(r_glj);
  1015. }//要先更新树节点工程量,加载项目工料机并计算消耗量才有值
  1016. project.projectGLJ.loadData(function () {
  1017. for(let r_glj of data){
  1018. r_glj = me.setGLJPrice(r_glj);//设置工料机价格
  1019. newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
  1020. newNode.source = r_glj;
  1021. newNode.sourceType = project.Ration.getSourceType();
  1022. newNode.data = r_glj;
  1023. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  1024. }
  1025. project.calcProgram.calcLeafAndSave(newNode.parent);//计算父级清单的所有子节点
  1026. projectObj.mainController.refreshTreeNode([newNode]);
  1027. if(me.hasComposition(newNode.data,true)){
  1028. me.showMixRatio(newNode);
  1029. }else {
  1030. me.showRationGLJSheetData();
  1031. }
  1032. $.bootstrapLoading.end();
  1033. });
  1034. })
  1035. },
  1036. doAddGLJ: function () {
  1037. var selected = projectObj.project.mainTree.selected;
  1038. var project = projectObj.project;
  1039. gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
  1040. var rg = _.find(gljOprObj.sheetData, function (item) {
  1041. if(item.isMixRatio == true){
  1042. return false;
  1043. }
  1044. var i_key = gljOprObj.getIndex(item, gljKeyArray);
  1045. return n == i_key
  1046. });
  1047. return rg ? false : true;
  1048. })
  1049. if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
  1050. $("#glj_tree_div").modal('hide');
  1051. project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
  1052. if (result) {
  1053. selected.data.adjustState = result.adjustState;
  1054. //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
  1055. project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
  1056. gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
  1057. project.projectGLJ.loadData(function () {
  1058. project.ration_glj.addToMainTree(result.showData);
  1059. gljOprObj.showRationGLJSheetData();
  1060. project.calcProgram.calcAndSave(selected);
  1061. projectObj.mainController.refreshTreeNode([selected]);
  1062. $.bootstrapLoading.end();
  1063. });
  1064. }
  1065. });//doc.rationID=selected.data.ID;
  1066. } else {
  1067. $("#glj_tree_div").modal('hide');
  1068. }
  1069. },
  1070. doReplaceGLJ: function () {
  1071. var me = this;
  1072. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1073. var project = projectObj.project;
  1074. var selectCode = gljOprObj.GLJSelection[0];
  1075. var selected = projectObj.project.mainTree.selected;
  1076. $("#glj_tree_div").modal('hide');
  1077. project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
  1078. if (result) {
  1079. //result.adjustState;
  1080. var glj_list = projectObj.project.ration_glj.datas;
  1081. var data = result.data;
  1082. var index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
  1083. var list_index = _.findIndex(glj_list, {'ID': data.ID});
  1084. var nodes = [selected];
  1085. gljOprObj.sheetData[index] = data;
  1086. glj_list[list_index] = data;
  1087. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  1088. gljOprObj.showRationGLJSheetData();
  1089. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  1090. var node = project.ration_glj.findGLJNodeByID(data.ID);
  1091. if (node) {
  1092. project.ration_glj.transferToNodeData(data);
  1093. node.source = data;
  1094. node.data = data;
  1095. }
  1096. node ? nodes.push(node) : "";
  1097. }
  1098. //project.ration_glj.addToMainTree(data);
  1099. selected.data.adjustState = result.adjustState;
  1100. selected.data.name = result.name;
  1101. projectObj.mainController.refreshTreeNode(nodes);
  1102. project.calcProgram.calcAndSave(selected);
  1103. $.bootstrapLoading.end();
  1104. });
  1105. }
  1106. })
  1107. },
  1108. doMReplaceGLJ: function () {
  1109. let me = this;
  1110. let oldData = me.sheetData[gljContextMenu.selectedRow];
  1111. let project = projectObj.project;
  1112. let selectCode = me.GLJSelection[0];
  1113. $("#glj_tree_div").modal('hide');
  1114. project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result,updateMap) {
  1115. if(result == null){
  1116. return;
  1117. }
  1118. let data = result.data;
  1119. let stateList = result.stateList;
  1120. //let n_index = me.getIndex(data.query, gljKeyArray);
  1121. let nodes = [];
  1122. _.forEach(project.ration_glj.datas, function (t) {
  1123. // let t_index = me.getIndex(t, gljKeyArray);
  1124. if (updateMap[t.ID]) {
  1125. me.updateProperty(t, data.doc);
  1126. me.updateProperty(t, updateMap[t.ID]);
  1127. if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
  1128. project.ration_glj.transferToNodeData(t);
  1129. var node = project.ration_glj.findGLJNodeByID(t.ID);
  1130. node ? nodes.push(node):'';
  1131. }
  1132. }
  1133. })
  1134. project.projectGLJ.loadData(function () {
  1135. me.showRationGLJSheetData();
  1136. var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
  1137. project.calcProgram.calcNodesAndSave(rationNodes);
  1138. $.bootstrapLoading.end();
  1139. });
  1140. })
  1141. },
  1142. updateProperty: function (obj, doc) {
  1143. _.forEach(doc, function (n, key) {
  1144. obj[key] = n;
  1145. });
  1146. },
  1147. refreshStateAfterMreplace: function (stateList, gljNodes) {
  1148. var nodes = [];
  1149. var rationNodes = [];
  1150. _.forEach(stateList, function (s) {
  1151. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1152. return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
  1153. })
  1154. if (node) {
  1155. node.data.adjustState = s.adjustState;
  1156. node.data.name = s.name;
  1157. nodes.push(node);
  1158. rationNodes.push(node);
  1159. }
  1160. });
  1161. gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
  1162. projectObj.mainController.refreshTreeNode(nodes);
  1163. return rationNodes;
  1164. },
  1165. refreshView: function () {
  1166. let node = projectObj.project.mainTree.selected;
  1167. this.showDataIfRationSelect(node,"111111");
  1168. //this.showRationGLJData();
  1169. },
  1170. //
  1171. refreshTreeNode: function (obj) {
  1172. if (!obj) {
  1173. return;
  1174. }
  1175. var objectArray = [];
  1176. var nodes = [];
  1177. if (obj instanceof Array) {
  1178. objectArray.concat(obj);
  1179. } else {
  1180. objectArray.push(obj);
  1181. }
  1182. for (let o of objectArray) {
  1183. let node = this.updateDataNodeProperty(o.ID,o.data);
  1184. if (node) {
  1185. nodes.push(node);
  1186. }
  1187. }
  1188. projectObj.mainController.refreshTreeNode(nodes);
  1189. return nodes;
  1190. },
  1191. updateDataNodeProperty:function(nodeID,data){
  1192. let node = projectObj.project.mainTree.findNode(nodeID);
  1193. if (node) {
  1194. for (let k in data) {
  1195. node.data[k] = data[k];
  1196. }
  1197. }
  1198. return node;
  1199. },
  1200. getTreeNodeCellType: function (data,comboboxOptions) {
  1201. var ns = GC.Spread.Sheets;
  1202. var rectW = 10;
  1203. var rectH = 10;
  1204. var margin = 3;
  1205. function TreeNodeCellType() {
  1206. }
  1207. function drowRect(ctx, x, y, w, h) {
  1208. ctx.save();
  1209. ctx.strokeStyle = "gray";
  1210. ctx.translate(0.5, 0.5);
  1211. ctx.beginPath();
  1212. var rectX = x + margin;
  1213. var rectY = y + Math.round(h / 2) - rectH / 2;
  1214. ctx.moveTo(rectX, rectY);
  1215. ctx.lineTo(rectX, rectY + rectH);
  1216. ctx.lineTo(rectX + rectW, rectY + rectH);
  1217. ctx.lineTo(rectX + rectW, rectY);
  1218. ctx.lineTo(rectX, rectY);
  1219. ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
  1220. ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
  1221. ctx.stroke();
  1222. ctx.restore();
  1223. }
  1224. function drowSymbol(ctx, x, y, w, h, collapsed) {
  1225. ctx.save();
  1226. ctx.strokeStyle = "#000000";
  1227. ctx.translate(0.5, 0.5);
  1228. ctx.beginPath();
  1229. ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
  1230. ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
  1231. var rectY = y + Math.round(h / 2) - rectH / 2;
  1232. if (collapsed) {
  1233. ctx.moveTo(x + margin + rectW / 2, rectY + 2);
  1234. ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
  1235. }
  1236. ctx.stroke();
  1237. ctx.restore();
  1238. }
  1239. function drowSubItem(ctx, x, y, w, h, offset, nextItem) {
  1240. offset += 6;
  1241. ctx.save();
  1242. ctx.strokeStyle = "gray";
  1243. ctx.translate(0.5, 0.5);
  1244. ctx.beginPath();
  1245. ctx.moveTo(x + offset, y);
  1246. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1247. offset += 9;
  1248. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1249. if (nextItem && nextItem.isMixRatio) {
  1250. ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
  1251. ctx.lineTo(x + offset - 9, y + h);
  1252. }
  1253. ctx.stroke();
  1254. ctx.restore();
  1255. return offset;
  1256. }
  1257. TreeNodeCellType.prototype = comboboxOptions?sheetCommonObj.getDynamicCombo():new ns.CellTypes.Text();
  1258. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  1259. if (style.backColor) {//先画背景色
  1260. ctx.save();
  1261. ctx.fillStyle = style.backColor;
  1262. ctx.fillRect(x, y, w, h);
  1263. ctx.restore();
  1264. } else {
  1265. ctx.clearRect(x, y, w, h);
  1266. }
  1267. if (value != null) {
  1268. var offset = margin + rectW + 6;
  1269. var recode = data[options.row];
  1270. if (recode && recode.hasOwnProperty('subList')) {
  1271. drowRect(ctx, x, y, w, h);
  1272. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
  1273. drowSymbol(ctx, x, y, w, h, collapsed);
  1274. } else if (recode && recode.isMixRatio) {
  1275. offset = drowSubItem(ctx, x, y, w, h, offset, data[options.row + 1]);
  1276. offset += 1;
  1277. }
  1278. arguments[2] = x + offset;
  1279. arguments[4] = w - offset;
  1280. //x = x + offset;
  1281. //w = w - offset;
  1282. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1283. }
  1284. };
  1285. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1286. if(x < cellRect.x+cellRect.width -15){//这里要判断点击的位置来决定return的内容,不能直接用combobox的方法
  1287. return {
  1288. x: x,
  1289. y: y,
  1290. row: context.row,
  1291. col: context.col,
  1292. cellStyle: cellStyle,
  1293. cellRect: cellRect,
  1294. sheetArea: context.sheetArea
  1295. };
  1296. }else {
  1297. return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(this, arguments);
  1298. }
  1299. };
  1300. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1301. var recode = data[hitinfo.row];
  1302. if (recode && recode.hasOwnProperty('subList')) {
  1303. var hoffset = hitinfo.cellRect.x + 3;
  1304. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1305. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;
  1306. collapsed = !collapsed
  1307. recode.collapsed = collapsed;
  1308. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1309. hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
  1310. hitinfo.sheet.invalidateLayout();
  1311. hitinfo.sheet.repaint();
  1312. return;
  1313. }
  1314. }
  1315. GC.Spread.Sheets.CellTypes.ComboBox.prototype.processMouseDown.apply(this, arguments);
  1316. // GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1317. };
  1318. let cellType = new TreeNodeCellType();
  1319. if(comboboxOptions){
  1320. cellType.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  1321. cellType.itemHeight(comboboxOptions.length).items(comboboxOptions);
  1322. }
  1323. return cellType;
  1324. },
  1325. marketPriceReadOnly: function (node) {
  1326. let hasCom = false;
  1327. if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
  1328. hasCom = this.hasComposition(node.data,true);
  1329. }else {
  1330. hasCom = this.hasComposition(node.data);
  1331. }
  1332. return hasCom|| node.data.isEstimate == 1;
  1333. },
  1334. locateZTree: function(ID) {
  1335. let zTree = $.fn.zTree.getZTreeObj("gljTree");
  1336. let node = null;
  1337. if (ID) node = zTree.getNodesByParam('ID', ID, null)[0]
  1338. if (!node) node = zTree.getNodeByTId('gljTree_1');
  1339. zTree.selectNode(node);
  1340. gljOprObj.gljCurTypeId = ID;
  1341. gljOprObj.filterLibGLJSheetData();
  1342. gljOprObj.showLibGLJSheetData();
  1343. }
  1344. }
  1345. $(function () {
  1346. $('#glj_tree_div').on('shown.bs.modal', function (e) {
  1347. if (gljOprObj.gljLibSpresd == undefined) {
  1348. gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
  1349. sheetCommonObj.spreadDefaultStyle(gljOprObj.gljLibSpresd);
  1350. gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
  1351. gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
  1352. gljOprObj.gljLibSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, gljOprObj.onSelectionChanged);
  1353. gljOprObj.gljLibSheet.setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  1354. gljOprObj.gljLibSheet.options.isProtected = true;
  1355. gljOprObj.gljLibSheet.name('glj_lib');
  1356. }
  1357. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1358. let gljClass = 0, selectMap = {};
  1359. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {//插入,添加
  1360. gljOprObj.GLJSelection = [];
  1361. } else if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){//替换、批量替换
  1362. let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1363. var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
  1364. gljOprObj.GLJSelection = [connect_key];
  1365. selectMap[connect_key] = true;
  1366. gljOprObj.filterLibGLJByType();
  1367. }else if($('#actionType').val() =='addMix'){//添加组成物
  1368. gljOprObj.GLJSelection = [];
  1369. projectGljObject.filterLibGLJForMixRatio();
  1370. /*selections = projectGljObject.mixRatioData; 添加组成物的时候先不选中
  1371. gljOprObj.GLJSelection = [];
  1372. for(let s of selections){
  1373. let s_key = gljOprObj.getIndex(s, gljKeyArray);
  1374. selectMap[s_key] = true;
  1375. gljOprObj.GLJSelection.push(s_key);
  1376. }*/
  1377. }
  1378. for(let item of gljOprObj.gljLibSheetData){
  1379. let item_key = gljOprObj.getIndex(item, gljLibKeyArray);
  1380. if(selectMap[item_key]){
  1381. item.select = 1 ;
  1382. gljClass = item.gljClass;
  1383. }
  1384. }
  1385. //替换,焦点定位至当前选中人材机
  1386. if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){
  1387. gljOprObj.locateZTree(gljClass);
  1388. let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1389. let index = _.findIndex(gljOprObj.gljLibSheetData, {code: selected.code});
  1390. gljOprObj.gljLibSheet.showRow(index, GC.Spread.Sheets.VerticalPosition.center);
  1391. gljOprObj.gljLibSheet.setActiveCell(index, 0);
  1392. gljOprObj.initSelection({row: index});
  1393. gljOprObj.gljLibSpresd.focus(true);
  1394. }
  1395. else gljOprObj.showLibGLJSheetData();
  1396. });
  1397. $('#glj_tree_div').on('hidden.bs.modal', function () {
  1398. $('#gljSearchKeyword').val('');
  1399. });
  1400. $('.glj-radio').change(function () {
  1401. let val = $("input[name='glj']:checked").val();
  1402. if (val == 'allGljs') {
  1403. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1404. gljOprObj.filterLibGLJSheetData();
  1405. gljOprObj.showLibGLJSheetData();
  1406. } else {
  1407. gljOprObj.gljLibSheetData = gljOprObj[val];
  1408. gljOprObj.filterLibGLJSheetData();
  1409. gljOprObj.showLibGLJSheetData();
  1410. }
  1411. })
  1412. /* //工料机搜索
  1413. $('#gljSearchKeyword').change(function () {
  1414. gljOprObj.filterLibGLJSheetData();
  1415. gljOprObj.showLibGLJSheetData();
  1416. });
  1417. $('#gljSearchKeyword').bind('keypress', function (e) {
  1418. if(e.keyCode === 13){
  1419. alert('2');
  1420. $(this).blur();
  1421. return false;
  1422. }
  1423. });*/
  1424. $('#gljSearchKeyword').bind('keyup', function (e) {
  1425. gljOprObj.filterLibGLJSheetData();
  1426. gljOprObj.showLibGLJSheetData();
  1427. });
  1428. $('#glj_selected_conf').click(function () {
  1429. if (gljOprObj.GLJSelection.length < 1) {
  1430. return;
  1431. }
  1432. if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
  1433. gljOprObj.doInsertGLJ();
  1434. } else if ($('#actionType').val() == 'add') { //添加工料机
  1435. gljOprObj.doAddGLJ();
  1436. } else if ($('#actionType').val() == 'replace') {//替换工料机
  1437. gljOprObj.doReplaceGLJ();
  1438. } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
  1439. gljOprObj.doMReplaceGLJ();
  1440. }else if($('#actionType').val() == 'addMix'){
  1441. projectGljObject.addMixRatio();
  1442. }
  1443. })
  1444. $('#class_selected_conf').click(function () {
  1445. var gljClass = $('#selected_class').val();
  1446. var glj = gljOprObj.selectedGLJClass;
  1447. if (glj && gljClass && gljClass != "") {
  1448. //保存到我的工料机库
  1449. /*1 检查是否有组成物
  1450. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  1451. * 3 保存
  1452. * */
  1453. var newItem = {
  1454. code: glj.code,
  1455. name: glj.name,
  1456. specs: glj.specs,
  1457. unit: glj.unit,
  1458. basePrice: glj.basePrice,
  1459. gljType: glj.type,
  1460. shortName: glj.shortName,
  1461. component: [],
  1462. gljClass: gljClass
  1463. };
  1464. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  1465. for (var i = 0; i < glj.subList.length; i++) {
  1466. let tem = {
  1467. ID: glj.subList[i].GLJID,
  1468. consumeAmt: glj.rationItemQuantity,
  1469. isStd: true
  1470. }
  1471. newItem.component.push(tem);
  1472. }
  1473. }
  1474. var data = getcmpUpdateData([newItem]);
  1475. $.bootstrapLoading.start();
  1476. var callback = function (data) {
  1477. $("#glj_class_div").modal('hide');
  1478. $.bootstrapLoading.end();
  1479. }
  1480. CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
  1481. $.bootstrapLoading.end();
  1482. });
  1483. }
  1484. })
  1485. $('#glj_class_div').on('hidden.bs.modal', function (e) {
  1486. gljOprObj.selectedGLJClass = null;
  1487. $('#class_selected_conf').attr("disabled", "disabled");
  1488. $('#selected_class').val("");
  1489. })
  1490. function getcmpUpdateData(items) {
  1491. var data = {
  1492. "updateItems": [],
  1493. "removeIds": []
  1494. }
  1495. data.addItems = items;
  1496. return data;
  1497. }
  1498. })
  1499. function operationWithRound(value1,value2,field,symble) {
  1500. let decimal = getDecimal(field);
  1501. value1 = scMathUtil.roundForObj(value1,decimal);
  1502. value2 = scMathUtil.roundForObj(value2,decimal);
  1503. let result;
  1504. switch (symble){
  1505. case "+" :
  1506. result=scMathUtil.roundForObj(value1 + value2,decimal);
  1507. break;
  1508. case "-":
  1509. result=scMathUtil.roundForObj(value1 - value2,decimal);
  1510. break;
  1511. case "*":
  1512. result=scMathUtil.roundForObj(value1 * value2,decimal);
  1513. break;
  1514. case "/":
  1515. result=scMathUtil.roundForObj(value1 / value2,decimal);
  1516. break
  1517. }
  1518. return result;
  1519. }
  1520. function getDecimal(fieldID, node) {
  1521. if (node) {
  1522. return decimalObj.decimal(fieldID, node);
  1523. } else if (fieldID.indexOf(".") != -1) {
  1524. var keyArray = fieldID.split(".");
  1525. return decimalObj[keyArray[0]][keyArray[1]];
  1526. } else {
  1527. return decimalObj.decimal(fieldID);
  1528. }
  1529. }
  1530. function sortRationGLJ(list) {
  1531. list = _.sortByAll(list, [function (item) {
  1532. return item.type + "";
  1533. }, "code"])
  1534. return list;
  1535. }
  1536. function compareRationGLJ(a, b) {
  1537. if ((a.type + "") < (b.type + "")) {
  1538. return true
  1539. }
  1540. if ((a.type + "") == (b.type + "")) {
  1541. if (a.code < b.code) {
  1542. return true
  1543. }
  1544. }
  1545. return false;
  1546. }