glj_view.js 63 KB

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