glj_view.js 65 KB

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