glj_view.js 59 KB

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