glj_view.js 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572
  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. if(code){
  548. let preCode = code.split("-")[0];
  549. if(codeMap[preCode]) {
  550. codeMap[preCode].push({text:code,value:connectKey});
  551. }else {
  552. codeMap[preCode]=[{text:code ,value:connectKey}];
  553. }
  554. }
  555. }
  556. }
  557. return codeMap;
  558. },
  559. initRationTree: function (init,codeMap) {
  560. this.sheet.suspendPaint();
  561. this.sheet.suspendEvent();
  562. this.sheet.setRowCount(this.sheetData.length >30?this.sheetData.length:30);
  563. for (var i = 0; i < this.sheetData.length; i++) {
  564. this.sheet.setCellType(i, 0,this.getTreeNodeCellType(this.sheetData,i,codeMap),GC.Spread.Sheets.SheetArea.viewport);
  565. if (this.sheetData[i].hasOwnProperty('subList')) {
  566. var collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
  567. if (collapsed == true) {
  568. this.sheet.getRange(i + 1, -1, this.sheetData[i].subList.length, -1).visible(false);
  569. }
  570. }
  571. }
  572. this.sheet.resumeEvent();
  573. this.sheet.resumePaint();
  574. },
  575. filterGljByRation: function (ration, datas) {
  576. var gljList = [];
  577. if (datas && datas.length > 0) {
  578. gljList = _.filter(datas, {'rationID': ration.ID})
  579. }
  580. return gljList;
  581. },
  582. showInSheet: function (gljList) {
  583. this.sheetData = gljList;
  584. this.showRationGLJSheetData(true);
  585. },
  586. sumQuantity: function (node) {
  587. if (this.sheetData.length > 0) {
  588. node = node ? node : projectObj.project.mainTree.selected;
  589. let ration = node.data;
  590. let quantity = ration.quantity;
  591. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  592. for (let glj of this.sheetData) {
  593. glj.totalQuantity= this.getTotalQuantity(glj,ration);
  594. }
  595. }
  596. },
  597. getTotalQuantity:function(glj,ration){
  598. ration=ration?ration: _.find(projectObj.project.Ration.datas,{"ID":glj.rationID});
  599. if(ration){
  600. let quantity = ration.quantity;
  601. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  602. if (glj.isMixRatio == true) {//如果是用于显示的组成物,则不用计算,跳过
  603. return;
  604. }
  605. quantity = scMathUtil.roundForObj(quantity, getDecimal("ration.quantity"));//计算前进行4舍5入
  606. glj.quantity = scMathUtil.roundForObj(glj.quantity, getDecimal("glj.quantity"));
  607. glj.totalQuantity = scMathUtil.roundToString(quantity * glj.quantity, getDecimal("glj.quantity"));
  608. if (glj.hasOwnProperty('subList')) {//需要计算glj下挂的组成物的总消耗量
  609. this.calcMixRationTotalQuantity(glj.subList,glj.totalQuantity);
  610. }
  611. return glj.totalQuantity;
  612. }
  613. },
  614. calcMixRationTotalQuantity(mList,pTotal){ //计算组成物的总消耗量
  615. for (let subG of mList) {
  616. subG.rationItemQuantity = scMathUtil.roundForObj(subG.rationItemQuantity, getDecimal("glj.quantity"));
  617. subG.totalQuantity = scMathUtil.roundToString(subG.rationItemQuantity * pTotal, getDecimal("glj.quantity"));
  618. }
  619. },
  620. addMixRatioToShow: function () {
  621. var newList = [];
  622. _.remove(this.sheetData, {'isMixRatio': true});
  623. for (var i = 0; i < this.sheetData.length; i++) {
  624. newList.push(this.sheetData[i]);
  625. if (this.sheetData[i].hasOwnProperty('subList')) {
  626. newList = newList.concat(this.sheetData[i].subList);
  627. }
  628. }
  629. this.sheetData = newList;
  630. },
  631. combineWithProjectGlj: function (ration_gljs,needRatio=true) {
  632. var projectGLJData = projectObj.project.projectGLJ.datas;
  633. var projectGljs = projectGLJData.gljList;
  634. var mixRatioMap = projectGLJData.mixRatioMap;
  635. if (ration_gljs && ration_gljs.length > 0 && projectGljs && projectGljs.length > 0) {
  636. for (var i = 0; i < ration_gljs.length; i++) {
  637. var glj = _.find(projectGljs, {'id': ration_gljs[i].projectGLJID});
  638. if (glj) {
  639. if(projectObj.project.projectGLJ.isEstimateType(ration_gljs[i].type )){
  640. ration_gljs[i].isEstimate = glj.is_evaluate;
  641. }
  642. ration_gljs[i].shortName =projectObj.project.projectGLJ.getShortNameByID(ration_gljs[i].type);
  643. ration_gljs[i].isAdd = glj.unit_price.is_add;
  644. ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
  645. var connect_index = this.getIndex(glj, gljKeyArray);
  646. if (needRatio==true&&mixRatioMap.hasOwnProperty(connect_index)) {
  647. var mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  648. ration_gljs[i].subList = mixRatios;
  649. }
  650. }
  651. }
  652. }
  653. return ration_gljs;
  654. },
  655. setGLJPrice:function (data,glj,isRadio = false) {//isRadio 标记是否算组成物的价格
  656. let proGLJ = projectObj.project.projectGLJ;
  657. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  658. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  659. let labourCoeDatas = projectObj.project.labourCoe.datas;
  660. glj = glj?glj:_.find(proGLJ.datas.gljList, {'id': data.projectGLJID});
  661. let result = gljUtil.getGLJPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  662. data.marketPrice = result.marketPrice;
  663. data.basePrice = result.basePrice;
  664. data.adjustPrice = result.adjustPrice;
  665. data.marketUnitFee = data.marketPrice;//更新树节点市场单价列的值
  666. return data;
  667. },
  668. getBasePrice:function (treeNode) {//造价书中的工料机修改的节点要用到
  669. let proGLJ = projectObj.project.projectGLJ;
  670. let glj =_.find(proGLJ.datas.gljList, {'id': treeNode.data.projectGLJID});
  671. if(this.calcPriceDiff(glj)==true){
  672. return proGLJ.getBasePrice(glj);
  673. }else {
  674. return scMathUtil.roundForObj(treeNode.data.marketUnitFee,getDecimal("glj.unitPrice"));
  675. }
  676. },
  677. calcPriceDiff:function (glj) {
  678. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  679. return gljUtil.calcPriceDiff(glj,calcOptions);
  680. },
  681. getIndex(obj, pops){
  682. let t_index = '';
  683. let k_arr = [];
  684. for (let p of pops) {
  685. let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
  686. k_arr.push(tmpK);
  687. }
  688. t_index = k_arr.join("|-|");
  689. return t_index;
  690. },
  691. getConditionByKey(conKey){//将连接字符串转换成对象
  692. let valueArray = conKey.split("|-|");
  693. let obj ={};
  694. for(let i = 0;i<valueArray.length;i++){
  695. if(valueArray[i]!='null'){
  696. if(gljKeyArray[i]=='type'){
  697. valueArray[i] = parseInt(valueArray[i]);
  698. }
  699. obj[gljKeyArray[i]]=valueArray[i];
  700. }
  701. }
  702. return obj;
  703. },
  704. getMixRationShowDatas: function (mixRatioList, projectGljs) {
  705. var temRationGLJs = [];
  706. for (var i = 0; i < mixRatioList.length; i++) {
  707. var pg = _.find(projectGljs, {
  708. 'code': mixRatioList[i].code,
  709. 'name': mixRatioList[i].name,
  710. 'specs': mixRatioList[i].specs,
  711. 'type': mixRatioList[i].type,
  712. 'unit': mixRatioList[i].unit
  713. });//改关联关系
  714. var tem = {
  715. projectGLJID: pg.id,
  716. code: pg.code,
  717. name: pg.name,
  718. specs: pg.specs,
  719. unit: pg.unit,
  720. type:mixRatioList[i].type,
  721. shortName: projectObj.project.projectGLJ.getShortNameByID(mixRatioList[i].type),
  722. consumption:mixRatioList[i].consumption,
  723. rationItemQuantity: mixRatioList[i].consumption,
  724. // quantity:mixRatioList[i].consumption,
  725. /* basePrice: pg.unit_price.base_price,
  726. marketPrice: pg.unit_price.market_price,
  727. adjustPrice: pg.adjust_price,*/
  728. //isEstimate: pg.is_evaluate,
  729. isMixRatio: true,
  730. isAdd: pg.unit_price.is_add,
  731. GLJID: pg.glj_id
  732. };
  733. if(projectObj.project.projectGLJ.isEstimateType(pg.type)){
  734. tem.isEstimate = pg.is_evaluate;
  735. }
  736. this.setGLJPrice(tem,pg);
  737. temRationGLJs.push(tem);
  738. }
  739. temRationGLJs = _.sortBy(temRationGLJs, 'code');
  740. return temRationGLJs;
  741. },
  742. showQuantityDetailData: function (node) {
  743. node = node ? node : projectObj.project.mainTree.selected;
  744. var quantity_detail = projectObj.project.quantity_detail;
  745. let field = node.sourceType == ModuleNames.ration?'rationID':'billID';
  746. let details = quantity_detail.getListByID(node.data.ID,field);
  747. sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
  748. this.detailData = details;
  749. if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
  750. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
  751. }
  752. },
  753. clearSheetData: function () {
  754. if($('#linkGLJ').hasClass('active')){
  755. sheetCommonObj.showData(this.sheet, this.setting, []);
  756. }
  757. if($('#linkAZZJF').hasClass('active')){
  758. installationFeeObj.rationInstallSheet.setRowCount(0);//清除combobox cell
  759. sheetCommonObj.showData(installationFeeObj.rationInstallSheet, installationFeeObj.rationInstallSetting, []);
  760. }
  761. // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
  762. this.sheetData = [];
  763. installationFeeObj.rationInstallData = [];
  764. //this.detailData=[];
  765. },
  766. updateRationGLJ: function (args) {
  767. var me = this;
  768. var updateField = me.setting.header[args.col].dataCode;
  769. var recode = me.sheetData[args.row];
  770. var newval;
  771. if(!me.rationGLJEditCheck(args)){
  772. recode? me.sheet.getCell(args.row, args.col).value(recode[updateField]): me.sheet.getCell(args.row, args.col).value(null);
  773. return;
  774. }
  775. if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
  776. if (args.editingText == null) {
  777. updateField == 'marketPrice' ? newval = 0 : newval = "";
  778. } else {
  779. var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : 6;//对于市场价和定额价,这里只是中间的小数位数,后面更新前会根据有没有组成物再取值
  780. newval = number_util.checkNumberValue(args.editingText, decimal);
  781. if (newval == null) {
  782. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  783. return;
  784. }
  785. }
  786. } else {
  787. if (updateField == 'name' || updateField == 'unit') {
  788. if (args.editingText === null) {
  789. alert(me.setting.header[args.col].headerName + '不能为空!');
  790. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  791. return;
  792. }
  793. }
  794. if(updateField == 'code'){
  795. if (!gljUtil.isDef(args.editingText)||args.editingText==''||args.editingText.indexOf('|-|') === -1||this.isRationGLJExit(args.editingText)) {//说明是选中自已,或者是已存在的工料机
  796. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  797. return;
  798. }
  799. }
  800. newval = args.editingText == null ? "" : args.editingText;
  801. }
  802. if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
  803. return
  804. }
  805. if (updateField == 'marketPrice' || updateField == 'basePrice') {
  806. projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
  807. }else if(updateField == 'code'){//替换单价文件中已经有的工料机
  808. projectObj.project.ration_glj.updateRationGLJByChangeCode(recode, updateField, newval);
  809. } else {
  810. projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
  811. }
  812. },
  813. isRationGLJExit:function (connectKey) {
  814. for(let rg of gljOprObj.sheetData){
  815. if(rg.isMixRatio == true){
  816. continue;
  817. }
  818. if(gljOprObj.getIndex(rg, gljKeyArray) == connectKey){//存在一样的工料机
  819. return true;
  820. }
  821. }
  822. return false;
  823. },
  824. updateRationTypeGLJ: function (value, node, fieldName,editingText) {
  825. let newval;
  826. let updatePrice = false;
  827. if (fieldName == "marketUnitFee") {
  828. updatePrice = true;
  829. if (value == null) {
  830. newval = 0;
  831. } else {
  832. var decimal = getDecimal("glj.unitPrice");
  833. newval = number_util.checkNumberValue(value, decimal);
  834. }
  835. } else {
  836. if (value != null) {
  837. projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value,editingText);
  838. return;
  839. //update
  840. }
  841. }
  842. if (newval && updatePrice == true) {
  843. projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
  844. return
  845. }
  846. projectObj.mainController.refreshTreeNode([node]);
  847. },
  848. updateIsEstimate:function (args, newval) {
  849. var me = gljOprObj;
  850. if(me.setting.header[args.col].dataCode=="isEstimate"){
  851. var pspread= new ProjectGLJSpread();
  852. var recode = me.sheetData[args.row];
  853. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  854. let glj = _.find(projectGljs, {'id': recode.projectGLJID});
  855. if(glj){
  856. glj["is_evaluate"]=newval;
  857. args.fromRG=true;
  858. pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
  859. }
  860. }
  861. },
  862. showLibGLJSheetData: function () {
  863. this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
  864. sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
  865. this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
  866. },
  867. filterLibGLJSheetData: function () {
  868. let me = this;
  869. let val = $("input[name='glj']:checked").val();
  870. if (val == 'allGljs') {
  871. me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
  872. } else {
  873. me.gljLibSheetData = me[val];
  874. }
  875. if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
  876. me.filterLibGLJByType();
  877. }else if($('#actionType').val() == 'addMix'){
  878. projectGljObject.filterLibGLJForMixRatio();
  879. }
  880. //文本筛选
  881. let searchStr = $('#gljSearchKeyword').val();
  882. if(searchStr && searchStr.trim() != ''){
  883. let reg = new RegExp(searchStr);
  884. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  885. return reg.test(data.code) || reg.test(data.name);
  886. });
  887. }
  888. if (me.gljCurTypeId == undefined) {
  889. return;
  890. }
  891. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  892. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  893. return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
  894. });
  895. } else {
  896. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
  897. }
  898. },
  899. setGLJSelection: function (args, newVal) {
  900. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert'|| $('#actionType').val() == 'addMix') {
  901. this.addGLJsSelection(args, newVal);
  902. } else {
  903. this.replaceGLJSelection(args, newVal);
  904. }
  905. },
  906. addGLJsSelection: function (args, newVal) {
  907. var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
  908. if (newVal == 1) {
  909. this.GLJSelection.push(con_key);
  910. this.gljLibSheetData[args.row].select = 1;
  911. } else if (newVal == 0) {
  912. _.pull(this.GLJSelection, con_key);
  913. this.gljLibSheetData[args.row].select = 0;
  914. }
  915. },
  916. replaceGLJSelection: function (args, newVal) {
  917. var me = this;
  918. var oldSelection = this.GLJSelection[0];
  919. if (newVal == 0) {
  920. args.sheet.getCell(args.row, args.col).value(1);
  921. return;
  922. }
  923. this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
  924. this.gljLibSheetData[args.row].select = 1;
  925. var oindex = _.findIndex(this.gljLibSheetData, function (item) {
  926. var i_key = me.getIndex(item, gljLibKeyArray);
  927. return oldSelection == i_key;
  928. });
  929. if (oindex != -1) {
  930. args.sheet.getCell(oindex, args.col).value(0);
  931. this.gljLibSheetData[oindex].select = 0;
  932. } else {
  933. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  934. var i_key = me.getIndex(item, gljLibKeyArray);
  935. return oldSelection == i_key;
  936. });
  937. oldData ? oldData.select = 0 : "";
  938. }
  939. },
  940. filterLibGLJByType: function () {
  941. var me = this;
  942. var selected = me.sheetData[gljContextMenu.selectedRow];
  943. //当前人材机类型是“混凝土、砂浆、配合比、商品混凝土、商品砂浆”时,筛选的可替换的人材机类型应是“混凝土、或砂浆、或配合比、或商品混凝土、或商品砂浆”。
  944. let materialTypes = [202, 203, 204, 205, 206];//除了普通材料
  945. let filterTypes = materialTypes.includes(selected.type) ? materialTypes : [selected.type];
  946. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  947. return filterTypes.includes(data.gljType);
  948. });
  949. //me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljType': selected.type});
  950. },
  951. getComboData: function (gljDistType) {
  952. let me = this;
  953. let distType;
  954. let distTypeTree = {
  955. prefix: 'gljType',
  956. distTypes: {},
  957. comboDatas: [],
  958. distTypesArr: []
  959. };
  960. gljDistType.forEach(function (typeData) {
  961. let typeObj = {
  962. data: typeData,
  963. children: [],
  964. parent: null
  965. }
  966. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  967. distTypeTree.distTypesArr.push(typeObj);
  968. });
  969. gljDistType.forEach(function (typeData) {
  970. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  971. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  972. if (parent) {
  973. distType.parent = parent;
  974. parent.children.push(distType);
  975. }
  976. });
  977. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  978. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  979. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  980. }
  981. });
  982. return distTypeTree;
  983. },
  984. doInsertGLJ: function () {
  985. var me = this;
  986. var selected = projectObj.project.mainTree.selected;
  987. var project = projectObj.project;
  988. if (me.GLJSelection.length <= 0) {
  989. return;
  990. }
  991. $("#glj_tree_div").modal('hide');
  992. $.bootstrapLoading.start();
  993. project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (parentNodeID,nextNodeID,data) {
  994. let newNode=null;
  995. for (let r_glj of data) {
  996. r_glj.quantity = r_glj.quantity + "";
  997. project.Ration.datas.push(r_glj);
  998. }//要先更新树节点工程量,加载项目工料机并计算消耗量才有值
  999. project.projectGLJ.loadData(function () {
  1000. for(let r_glj of data){
  1001. r_glj = me.setGLJPrice(r_glj);//设置工料机价格
  1002. newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
  1003. newNode.source = r_glj;
  1004. newNode.sourceType = project.Ration.getSourceType();
  1005. newNode.data = r_glj;
  1006. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  1007. }
  1008. project.calcProgram.calcLeafAndSave(newNode.parent);//计算父级清单的所有子节点
  1009. projectObj.mainController.refreshTreeNode([newNode]);
  1010. if(me.hasComposition(newNode.data,true)){
  1011. me.showMixRatio(newNode);
  1012. }else {
  1013. me.showRationGLJSheetData();
  1014. }
  1015. $.bootstrapLoading.end();
  1016. });
  1017. })
  1018. },
  1019. doAddGLJ: function () {
  1020. var selected = projectObj.project.mainTree.selected;
  1021. var project = projectObj.project;
  1022. gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
  1023. var rg = _.find(gljOprObj.sheetData, function (item) {
  1024. if(item.isMixRatio == true){
  1025. return false;
  1026. }
  1027. var i_key = gljOprObj.getIndex(item, gljKeyArray);
  1028. return n == i_key
  1029. });
  1030. return rg ? false : true;
  1031. })
  1032. if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
  1033. $("#glj_tree_div").modal('hide');
  1034. project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
  1035. if (result) {
  1036. selected.data.adjustState = result.adjustState;
  1037. //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
  1038. project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
  1039. gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
  1040. project.projectGLJ.loadData(function () {
  1041. project.ration_glj.addToMainTree(result.showData);
  1042. gljOprObj.showRationGLJSheetData();
  1043. project.calcProgram.calcAndSave(selected);
  1044. projectObj.mainController.refreshTreeNode([selected]);
  1045. $.bootstrapLoading.end();
  1046. });
  1047. }
  1048. });//doc.rationID=selected.data.ID;
  1049. } else {
  1050. $("#glj_tree_div").modal('hide');
  1051. }
  1052. },
  1053. doReplaceGLJ: function () {
  1054. var me = this;
  1055. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1056. var project = projectObj.project;
  1057. var selectCode = gljOprObj.GLJSelection[0];
  1058. var selected = projectObj.project.mainTree.selected;
  1059. $("#glj_tree_div").modal('hide');
  1060. project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
  1061. if (result) {
  1062. //result.adjustState;
  1063. var glj_list = projectObj.project.ration_glj.datas;
  1064. var data = result.data;
  1065. var index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
  1066. var list_index = _.findIndex(glj_list, {'ID': data.ID});
  1067. var nodes = [selected];
  1068. gljOprObj.sheetData[index] = data;
  1069. glj_list[list_index] = data;
  1070. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  1071. gljOprObj.showRationGLJSheetData();
  1072. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  1073. var node = project.ration_glj.findGLJNodeByID(data.ID);
  1074. if (node) {
  1075. project.ration_glj.transferToNodeData(data);
  1076. node.source = data;
  1077. node.data = data;
  1078. }
  1079. node ? nodes.push(node) : "";
  1080. }
  1081. //project.ration_glj.addToMainTree(data);
  1082. selected.data.adjustState = result.adjustState;
  1083. selected.data.name = result.name;
  1084. projectObj.mainController.refreshTreeNode(nodes);
  1085. project.calcProgram.calcAndSave(selected);
  1086. $.bootstrapLoading.end();
  1087. });
  1088. }
  1089. })
  1090. },
  1091. doMReplaceGLJ: function () {
  1092. let me = this;
  1093. let oldData = me.sheetData[gljContextMenu.selectedRow];
  1094. let project = projectObj.project;
  1095. let selectCode = me.GLJSelection[0];
  1096. $("#glj_tree_div").modal('hide');
  1097. project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result,updateMap) {
  1098. if(result == null){
  1099. return;
  1100. }
  1101. let data = result.data;
  1102. let stateList = result.stateList;
  1103. //let n_index = me.getIndex(data.query, gljKeyArray);
  1104. let nodes = [];
  1105. _.forEach(project.ration_glj.datas, function (t) {
  1106. // let t_index = me.getIndex(t, gljKeyArray);
  1107. if (updateMap[t.ID]) {
  1108. me.updateProperty(t, data.doc);
  1109. me.updateProperty(t, updateMap[t.ID]);
  1110. if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
  1111. project.ration_glj.transferToNodeData(t);
  1112. var node = project.ration_glj.findGLJNodeByID(t.ID);
  1113. node ? nodes.push(node):'';
  1114. }
  1115. }
  1116. })
  1117. project.projectGLJ.loadData(function () {
  1118. me.showRationGLJSheetData();
  1119. var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
  1120. project.calcProgram.calcNodesAndSave(rationNodes);
  1121. $.bootstrapLoading.end();
  1122. });
  1123. })
  1124. },
  1125. updateProperty: function (obj, doc) {
  1126. _.forEach(doc, function (n, key) {
  1127. obj[key] = n;
  1128. });
  1129. },
  1130. refreshStateAfterMreplace: function (stateList, gljNodes) {
  1131. var nodes = [];
  1132. var rationNodes = [];
  1133. _.forEach(stateList, function (s) {
  1134. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1135. return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
  1136. })
  1137. if (node) {
  1138. node.data.adjustState = s.adjustState;
  1139. node.data.name = s.name;
  1140. nodes.push(node);
  1141. rationNodes.push(node);
  1142. }
  1143. });
  1144. gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
  1145. projectObj.mainController.refreshTreeNode(nodes);
  1146. return rationNodes;
  1147. },
  1148. refreshView: function () {
  1149. let node = projectObj.project.mainTree.selected;
  1150. this.showDataIfRationSelect(node,"111111");
  1151. //this.showRationGLJData();
  1152. },
  1153. //
  1154. refreshTreeNode: function (obj) {
  1155. if (!obj) {
  1156. return;
  1157. }
  1158. var objectArray = [];
  1159. var nodes = [];
  1160. if (obj instanceof Array) {
  1161. objectArray.concat(obj);
  1162. } else {
  1163. objectArray.push(obj);
  1164. }
  1165. for (let o of objectArray) {
  1166. let node = this.updateDataNodeProperty(o.ID,o.data);
  1167. if (node) {
  1168. nodes.push(node);
  1169. }
  1170. }
  1171. projectObj.mainController.refreshTreeNode(nodes);
  1172. return nodes;
  1173. },
  1174. updateDataNodeProperty:function(nodeID,data){
  1175. let node = projectObj.project.mainTree.findNode(nodeID);
  1176. if (node) {
  1177. for (let k in data) {
  1178. node.data[k] = data[k];
  1179. }
  1180. }
  1181. return node;
  1182. },
  1183. getTreeNodeCellType: function (data,index,codeMap) {
  1184. var ns = GC.Spread.Sheets;
  1185. var rectW = 10;
  1186. var rectH = 10;
  1187. var margin = 3;
  1188. function TreeNodeCellType() {
  1189. }
  1190. function drowRect(ctx, x, y, w, h) {
  1191. ctx.save();
  1192. ctx.strokeStyle = "gray";
  1193. ctx.translate(0.5, 0.5);
  1194. ctx.beginPath();
  1195. var rectX = x + margin;
  1196. var rectY = y + Math.round(h / 2) - rectH / 2;
  1197. ctx.moveTo(rectX, rectY);
  1198. ctx.lineTo(rectX, rectY + rectH);
  1199. ctx.lineTo(rectX + rectW, rectY + rectH);
  1200. ctx.lineTo(rectX + rectW, rectY);
  1201. ctx.lineTo(rectX, rectY);
  1202. ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
  1203. ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
  1204. ctx.stroke();
  1205. ctx.restore();
  1206. }
  1207. function drowSymbol(ctx, x, y, w, h, collapsed) {
  1208. ctx.save();
  1209. ctx.strokeStyle = "#000000";
  1210. ctx.translate(0.5, 0.5);
  1211. ctx.beginPath();
  1212. ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
  1213. ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
  1214. var rectY = y + Math.round(h / 2) - rectH / 2;
  1215. if (collapsed) {
  1216. ctx.moveTo(x + margin + rectW / 2, rectY + 2);
  1217. ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
  1218. }
  1219. ctx.stroke();
  1220. ctx.restore();
  1221. }
  1222. function drowSubItem(ctx, x, y, w, h, offset, nextItem) {
  1223. offset += 6;
  1224. ctx.save();
  1225. ctx.strokeStyle = "gray";
  1226. ctx.translate(0.5, 0.5);
  1227. ctx.beginPath();
  1228. ctx.moveTo(x + offset, y);
  1229. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1230. offset += 9;
  1231. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1232. if (nextItem && nextItem.isMixRatio) {
  1233. ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
  1234. ctx.lineTo(x + offset - 9, y + h);
  1235. }
  1236. ctx.stroke();
  1237. ctx.restore();
  1238. return offset;
  1239. }
  1240. if(isDef(index) && data[index] && data[index].isMixRatio !==true){
  1241. TreeNodeCellType.prototype = sheetCommonObj.getDynamicCombo();
  1242. }else {
  1243. TreeNodeCellType.prototype = new ns.CellTypes.Text();
  1244. }
  1245. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  1246. if (value != null) {
  1247. var offset = margin + rectW + 6;
  1248. var recode = data[options.row];
  1249. if (recode && recode.hasOwnProperty('subList')) {
  1250. drowRect(ctx, x, y, w, h);
  1251. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
  1252. drowSymbol(ctx, x, y, w, h, collapsed);
  1253. } else if (recode && recode.isMixRatio) {
  1254. offset = drowSubItem(ctx, x, y, w, h, offset, data[options.row + 1]);
  1255. offset += 1;
  1256. }
  1257. arguments[2] = x + offset;
  1258. arguments[4] = w - offset;
  1259. //x = x + offset;
  1260. //w = w - offset;
  1261. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1262. }
  1263. };
  1264. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1265. if(x < cellRect.x+cellRect.width -15){
  1266. return {
  1267. x: x,
  1268. y: y,
  1269. row: context.row,
  1270. col: context.col,
  1271. cellStyle: cellStyle,
  1272. cellRect: cellRect,
  1273. sheetArea: context.sheetArea
  1274. };
  1275. }else {
  1276. return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(this, arguments);
  1277. }
  1278. };
  1279. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1280. var recode = data[hitinfo.row];
  1281. if (recode && recode.hasOwnProperty('subList')) {
  1282. var hoffset = hitinfo.cellRect.x + 3;
  1283. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1284. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;
  1285. collapsed = !collapsed
  1286. recode.collapsed = collapsed;
  1287. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1288. hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
  1289. hitinfo.sheet.invalidateLayout();
  1290. hitinfo.sheet.repaint();
  1291. return;
  1292. }
  1293. }
  1294. GC.Spread.Sheets.CellTypes.ComboBox.prototype.processMouseDown.apply(this, arguments);
  1295. // GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1296. };
  1297. let cellType = new TreeNodeCellType();
  1298. let options = [];
  1299. if(isDef(index) && data[index] && data[index].isMixRatio !==true){
  1300. let code = data[index].code;
  1301. if(code) {
  1302. let preCode = code.split("-")[0];
  1303. if( codeMap[preCode]) options = codeMap[preCode];
  1304. if(options.length>0) _.remove(options,{'value':gljOprObj.getIndex(data[index], gljKeyArray)})//去掉本身
  1305. }
  1306. cellType.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  1307. cellType.itemHeight(options.length).items(options);
  1308. }
  1309. return cellType;
  1310. },
  1311. marketPriceReadOnly: function (node) {
  1312. let hasCom = false;
  1313. if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
  1314. hasCom = this.hasComposition(node.data,true);
  1315. }else {
  1316. hasCom = this.hasComposition(node.data);
  1317. }
  1318. return hasCom|| node.data.isEstimate == 1;
  1319. },
  1320. locateZTree: function(ID) {
  1321. let zTree = $.fn.zTree.getZTreeObj("gljTree");
  1322. let node = null;
  1323. if (ID) node = zTree.getNodesByParam('ID', ID, null)[0]
  1324. if (!node) node = zTree.getNodeByTId('gljTree_1');
  1325. zTree.selectNode(node);
  1326. gljOprObj.gljCurTypeId = ID;
  1327. gljOprObj.filterLibGLJSheetData();
  1328. gljOprObj.showLibGLJSheetData();
  1329. }
  1330. }
  1331. $(function () {
  1332. $('#glj_tree_div').on('shown.bs.modal', function (e) {
  1333. if (gljOprObj.gljLibSpresd == undefined) {
  1334. gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
  1335. sheetCommonObj.spreadDefaultStyle(gljOprObj.gljLibSpresd);
  1336. gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
  1337. gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
  1338. gljOprObj.gljLibSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, gljOprObj.onSelectionChanged);
  1339. gljOprObj.gljLibSheet.setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  1340. gljOprObj.gljLibSheet.options.isProtected = true;
  1341. gljOprObj.gljLibSheet.name('glj_lib');
  1342. }
  1343. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1344. let gljClass = 0, selectMap = {};
  1345. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {//插入,添加
  1346. gljOprObj.GLJSelection = [];
  1347. } else if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){//替换、批量替换
  1348. let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1349. var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
  1350. gljOprObj.GLJSelection = [connect_key];
  1351. selectMap[connect_key] = true;
  1352. gljOprObj.filterLibGLJByType();
  1353. }else if($('#actionType').val() =='addMix'){//添加组成物
  1354. gljOprObj.GLJSelection = [];
  1355. projectGljObject.filterLibGLJForMixRatio();
  1356. /*selections = projectGljObject.mixRatioData; 添加组成物的时候先不选中
  1357. gljOprObj.GLJSelection = [];
  1358. for(let s of selections){
  1359. let s_key = gljOprObj.getIndex(s, gljKeyArray);
  1360. selectMap[s_key] = true;
  1361. gljOprObj.GLJSelection.push(s_key);
  1362. }*/
  1363. }
  1364. for(let item of gljOprObj.gljLibSheetData){
  1365. let item_key = gljOprObj.getIndex(item, gljLibKeyArray);
  1366. if(selectMap[item_key]){
  1367. item.select = 1 ;
  1368. gljClass = item.gljClass;
  1369. }
  1370. }
  1371. //替换,焦点定位至当前选中人材机
  1372. if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){
  1373. gljOprObj.locateZTree(gljClass);
  1374. let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1375. let index = _.findIndex(gljOprObj.gljLibSheetData, {code: selected.code});
  1376. gljOprObj.gljLibSheet.showRow(index, GC.Spread.Sheets.VerticalPosition.center);
  1377. gljOprObj.gljLibSheet.setActiveCell(index, 0);
  1378. gljOprObj.initSelection({row: index});
  1379. gljOprObj.gljLibSpresd.focus(true);
  1380. }
  1381. else gljOprObj.showLibGLJSheetData();
  1382. });
  1383. $('#glj_tree_div').on('hidden.bs.modal', function () {
  1384. $('#gljSearchKeyword').val('');
  1385. });
  1386. $('.glj-radio').change(function () {
  1387. let val = $("input[name='glj']:checked").val();
  1388. if (val == 'allGljs') {
  1389. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1390. gljOprObj.filterLibGLJSheetData();
  1391. gljOprObj.showLibGLJSheetData();
  1392. } else {
  1393. gljOprObj.gljLibSheetData = gljOprObj[val];
  1394. gljOprObj.filterLibGLJSheetData();
  1395. gljOprObj.showLibGLJSheetData();
  1396. }
  1397. })
  1398. /* //工料机搜索
  1399. $('#gljSearchKeyword').change(function () {
  1400. gljOprObj.filterLibGLJSheetData();
  1401. gljOprObj.showLibGLJSheetData();
  1402. });
  1403. $('#gljSearchKeyword').bind('keypress', function (e) {
  1404. if(e.keyCode === 13){
  1405. alert('2');
  1406. $(this).blur();
  1407. return false;
  1408. }
  1409. });*/
  1410. $('#gljSearchKeyword').bind('keyup', function (e) {
  1411. gljOprObj.filterLibGLJSheetData();
  1412. gljOprObj.showLibGLJSheetData();
  1413. });
  1414. $('#glj_selected_conf').click(function () {
  1415. if (gljOprObj.GLJSelection.length < 1) {
  1416. return;
  1417. }
  1418. if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
  1419. gljOprObj.doInsertGLJ();
  1420. } else if ($('#actionType').val() == 'add') { //添加工料机
  1421. gljOprObj.doAddGLJ();
  1422. } else if ($('#actionType').val() == 'replace') {//替换工料机
  1423. gljOprObj.doReplaceGLJ();
  1424. } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
  1425. gljOprObj.doMReplaceGLJ();
  1426. }else if($('#actionType').val() == 'addMix'){
  1427. projectGljObject.addMixRatio();
  1428. }
  1429. })
  1430. $('#class_selected_conf').click(function () {
  1431. var gljClass = $('#selected_class').val();
  1432. var glj = gljOprObj.selectedGLJClass;
  1433. if (glj && gljClass && gljClass != "") {
  1434. //保存到我的工料机库
  1435. /*1 检查是否有组成物
  1436. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  1437. * 3 保存
  1438. * */
  1439. var newItem = {
  1440. code: glj.code,
  1441. name: glj.name,
  1442. specs: glj.specs,
  1443. unit: glj.unit,
  1444. basePrice: glj.basePrice,
  1445. gljType: glj.type,
  1446. shortName: glj.shortName,
  1447. component: [],
  1448. gljClass: gljClass
  1449. };
  1450. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  1451. for (var i = 0; i < glj.subList.length; i++) {
  1452. let tem = {
  1453. ID: glj.subList[i].GLJID,
  1454. consumeAmt: glj.rationItemQuantity,
  1455. isStd: true
  1456. }
  1457. newItem.component.push(tem);
  1458. }
  1459. }
  1460. var data = getcmpUpdateData([newItem]);
  1461. $.bootstrapLoading.start();
  1462. var callback = function (data) {
  1463. $("#glj_class_div").modal('hide');
  1464. $.bootstrapLoading.end();
  1465. }
  1466. CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
  1467. $.bootstrapLoading.end();
  1468. });
  1469. }
  1470. })
  1471. $('#glj_class_div').on('hidden.bs.modal', function (e) {
  1472. gljOprObj.selectedGLJClass = null;
  1473. $('#class_selected_conf').attr("disabled", "disabled");
  1474. $('#selected_class').val("");
  1475. })
  1476. function getcmpUpdateData(items) {
  1477. var data = {
  1478. "updateItems": [],
  1479. "removeIds": []
  1480. }
  1481. data.addItems = items;
  1482. return data;
  1483. }
  1484. })
  1485. function operationWithRound(value1,value2,field,symble) {
  1486. let decimal = getDecimal(field);
  1487. value1 = scMathUtil.roundForObj(value1,decimal);
  1488. value2 = scMathUtil.roundForObj(value2,decimal);
  1489. let result;
  1490. switch (symble){
  1491. case "+" :
  1492. result=scMathUtil.roundForObj(value1 + value2,decimal);
  1493. break;
  1494. case "-":
  1495. result=scMathUtil.roundForObj(value1 - value2,decimal);
  1496. break;
  1497. case "*":
  1498. result=scMathUtil.roundForObj(value1 * value2,decimal);
  1499. break;
  1500. case "/":
  1501. result=scMathUtil.roundForObj(value1 / value2,decimal);
  1502. break
  1503. }
  1504. return result;
  1505. }
  1506. function getDecimal(fieldID, node) {
  1507. if (node) {
  1508. return decimalObj.decimal(fieldID, node);
  1509. } else if (fieldID.indexOf(".") != -1) {
  1510. var keyArray = fieldID.split(".");
  1511. return decimalObj[keyArray[0]][keyArray[1]];
  1512. } else {
  1513. return decimalObj.decimal(fieldID);
  1514. }
  1515. }
  1516. function sortRationGLJ(list) {
  1517. list = _.sortByAll(list, [function (item) {
  1518. return item.type + "";
  1519. }, "code"])
  1520. return list;
  1521. }
  1522. function compareRationGLJ(a, b) {
  1523. if ((a.type + "") < (b.type + "")) {
  1524. return true
  1525. }
  1526. if ((a.type + "") == (b.type + "")) {
  1527. if (a.code < b.code) {
  1528. return true
  1529. }
  1530. }
  1531. return false;
  1532. }