project_glj_view.js 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909
  1. /**
  2. * Created by zhang on 2018/3/13.
  3. */
  4. projectGljObject = {
  5. showTag: "ration", //mixRatio/machine
  6. showMixRatioMark: "",
  7. displayType: filterType.ALL,
  8. mixRatioType: [gljType.CONCRETE, gljType.MORTAR, gljType.MIX_RATIO, gljType.MAIN_MATERIAL],
  9. machineType: [gljType.GENERAL_MACHINE],
  10. projectGljSetting: {},
  11. projectGljSpread: null,
  12. projectGljSheet: null,
  13. materialTreeSheet: null,
  14. projectGljSheetData: [],
  15. mixRatioSetting: {},
  16. relatedRationSetting: {
  17. header: [
  18. { headerName: "编码", headerWidth: 100, dataCode: "code", dataType: "String" },
  19. { headerName: "名称", headerWidth: 180, dataCode: "name", dataType: "String" },
  20. { headerName: "单位", headerWidth: 50, dataCode: "unit", dataType: "String", hAlign: "center" },
  21. { headerName: "工程量", headerWidth: 65, dataCode: "quantity", dataType: "Number", hAlign: "right", decimalField: "ration.quantity" },
  22. { headerName: "单价", headerWidth: 65, dataCode: "feesIndex.common.unitFee", dataType: "Number", hAlign: "right", decimalField: "ration.unitPrice" },
  23. ],
  24. view: {
  25. lockColumns: [0, 1, 2, 3, 4], //,
  26. //colHeaderHeight:30
  27. },
  28. },
  29. materialTreeSetting: {
  30. emptyRows: 0,
  31. headRows: 1,
  32. headRowHeight: [21],
  33. defaultRowHeight: 21,
  34. treeCol: 0,
  35. cols: [],
  36. },
  37. materialSetting: {
  38. header: [
  39. { headerName: "编码", headerWidth: 200, dataCode: "code", dataType: "String" },
  40. { headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String" },
  41. { headerName: "规格型号", headerWidth: 160, dataCode: "specs", hAlign: "left", dataType: "String" },
  42. { headerName: "单位", headerWidth: 45, dataCode: "unit", hAlign: "center", dataType: "String" },
  43. { headerName: "定额价", headerWidth: 70, dataCode: "basePrice", hAlign: "right", dataType: "Number", validator: "number" }, //,decimalField:'glj.unitPrice'
  44. { headerName: "预算价", headerWidth: 70, dataCode: "marketPrice", hAlign: "right", dataType: "Number", validator: "number" }, //,decimalField:"glj.unitPrice"
  45. { headerName: "总消耗量", headerWidth: 70, dataCode: "quantity", hAlign: "right", dataType: "Number", decimalField: "glj.quantity" },
  46. { headerName: "三材系数", headerWidth: 70, dataCode: "materialCoe", hAlign: "right", dataType: "Number", validator: "number" }, //,decimalField:'material'
  47. { headerName: "三材量", headerWidth: 100, dataCode: "materialQuantity", hAlign: "right", dataType: "Number", decimalField: "glj.quantity" },
  48. {
  49. headerName: "三材类别",
  50. headerWidth: 70,
  51. dataCode: "materialType",
  52. hAlign: "center",
  53. dataType: "String",
  54. cellType: "comboBox",
  55. editorValueType: true,
  56. options: materialComboMap,
  57. },
  58. ],
  59. view: {
  60. lockColumns: [0, 1, 2, 3, 6, 8],
  61. },
  62. },
  63. mixRatioSpread: null,
  64. mixRatioSheet: null,
  65. mixRatioData: [],
  66. usedTenderList: [],
  67. usedUnitPriceInfo: null,
  68. displayTypeMap: [
  69. { ID: "LABOUR", text: "人工" },
  70. { ID: "GENERAL_MATERIAL", text: "材料" },
  71. { ID: "GENERAL_MACHINE", text: "机械" },
  72. /*{ID:'MAIN_MATERIAL',text:'主材'},
  73. {ID:'EQUIPMENT',text:'设备'}*/
  74. ],
  75. initSpreads: function () {
  76. if (this.projectGljSpread == null) this.initProjectGljSpread();
  77. //if(materialAdjustObj.spread == null) materialAdjustObj.initSpread();
  78. if (configMaterialObj.configSpread == null) configMaterialObj.initSpread();
  79. },
  80. initProjectGljSpread: function () {
  81. if (!this.projectGljSpread) {
  82. this.projectGljSpread = SheetDataHelper.createNewSpread($("#project_glj_sheet")[0], 2);
  83. sheetCommonObj.spreadDefaultStyle(this.projectGljSpread);
  84. }
  85. this.projectGljSpread.bind(GC.Spread.Sheets.Events.RangeChanged, this.onProjectGljRangeChange);
  86. this.projectGljSpread.getActiveSheet().options.frozenlineColor = "#ababab";
  87. this.initProjectGljSheet();
  88. this.initMaterialTreeSheet();
  89. //打开别人分享的项目,只读
  90. if (projectReadOnly) {
  91. //锁定逻辑走disabledSpread里的
  92. if (this.projectGljSetting.view.lockColumns) {
  93. this.projectGljSetting.view.lockColumns = null;
  94. }
  95. sheetCommonObj.disableSpread(this.projectGljSpread); //disableRightMenu("project_glj_sheet",this.projectGljSpread,this.rightClickCallback);
  96. } else {
  97. this.initProjectGljRightClick();
  98. }
  99. },
  100. initProjectGljSheet: function () {
  101. this.projectGljSheet = this.projectGljSpread.getSheet(0);
  102. this.initSheet(this.projectGljSheet, this.projectGljSetting);
  103. this.projectGljSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, this.onProjectGljSelectionChange);
  104. this.projectGljSheet.bind(GC.Spread.Sheets.Events.EditStarting, this.onProjectGljEditStarting);
  105. this.projectGljSheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onProjectGljDoubleClick);
  106. this.projectGljSheet.name("projectGljSheet");
  107. this.projectGljSheet.setRowHeight(0, 36, 1);
  108. },
  109. initMixRatio: function () {
  110. let me = projectGljObject;
  111. if (me.mixRatioSpread == null) {
  112. me.initMixRatioSpread();
  113. if (!projectReadOnly) {
  114. me.initMixRatioRightClick();
  115. }
  116. }
  117. },
  118. initMixRatioSpread: function () {
  119. this.mixRatioSpread = SheetDataHelper.createNewSpread($("#mix_ratio_sheet")[0], 2);
  120. sheetCommonObj.spreadDefaultStyle(this.mixRatioSpread);
  121. this.mixRatioSheet = this.mixRatioSpread.getSheet(0);
  122. this.initSheet(this.mixRatioSheet, this.mixRatioSetting);
  123. this.mixRatioSheet.name("mixRatioSheet");
  124. this.mixRatioSheet.bind(GC.Spread.Sheets.Events.EditStarting, this.onMixRatioEditStarting);
  125. this.mixRatioSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onMixRatioRangeChange);
  126. this.initRelatedRationSheet();
  127. if (projectReadOnly) {
  128. if (this.mixRatioSetting.view.lockColumns) {
  129. this.mixRatioSetting.view.lockColumns = null;
  130. }
  131. sheetCommonObj.disableSpread(this.mixRatioSpread);
  132. }
  133. },
  134. initRelatedRationSheet: function () {
  135. this.relatedRationSheet = this.mixRatioSpread.getSheet(1);
  136. sheetCommonObj.initSheet(this.relatedRationSheet, this.relatedRationSetting, 30);
  137. this.relatedRationSheet.name("relatedRation");
  138. this.relatedRationSheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onRelatedRationDoubleClick);
  139. //this.mixRatioSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onMixRatioRangeChange);
  140. },
  141. initMaterialTreeSheet: function () {
  142. this.materialTreeSheet = this.projectGljSpread.getSheet(1);
  143. this.materialTreeSetting = this.createMaterialTreeSheetSetting();
  144. this.materialTree = cacheTree.createNew(this);
  145. this.materialTreeController = TREE_SHEET_CONTROLLER.createNew(this.materialTree, this.materialTreeSheet, this.materialTreeSetting);
  146. this.materialTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, this.onSelectionChange);
  147. this.materialTreeSheet.bind(GC.Spread.Sheets.Events.EditStarting, this.onProjectGljEditStarting);
  148. this.materialTreeSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onProjectGLJValueChange);
  149. this.materialTreeSheet.name("materialTreeSheet");
  150. if (projectReadOnly && this.materialSetting.view.lockColumns) {
  151. if (this.materialSetting.view.lockColumns) {
  152. this.materialSetting.view.lockColumns = null;
  153. }
  154. }
  155. },
  156. createMaterialTreeSheetSetting: function () {
  157. return sheetCommonObj.transferToTreeSetting(this.materialSetting, this.materialTreeSetting);
  158. },
  159. unitPriceFileInit: function () {
  160. let me = this;
  161. let projectGLJ = projectObj.project.projectGLJ;
  162. let data = projectGLJ.datas;
  163. me.usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
  164. me.usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ? data.constData.usedUnitPriceInfo : {};
  165. $("#current-name").text(me.usedUnitPriceInfo.name);
  166. let usedCount = me.usedTenderList.length <= 0 ? 1 : me.usedTenderList.length;
  167. $("#used-project-count").text(usedCount);
  168. $("#editUnitFile").attr("href", `/unitPrice/index/${me.usedUnitPriceInfo.id}`);
  169. },
  170. getUsedTenderInfo: function () {
  171. return "人材机单价的变化,将自动影响以下单位工程造价:<br>" + projectGljObject.usedTenderList.join("<br>");
  172. },
  173. filterLibGLJForMixRatio: function () {
  174. let me = this;
  175. if (me.selectedProjectGLJ) {
  176. let showTypes = [];
  177. if (me.selectedProjectGLJ.type == gljType.MAIN_MATERIAL) {
  178. //对于主材,只显示没有组成物并且除了自已的主材
  179. showTypes = [gljType.MAIN_MATERIAL];
  180. } else if (_.includes(gljUtil.hasCompMaterial, me.selectedProjectGLJ.type)) {
  181. //混凝土、砂浆、配合比
  182. showTypes = [gljType.GENERAL_MATERIAL];
  183. } else if (_.includes(gljUtil.hasCompMachine, me.selectedProjectGLJ.type)) {
  184. //me.selectedProjectGLJ.type == gljType.GENERAL_MACHINE//机械中有组成物的类型
  185. showTypes = gljUtil.machineComposition;
  186. }
  187. gljOprObj.gljLibSheetData = _.filter(gljOprObj.gljLibSheetData, function (item) {
  188. if (me.selectedProjectGLJ.type == gljType.MAIN_MATERIAL) {
  189. let p_index = gljOprObj.getIndex(me.selectedProjectGLJ, gljKeyArray);
  190. let i_index = gljOprObj.getIndex(item, gljLibKeyArray);
  191. return item.gljType == gljType.MAIN_MATERIAL && item.component.length == 0 && p_index != i_index;
  192. } else {
  193. return _.includes(showTypes, item.gljType);
  194. }
  195. });
  196. }
  197. },
  198. addMixRatio: async function () {
  199. let me = this,
  200. projectGLJ = projectObj.project.projectGLJ;
  201. for (let mix of me.mixRatioData) {
  202. let m_key = gljUtil.getIndex(mix);
  203. _.remove(gljOprObj.GLJSelection, (n) => {
  204. return m_key == n;
  205. });
  206. }
  207. await me.addMixRatioFromLib(gljOprObj.GLJSelection, () => {
  208. me.showMixRatioData(); //这里添加的组成物的消耗量默认都是0,所以对父工料机的价格不会有影响,不用触发计算
  209. projectGLJ.loadData(function () {
  210. me.showProjectGljData();
  211. gljOprObj.showRationGLJSheetData();
  212. me.onUnitFileChange(me.selectedProjectGLJ);
  213. });
  214. });
  215. },
  216. addMixRatioFromLib: async function (selections, callback) {
  217. let gljList = [],
  218. allGLJ = gljOprObj.AllRecode;
  219. let url = "/glj/add-ratio";
  220. let result = null;
  221. if (selections.length == 0) {
  222. return;
  223. }
  224. try {
  225. for (let glj of allGLJ) {
  226. let i_key = gljUtil.getIndex(glj, gljLibKeyArray);
  227. if (_.includes(selections, i_key)) {
  228. let pglj = {
  229. glj_id: glj.ID,
  230. name: glj.name,
  231. code: glj.code,
  232. original_code: glj.code,
  233. unit: glj.unit,
  234. specs: glj.specs,
  235. base_price: glj.basePrice,
  236. market_price: glj.basePrice,
  237. shortName: glj.shortName,
  238. type: glj.gljType,
  239. model: glj.model,
  240. adjCoe: glj.adjCoe,
  241. from: "std",
  242. repositoryId: glj.repositoryId,
  243. materialType: glj.materialType,
  244. materialCoe: glj.materialCoe,
  245. grossWeightCoe: glj.grossWeightCoe,
  246. purchaseStorageRate: glj.purchaseStorageRate,
  247. offSiteTransportLossRate: glj.offSiteTransportLossRate,
  248. handlingLossRate: glj.handlingLossRate,
  249. };
  250. if (typeof projectObj !== "undefined") pglj.project_id = projectObj.project.ID();
  251. if (glj.hasOwnProperty("compilationId")) {
  252. pglj.from = "cpt";
  253. if (glj.code.indexOf("-") != -1) {
  254. //这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  255. pglj.original_code = glj.code.split("-")[0]; //取-前的编号作为原始编号
  256. }
  257. }
  258. gljList.push(pglj);
  259. }
  260. }
  261. gljList = _.sortByAll(gljList, ["type", "code"]);
  262. if (gljList.length == 0) return;
  263. let parentInfo = {};
  264. if (typeof unitPriceObj !== "undefined") {
  265. url = "/unitPrice/addMixRatio";
  266. pdata = unitPriceObj.getSelectedUnitPrice();
  267. parentInfo = {
  268. unit_price_file_id: pdata.unit_price_file_id,
  269. connect_key: gljUtil.getIndex(pdata),
  270. };
  271. } else {
  272. parentInfo = {
  273. unit_price_file_id: projectObj.project.property.unitPriceFile.id,
  274. connect_key: gljOprObj.getIndex(projectGljObject.selectedProjectGLJ, gljKeyArray),
  275. };
  276. }
  277. $.bootstrapLoading.start();
  278. result = await ajaxPost(url, { gljList: gljList, parentInfo: parentInfo });
  279. if (callback) callback(result);
  280. } catch (error) {
  281. alert(error);
  282. console.log(error);
  283. }
  284. $.bootstrapLoading.end();
  285. return result;
  286. },
  287. showMixRatioData: function () {
  288. let me = this,
  289. gljId = null,
  290. gljType = null;
  291. if (!$("#mixRatio-nav").hasClass("active")) return;
  292. me.mixRatioSpread.setActiveSheetIndex(0);
  293. let oldSel = me.mixRatioSheet.getSelections()[0];
  294. let projectGLJData = me.getProjectGLJSelected();
  295. if (projectGLJData) {
  296. gljId = projectGLJData.id;
  297. gljType = projectGLJData.type;
  298. }
  299. if (compositionTypes.indexOf(gljType) == -1) {
  300. //如果不是有组成物的类型,工料机id设置为空,组成物表设置为空
  301. gljId = null;
  302. }
  303. projectObj.project.projectGLJ.getRatioData(gljId, function (data) {
  304. if (gljId !== projectObj.project.projectGLJ.getRatioId) {
  305. //两个id不一致说明不是最新的请求,不用往下执行。
  306. return;
  307. }
  308. let ratioList = [];
  309. for (let glj of data) {
  310. ratioList.push(me.getMixRatioSheetData(glj));
  311. }
  312. ratioList = gljUtil.sortMixRatio(ratioList);
  313. me.mixRatioData = ratioList;
  314. me.mixRatioSheet.setRowCount(0);
  315. sheetCommonObj.showData(me.mixRatioSheet, me.mixRatioSetting, me.mixRatioData);
  316. me.mixRatioSheet.setRowCount(me.mixRatioData.length);
  317. me.mixRatioSheet.setSelection(oldSel.row == -1 ? 0 : oldSel.row, oldSel.col, oldSel.rowCount, oldSel.colCount);
  318. });
  319. },
  320. showRelatedRationDatas: function () {
  321. let me = this;
  322. if (!$("#ration-nav").hasClass("active")) return;
  323. me.mixRatioSpread.setActiveSheetIndex(1);
  324. let projectGLJData = me.getProjectGLJSelected();
  325. let rationIDMap = {};
  326. let rations = [];
  327. if (projectGLJData) {
  328. for (let rg of projectObj.project.ration_glj.datas) {
  329. if (rg.projectGLJID == projectGLJData.id) rationIDMap[rg.rationID] = true;
  330. }
  331. for (let r of projectObj.project.Ration.datas) {
  332. if (rationIDMap[r.ID] || (r.type == rationType.gljRation && r.projectGLJID == projectGLJData.id)) {
  333. let billNode = projectObj.project.mainTree.findNode(r.billsItemID); ////如果定额工料的父项没有找到,则忽略
  334. if (!billNode) continue;
  335. rations.push(r);
  336. }
  337. }
  338. }
  339. this.relatedRationSheetData = rations;
  340. sheetCommonObj.showData(me.relatedRationSheet, me.relatedRationSetting, rations);
  341. me.relatedRationSheet.setRowCount(rations.length);
  342. },
  343. getMixRatioSheetData: function (glj) {
  344. let data = {
  345. id: glj.id,
  346. mix_ratio_id: glj.ratio_data.id,
  347. code: glj.code,
  348. name: glj.name,
  349. specs: glj.specs,
  350. unit: glj.unit,
  351. type: glj.type,
  352. short_name: projectObj.project.projectGLJ.getShortNameByID(glj.type),
  353. consumption: glj.ratio_data.consumption,
  354. unit_price: glj.unit_price,
  355. connect_key: glj.ratio_data.connect_key,
  356. };
  357. gljOprObj.setGLJPrice(data, glj);
  358. return data;
  359. },
  360. onProjectGljEditStarting: function (sender, args) {
  361. let me = projectGljObject;
  362. let row = args.row;
  363. let col = args.col;
  364. if (me.projectGljEditChecking(row, col) == false) {
  365. args.cancel = true;
  366. }
  367. },
  368. projectGljEditChecking: function (row, col, isPaste = false) {
  369. //return false表示不能编辑
  370. let me = projectGljObject;
  371. let data = null,
  372. setting = null;
  373. let sheet = me.projectGljSpread.getActiveSheet();
  374. if (sheet.name() == "projectGljSheet") {
  375. if (row >= me.projectGljSheetData.length) return false;
  376. data = me.projectGljSheetData[row];
  377. setting = me.projectGljSetting;
  378. } else if (sheet.name() == "materialTreeSheet") {
  379. data = me.materialTree.selected.data;
  380. setting = me.materialSetting;
  381. let notEditId = ["GC", "GJ", "MC", "SN", "SZ"];
  382. if (notEditId.indexOf(data.id) != -1) {
  383. return false;
  384. }
  385. }
  386. let dataCode = setting.header[col].dataCode;
  387. let lockColumns = setting.view.lockColumns;
  388. if (lockColumns.indexOf(col) != -1) {
  389. return false;
  390. }
  391. if (isPaste == false && (dataCode == "is_adjust_price" || dataCode == "is_evaluate" || dataCode == "is_main_material" || dataCode == "is_eval_material")) {
  392. //除了粘贴,拖动填充等操作,其它的都不能编辑
  393. return false;
  394. }
  395. if (dataCode == "basePrice" || dataCode == "marketPrice" || dataCode == "supply") {
  396. //有组成物时,市场单价、定额价、供货方式不能修改
  397. if ((dataCode == "basePrice" || dataCode == "marketPrice") && gljUtil.isConcreteType(data.type)) {
  398. //混凝土,浆砂,配合比,不能修改市场单价,定额价
  399. return false;
  400. }
  401. if (data.ratio_data && data.ratio_data.length > 0) {
  402. return false;
  403. }
  404. if (dataCode == "basePrice" && data.is_add != 1) {
  405. //如果不是新增,定额价不可修改。
  406. return false;
  407. }
  408. if (dataCode == "marketPrice" && data.calcMaterial == 1) return false; //有材料计算时不能修改
  409. }
  410. if (dataCode == "supply_quantity") {
  411. if (data.supply != 1) {
  412. // 如果为部分甲供则甲供数量需要可编辑,其它的都不能编辑
  413. return false;
  414. }
  415. }
  416. if (dataCode == "materialCoe") {
  417. //三材类别为空时,三材系数应只读,不允许输入。
  418. if (data.materialType == undefined || data.materialType == null || data.materialType == "") {
  419. return false;
  420. }
  421. }
  422. return true;
  423. },
  424. onSelectionChange: function () {
  425. let me = projectGljObject;
  426. me.showMixRatioData();
  427. me.materialTreeSheet.repaint();
  428. },
  429. onProjectGljDoubleClick: function (sender, args) {
  430. let me = projectGljObject;
  431. let recode = me.projectGljSheetData[args.row];
  432. let dataCode = me.projectGljSetting.header[args.col].dataCode;
  433. if (dataCode == "name" && recode && gljUtil.isMaterialType(recode.type)) projectObj.project.projectGLJ.updateCalcMaterial(recode, 1);
  434. },
  435. onRelatedRationDoubleClick: function (sender, args) {
  436. let me = projectGljObject;
  437. let record = me.relatedRationSheetData[args.row];
  438. $("#tab_zaojiashu").click();
  439. locateObject.locateNode(record.ID);
  440. },
  441. setSelectionWhenMaterialChange: function (material) {
  442. if (material) {
  443. let i = _.findIndex(this.projectGljSheetData, { id: material.id });
  444. if (i != -1) {
  445. let os = this.projectGljSheet.getSelections();
  446. let ns = [{ col: os[0].col, colCount: 1, row: i, rowCount: 1 }];
  447. this.projectGljSheet.setSelection(ns[0].row, ns[0].col, ns[0].rowCount, ns[0].colCount);
  448. this.projectGljSheet.showRow(i, GC.Spread.Sheets.VerticalPosition.center);
  449. this.onProjectGljSelectionChange({}, { newSelections: ns, oldSelections: os }, true);
  450. }
  451. }
  452. },
  453. onProjectGljSelectionChange: function (sender, args, fromMaterial = false) {
  454. let me = projectGljObject;
  455. console.log(args);
  456. let newSel = args.newSelections[0];
  457. let oldSel = args.oldSelections ? args.oldSelections[0] : {};
  458. me.projectGljSheet.suspendPaint();
  459. me.projectGljSheet.suspendEvent();
  460. if (newSel.row != oldSel.row) {
  461. let style = gljOprObj.getSelStyle(true, {});
  462. me.projectGljSheet.setStyle(newSel.row, -1, style);
  463. let orow = oldSel.row == "" || oldSel.row == -1 ? 0 : oldSel.row;
  464. if (me.projectGljSheetData[orow]) {
  465. let tstyle = gljOprObj.getSelStyle(false, {}, me.projectGljSheetData[orow].bgColour);
  466. me.projectGljSheet.setStyle(orow, -1, tstyle);
  467. me.projectGljRowChang(fromMaterial);
  468. }
  469. } else {
  470. me.projectGljSheet.repaint();
  471. }
  472. me.projectGljSheet.resumeEvent();
  473. me.projectGljSheet.resumePaint();
  474. },
  475. projectGljRowChang: function (fromMaterial) {
  476. let me = projectGljObject;
  477. let sel = me.mixRatioSheet.getSelections()[0];
  478. sel.row = -1;
  479. sel.col = 0;
  480. sel.rowCount = 1;
  481. sel.colCount = 1;
  482. me.showMixRatioData();
  483. me.showRelatedRationDatas();
  484. if (fromMaterial != true) materialCalcObj.showDatas();
  485. },
  486. rightClickCallback: function (row) {
  487. let me = projectGljObject;
  488. let sheet = me.projectGljSpread.getActiveSheet();
  489. if (sheet.name() == "projectGljSheet") {
  490. me.projectGljRowChang(row);
  491. } else if (sheet.name() == "materialTreeSheet") {
  492. me.materialTreeController.setTreeSelected(me.materialTreeController.tree.items[row]);
  493. }
  494. },
  495. onProjectGljRangeChange: function (sender, info) {
  496. let me = projectGljObject;
  497. let changeInfo = [];
  498. let canChange = true;
  499. if (info.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  500. if (me.projectGljEditChecking(info.row, info.col) == false) {
  501. canChange = false;
  502. } else {
  503. info.newValue = null;
  504. me.onProjectGLJValueChange(sender, info);
  505. return;
  506. }
  507. }
  508. for (let c of info.changedCells) {
  509. let value = info.sheet.getCell(c.row, c.col).text();
  510. changeInfo.push({ row: c.row, col: c.col, value: value });
  511. if (me.projectGljEditChecking(c.row, c.col, true) == false) {
  512. //如果不能编辑
  513. canChange = false;
  514. break;
  515. }
  516. if (!me.checkData(c.col, me.projectGljSetting, value)) {
  517. alert("输入的数据类型不对,请重新输入!");
  518. canChange = false;
  519. break;
  520. }
  521. }
  522. if (canChange == false) {
  523. //恢复原来的值
  524. info.sheetName == "materialTreeSheet" ? me.showMaterialTreeData() : me.showProjectGljData();
  525. } else if (info.sheetName == "projectGljSheet") {
  526. me.batchUpdateProjectGLJ(changeInfo, info.sheetName);
  527. }
  528. },
  529. onMixRatioEditStarting: function (sender, info) {
  530. let me = projectGljObject,
  531. row = info.row,
  532. col = info.col;
  533. let parentSheet = me.projectGljSpread.getActiveSheet();
  534. let prow = parentSheet.getActiveRowIndex(); //取父机械或组成物的下标
  535. let prowData = parentSheet.name() == "projectGljSheet" ? me.projectGljSheetData[prow] : me.materialTree.items[prow].data;
  536. console.log(prowData);
  537. if (gljUtil.isConcreteType(prowData.type)) info.cancel = true;
  538. },
  539. onMixRatioRangeChange: function (sender, info) {
  540. let me = projectGljObject;
  541. let canChange = true;
  542. let changeInfo = [];
  543. /* if (info.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  544. info.newValue = 0;
  545. me.onMixRatioValueChange(sender,info);
  546. info.sheet.getCell(info.row, info.col).text(0);
  547. return ;
  548. } */
  549. for (let c of info.changedCells) {
  550. let value = info.sheet.getCell(c.row, c.col).text();
  551. if (_.isEmpty(value)) value = 0;
  552. if (!me.checkData(c.col, me.mixRatioSetting, value)) {
  553. alert("输入的数据类型不对,请重新输入!");
  554. canChange = false;
  555. break;
  556. } else {
  557. changeInfo.push({ row: c.row, col: c.col, value: value });
  558. }
  559. }
  560. if (canChange == false) me.showMixRatioData(); //数据类型不对
  561. if (changeInfo.length > 0) me.batchUpdateConsumption(changeInfo);
  562. },
  563. batchUpdateProjectGLJ: function (changeInfo, sheetName) {
  564. let projectGLJ = projectObj.project.projectGLJ;
  565. let me = projectGljObject;
  566. let propertyCells = [],
  567. priceCells = [];
  568. let setting = sheetName == "materialTreeSheet" ? me.materialSetting : me.projectGljSetting;
  569. for (let c of changeInfo) {
  570. c.dataCode = setting.header[c.col].dataCode;
  571. if (c.dataCode == "basePrice" || c.dataCode == "marketPrice") {
  572. priceCells.push(c);
  573. } else {
  574. propertyCells.push(c);
  575. }
  576. }
  577. me.batchUpdateGLJProperty(propertyCells, sheetName, function () {
  578. //价格属于单价文件表,如果与项目工料机的其它属性一起的话计算起来会比较复杂,同时出现价格与其它属性一起更新的情况也会比较少;
  579. projectGLJ.batchUpdatePrice(priceCells, sheetName, function (impactList) {
  580. me.refreshBySheetName(sheetName);
  581. gljOprObj.refreshView();
  582. });
  583. });
  584. },
  585. refreshBySheetName: function (sheetName) {
  586. let me = projectGljObject;
  587. if (sheetName == "projectGljSheet") {
  588. me.showProjectGljData();
  589. } else if (sheetName == "materialTreeSheet") {
  590. me.showMaterialTreeData();
  591. }
  592. },
  593. batchUpdateGLJProperty: function (changeInfo, sheetName, callback) {
  594. let me = projectGljObject,
  595. updateMap = {};
  596. let projectGLJ = projectObj.project.projectGLJ;
  597. for (let c of changeInfo) {
  598. let recode = sheetName == "materialTreeSheet" ? me.materialTree.items[c.row].data : me.projectGljSheetData[c.row];
  599. if (recode[c.dataCode] == c.value) {
  600. continue;
  601. }
  602. me.getUpdateData(recode.id, c.value, c.dataCode, recode.quantity, updateMap);
  603. }
  604. if (_.isEmpty(updateMap)) {
  605. callback ? callback() : "";
  606. return;
  607. }
  608. projectGLJ.batchUpdateGLJProperty(updateMap, callback);
  609. },
  610. getUpdateData: function (id, value, dataCode, quantity, updateMap) {
  611. let me = projectGljObject;
  612. let supplyMap = { 自行采购: 0, 部分甲供: 1, 完全甲供: 2, 甲定乙供: 3 };
  613. let materialMap = { 钢材: 1, 钢筋: 2, 木材: 3, 水泥: 4, 标准砖: 5 };
  614. let data = updateMap[id] ? updateMap[id] : {};
  615. //供货方式 和三材类型 粘贴和填充过来的数据,要做对应转换,因为这里value只是中文文本,并不是实际的值
  616. // 如果是供货方式则需要处理数据
  617. if (dataCode === "supply") {
  618. if (supplyMap[value] !== undefined || supplyMap[value] !== null) {
  619. value = supplyMap[value];
  620. }
  621. data.supply_quantity = me.getSupplyQuantity(value, quantity);
  622. }
  623. if (dataCode === "supply_quantity") {
  624. //修改数量需做4舍5入
  625. value = scMathUtil.roundForObj(value, getDecimal("glj.quantity"));
  626. }
  627. if (dataCode === "is_evaluate" || dataCode === "is_adjust_price" || dataCode === "is_main_material") {
  628. value = value ? 1 : 0;
  629. }
  630. if (dataCode === "materialType") {
  631. //三材类型要做对应转换,因为这里value只是中文文本,并不是实际的值
  632. if (materialMap[value] !== undefined || materialMap[value] !== null) {
  633. value = materialMap[value];
  634. }
  635. if (value == null || value == "") {
  636. //删除三材类别时,清空三材系数
  637. value = null;
  638. data.materialCoe = null;
  639. }
  640. }
  641. if (dataCode == "materialCoe") {
  642. value = scMathUtil.roundForObj(value, getDecimal("material"));
  643. }
  644. data[dataCode] = value;
  645. updateMap[id] = data;
  646. },
  647. batchUpdateConsumption: function (changeInfo) {
  648. let projectGLJ = projectObj.project.projectGLJ;
  649. let me = projectGljObject;
  650. let updateMap = {},
  651. updateData = [],
  652. parentBasePrice = 0,
  653. parentMarketPrice = 0;
  654. let parentKey = "",
  655. unit_price_file_id = null;
  656. for (let c of changeInfo) {
  657. let record = me.mixRatioData[c.row];
  658. let value = scMathUtil.roundForObj(c.value, getDecimal("glj.quantity"));
  659. updateMap[record.mix_ratio_id] = { consumption: value, record: record };
  660. updateData.push({ type: "mix_ratio", query: { id: record.mix_ratio_id }, doc: { consumption: value } });
  661. parentKey = record.connect_key;
  662. unit_price_file_id = record.unit_price.unit_price_file_id;
  663. }
  664. if (!gljUtil.isConcreteType(parseInt(parentKey.split("|-|")[4]))) {
  665. //父类型不属于混凝土浆砂配合比,才要计算
  666. for (let sub of me.mixRatioData) {
  667. let marketPrice = scMathUtil.roundForObj(sub.unit_price.market_price, getDecimal("process"));
  668. let basePrice = scMathUtil.roundForObj(sub.unit_price.base_price, getDecimal("process"));
  669. let consumption = updateMap[sub.mix_ratio_id]
  670. ? updateMap[sub.mix_ratio_id].consumption
  671. : scMathUtil.roundForObj(sub.consumption, getDecimal("glj.quantity"));
  672. parentMarketPrice = scMathUtil.roundForObj(marketPrice * consumption + parentMarketPrice, getDecimal("process"));
  673. // parentBasePrice = scMathUtil.roundForObj(basePrice*consumption + parentBasePrice,getDecimal("process"));
  674. }
  675. }
  676. // parentBasePrice = scMathUtil.roundForObj(parentBasePrice,getDecimal("glj.unitPrice"));
  677. parentMarketPrice = scMathUtil.roundForObj(parentMarketPrice, getDecimal("glj.unitPrice"));
  678. let parentData = me.getProjectGLJSelected();
  679. if (parentData) {
  680. //计算受影响的综合电价
  681. let ext = {};
  682. ext[parentData.id] = { marketPrice: parentMarketPrice };
  683. let elecP = electrovalenceObj.clacNewElecPrice(ext);
  684. if (elecP) {
  685. updateData.push({ type: "unitPrice", projectGLJID: elecP.projectGLJID, query: { id: elecP.id }, doc: elecP.doc });
  686. }
  687. updateData.push({
  688. type: "unitPrice",
  689. isParent: true,
  690. projectGLJID: parentData.id,
  691. query: { id: parentData.unit_price.id },
  692. doc: { market_price: parentMarketPrice },
  693. }); //base_price:parentBasePrice,
  694. }
  695. // updateData.push({type:'parent',connect_key:parentKey,base_price:parentBasePrice,market_price:parentMarketPrice,unit_price_file_id:unit_price_file_id});
  696. projectGLJ.batchUpdateConsumption(updateData, updateMap, async function () {
  697. //更新人材机汇总表
  698. me.refreshDataSheet();
  699. let materialGljList = await projectGLJ.calcAllMaterialWhenChange();
  700. if (materialGljList.length == 0) me.onUnitFileChange(true);
  701. gljOprObj.refreshView();
  702. });
  703. },
  704. showProjectGljData: function () {
  705. let me = this;
  706. this.projectGljSpread.setActiveSheetIndex(0);
  707. let sel = this.projectGljSheet.getSelections()[0];
  708. let oldData = sel.row < this.projectGljSheetData.length ? this.projectGljSheetData[sel.row] : "";
  709. let projectGljSheetData = [];
  710. let gljList = projectObj.project.projectGLJ.datas.gljList;
  711. gljList = this.filterProjectGLJ(gljList);
  712. gljList = sortProjectGLJ(gljList);
  713. for (let glj of gljList) {
  714. projectGljSheetData.push(this.getSheetDataByGLJ(glj));
  715. }
  716. this.projectGljSheetData = projectGljSheetData;
  717. this.projectGljSheet.setRowCount(this.projectGljSheetData.length);
  718. sheetCommonObj.showData(this.projectGljSheet, this.projectGljSetting, this.projectGljSheetData, null, function () {
  719. //this.projectGljSheet.setRowCount(this.projectGljSheetData.length);
  720. sel.row = oldData ? _.findIndex(me.projectGljSheetData, { id: oldData.id }) : 0;
  721. me.projectGljSheet.setSelection(sel.row == -1 ? 0 : sel.row, sel.col, sel.rowCount, sel.colCount);
  722. });
  723. },
  724. showMaterialTreeData: function () {
  725. this.projectGljSpread.setActiveSheetIndex(1);
  726. let sel = this.materialTreeSheet.getSelections()[0];
  727. let oldNodeID = this.materialTree.selected ? this.materialTree.selected.data.id : "";
  728. let gljList = projectObj.project.projectGLJ.datas.gljList;
  729. gljList = _.sortByAll(gljList, ["code"]);
  730. this.createMaterialTree(gljList);
  731. this.materialTreeController.showTreeData();
  732. let newNode = this.materialTree.getNodeByID(oldNodeID);
  733. sel.row = newNode ? newNode.serialNo() : -1;
  734. this.materialTreeSheet.setSelection(sel.row == -1 ? 0 : sel.row, sel.col, sel.rowCount, sel.colCount);
  735. this.materialTreeController.setTreeSelected(this.materialTree.items[sel.row == -1 ? 0 : sel.row]);
  736. },
  737. initSheetViews() {
  738. let me = projectGljObject;
  739. if (me.displayType == filterType.ZGCL || me.displayType == filterType.PBCL) {
  740. configMaterialObj.setNavLinkText(me.displayType);
  741. $("#project-glj-main").hide();
  742. $("#config_material").show();
  743. } else {
  744. $("#config_material").hide();
  745. $("#project-glj-main").show();
  746. }
  747. },
  748. refreshViewsData: function () {
  749. let me = projectGljObject;
  750. if (me.displayType == filterType.ZGCL || me.displayType == filterType.PBCL) return configMaterialObj.refreshSheetDatas();
  751. me.refreshDataSheet();
  752. },
  753. refreshDataSheet: function (refresh) {
  754. //refresh = true 的时候不用更新表头信息
  755. let me = projectGljObject;
  756. if (!me.projectGljSpread) return;
  757. if (!refresh) {
  758. let quantityCol = _.findIndex(me.projectGljSetting.header, function (header) {
  759. return header.dataCode == "quantity" || header.dataCode == "techQuantity" || header.dataCode == "subdivisionQuantity";
  760. });
  761. if (me.displayType == filterType.FBFX) {
  762. //分部分项人材机,将“总消耗量”替换显示为“分部分项总消耗量”。
  763. me.projectGljSetting.header[quantityCol].dataCode = "subdivisionQuantity";
  764. if (me.projectGljSheet) me.projectGljSheet.setValue(0, quantityCol, "分部分项总消耗量", GC.Spread.Sheets.SheetArea.colHeader);
  765. } else if (me.displayType == filterType.TECH) {
  766. //措施项目人材机,将“总消耗量”替换显示为“措施项目总消耗量”。
  767. me.projectGljSetting.header[quantityCol].dataCode = "techQuantity";
  768. if (me.projectGljSheet) me.projectGljSheet.setValue(0, quantityCol, "措施项目总消耗量", GC.Spread.Sheets.SheetArea.colHeader);
  769. } else {
  770. me.projectGljSetting.header[quantityCol].dataCode = "quantity";
  771. if (me.projectGljSheet) me.projectGljSheet.setValue(0, quantityCol, "总消耗量", GC.Spread.Sheets.SheetArea.colHeader);
  772. }
  773. }
  774. if (me.displayType == filterType.SCHZ) {
  775. //三材汇总树节点
  776. me.showMaterialTreeData();
  777. } else {
  778. me.showProjectGljData();
  779. me.showMixRatioData();
  780. me.showRelatedRationDatas();
  781. }
  782. },
  783. createMaterialTree: function (gljList) {
  784. let me = projectGljObject;
  785. let q_decimal = getDecimal("glj.quantity");
  786. let GC = { id: "GC", name: materialType[materialTypeMap.GC], code: "GC", unit: "t", ParentID: -1, NextSiblingID: "MC" };
  787. let GJ = { id: "GJ", name: materialType[materialTypeMap.GJ], code: "GJ", unit: "t", ParentID: "GC", NextSiblingID: -1 };
  788. let MC = { id: "MC", name: materialType[materialTypeMap.MC], code: "MC", unit: "m3", ParentID: -1, NextSiblingID: "SN" };
  789. let SN = { id: "SN", name: materialType[materialTypeMap.SN], code: "SN", unit: "t", ParentID: -1, NextSiblingID: "SZ" };
  790. let SZ = { id: "SZ", name: materialType[materialTypeMap.SZ], code: "BZZ", unit: "千块", ParentID: -1, NextSiblingID: -1 };
  791. let rootDatas = [GC, GJ, MC, SN, SZ];
  792. let parentMap = {};
  793. let sumMap = {};
  794. (this.materialTree.nodes = {}), (this.materialTree.selected = null), (this.materialTree.roots = []), (this.materialTree.items = []);
  795. for (let r of rootDatas) {
  796. let baseNode = null;
  797. if (r.id == "GJ") {
  798. baseNode = createMaterialNode(r, parentMap["GC"], null); //钢筋的父节点为钢材
  799. } else {
  800. baseNode = createMaterialNode(r, null, null);
  801. }
  802. parentMap[r.id] = baseNode;
  803. }
  804. for (let g of gljList) {
  805. if (g.quantity !== 0 && g.quantity !== "0") {
  806. if (g.materialType) {
  807. let tem = me.getMaterialSheetDataByGLJ(g);
  808. if (tem.materialQuantity) {
  809. sumMap[g.materialType] = sumMap[g.materialType] ? sumMap[g.materialType] + tem.materialQuantity : tem.materialQuantity;
  810. tem.materialQuantity = scMathUtil.roundToString(tem.materialQuantity, q_decimal); //转成string
  811. }
  812. if (g.materialType == materialTypeMap.GC) {
  813. //钢材的下一节点是钢筋
  814. createMaterialNode(tem, parentMap["GC"], parentMap["GJ"]);
  815. } else {
  816. createMaterialNode(tem, parentMap[materialTypeMap[g.materialType]]);
  817. }
  818. }
  819. }
  820. }
  821. for (let mkey in sumMap) {
  822. if (mkey == materialTypeMap.GC && sumMap[materialTypeMap.GJ]) {
  823. //钢材汇总要加上钢筋的总量
  824. parentMap["GC"].data.materialQuantity = scMathUtil.roundToString(sumMap[mkey] + sumMap[materialTypeMap.GJ], q_decimal);
  825. } else {
  826. parentMap[materialTypeMap[mkey]].data.materialQuantity = scMathUtil.roundToString(sumMap[mkey], q_decimal);
  827. }
  828. }
  829. this.materialTree.sortTreeItems();
  830. function createMaterialNode(data, parent, next) {
  831. let newNode = me.materialTree.addNode(parent, next, data.id);
  832. newNode.data = data;
  833. return newNode;
  834. }
  835. },
  836. getMaterialSheetDataByGLJ: function (glj) {
  837. let q_decimal = getDecimal("glj.quantity");
  838. let m_decimal = getDecimal("material");
  839. let p_decimal = getDecimal("glj.unitPrice");
  840. let projectGLJ = projectObj.project.projectGLJ;
  841. let data = {
  842. id: glj.id,
  843. code: glj.code,
  844. name: glj.name,
  845. specs: glj.specs,
  846. unit: glj.unit,
  847. type: glj.type,
  848. short_name: projectGLJ.getShortNameByID(glj.type),
  849. quantity: scMathUtil.roundToString(glj.quantity, q_decimal),
  850. supply: glj.supply,
  851. supply_quantity: glj.supply_quantity,
  852. materialType: glj.materialType,
  853. delivery: glj.delivery,
  854. delivery_address: glj.delivery_address,
  855. is_adjust_price: glj.is_adjust_price,
  856. ratio_data: glj.ratio_data,
  857. is_add: glj.unit_price.is_add,
  858. bgColour: "white",
  859. };
  860. if (glj.materialCoe) {
  861. data.materialCoe = scMathUtil.roundForObj(glj.materialCoe, m_decimal);
  862. data.materialQuantity = scMathUtil.roundForObj(glj.materialCoe * glj.quantity, q_decimal); //还要做汇总,汇总完再转成string
  863. }
  864. gljOprObj.setGLJPrice(data, glj);
  865. data.basePrice = scMathUtil.roundToString(data.basePrice, p_decimal);
  866. data.marketPrice = scMathUtil.roundToString(data.marketPrice, p_decimal);
  867. return data;
  868. },
  869. filterProjectGLJ: function (gljList) {
  870. let me = projectGljObject;
  871. if (gljList.length > 0) {
  872. gljList = _.filter(gljList, function (item) {
  873. return me.displayTypeFilter(item);
  874. });
  875. }
  876. return gljList;
  877. },
  878. displayTypeFilter: function (item) {
  879. let me = this;
  880. if (item.quantity !== 0 && item.quantity !== "0") {
  881. //过滤掉消耗量为0的工料机
  882. if (me.displayType == filterType.ALL) {
  883. //所有工料机
  884. return true;
  885. } else if (filterTypeArray.indexOf(me.displayType) != -1) {
  886. //人工、材料、机械、主材、设备
  887. let typeString = item.type + "";
  888. return typeString.startsWith(me.displayType);
  889. } else if (me.displayType == filterType.FBFX) {
  890. //“分部分项总消耗量”≠0的工料机行
  891. return item.subdivisionQuantity !== 0 && item.subdivisionQuantity !== "0";
  892. } else if (me.displayType == filterType.TECH) {
  893. //筛选“措施项目总消耗量”≠0的工料机行
  894. return item.techQuantity !== 0 && item.techQuantity !== "0";
  895. } else if (me.displayType == filterType.JGCL) {
  896. //筛选“供货方式”=“完全甲供”或“部分甲供”的工料机行
  897. return item.supply == supplyType.WQJG || item.supply == supplyType.BFJG;
  898. } else if (me.displayType == filterType.ZGCL) {
  899. //筛选“是否暂估”=“是”的工料机行。
  900. return item.is_evaluate == 1;
  901. } else if (me.displayType == filterType.ZYCL) {
  902. //筛选“主要材料”=“是”的工料机行。
  903. return item.is_main_material == 1;
  904. }
  905. }
  906. return false;
  907. },
  908. getSheetDataByGLJ: function (glj) {
  909. let projectGLJ = projectObj.project.projectGLJ;
  910. let materialIdList = projectGLJ.datas.constData.materialIdList;
  911. let data = {
  912. id: glj.id,
  913. code: glj.code,
  914. name: glj.name,
  915. specs: glj.specs,
  916. unit: glj.unit,
  917. type: glj.type,
  918. short_name: projectGLJ.getShortNameByID(glj.type),
  919. quantity: glj.quantity,
  920. tenderQuantity: glj.tenderQuantity,
  921. supply: glj.supply,
  922. supply_quantity: glj.supply_quantity,
  923. materialType: glj.materialType,
  924. materialCoe: glj.materialCoe,
  925. grossWeightCoe: glj.grossWeightCoe,
  926. purchaseStorageRate: glj.purchaseStorageRate,
  927. offSiteTransportLossRate: glj.offSiteTransportLossRate,
  928. handlingLossRate: glj.handlingLossRate,
  929. delivery: glj.delivery,
  930. delivery_address: glj.delivery_address,
  931. is_adjust_price: glj.is_adjust_price,
  932. ratio_data: glj.ratio_data,
  933. unit_price: glj.unit_price,
  934. calcMaterial: glj.unit_price.calcMaterial,
  935. is_add: glj.unit_price.is_add,
  936. bgColour: "white",
  937. techQuantity: glj.techQuantity,
  938. subdivisionQuantity: glj.subdivisionQuantity,
  939. remark: glj.remark,
  940. };
  941. gljOprObj.setGLJPrice(data, glj);
  942. data.is_main_material = glj.is_main_material == 1 ? 1 : 0;
  943. //供货方式为完全甲供时设置甲供数量为总消耗量
  944. if (data.supply == 2) {
  945. data.supply_quantity = glj.quantity;
  946. }
  947. // 只有材料才显示是否暂估
  948. if (materialIdList.indexOf(glj.type) >= 0) {
  949. data.is_evaluate = glj.is_evaluate;
  950. }
  951. //是“材料”、“主材”、“设备”时显示评标材料
  952. if (materialIdList.indexOf(glj.type) >= 0 || glj.type == gljType.MAIN_MATERIAL || glj.type == gljType.EQUIPMENT)
  953. data.is_eval_material = glj.is_eval_material ? glj.is_eval_material : 0;
  954. if (glj.materialCoe !== null && glj.materialCoe !== undefined) {
  955. data.materialCoe = scMathUtil.roundForObj(glj.materialCoe, getDecimal("material"));
  956. }
  957. //bgColour
  958. if (data.basePrice == data.marketPrice) {
  959. //如果定额价等于市场价时,改底色。 优先度低于有组成物时的底色
  960. data.bgColour = "#C4CAFB";
  961. }
  962. if (gljUtil.notEditType.indexOf(glj.type) >= 0) {
  963. if (data.ratio_data && data.ratio_data.length > 0) {
  964. //有组成物时
  965. //设置底色
  966. data.bgColour = "#E0E0E0";
  967. }
  968. }
  969. if (gljUtil.isConcreteType(glj.type)) data.bgColour = "#E0E0E0"; //混凝土、砂浆、配合比的底色显示为 灰色#E0E0E0,灰色底色提醒用户不可修改。
  970. return data;
  971. },
  972. refreshProjectGljRow: function (row) {
  973. let me = projectGljObject;
  974. let rowData = me.projectGljSheetData[row];
  975. let glj = projectObj.project.projectGLJ.getByID(rowData.id);
  976. let newRow = null;
  977. if (glj) {
  978. newRow = me.getSheetDataByGLJ(glj);
  979. }
  980. if (me.displayTypeFilter(newRow) == true) {
  981. me.projectGljSheetData[row] = newRow;
  982. sheetCommonObj.showRowData(this.projectGljSheet, this.projectGljSetting, row, this.projectGljSheetData);
  983. } else {
  984. me.projectGljSheetData.splice(row, 1);
  985. me.projectGljSheet.deleteRows(row, 1);
  986. me.showMixRatioData();
  987. me.showRelatedRationDatas();
  988. }
  989. //me.projectGljSheetData[row] = me.getSheetDataByGLJ(glj);
  990. },
  991. initSheet: function (sheet, setting) {
  992. var me = this;
  993. sheetCommonObj.initSheet(sheet, setting, 30);
  994. sheet.bind(GC.Spread.Sheets.Events.ValueChanged, me.onSheetValueChange);
  995. },
  996. onSheetValueChange: function (e, info) {
  997. let me = projectGljObject;
  998. if (info.sheetName == "projectGljSheet") {
  999. me.onProjectGLJValueChange(e, info);
  1000. } else if (info.sheetName == "mixRatioSheet") {
  1001. me.onMixRatioValueChange(e, info);
  1002. }
  1003. },
  1004. onMixRatioValueChange: function (e, info) {
  1005. let composition = projectObj.project.composition;
  1006. let me = projectGljObject,
  1007. row = info.row,
  1008. col = info.col;
  1009. let dataCode = me.mixRatioSetting.header[col].dataCode;
  1010. let recode = me.mixRatioData[row];
  1011. let value = info.newValue;
  1012. let parentSheet = me.projectGljSpread.getActiveSheet(); //三材汇总表和工料机汇总表
  1013. if (!me.checkData(col, me.mixRatioSetting, value)) {
  1014. alert("输入的数据类型不对,请重新输入!");
  1015. me.mixRatioSheet.setValue(row, col, info.oldValue);
  1016. return false;
  1017. }
  1018. value = scMathUtil.roundToString(value, getDecimal("glj.quantity"));
  1019. me.batchUpdateConsumption([{ row: row, col: col, value }]);
  1020. },
  1021. onUnitFileChange: function (isInclude, changeMark = "unitFile") {
  1022. //include用来标计是否排除本身, true时,不排除本身
  1023. if (isInclude == true) projectObj.project.projectInfo.changeMark = changeMark; //项目单价文件修改标记
  1024. projectObj.project.markUpdateProject(
  1025. { projectID: projectObj.project.ID(), unitFileID: socketObject.getUnitFileRoomID(), isInclude: isInclude },
  1026. "unitFile",
  1027. function () {
  1028. //socket.emit('unitFileChangeNotify', JSON.stringify(data));
  1029. socket.emit("unitFileChangeNotify", { projectID: projectObj.project.ID(), userID: userID, unitFileID: socketObject.getUnitFileRoomID() });
  1030. }
  1031. );
  1032. },
  1033. deleteMixRatio: function (row) {
  1034. let me = this,
  1035. deleteRecode = me.mixRatioData[row];
  1036. let consumption = deleteRecode.consumption;
  1037. let [parentMarketPrice, parentBasePrice] = me.getCompositionSumPrice("delete", row);
  1038. let prowData = me.getProjectGLJSelected();
  1039. let updateData = { id: deleteRecode.mix_ratio_id, field: "mix_ratio.consumption", value: 0, market_price: parentMarketPrice, base_price: parentBasePrice };
  1040. let ext = {};
  1041. ext[prowData.id] = { marketPrice: parentMarketPrice };
  1042. updateData.parent = { query: { id: prowData.unit_price.id }, doc: { market_price: parentMarketPrice } };
  1043. let elecP = electrovalenceObj.clacNewElecPrice(ext);
  1044. if (elecP) {
  1045. updateData.unitPrice = { projectGLJID: elecP.projectGLJID, query: { id: elecP.id }, doc: elecP.doc };
  1046. }
  1047. projectObj.project.composition.deleteComposition(updateData, deleteRecode, prowData.id, function () {
  1048. _.remove(me.mixRatioData, { mix_ratio_id: deleteRecode.mix_ratio_id });
  1049. //me.refreshParentData(prow,prowData.id);
  1050. me.refreshDataSheet();
  1051. me.mixRatioSheet.deleteRows(row, 1);
  1052. me.onUnitFileChange(true);
  1053. });
  1054. },
  1055. getCompositionSumPrice: function (scene, affectRow, newValue = 0) {
  1056. let me = this;
  1057. let parentMarketPrice = 0;
  1058. let parentBasePrice = 0;
  1059. let parentKey = me.mixRatioData[affectRow].connect_key;
  1060. let parentType = parentKey.split("|-|")[4];
  1061. if (gljUtil.isConcreteType(parseInt(parentType))) return [0, 0]; //父工料机是混凝土浆砂,配合比,则父价格为0,不用计算
  1062. for (let i = 0; i < me.mixRatioData.length; i++) {
  1063. let ratio = me.mixRatioData[i];
  1064. let marketPrice = ratio.unit_price.market_price;
  1065. let basePrice = ratio.unit_price.base_price;
  1066. // 如果是删除则忽略即将被删除的行数据
  1067. if (scene === "delete" && affectRow === i) {
  1068. continue;
  1069. }
  1070. let consumption = i === affectRow ? newValue : ratio.consumption;
  1071. parentMarketPrice += operationWithRound(consumption, marketPrice, "glj.unitPrice", "*");
  1072. parentBasePrice += operationWithRound(consumption, basePrice, "glj.unitPrice", "*");
  1073. }
  1074. parentMarketPrice = parentMarketPrice.toDecimal(getDecimal("glj.unitPrice"));
  1075. parentBasePrice = parentBasePrice.toDecimal(getDecimal("glj.unitPrice"));
  1076. return [parentMarketPrice, parentBasePrice];
  1077. },
  1078. onProjectGLJValueChange: function (e, info) {
  1079. //me.projectGljSetting
  1080. let projectGLJ = projectObj.project.projectGLJ;
  1081. let me = projectGljObject,
  1082. row = info.row,
  1083. col = info.col;
  1084. let setting = info.sheetName == "materialTreeSheet" ? me.materialSetting : me.projectGljSetting;
  1085. let dataCode = setting.header[col].dataCode;
  1086. let recode = info.sheetName == "materialTreeSheet" ? me.materialTree.selected.data : me.projectGljSheetData[row];
  1087. let value = info.newValue;
  1088. if (info.newValue === undefined) {
  1089. return;
  1090. }
  1091. if (value && !me.checkData(col, setting, value)) {
  1092. alert("输入的数据类型不对,请重新输入!");
  1093. info.sheetName == "materialTreeSheet" ? me.materialTreeController.refreshTreeNode([me.materialTree.selected]) : me.refreshProjectGljRow(row);
  1094. return;
  1095. }
  1096. let callback = function (impactList) {
  1097. info.sheet.suspendPaint();
  1098. info.sheet.suspendEvent();
  1099. if (dataCode === "is_adjust_price") {
  1100. projectGLJ.calcQuantity();
  1101. }
  1102. if (info.sheetName == "materialTreeSheet") {
  1103. me.showMaterialTreeData();
  1104. } else {
  1105. // me.refreshProjectGljRow(row);
  1106. me.showProjectGljData();
  1107. for (let g of impactList) {
  1108. me.refreshProjectGljRowByID(g.id, row);
  1109. }
  1110. }
  1111. info.sheet.resumeEvent();
  1112. info.sheet.resumePaint();
  1113. if (dataCode === "supply" || dataCode === "supply_quantity" || dataCode === "is_adjust_price") {
  1114. // basePrice、marketPrice 有自己的计算代码,无需走这里重复计算
  1115. let rations = calcTools.getRationsByProjectGLJ(recode.id);
  1116. projectObj.project.calcProgram.calcNodesAndSave(rations, function () {
  1117. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  1118. });
  1119. }
  1120. gljOprObj.refreshView();
  1121. };
  1122. if (dataCode == "basePrice" || dataCode == "marketPrice") {
  1123. //修改市场价和修改定额价时需要重新记算很多受影响的树节点,现在改成与定字额工料机那里调相同的方法。
  1124. let editField = dataCode === "basePrice" ? "base_price" : "market_price";
  1125. projectObj.project.projectGLJ.updatePrice(recode, editField, value, "pg", callback);
  1126. } else {
  1127. let extend = {};
  1128. // 如果是供货方式则需要处理数据
  1129. if (dataCode === "supply") {
  1130. extend.supply_quantity = me.getSupplyQuantity(value, recode.quantity);
  1131. }
  1132. if (dataCode === "supply_quantity") {
  1133. //修改数量需做4舍5入
  1134. value = scMathUtil.roundForObj(value, getDecimal("glj.quantity"));
  1135. }
  1136. if (dataCode === "is_evaluate" || dataCode === "is_adjust_price" || dataCode === "is_main_material" || dataCode == "is_eval_material") {
  1137. value = value == true ? 1 : 0;
  1138. if (dataCode === "is_evaluate" || dataCode == "is_eval_material") {
  1139. configMaterialObj.updateConfigMaterial(dataCode, value, recode); //暂估材料,主要材料等新需求
  1140. return;
  1141. }
  1142. }
  1143. if (dataCode === "materialType" && (value == null || value == "")) {
  1144. //删除三材类别时,清空三材系数
  1145. value = null;
  1146. extend.materialCoe = null;
  1147. }
  1148. if (dataCode == "materialCoe") {
  1149. value = scMathUtil.roundForObj(value, getDecimal("material"));
  1150. }
  1151. extend = Object.keys(extend).length > 0 ? JSON.stringify(extend) : "";
  1152. if (recode[dataCode] == value) return;
  1153. let updateData = { id: recode.id, field: dataCode, value: value, extend: extend };
  1154. projectGLJ.pGljUpdate(updateData, callback);
  1155. }
  1156. },
  1157. refreshProjectGljRowByID: function (ID, row) {
  1158. //row 可以不传,如果row 和 index 相等就不刷新
  1159. let me = this;
  1160. let index = _.findIndex(me.projectGljSheetData, { id: ID });
  1161. if (index >= 0 && index != row) {
  1162. me.refreshProjectGljRow(index);
  1163. }
  1164. },
  1165. getSupplyQuantity: function (supplyType, quantity) {
  1166. // 自行采购和甲定乙供则把甲供数量设置为0,其余情况则设置为当前总消耗量
  1167. let supplyQuantity = supplyType == 0 || supplyType == 3 ? 0 : quantity;
  1168. supplyQuantity = parseFloat(supplyQuantity);
  1169. return supplyQuantity;
  1170. },
  1171. getSupplyQuantityByGlj: function (glj) {
  1172. //{"自行采购":0,"部分甲供":1,"完全甲供":2,"甲定乙供":3};
  1173. let supply_quantity = glj.supply_quantity;
  1174. switch (glj.supply) {
  1175. case 0:
  1176. supply_quantity = 0;
  1177. break;
  1178. case 1:
  1179. break;
  1180. case 2:
  1181. supply_quantity = glj.quantity;
  1182. break;
  1183. case 3:
  1184. supply_quantity = 0;
  1185. break;
  1186. }
  1187. return supply_quantity;
  1188. },
  1189. checkData: function (col, setting, value) {
  1190. return sheetCommonObj.checkData(col, setting, value);
  1191. },
  1192. getProjectGLJSelected: function () {
  1193. let me = this,
  1194. data = null;
  1195. let sheet = me.projectGljSpread.getActiveSheet();
  1196. if (sheet.name() == "projectGljSheet") {
  1197. //projectGljSheet/materialSheet 工料机汇总和三材汇总表
  1198. let sel = me.projectGljSheet.getSelections()[0];
  1199. let srow = sel.row == -1 || sel.row == "" ? 0 : sel.row;
  1200. if (me.projectGljSheetData.length > srow) {
  1201. data = me.projectGljSheetData[srow];
  1202. }
  1203. } else if (sheet.name() == "materialTreeSheet") {
  1204. if (this.materialTree.selected) {
  1205. data = this.materialTree.selected.data;
  1206. }
  1207. }
  1208. return data;
  1209. },
  1210. mutiAddCalcMaterial: function () {
  1211. let sel = this.projectGljSheet.getSelections()[0];
  1212. let projectGLJs = [];
  1213. for (let i = 0; i < sel.rowCount; i++) {
  1214. let row = sel.row + i;
  1215. if (this.projectGljSheetData.length > row) {
  1216. let projectGLJ = this.projectGljSheetData[row];
  1217. if (gljUtil.isMaterialType(projectGLJ.type)) projectGLJs.push(projectGLJ);
  1218. }
  1219. }
  1220. projectObj.project.projectGLJ.updateCalcMaterials(projectGLJs, 1);
  1221. },
  1222. initProjectGljRightClick: function () {
  1223. //如果当前行是无组成物的“普通材料”、“绿化苗木”、“外购砼构件”、“商品混凝土”、“商品砂浆”,则右键“添加计算材料”按钮有效。
  1224. let me = this;
  1225. $.contextMenu({
  1226. selector: "#project_glj_sheet",
  1227. build: function ($trigger, e) {
  1228. let os = me.projectGljSheet.getSelections();
  1229. me.rightClickTarget = SheetDataHelper.safeRightClickSelection($trigger, e, me.projectGljSpread);
  1230. let ns = me.projectGljSheet.getSelections();
  1231. me.onProjectGljSelectionChange({}, { newSelections: ns, oldSelections: os }, true);
  1232. return (
  1233. me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.viewport || me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader
  1234. );
  1235. },
  1236. items: {
  1237. addCalcMaterial: {
  1238. name: "添加计算材料",
  1239. icon: "fa-plus-square",
  1240. disabled: function () {
  1241. let projectGLJ = projectGljObject.getProjectGLJSelected();
  1242. return !projectGLJ || !gljUtil.isMaterialType(projectGLJ.type);
  1243. },
  1244. callback: function (key, opt) {
  1245. projectGljObject.mutiAddCalcMaterial();
  1246. /* console.log(me.projectGljSheet.getSelections())
  1247. let projectGLJ = projectGljObject.getProjectGLJSelected();
  1248. projectObj.project.projectGLJ.updateCalcMaterial(projectGLJ,1); */
  1249. },
  1250. },
  1251. calcElectrovalence: {
  1252. name: "计算综合电价",
  1253. icon: "fa-calculator",
  1254. disabled: function () {
  1255. return false;
  1256. },
  1257. callback: function (key, opt) {
  1258. $("#electrovalenceDiv").modal("show");
  1259. },
  1260. },
  1261. exportPriceToExcel: {
  1262. name: "导出Excel预算价",
  1263. icon: "fa-reply",
  1264. visible: function () {
  1265. return compilationName === "四川养护(2013)" || compilationName === "部颁2018计价标准";
  1266. },
  1267. callback: function (key, opt) {
  1268. $("#electrovalenceDiv").modal("show");
  1269. },
  1270. },
  1271. importPriceFromExcel: {
  1272. name: "导入Excel预算价",
  1273. icon: "fa-share",
  1274. visible: function () {
  1275. return compilationName === "四川养护(2013)" || compilationName === "部颁2018计价标准";
  1276. },
  1277. callback: function (key, opt) {
  1278. $("#importPriceForm").modal("show");
  1279. },
  1280. },
  1281. },
  1282. });
  1283. },
  1284. initMixRatioRightClick: function () {
  1285. let activeSheet = this.mixRatioSheet;
  1286. let me = this;
  1287. $.contextMenu({
  1288. selector: "#mix_ratio_sheet",
  1289. build: function ($trigger, e) {
  1290. me.rightClickTarget = SheetDataHelper.safeRightClickSelection($trigger, e, me.mixRatioSpread);
  1291. return (
  1292. me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.viewport || me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader
  1293. );
  1294. },
  1295. items: {
  1296. deleteMixRatio: {
  1297. name: "删除",
  1298. icon: "fa-trash-o",
  1299. disabled: function () {
  1300. return me.rightClickTarget.row === undefined;
  1301. },
  1302. callback: function (key, opt) {
  1303. let row = me.rightClickTarget.row;
  1304. me.deleteMixRatio(row);
  1305. },
  1306. visible: function (key, opt) {
  1307. if (!$("#mixRatio-nav").hasClass("active")) return false;
  1308. let projectGLJ = projectGljObject.getProjectGLJSelected();
  1309. return projectGLJ && !gljUtil.isConcreteType(projectGLJ.type);
  1310. },
  1311. },
  1312. addMixRatio: {
  1313. name: "添加",
  1314. icon: "fa-sign-in",
  1315. disabled: function () {
  1316. let projectGLJ = projectGljObject.getProjectGLJSelected();
  1317. return !_.includes(compositionTypes, projectGLJ.type);
  1318. },
  1319. callback: function (key, opt) {
  1320. me.selectedProjectGLJ = projectGljObject.getProjectGLJSelected();
  1321. getGLJData("addMix");
  1322. },
  1323. visible: function (key, opt) {
  1324. if (!$("#mixRatio-nav").hasClass("active")) return false;
  1325. let projectGLJ = projectGljObject.getProjectGLJSelected();
  1326. return projectGLJ && !gljUtil.isConcreteType(projectGLJ.type);
  1327. },
  1328. },
  1329. },
  1330. });
  1331. },
  1332. changeFileCallback: function () {
  1333. projectGljObject.unitPriceFileInit();
  1334. projectGljObject.refreshDataSheet();
  1335. projectGljObject.initVvTax();
  1336. materialCalcObj.showDatas();
  1337. projectObj.project.calcProgram.calcAllNodesAndSave(calcAllType.catAll, function () {
  1338. if (socketObject.roomInfo) {
  1339. let data = {
  1340. projectID: projectObj.project.ID(),
  1341. oldRoom: socketObject.roomInfo.unitFile,
  1342. newRoom: socketObject.getUnitFileRoomID(),
  1343. userID: userID,
  1344. name: "unitFile",
  1345. };
  1346. socket.emit("changeNewRoom", data);
  1347. socketObject.roomInfo.unitFile = socketObject.getUnitFileRoomID();
  1348. }
  1349. });
  1350. gljOprObj.refreshView();
  1351. },
  1352. calcPartASupplyFeeByProjectGLJs: function (projectGLJsArr) {
  1353. for (let pGLJ of projectGLJsArr) {
  1354. if (pGLJ.supply == supplyType.BFJG) {
  1355. let rations = calcTools.getRationsByProjectGLJ(pGLJ.id);
  1356. projectObj.project.calcProgram.calcNodesAndSave(rations, function () {
  1357. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  1358. });
  1359. }
  1360. }
  1361. },
  1362. checkUnitFileName: function (name, callback) {
  1363. let projectGLJ = projectObj.project.projectGLJ;
  1364. projectGLJ.checkUnitFileName(name, function (data) {
  1365. if (data) {
  1366. $("#save-as-tips").text("已存在同名单价文件").show();
  1367. $("#save-as-confirm").attr("disabled", "disabled");
  1368. } else {
  1369. $("#save-as-tips").hide();
  1370. $("#save-as-confirm").removeAttr("disabled");
  1371. if (callback) callback();
  1372. }
  1373. });
  1374. },
  1375. initFilterTypeList: function () {
  1376. //初始化人材机汇总工料机类型过滤列表
  1377. let htmlString = "";
  1378. for (let t of this.displayTypeMap) {
  1379. htmlString += '<li class="nav-item "><a class="nav-link pl-4" href="javascript:void(0)" id="' + t.ID + '">' + t.text + "</a></li>";
  1380. }
  1381. $("#ALL").after(htmlString);
  1382. },
  1383. initVvTax: async function () {
  1384. //初始化车船税选择
  1385. try {
  1386. let engineeringID = projectObj.project.projectInfo.property.engineering_id;
  1387. let result = await ajaxGet("/glj/getVvTaxList", { engineeringID: engineeringID });
  1388. let optionString = ` <option value="">车船税标准</option>`;
  1389. for (let r of result) {
  1390. optionString += `<option value="${r.id}">${r.name}</option>`;
  1391. }
  1392. $("#vvTax").empty();
  1393. $("#vvTax").html(optionString);
  1394. $("#vvTax").val(projectObj.project.projectGLJ.datas.constData.vvTaxFileID ? projectObj.project.projectGLJ.datas.constData.vvTaxFileID : "");
  1395. } catch (e) {
  1396. console.log(e);
  1397. }
  1398. },
  1399. refreshSubViews: function () {
  1400. if ($("#mix_ratio_sheet").is(":visible") && this.mixRatioSpread) this.mixRatioSpread.refresh();
  1401. if ($("#materialCalcSheet").is(":visible") && materialCalcObj.materialSpread) materialCalcObj.materialSpread.refresh();
  1402. if ($("#freightSheet").is(":visible") && materialCalcObj.freightSpread) materialCalcObj.freightSpread.refresh();
  1403. if ($("#priceSheet").is(":visible") && materialCalcObj.priceSpread) materialCalcObj.priceSpread.refresh();
  1404. if ($("#freight_ration").is(":visible") && materialCalcObj.freightRationSpread) materialCalcObj.freightRationSpread.refresh();
  1405. if ($("#price_ration").is(":visible") && materialCalcObj.priceRationSpread) materialCalcObj.priceRationSpread.refresh();
  1406. },
  1407. getColIndex: function (colName) {
  1408. const headerArr = this.projectGljSetting.header;
  1409. for (let index = 0; index < headerArr.length; index++) {
  1410. const e = headerArr[index];
  1411. if (e.headerName === colName) return index;
  1412. }
  1413. return -1;
  1414. },
  1415. getSheetDataRowAndPrice: function (gljIndex) {
  1416. const pGlj = projectObj.project.projectGLJ.datas.gljMap[gljIndex];
  1417. if (!pGlj) return null;
  1418. const sheetDataArr = this.projectGljSheetData;
  1419. for (let index = 0; index < sheetDataArr.length; index++) {
  1420. const e = sheetDataArr[index];
  1421. if (e.id === pGlj.id) return { row: index, price: e.unit_price.market_price };
  1422. }
  1423. return null;
  1424. },
  1425. };
  1426. function getProjectResizeEles() {
  1427. let pojGljResizeEles = {};
  1428. pojGljResizeEles.eleObj = {
  1429. module: "projectGlj",
  1430. resize: $("#projectGljResize"),
  1431. top: $("#projectGljTop"),
  1432. topSpread: $("#project_glj_sheet"),
  1433. bottom: $("#projectGljBottom"),
  1434. bottomSpread: [$("#mix_ratio_sheet"), $("#materialCalcSheet"), $("#calcDiv")],
  1435. };
  1436. pojGljResizeEles.limit = {
  1437. min: 150,
  1438. max: `$(window).height()-$('.header').height()-$('#projectGljToolsBar').height()-150-5`, //5: resize.height()
  1439. notTopSpread: 0,
  1440. notBottomSpread: 0,
  1441. bottomNav: `$('#projectGljBottom ul').height()`,
  1442. totalHeight: `$(window).height()-$('.header').height()-$('#projectGljToolsBar').height()-5`,
  1443. };
  1444. return pojGljResizeEles;
  1445. }
  1446. function getConficMaterialResizeEles() {
  1447. let conficMaterialResizeEles = {};
  1448. conficMaterialResizeEles.eleObj = {
  1449. module: "conficMaterial",
  1450. resize: $("#configMaterialResize"),
  1451. top: $("#configMaterialTop"),
  1452. topSpread: $("#config_material_sheet"),
  1453. bottom: $("#configMaterialBottom"),
  1454. bottomSpread: $("#related_sheet"),
  1455. };
  1456. conficMaterialResizeEles.limit = {
  1457. min: 150,
  1458. max: `$(window).height()-$('.header').height()-$('#projectGljToolsBar').height()-150-5`, //5: resize.height()
  1459. notTopSpread: 0,
  1460. notBottomSpread: 0,
  1461. totalHeight: `$(window).height()-$('.header').height()-$('#projectGljToolsBar').height()-5`,
  1462. bottomNav: `$('#configMaterialBottom ul').height() + $('#filterToolDiv').height()+10`,
  1463. };
  1464. return conficMaterialResizeEles;
  1465. }
  1466. function loadProjectGljSize() {
  1467. if ($("#project-glj-main").is(":visible")) {
  1468. let me = projectGljObject;
  1469. let pojGljResizeEles = getProjectResizeEles();
  1470. SlideResize.loadVerticalHeight(pojGljResizeEles.eleObj.module, pojGljResizeEles.eleObj, pojGljResizeEles.limit, function () {
  1471. me.projectGljSpread ? me.projectGljSpread.refresh() : "";
  1472. materialCalcObj.initTabWidth();
  1473. me.refreshSubViews();
  1474. });
  1475. } else if ($("#config_material").is(":visible")) {
  1476. let configMaterialResizeEles = getConficMaterialResizeEles();
  1477. SlideResize.loadVerticalHeight(configMaterialResizeEles.eleObj.module, configMaterialResizeEles.eleObj, configMaterialResizeEles.limit, function () {
  1478. configMaterialObj.configSpread ? configMaterialObj.configSpread.refresh() : "";
  1479. configMaterialObj.relatedSpread ? configMaterialObj.relatedSpread.refresh() : "";
  1480. /*
  1481. me.mixRatioSpread?me.mixRatioSpread.refresh():'';*/
  1482. });
  1483. }
  1484. }
  1485. //从其他建设项目中复制中,建设项目的文件层次结构名称和顺序
  1486. function getFileHierarchyInfo(treeData) {
  1487. let tree = idTree.createNew({ id: "ID", pid: "ParentID", nid: "NextSiblingID", rootId: -1 });
  1488. tree.loadDatas(treeData);
  1489. let items = tree.items;
  1490. let rst = [];
  1491. function getFileHierarchyName(node) {
  1492. let nodeName = node.data.name;
  1493. let name = [];
  1494. while (node.parent) {
  1495. name.push(node.parent.data.name ? node.parent.data.name : "");
  1496. node = node.parent;
  1497. }
  1498. name = name.reverse();
  1499. name.push(nodeName);
  1500. return name.join("\\");
  1501. }
  1502. for (let node of items) {
  1503. if (node.children.length === 0) {
  1504. //project
  1505. rst.push({ ID: node.data.ID, fileHierarchyName: getFileHierarchyName(node) });
  1506. }
  1507. }
  1508. return rst;
  1509. }
  1510. $(function () {
  1511. let pojGljResizeEles = getProjectResizeEles();
  1512. SlideResize.verticalSlide(pojGljResizeEles.eleObj, pojGljResizeEles.limit, function () {
  1513. projectGljObject.projectGljSpread.refresh();
  1514. projectGljObject.refreshSubViews();
  1515. });
  1516. let tr = getConficMaterialResizeEles();
  1517. SlideResize.verticalSlide(tr.eleObj, tr.limit, function () {
  1518. configMaterialObj.configSpread ? configMaterialObj.configSpread.refresh() : "";
  1519. configMaterialObj.relatedSpread ? configMaterialObj.relatedSpread.refresh() : "";
  1520. });
  1521. $("#tab_project_glj").on("shown.bs.tab", function (e) {
  1522. sessionStorage.setItem("mainTab", "#tab_project_glj");
  1523. let me = projectGljObject;
  1524. $(e.relatedTarget.hash).removeClass("active");
  1525. if (me.projectGljSpread == null) {
  1526. me.initSpreads();
  1527. }
  1528. me.unitPriceFileInit();
  1529. me.initMixRatio();
  1530. //projectObj.project.projectGLJ.calcQuantity(); 在工程量有更新的地方调用
  1531. me.initSheetViews();
  1532. me.refreshViewsData();
  1533. loadProjectGljSize();
  1534. me.initVvTax();
  1535. materialCalcObj.initTabWidth();
  1536. materialCalcObj.showDatas();
  1537. });
  1538. /* $('#ration_link').on('shown.bs.tab', function (e) {
  1539. let me = projectGljObject;
  1540. me.showTag='ration';
  1541. me.showProjectGljData();
  1542. });
  1543. $('#mix_ratio_link').on('shown.bs.tab', function (e) {
  1544. let me = projectGljObject;
  1545. me.showTag='mixRatio';
  1546. me.showProjectGljData();
  1547. me.initMixRatio();
  1548. });
  1549. $('#machine_ratio_link').on('shown.bs.tab', function (e) {
  1550. let me = projectGljObject;
  1551. me.showTag='machine';
  1552. me.showProjectGljData();
  1553. me.initMixRatio();
  1554. });*/
  1555. $("#pop-used-list").tooltip({
  1556. placement: "bottom",
  1557. html: true,
  1558. trigger: "hover | focus",
  1559. title: projectGljObject.getUsedTenderInfo,
  1560. });
  1561. // 单价文件切换弹框
  1562. $("#change-unitFile").on("shown.bs.modal", function () {
  1563. let rootProjectID = projectObj.project.projectInfo.property.rootProjectID;
  1564. // 获取切换单价文件相关数据
  1565. $.ajax({
  1566. url: "/glj/get-project-info",
  1567. type: "post",
  1568. data: { project_id: scUrlUtil.GetQueryString("project"), rootProjectID: rootProjectID },
  1569. dataType: "json",
  1570. success: function (response) {
  1571. if (response.err === 1) {
  1572. alert("数据传输错误!");
  1573. return false;
  1574. }
  1575. let data = response.data;
  1576. projectGljObject.changeInfo = data;
  1577. $("#current-project-name").text(data.currentProjectName);
  1578. // 本项目中的单价文件
  1579. if (data.self.length > 0) {
  1580. let selfFileHtml = "";
  1581. for (let tmp of data.self) {
  1582. let select = usedUnitPriceInfo === tmp.id ? ' selected="selected"' : "";
  1583. selfFileHtml += "<option" + select + ' value="' + tmp.id + '">' + tmp.name + "</option>";
  1584. }
  1585. $("#self-file").html(selfFileHtml);
  1586. }
  1587. // 其他建设项目数据
  1588. let newDataOther = [];
  1589. if (data.other.length > 0) {
  1590. //转换成按项目管理顺序,名称包含文件夹层次
  1591. let fileHierarchyDatas = getFileHierarchyInfo(data.treeData);
  1592. for (let fileHierarchyData of fileHierarchyDatas) {
  1593. let projData = _.find(data.other, { ID: fileHierarchyData.ID });
  1594. if (projData) {
  1595. projData.name = fileHierarchyData.fileHierarchyName;
  1596. newDataOther.push(projData);
  1597. }
  1598. }
  1599. data.other = newDataOther;
  1600. let otherProjectHtml = "";
  1601. let otherFileHtml = "";
  1602. for (let tmp of data.other) {
  1603. otherProjectHtml += '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1604. otherFileData[tmp.ID] = tmp.unitPriceList;
  1605. if (otherFileHtml !== "") {
  1606. continue;
  1607. }
  1608. for (let unitPrice of tmp.unitPriceList) {
  1609. otherFileHtml += '<option value="' + unitPrice.id + '">' + unitPrice.name + "</option>";
  1610. }
  1611. }
  1612. $("#other-project").html(otherProjectHtml);
  1613. $("#other-file").html(otherFileHtml);
  1614. }
  1615. },
  1616. });
  1617. });
  1618. // 单价文件切换确认
  1619. $("#change-file-confirm").click(function () {
  1620. let type = $("input[name='change-type']:checked").val();
  1621. type = parseInt(type);
  1622. let changeUnitPriceId = 0;
  1623. $("#change-unitFile").modal("hide");
  1624. if (type === 0) {
  1625. // 从本项目中选择
  1626. changeUnitPriceId = $("#self-file").val();
  1627. if (!changeUnitPriceId) {
  1628. alert("单价文件不可为空");
  1629. return;
  1630. }
  1631. submitFileChange(changeUnitPriceId, type);
  1632. } else {
  1633. // 从其他项目中复制
  1634. changeUnitPriceId = $("#other-file").val();
  1635. let newName = $("#other-file").children("option:selected").text();
  1636. projectObj.project.projectGLJ.checkUnitFileName(newName, function (need_rename) {
  1637. if (need_rename) {
  1638. $("#rename-unitFile").modal({ show: true });
  1639. $("#newUnitFileID").val(changeUnitPriceId);
  1640. $("#newUnitFileName").val(newName);
  1641. } else {
  1642. submitFileChange(changeUnitPriceId, type);
  1643. }
  1644. });
  1645. }
  1646. function submitFileChange(changeUnitPriceId, type) {
  1647. let data = { project_id: scUrlUtil.GetQueryString("project"), change_id: changeUnitPriceId, type: type };
  1648. projectObj.project.projectGLJ.changeFile(data, function () {
  1649. projectGljObject.changeFileCallback();
  1650. });
  1651. }
  1652. });
  1653. // 单价文件选项切换
  1654. $("input[name='change-type']").change(function () {
  1655. let type = $(this).val();
  1656. type = parseInt(type);
  1657. $("#change-unitFile .option").hide();
  1658. if (type === 0) {
  1659. $(".option.select").show();
  1660. } else {
  1661. $(".option.copy").show();
  1662. }
  1663. });
  1664. $("#vvTax").change(function () {
  1665. let newVvTaxFileID = $(this).val();
  1666. console.log(newVvTaxFileID);
  1667. projectObj.project.projectGLJ.changeVvTaxFile(newVvTaxFileID);
  1668. });
  1669. $("#unitFile-save-as").on("shown.bs.modal", function () {
  1670. // 获取当前建设项数据
  1671. $("#save-as-name").val(projectGljObject.usedUnitPriceInfo.name + "副本");
  1672. projectGljObject.checkUnitFileName(projectGljObject.usedUnitPriceInfo.name + "副本");
  1673. });
  1674. // 从其他建设项目中复制 选择建设项目
  1675. $("#other-project").change(function () {
  1676. let projectId = $(this).val();
  1677. if (otherFileData[projectId] === undefined) {
  1678. return false;
  1679. }
  1680. let otherFileHtml = "";
  1681. for (let unitPrice of otherFileData[projectId]) {
  1682. otherFileHtml += '<option value="' + unitPrice.id + '">' + unitPrice.name + "</option>";
  1683. }
  1684. $("#other-file").html(otherFileHtml);
  1685. });
  1686. $("#save-as-name").change(function () {
  1687. projectGljObject.checkUnitFileName(this.value);
  1688. });
  1689. $("#newUnitFileName").change(function () {
  1690. let projectGLJ = projectObj.project.projectGLJ;
  1691. projectGLJ.checkUnitFileName(this.value, function (data) {
  1692. if (data) {
  1693. $("#renameError_unitFile").text("已存在同名单价文件").show();
  1694. //$('#renameUnitFileConfirm').attr("disabled","disabled");
  1695. } else {
  1696. $("#renameError_unitFile").hide();
  1697. // $('#renameUnitFileConfirm').removeAttr("disabled");
  1698. }
  1699. });
  1700. });
  1701. $("#renameUnitFileConfirm").click(function () {
  1702. let projectGLJ = projectObj.project.projectGLJ;
  1703. let newName = $("#newUnitFileName").val();
  1704. let changeUnitPriceId = $("#newUnitFileID").val();
  1705. projectGLJ.checkUnitFileName(newName, function (data) {
  1706. if (data) {
  1707. $("#renameError_unitFile").text("已存在同名单价文件").show();
  1708. //$('#renameUnitFileConfirm').attr("disabled","disabled");
  1709. } else {
  1710. $("#renameError_unitFile").hide();
  1711. $("#rename-unitFile").modal("hide");
  1712. // $('#renameUnitFileConfirm').removeAttr("disabled");
  1713. let data = { project_id: scUrlUtil.GetQueryString("project"), change_id: changeUnitPriceId, type: 1, newName: newName };
  1714. projectObj.project.projectGLJ.changeFile(data, function () {
  1715. projectGljObject.changeFileCallback();
  1716. });
  1717. }
  1718. });
  1719. });
  1720. // 单价文件另存为操作
  1721. $("#save-as-confirm").click(function () {
  1722. let projectGLJ = projectObj.project.projectGLJ;
  1723. let name = $("#save-as-name").val();
  1724. if (name === "") {
  1725. $("#save-as-tips").text("请填写单价文件名称").show();
  1726. return false;
  1727. }
  1728. let saveData = { name: name, project_id: scUrlUtil.GetQueryString("project") };
  1729. projectGljObject.checkUnitFileName(name, function () {
  1730. projectGLJ.saveAs(saveData, function () {
  1731. projectGljObject.changeFileCallback();
  1732. $("#unitFile-save-as").modal("hide");
  1733. });
  1734. });
  1735. });
  1736. $("#filterType").on("click", "ul li a", function (e) {
  1737. let children = $("#filterType a");
  1738. for (let c of children) {
  1739. $(c).removeClass("active");
  1740. }
  1741. $(this).addClass("active");
  1742. let me = projectGljObject;
  1743. me.displayType = filterType[this.id];
  1744. me.initSheetViews();
  1745. me.refreshViewsData();
  1746. loadProjectGljSize();
  1747. });
  1748. $("#mixRatio-nav").on("shown.bs.tab", function () {
  1749. projectGljObject.mixRatioSpread.refresh();
  1750. projectGljObject.showMixRatioData();
  1751. });
  1752. $("#ration-nav").on("shown.bs.tab", function () {
  1753. projectGljObject.mixRatioSpread.refresh();
  1754. projectGljObject.showRelatedRationDatas();
  1755. });
  1756. let importJson = null;
  1757. function showAlert(msg, isHint) {
  1758. $("#showAlert").removeClass("alert-success");
  1759. if (isHint) $("#showAlert").addClass("alert-info");
  1760. else $("#showAlert").addClass("alert-danger");
  1761. $("#showAlert").text(msg);
  1762. $("#showAlert").show();
  1763. }
  1764. function getExcelData(sheets) {
  1765. const err = "当前Excel文件格式不正确,请参考导出Excel材料预算价文件!";
  1766. const sheet = sheets["材料预算价"];
  1767. if (!sheet) throw err;
  1768. const sheetData = sheet.data.dataTable;
  1769. if (!sheetData) throw err;
  1770. const isRightHead =
  1771. sheetData[0][0].value === "编号" &&
  1772. sheetData[0][1].value === "名称" &&
  1773. sheetData[0][2].value === "规格" &&
  1774. sheetData[0][3].value === "单位" &&
  1775. sheetData[0][4].value === "类型" &&
  1776. sheetData[0][5].value === "预算价";
  1777. if (!isRightHead) throw err;
  1778. let rst = [];
  1779. for (let row = 1; row < sheet.rowCount; row++) {
  1780. const rowData = {
  1781. code: sheetData[row][0].value,
  1782. name: sheetData[row][1].value,
  1783. specs: sheetData[row][2].value,
  1784. unit: sheetData[row][3].value,
  1785. type: sheetData[row][4].value,
  1786. unitPrice: sheetData[row][5].value,
  1787. };
  1788. rst.push(rowData);
  1789. }
  1790. return rst;
  1791. }
  1792. //选择导入的excel文件
  1793. $("#customPriceFile").change(function () {
  1794. let file = $(this)[0];
  1795. let excelFile = file.files[0];
  1796. $("#showAlert").hide();
  1797. if (excelFile) {
  1798. let xlsReg = /xls$/g;
  1799. if (excelFile.name && xlsReg.test(excelFile.name)) {
  1800. showAlert(false, "请选择xlsx文件");
  1801. $(this).val("");
  1802. return;
  1803. }
  1804. $(".custom-file-label").text(`${file.files[0].name}`);
  1805. $("#showAlert").hide();
  1806. $.bootstrapLoading.start();
  1807. $("#loadingPage").css("z-index", "2000");
  1808. //前端解析excel数据
  1809. if (importJson) {
  1810. importJson = null;
  1811. }
  1812. let excelIo = new GC.Spread.Excel.IO();
  1813. let sDate = +new Date();
  1814. excelIo.open(
  1815. excelFile,
  1816. function (json) {
  1817. importJson = json;
  1818. console.log(json);
  1819. console.log(`解析Excel文件时间:${+new Date() - sDate}`);
  1820. $.bootstrapLoading.end();
  1821. },
  1822. function (e) {
  1823. $.bootstrapLoading.end();
  1824. alert(e.errorMessage);
  1825. }
  1826. );
  1827. }
  1828. });
  1829. $("#importPriceBtn").click(function () {
  1830. let me = this;
  1831. $(me).addClass("disabled");
  1832. try {
  1833. $.bootstrapLoading.start();
  1834. let file = $("#customPriceFile")[0];
  1835. if (file.files.length <= 0) {
  1836. throw "未选择文件";
  1837. }
  1838. let projectID = scUrlUtil.GetQueryString("project");
  1839. if (!projectID || projectID <= 0) {
  1840. throw "项目数据出错";
  1841. }
  1842. const priceData = getExcelData(importJson.sheets);
  1843. if (priceData.length === 0) {
  1844. throw "当前Excel文件没有材料预算价!";
  1845. }
  1846. showAlert("正在导入预算价...", true);
  1847. debugger;
  1848. const priceCol = projectGljObject.getColIndex("预算价");
  1849. console.log(projectGljObject.projectGljSheetData);
  1850. const changeInfo = [];
  1851. for (const pd of priceData) {
  1852. const idx = gljUtil.getIndex(pd, gljKeyArray);
  1853. const pGlj = projectGljObject.getSheetDataRowAndPrice(idx);
  1854. if (pGlj && pGlj.price !== pd.unitPrice) {
  1855. changeInfo.push({ row: pGlj.row, col: priceCol, value: pd.unitPrice });
  1856. }
  1857. }
  1858. if (changeInfo.length > 0) projectGljObject.batchUpdateProjectGLJ(changeInfo, "projectGljSheet");
  1859. $("#showAlert").hide();
  1860. $(me).removeClass("disabled");
  1861. $("#importPriceForm").modal("hide");
  1862. if ($.bootstrapLoading.isLoading()) {
  1863. $.bootstrapLoading.end();
  1864. }
  1865. } catch (err) {
  1866. console.log(err);
  1867. showAlert(err);
  1868. $(me).removeClass("disabled");
  1869. if ($.bootstrapLoading.isLoading()) {
  1870. $.bootstrapLoading.end();
  1871. }
  1872. }
  1873. });
  1874. });