glj_view.js 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555
  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()){
  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. this.showMixRatio(node);
  556. }else {
  557. this.showRationGLJData(node);
  558. installationFeeObj.showRationInstallationData(node);
  559. }
  560. isShow = true;
  561. }
  562. if(node.sourceType == ModuleNames.ration_glj){
  563. this.showMixRatio(node);
  564. isShow = true;
  565. }
  566. this.showQuantityDetailData(node);
  567. } else {
  568. this.selectedNodeId = null;
  569. }
  570. if (!isShow) {
  571. this.clearSheetData();
  572. }
  573. //子目换算
  574. zmhs_obj.showZMHSData(node);
  575. // $('#dropdown').hide();
  576. },
  577. showMixRatio:function (node) {//显示组成物到定额工料机
  578. let mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  579. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  580. let indexArray =node.sourceType==ModuleNames.ration?rationKeyArray:gljKeyArray;
  581. let connect_index = this.getIndex(node.data,indexArray);
  582. let gljList=[];
  583. if(mixRatioMap[connect_index]){ //说明是有组成物的类型
  584. gljList = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  585. }
  586. if(gljList.length>0){//计算总消耗量
  587. if(node.sourceType==ModuleNames.ration){
  588. this.calcMixRationTotalQuantity(gljList,node.data.quantity);
  589. }else {
  590. let totalQuantity = this.getTotalQuantity(node.data);
  591. this.calcMixRationTotalQuantity(gljList,totalQuantity)
  592. }
  593. }
  594. this.sheetData = gljList;
  595. this.sheet.setRowCount(0);
  596. this.sheetData = sortRationGLJ(this.sheetData);
  597. this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType([]));
  598. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  599. this.sheet.getRange(-1, 0, -1, this.setting.header.length).locked(true);//锁住定额工料机的所有列
  600. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);//锁住工程量明细的所有列
  601. },
  602. showRationGLJData: function (node) {
  603. var gljList = [];
  604. var ration_glj = projectObj.project.ration_glj;
  605. node = node ? node : projectObj.project.mainTree.selected;
  606. if (node.sourceType == ModuleNames.ration) {
  607. if(node.data.type==rationType.gljRation){
  608. this.showMixRatio(node);
  609. }else {
  610. let ration = node.data;
  611. gljList = this.filterGljByRation(ration, ration_glj.datas);
  612. this.showInSheet(gljList);
  613. }
  614. }else if(node.sourceType == ModuleNames.ration_glj){
  615. this.showMixRatio(node);
  616. }
  617. },
  618. showRationGLJSheetData: function (init) {
  619. let selected = this.sheet.getSelections();
  620. this.combineWithProjectGlj(this.sheetData);
  621. this.sheet.setRowCount(0);
  622. //console.log(+new Date())
  623. //this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true); //这个方法导致加载缓慢
  624. this.sheetData = sortRationGLJ(this.sheetData);
  625. this.sumQuantity();//计算总消耗量
  626. this.addMixRatioToShow();//显示组成物信息
  627. this.initRationTree(init);
  628. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  629. if(selected){//定位光标到之前的位置
  630. this.sheet.setSelection(selected[0].row,selected[0].col,selected[0].rowCount,selected[0].colCount);
  631. }
  632. },
  633. initRationTree: function (init) {
  634. this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType(this.sheetData));
  635. for (var i = 0; i < this.sheetData.length; i++) {
  636. if (this.sheetData[i].hasOwnProperty('subList')) {
  637. /* var collapsed = false;
  638. if (init) {
  639. this.sheetData[i].collapsed = true;
  640. collapsed = true;
  641. } else {
  642. collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
  643. }*/
  644. var collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
  645. if (collapsed == true) {
  646. this.sheet.getRange(i + 1, -1, this.sheetData[i].subList.length, -1).visible(false);
  647. }
  648. //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);
  649. //这个方法导致加载缓慢
  650. }
  651. }
  652. },
  653. filterGljByRation: function (ration, datas) {
  654. var gljList = [];
  655. if (datas && datas.length > 0) {
  656. gljList = _.filter(datas, {'rationID': ration.ID})
  657. }
  658. return gljList;
  659. },
  660. showInSheet: function (gljList) {
  661. this.sheetData = gljList;
  662. this.showRationGLJSheetData(true);
  663. },
  664. sumQuantity: function (node) {
  665. if (this.sheetData.length > 0) {
  666. node = node ? node : projectObj.project.mainTree.selected;
  667. let ration = node.data;
  668. let quantity = ration.quantity;
  669. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  670. for (let glj of this.sheetData) {
  671. glj.totalQuantity= this.getTotalQuantity(glj,ration);
  672. }
  673. }
  674. },
  675. getTotalQuantity:function(glj,ration){
  676. ration=ration?ration: _.find(projectObj.project.Ration.datas,{"ID":glj.rationID});
  677. if(ration){
  678. let quantity = ration.quantity;
  679. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  680. if (glj.isMixRatio == true) {//如果是用于显示的组成物,则不用计算,跳过
  681. return;
  682. }
  683. quantity = scMathUtil.roundForObj(quantity, getDecimal("ration.quantity"));//计算前进行4舍5入
  684. glj.quantity = scMathUtil.roundForObj(glj.quantity, getDecimal("glj.quantity"));
  685. glj.totalQuantity = scMathUtil.roundToString(quantity * glj.quantity, getDecimal("glj.quantity"));
  686. if (glj.hasOwnProperty('subList')) {//需要计算glj下挂的组成物的总消耗量
  687. this.calcMixRationTotalQuantity(glj.subList,glj.totalQuantity);
  688. }
  689. return glj.totalQuantity;
  690. }
  691. },
  692. calcMixRationTotalQuantity(mList,pTotal){ //计算组成物的总消耗量
  693. for (let subG of mList) {
  694. subG.rationItemQuantity = scMathUtil.roundForObj(subG.rationItemQuantity, getDecimal("glj.quantity"));
  695. subG.totalQuantity = scMathUtil.roundToString(subG.rationItemQuantity * pTotal, getDecimal("glj.quantity"));
  696. }
  697. },
  698. addMixRatioToShow: function () {
  699. var newList = [];
  700. _.remove(this.sheetData, {'isMixRatio': true});
  701. for (var i = 0; i < this.sheetData.length; i++) {
  702. newList.push(this.sheetData[i]);
  703. if (this.sheetData[i].hasOwnProperty('subList')) {
  704. newList = newList.concat(this.sheetData[i].subList);
  705. }
  706. }
  707. this.sheetData = newList;
  708. },
  709. combineWithProjectGlj: function (ration_gljs,needRatio=true) {
  710. var projectGLJData = projectObj.project.projectGLJ.datas;
  711. var projectGljs = projectGLJData.gljList;
  712. var mixRatioMap = projectGLJData.mixRatioMap;
  713. if (ration_gljs && ration_gljs.length > 0 && projectGljs && projectGljs.length > 0) {
  714. for (var i = 0; i < ration_gljs.length; i++) {
  715. var glj = _.find(projectGljs, {'id': ration_gljs[i].projectGLJID});
  716. if (glj) {
  717. if(projectObj.project.projectGLJ.isEstimateType(ration_gljs[i].type )){
  718. ration_gljs[i].isEstimate = glj.is_evaluate;
  719. }
  720. ration_gljs[i].shortName =projectObj.project.projectGLJ.getShortNameByID(ration_gljs[i].type);
  721. ration_gljs[i].isAdd = glj.unit_price.is_add;
  722. ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
  723. var connect_index = this.getIndex(glj, gljKeyArray);
  724. if (needRatio==true&&mixRatioMap.hasOwnProperty(connect_index)) {
  725. var mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  726. ration_gljs[i].subList = mixRatios;
  727. }
  728. }
  729. }
  730. }
  731. return ration_gljs;
  732. },
  733. setGLJPrice:function (data,glj,isRadio = false) {//isRadio 标记是否算组成物的价格
  734. let proGLJ = projectObj.project.projectGLJ;
  735. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  736. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  737. let labourCoeDatas = projectObj.project.labourCoe.datas;
  738. glj = glj?glj:_.find(proGLJ.datas.gljList, {'id': data.projectGLJID});
  739. let result = gljUtil.getGLJPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  740. data.marketPrice = result.marketPrice;
  741. data.basePrice = result.basePrice;
  742. data.adjustPrice = result.adjustPrice;
  743. data.marketUnitFee = data.marketPrice;//更新树节点市场单价列的值
  744. return data;
  745. },
  746. getBasePrice:function (treeNode) {//造价书中的工料机修改的节点要用到
  747. let proGLJ = projectObj.project.projectGLJ;
  748. let glj =_.find(proGLJ.datas.gljList, {'id': treeNode.data.projectGLJID});
  749. if(this.calcPriceDiff(glj)==true){
  750. return proGLJ.getBasePrice(glj);
  751. }else {
  752. return scMathUtil.roundForObj(treeNode.data.marketUnitFee,getDecimal("glj.unitPrice"));
  753. }
  754. },
  755. calcPriceDiff:function (glj) {
  756. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  757. return gljUtil.calcPriceDiff(glj,calcOptions);
  758. },
  759. getIndex(obj, pops){
  760. let t_index = '';
  761. let k_arr = [];
  762. for (let p of pops) {
  763. let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
  764. k_arr.push(tmpK);
  765. }
  766. t_index = k_arr.join("|-|");
  767. return t_index;
  768. },
  769. getConditionByKey(conKey){//将连接字符串转换成对象
  770. let valueArray = conKey.split("|-|");
  771. let obj ={};
  772. for(let i = 0;i<valueArray.length;i++){
  773. if(valueArray[i]!='null'){
  774. if(gljKeyArray[i]=='type'){
  775. valueArray[i] = parseInt(valueArray[i]);
  776. }
  777. obj[gljKeyArray[i]]=valueArray[i];
  778. }
  779. }
  780. return obj;
  781. },
  782. getMixRationShowDatas: function (mixRatioList, projectGljs) {
  783. var temRationGLJs = [];
  784. for (var i = 0; i < mixRatioList.length; i++) {
  785. var pg = _.find(projectGljs, {
  786. 'code': mixRatioList[i].code,
  787. 'name': mixRatioList[i].name,
  788. 'specs': mixRatioList[i].specs,
  789. 'type': mixRatioList[i].type,
  790. 'unit': mixRatioList[i].unit
  791. });//改关联关系
  792. var tem = {
  793. projectGLJID: pg.id,
  794. code: pg.code,
  795. name: pg.name,
  796. specs: pg.specs,
  797. unit: pg.unit,
  798. type:mixRatioList[i].type,
  799. shortName: projectObj.project.projectGLJ.getShortNameByID(mixRatioList[i].type),
  800. consumption:mixRatioList[i].consumption,
  801. rationItemQuantity: mixRatioList[i].consumption,
  802. // quantity:mixRatioList[i].consumption,
  803. /* basePrice: pg.unit_price.base_price,
  804. marketPrice: pg.unit_price.market_price,
  805. adjustPrice: pg.adjust_price,*/
  806. //isEstimate: pg.is_evaluate,
  807. isMixRatio: true,
  808. isAdd: pg.unit_price.is_add,
  809. GLJID: pg.glj_id
  810. };
  811. if(projectObj.project.projectGLJ.isEstimateType(pg.type)){
  812. tem.isEstimate = pg.is_evaluate;
  813. }
  814. this.setGLJPrice(tem,pg);
  815. temRationGLJs.push(tem);
  816. }
  817. temRationGLJs = _.sortBy(temRationGLJs, 'code');
  818. return temRationGLJs;
  819. },
  820. showQuantityDetailData: function (node) {
  821. var details = [];
  822. node = node ? node : projectObj.project.mainTree.selected;
  823. var quantity_detail = projectObj.project.quantity_detail;
  824. if (node.sourceType == ModuleNames.ration) {
  825. details = _.filter(quantity_detail.datas, {'rationID': node.data.ID});
  826. } else if (node.sourceType == ModuleNames.bills) {
  827. details = _.filter(quantity_detail.datas, {'billID': node.data.ID});
  828. }
  829. details = _.sortBy(details, 'seq');
  830. sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
  831. this.detailData = details;
  832. if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
  833. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
  834. }
  835. },
  836. clearSheetData: function () {
  837. sheetCommonObj.showData(this.sheet, this.setting, []);
  838. installationFeeObj.rationInstallSheet.setRowCount(0);//清除combobox cell
  839. sheetCommonObj.showData(installationFeeObj.rationInstallSheet, installationFeeObj.rationInstallSetting, []);
  840. // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
  841. this.sheetData = [];
  842. installationFeeObj.rationInstallData = [];
  843. //this.detailData=[];
  844. },
  845. updateRationGLJ: function (args) {
  846. var me = this;
  847. var updateField = me.setting.header[args.col].dataCode;
  848. var recode = me.sheetData[args.row];
  849. var newval;
  850. if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
  851. if (args.editingText == null) {
  852. updateField == 'marketPrice' ? newval = 0 : newval = "";
  853. } else {
  854. var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : getDecimal("glj.unitPrice");
  855. newval = number_util.checkNumberValue(args.editingText, decimal);
  856. if (newval == null) {
  857. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  858. return;
  859. }
  860. }
  861. } else {
  862. if (updateField == 'name' || updateField == 'unit') {
  863. if (args.editingText === null) {
  864. alert(me.setting.header[args.col].headerName + '不能为空!');
  865. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  866. return;
  867. }
  868. }
  869. newval = args.editingText == null ? "" : args.editingText;
  870. }
  871. if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
  872. return
  873. }
  874. if (updateField == 'marketPrice' || updateField == 'basePrice') {
  875. projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
  876. } else {
  877. projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
  878. }
  879. },
  880. updateRationTypeGLJ: function (value, node, fieldName,editingText) {
  881. let newval;
  882. let updatePrice = false;
  883. if (fieldName == "marketUnitFee") {
  884. updatePrice = true;
  885. if (value == null) {
  886. newval = 0;
  887. } else {
  888. var decimal = getDecimal("glj.unitPrice");
  889. newval = number_util.checkNumberValue(value, decimal);
  890. }
  891. } else {
  892. if (value != null) {
  893. projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value,editingText);
  894. return;
  895. //update
  896. }
  897. }
  898. if (newval && updatePrice == true) {
  899. projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
  900. return
  901. }
  902. projectObj.mainController.refreshTreeNode([node]);
  903. },
  904. updateIsEstimate:function (args, newval) {
  905. var me = gljOprObj;
  906. if(me.setting.header[args.col].dataCode=="isEstimate"){
  907. var pspread= new ProjectGLJSpread();
  908. var recode = me.sheetData[args.row];
  909. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  910. let glj = _.find(projectGljs, {'id': recode.projectGLJID});
  911. if(glj){
  912. glj["is_evaluate"]=newval;
  913. args.fromRG=true;
  914. pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
  915. }
  916. }
  917. },
  918. showLibGLJSheetData: function () {
  919. this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
  920. sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
  921. this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
  922. },
  923. filterLibGLJSheetData: function () {
  924. let me = this;
  925. let val = $("input[name='glj']:checked").val();
  926. if (val == 'allGljs') {
  927. me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
  928. } else {
  929. me.gljLibSheetData = me[val];
  930. }
  931. if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
  932. me.filterLibGLJByType();
  933. }else if($('#actionType').val() == 'addMix'){
  934. projectGljObject.filterLibGLJForMixRatio();
  935. }
  936. //文本筛选
  937. let searchStr = $('#gljSearchKeyword').val();
  938. if(searchStr && searchStr.trim() != ''){
  939. let reg = new RegExp(searchStr);
  940. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  941. return reg.test(data.code) || reg.test(data.name);
  942. });
  943. }
  944. if (me.gljCurTypeId == undefined) {
  945. return;
  946. }
  947. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  948. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  949. return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
  950. });
  951. } else {
  952. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
  953. }
  954. },
  955. setGLJSelection: function (args, newVal) {
  956. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert'|| $('#actionType').val() == 'addMix') {
  957. this.addGLJsSelection(args, newVal);
  958. } else {
  959. this.replaceGLJSelection(args, newVal);
  960. }
  961. },
  962. addGLJsSelection: function (args, newVal) {
  963. var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
  964. if (newVal == 1) {
  965. this.GLJSelection.push(con_key);
  966. this.gljLibSheetData[args.row].select = 1;
  967. } else if (newVal == 0) {
  968. _.pull(this.GLJSelection, con_key);
  969. this.gljLibSheetData[args.row].select = 0;
  970. }
  971. },
  972. replaceGLJSelection: function (args, newVal) {
  973. var me = this;
  974. var oldSelection = this.GLJSelection[0];
  975. if (newVal == 0) {
  976. args.sheet.getCell(args.row, args.col).value(1);
  977. return;
  978. }
  979. this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
  980. this.gljLibSheetData[args.row].select = 1;
  981. var oindex = _.findIndex(this.gljLibSheetData, function (item) {
  982. var i_key = me.getIndex(item, gljLibKeyArray);
  983. return oldSelection == i_key;
  984. });
  985. if (oindex != -1) {
  986. args.sheet.getCell(oindex, args.col).value(0);
  987. this.gljLibSheetData[oindex].select = 0;
  988. } else {
  989. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  990. var i_key = me.getIndex(item, gljLibKeyArray);
  991. return oldSelection == i_key;
  992. });
  993. oldData ? oldData.select = 0 : "";
  994. }
  995. },
  996. filterLibGLJByType: function () {
  997. var me = this;
  998. var selected = me.sheetData[gljContextMenu.selectedRow];
  999. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljType': selected.type});
  1000. },
  1001. getComboData: function (gljDistType) {
  1002. let me = this;
  1003. let distType;
  1004. let distTypeTree = {
  1005. prefix: 'gljType',
  1006. distTypes: {},
  1007. comboDatas: [],
  1008. distTypesArr: []
  1009. };
  1010. gljDistType.forEach(function (typeData) {
  1011. let typeObj = {
  1012. data: typeData,
  1013. children: [],
  1014. parent: null
  1015. }
  1016. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  1017. distTypeTree.distTypesArr.push(typeObj);
  1018. });
  1019. gljDistType.forEach(function (typeData) {
  1020. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  1021. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  1022. if (parent) {
  1023. distType.parent = parent;
  1024. parent.children.push(distType);
  1025. }
  1026. });
  1027. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  1028. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  1029. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  1030. }
  1031. });
  1032. return distTypeTree;
  1033. },
  1034. doInsertGLJ: function () {
  1035. var me = this;
  1036. var selected = projectObj.project.mainTree.selected;
  1037. var project = projectObj.project;
  1038. if (me.GLJSelection.length <= 0) {
  1039. return;
  1040. }
  1041. $("#glj_tree_div").modal('hide');
  1042. $.bootstrapLoading.start();
  1043. project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (parentNodeID,nextNodeID,data) {
  1044. let newNode=null;
  1045. for (let r_glj of data) {
  1046. r_glj.quantity = r_glj.quantity + "";
  1047. project.Ration.datas.push(r_glj);
  1048. }//要先更新树节点工程量,加载项目工料机并计算消耗量才有值
  1049. project.projectGLJ.loadData(function () {
  1050. for(let r_glj of data){
  1051. r_glj = me.setGLJPrice(r_glj);//设置工料机价格
  1052. newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
  1053. newNode.source = r_glj;
  1054. newNode.sourceType = project.Ration.getSourceType();
  1055. newNode.data = r_glj;
  1056. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  1057. }
  1058. project.calcProgram.calcLeafAndSave(newNode.parent);//计算父级清单的所有子节点
  1059. projectObj.mainController.refreshTreeNode([newNode]);
  1060. if(me.hasComposition(newNode.data,true)){
  1061. me.showMixRatio(newNode);
  1062. }else {
  1063. me.showRationGLJSheetData();
  1064. }
  1065. $.bootstrapLoading.end();
  1066. });
  1067. })
  1068. },
  1069. doAddGLJ: function () {
  1070. var selected = projectObj.project.mainTree.selected;
  1071. var project = projectObj.project;
  1072. gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
  1073. var rg = _.find(gljOprObj.sheetData, function (item) {
  1074. var i_key = gljOprObj.getIndex(item, gljKeyArray);
  1075. return n == i_key
  1076. })
  1077. return rg ? false : true;
  1078. })
  1079. if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
  1080. $("#glj_tree_div").modal('hide');
  1081. project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
  1082. if (result) {
  1083. selected.data.adjustState = result.adjustState;
  1084. //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
  1085. project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
  1086. gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
  1087. project.projectGLJ.loadData(function () {
  1088. project.ration_glj.addToMainTree(result.showData);
  1089. gljOprObj.showRationGLJSheetData();
  1090. project.calcProgram.calcAndSave(selected);
  1091. projectObj.mainController.refreshTreeNode([selected]);
  1092. $.bootstrapLoading.end();
  1093. });
  1094. }
  1095. });//doc.rationID=selected.data.ID;
  1096. } else {
  1097. $("#glj_tree_div").modal('hide');
  1098. }
  1099. },
  1100. doReplaceGLJ: function () {
  1101. var me = this;
  1102. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1103. var project = projectObj.project;
  1104. var selectCode = gljOprObj.GLJSelection[0];
  1105. var selected = projectObj.project.mainTree.selected;
  1106. $("#glj_tree_div").modal('hide');
  1107. project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
  1108. if (result) {
  1109. //result.adjustState;
  1110. var glj_list = projectObj.project.ration_glj.datas;
  1111. var data = result.data;
  1112. var index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
  1113. var list_index = _.findIndex(glj_list, {'ID': data.ID});
  1114. var nodes = [selected];
  1115. gljOprObj.sheetData[index] = data;
  1116. glj_list[list_index] = data;
  1117. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  1118. gljOprObj.showRationGLJSheetData();
  1119. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  1120. var node = project.ration_glj.findGLJNodeByID(data.ID);
  1121. if (node) {
  1122. project.ration_glj.transferToNodeData(data);
  1123. node.source = data;
  1124. node.data = data;
  1125. }
  1126. node ? nodes.push(node) : "";
  1127. }
  1128. //project.ration_glj.addToMainTree(data);
  1129. selected.data.adjustState = result.adjustState;
  1130. projectObj.mainController.refreshTreeNode(nodes);
  1131. project.calcProgram.calcAndSave(selected);
  1132. $.bootstrapLoading.end();
  1133. });
  1134. }
  1135. })
  1136. },
  1137. doMReplaceGLJ: function () {
  1138. let me = this;
  1139. let oldData = me.sheetData[gljContextMenu.selectedRow];
  1140. let project = projectObj.project;
  1141. let selectCode = me.GLJSelection[0];
  1142. $("#glj_tree_div").modal('hide');
  1143. project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result,updateMap) {
  1144. if(result == null){
  1145. return;
  1146. }
  1147. let data = result.data;
  1148. let stateList = result.stateList;
  1149. //let n_index = me.getIndex(data.query, gljKeyArray);
  1150. let nodes = [];
  1151. _.forEach(project.ration_glj.datas, function (t) {
  1152. // let t_index = me.getIndex(t, gljKeyArray);
  1153. if (updateMap[t.ID]) {
  1154. me.updateProperty(t, data.doc);
  1155. me.updateProperty(t, updateMap[t.ID]);
  1156. if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
  1157. project.ration_glj.transferToNodeData(t);
  1158. var node = project.ration_glj.findGLJNodeByID(t.ID);
  1159. node ? nodes.push(node):'';
  1160. }
  1161. }
  1162. })
  1163. project.projectGLJ.loadData(function () {
  1164. me.showRationGLJSheetData();
  1165. var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
  1166. project.calcProgram.calcNodesAndSave(rationNodes);
  1167. $.bootstrapLoading.end();
  1168. });
  1169. })
  1170. },
  1171. updateProperty: function (obj, doc) {
  1172. _.forEach(doc, function (n, key) {
  1173. obj[key] = n;
  1174. });
  1175. },
  1176. refreshStateAfterMreplace: function (stateList, gljNodes) {
  1177. var nodes = [];
  1178. var rationNodes = [];
  1179. _.forEach(stateList, function (s) {
  1180. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1181. return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
  1182. })
  1183. if (node) {
  1184. node.data.adjustState = s.adjustState;
  1185. nodes.push(node);
  1186. rationNodes.push(node);
  1187. }
  1188. });
  1189. gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
  1190. projectObj.mainController.refreshTreeNode(nodes);
  1191. return rationNodes;
  1192. },
  1193. refreshView: function () {
  1194. let node = projectObj.project.mainTree.selected;
  1195. this.showDataIfRationSelect(node,"111111");
  1196. //this.showRationGLJData();
  1197. },
  1198. //
  1199. refreshTreeNode: function (obj) {
  1200. if (!obj) {
  1201. return;
  1202. }
  1203. var objectArray = [];
  1204. var nodes = [];
  1205. if (obj instanceof Array) {
  1206. objectArray.concat(obj);
  1207. } else {
  1208. objectArray.push(obj);
  1209. }
  1210. for (let o of objectArray) {
  1211. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1212. return n.sourceType == o.type && n.data.ID == o.ID;
  1213. })
  1214. if (node) {
  1215. for (var k in o.data) {
  1216. node.data[k] = o.data[k];
  1217. }
  1218. nodes.push(node);
  1219. }
  1220. }
  1221. projectObj.mainController.refreshTreeNode(nodes);
  1222. return nodes;
  1223. },
  1224. getTreeNodeCellType: function (data) {
  1225. var ns = GC.Spread.Sheets;
  1226. var rectW = 10;
  1227. var rectH = 10;
  1228. var margin = 3;
  1229. function TreeNodeCellType() {
  1230. }
  1231. function drowRect(ctx, x, y, w, h) {
  1232. ctx.save();
  1233. ctx.strokeStyle = "gray";
  1234. ctx.translate(0.5, 0.5);
  1235. ctx.beginPath();
  1236. var rectX = x + margin;
  1237. var rectY = y + Math.round(h / 2) - rectH / 2;
  1238. ctx.moveTo(rectX, rectY);
  1239. ctx.lineTo(rectX, rectY + rectH);
  1240. ctx.lineTo(rectX + rectW, rectY + rectH);
  1241. ctx.lineTo(rectX + rectW, rectY);
  1242. ctx.lineTo(rectX, rectY);
  1243. ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
  1244. ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
  1245. ctx.stroke();
  1246. ctx.restore();
  1247. }
  1248. function drowSymbol(ctx, x, y, w, h, collapsed) {
  1249. ctx.save();
  1250. ctx.strokeStyle = "#000000";
  1251. ctx.translate(0.5, 0.5);
  1252. ctx.beginPath();
  1253. ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
  1254. ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
  1255. var rectY = y + Math.round(h / 2) - rectH / 2;
  1256. if (collapsed) {
  1257. ctx.moveTo(x + margin + rectW / 2, rectY + 2);
  1258. ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
  1259. }
  1260. ctx.stroke();
  1261. ctx.restore();
  1262. }
  1263. function drowSubItem(ctx, x, y, w, h, offset, nextItem) {
  1264. offset += 6;
  1265. ctx.save();
  1266. ctx.strokeStyle = "gray";
  1267. ctx.translate(0.5, 0.5);
  1268. ctx.beginPath();
  1269. ctx.moveTo(x + offset, y);
  1270. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1271. offset += 9;
  1272. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1273. if (nextItem && nextItem.isMixRatio) {
  1274. ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
  1275. ctx.lineTo(x + offset - 9, y + h);
  1276. }
  1277. ctx.stroke();
  1278. ctx.restore();
  1279. return offset;
  1280. }
  1281. TreeNodeCellType.prototype = new ns.CellTypes.Text();
  1282. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  1283. if (value != null) {
  1284. var offset = margin + rectW + 6;
  1285. var recode = data[options.row];
  1286. if (recode && recode.hasOwnProperty('subList')) {
  1287. drowRect(ctx, x, y, w, h);
  1288. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
  1289. drowSymbol(ctx, x, y, w, h, collapsed);
  1290. } else if (recode && recode.isMixRatio) {
  1291. offset = drowSubItem(ctx, x, y, w, h, offset, data[options.row + 1]);
  1292. offset += 1;
  1293. }
  1294. x = x + offset;
  1295. w = w - offset;
  1296. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1297. }
  1298. };
  1299. // override getHitInfo to allow cell type get mouse messages
  1300. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1301. return {
  1302. x: x,
  1303. y: y,
  1304. row: context.row,
  1305. col: context.col,
  1306. cellStyle: cellStyle,
  1307. cellRect: cellRect,
  1308. sheetArea: context.sheetArea
  1309. };
  1310. };
  1311. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1312. var recode = data[hitinfo.row];
  1313. if (recode && recode.hasOwnProperty('subList')) {
  1314. var hoffset = hitinfo.cellRect.x + 3;
  1315. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1316. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;
  1317. collapsed = !collapsed
  1318. recode.collapsed = collapsed;
  1319. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1320. hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
  1321. hitinfo.sheet.invalidateLayout();
  1322. hitinfo.sheet.repaint();
  1323. }
  1324. }
  1325. };
  1326. return new TreeNodeCellType()
  1327. },
  1328. marketPriceReadOnly: function (node) {
  1329. let hasCom = false;
  1330. if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
  1331. hasCom = this.hasComposition(node.data,true);
  1332. }else {
  1333. hasCom = this.hasComposition(node.data);
  1334. }
  1335. return hasCom|| node.data.isEstimate == 1;
  1336. }
  1337. }
  1338. $(function () {
  1339. $('#glj_tree_div').on('shown.bs.modal', function (e) {
  1340. if (gljOprObj.gljLibSpresd == undefined) {
  1341. gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
  1342. gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
  1343. gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
  1344. gljOprObj.gljLibSheet.options.isProtected = true;
  1345. gljOprObj.gljLibSheet.name('glj_lib');
  1346. }
  1347. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1348. let selections = [],selectMap = {};
  1349. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {//插入,添加
  1350. gljOprObj.GLJSelection = [];
  1351. } else if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){//替换、批量替换
  1352. let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1353. var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
  1354. gljOprObj.GLJSelection = [connect_key];
  1355. selectMap[connect_key] = true;
  1356. gljOprObj.filterLibGLJByType();
  1357. }else if($('#actionType').val() =='addMix'){//添加组成物
  1358. gljOprObj.GLJSelection = [];
  1359. projectGljObject.filterLibGLJForMixRatio();
  1360. /*selections = projectGljObject.mixRatioData; 添加组成物的时候先不选中
  1361. gljOprObj.GLJSelection = [];
  1362. for(let s of selections){
  1363. let s_key = gljOprObj.getIndex(s, gljKeyArray);
  1364. selectMap[s_key] = true;
  1365. gljOprObj.GLJSelection.push(s_key);
  1366. }*/
  1367. }
  1368. for(let item of gljOprObj.gljLibSheetData){
  1369. let item_key = gljOprObj.getIndex(item, gljLibKeyArray);
  1370. if(selectMap[item_key]){
  1371. item.select = 1 ;
  1372. }
  1373. }
  1374. gljOprObj.showLibGLJSheetData();
  1375. });
  1376. $('#glj_tree_div').on('hidden.bs.modal', function () {
  1377. $('#gljSearchKeyword').val('');
  1378. });
  1379. $('.glj-radio').change(function () {
  1380. let val = $("input[name='glj']:checked").val();
  1381. if (val == 'allGljs') {
  1382. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1383. gljOprObj.filterLibGLJSheetData();
  1384. gljOprObj.showLibGLJSheetData();
  1385. } else {
  1386. gljOprObj.gljLibSheetData = gljOprObj[val];
  1387. gljOprObj.filterLibGLJSheetData();
  1388. gljOprObj.showLibGLJSheetData();
  1389. }
  1390. })
  1391. //工料机搜索
  1392. $('#gljSearchKeyword').change(function () {
  1393. gljOprObj.filterLibGLJSheetData();
  1394. gljOprObj.showLibGLJSheetData();
  1395. });
  1396. $('#gljSearchKeyword').bind('keypress', function (e) {
  1397. if(e.keyCode === 13){
  1398. $(this).blur();
  1399. return false;
  1400. }
  1401. });
  1402. $('#glj_selected_conf').click(function () {
  1403. if (gljOprObj.GLJSelection.length < 1) {
  1404. return;
  1405. }
  1406. if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
  1407. gljOprObj.doInsertGLJ();
  1408. } else if ($('#actionType').val() == 'add') { //添加工料机
  1409. gljOprObj.doAddGLJ();
  1410. } else if ($('#actionType').val() == 'replace') {//替换工料机
  1411. gljOprObj.doReplaceGLJ();
  1412. } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
  1413. gljOprObj.doMReplaceGLJ();
  1414. }else if($('#actionType').val() == 'addMix'){
  1415. projectGljObject.addMixRatio();
  1416. }
  1417. })
  1418. $('#class_selected_conf').click(function () {
  1419. var gljClass = $('#selected_class').val();
  1420. var glj = gljOprObj.selectedGLJClass;
  1421. if (glj && gljClass && gljClass != "") {
  1422. //保存到我的工料机库
  1423. /*1 检查是否有组成物
  1424. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  1425. * 3 保存
  1426. * */
  1427. var newItem = {
  1428. code: glj.code,
  1429. name: glj.name,
  1430. specs: glj.specs,
  1431. unit: glj.unit,
  1432. basePrice: glj.basePrice,
  1433. gljType: glj.type,
  1434. shortName: glj.shortName,
  1435. component: [],
  1436. gljClass: gljClass
  1437. };
  1438. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  1439. for (var i = 0; i < glj.subList.length; i++) {
  1440. let tem = {
  1441. ID: glj.subList[i].GLJID,
  1442. consumeAmt: glj.rationItemQuantity,
  1443. isStd: true
  1444. }
  1445. newItem.component.push(tem);
  1446. }
  1447. }
  1448. var data = getcmpUpdateData([newItem]);
  1449. $.bootstrapLoading.start();
  1450. var callback = function (data) {
  1451. $("#glj_class_div").modal('hide');
  1452. $.bootstrapLoading.end();
  1453. }
  1454. CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
  1455. $.bootstrapLoading.end();
  1456. });
  1457. }
  1458. })
  1459. $('#glj_class_div').on('hidden.bs.modal', function (e) {
  1460. gljOprObj.selectedGLJClass = null;
  1461. $('#class_selected_conf').attr("disabled", "disabled");
  1462. $('#selected_class').val("");
  1463. })
  1464. function getcmpUpdateData(items) {
  1465. var data = {
  1466. "updateItems": [],
  1467. "removeIds": []
  1468. }
  1469. data.addItems = items;
  1470. return data;
  1471. }
  1472. })
  1473. function operationWithRound(value1,value2,field,symble) {
  1474. let decimal = getDecimal(field);
  1475. value1 = scMathUtil.roundForObj(value1,decimal);
  1476. value2 = scMathUtil.roundForObj(value2,decimal);
  1477. let result;
  1478. switch (symble){
  1479. case "+" :
  1480. result=scMathUtil.roundForObj(value1 + value2,decimal);
  1481. break;
  1482. case "-":
  1483. result=scMathUtil.roundForObj(value1 - value2,decimal);
  1484. break;
  1485. case "*":
  1486. result=scMathUtil.roundForObj(value1 * value2,decimal);
  1487. break;
  1488. case "/":
  1489. result=scMathUtil.roundForObj(value1 / value2,decimal);
  1490. break
  1491. }
  1492. return result;
  1493. }
  1494. function getDecimal(fieldID, node) {
  1495. if (node) {
  1496. return decimalObj.decimal(fieldID, node);
  1497. } else if (fieldID.indexOf(".") != -1) {
  1498. var keyArray = fieldID.split(".");
  1499. return decimalObj[keyArray[0]][keyArray[1]];
  1500. } else {
  1501. return decimalObj.decimal(fieldID);
  1502. }
  1503. }
  1504. function sortRationGLJ(list) {
  1505. list = _.sortByAll(list, [function (item) {
  1506. return item.type + "";
  1507. }, "code"])
  1508. return list;
  1509. }
  1510. function compareRationGLJ(a, b) {
  1511. if ((a.type + "") < (b.type + "")) {
  1512. return true
  1513. }
  1514. if ((a.type + "") == (b.type + "")) {
  1515. if (a.code < b.code) {
  1516. return true
  1517. }
  1518. }
  1519. return false;
  1520. }