glj_view.js 65 KB

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