glj_view.js 65 KB

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