glj_view.js 59 KB

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