project_glj_view.js 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299
  1. /**
  2. * Created by zhang on 2018/3/13.
  3. */
  4. let projectGljObject = {
  5. showTag: 'ration', //mixRatio/machine
  6. showMixRatioMark: '',
  7. commonInfoPriceID:'',
  8. displayType: filterType.ALL,
  9. mixRatioType: [gljType.CONCRETE, gljType.MORTAR, gljType.MIX_RATIO, gljType.MAIN_MATERIAL],
  10. machineType: [gljType.GENERAL_MACHINE],
  11. projectGljSetting: {},
  12. projectGljSpread: null,
  13. projectGljSheet: null,
  14. materialTreeSheet: null,
  15. projectGljSheetData: [],
  16. infoPriceData:[],
  17. infoClassData:[],
  18. mixRatioSetting: {},
  19. infoPriceSetting: {
  20. header: [
  21. { headerName: "材料名称", headerWidth: 320, dataCode: "name", dataType: "String"},
  22. { headerName: "规格型号", headerWidth: 200, dataCode: "specs",hAlign: "left",dataType: "String" },
  23. { headerName: "单位",headerWidth: 50,dataCode: "unit", dataType: "String", hAlign: "center"},
  24. { headerName: "含税市场价", headerWidth: 100, dataCode: "taxPrice", hAlign: "right",dataType: "Number", validator: "number" },
  25. { headerName: "不含税市场价", headerWidth: 100, dataCode: "noTaxPrice", hAlign: "right", dataType: "Number", validator: "number" } //,decimalField:"glj.unitPrice"
  26. ],
  27. view: {
  28. lockColumns: [0, 1, 2, 3, 4] //,
  29. //colHeaderHeight:30
  30. }
  31. },
  32. infoClassSetting:{
  33. header: [{ headerName: "分类", headerWidth: 420, dataCode: "name", dataType: "String"}],
  34. view: {
  35. lockColumns: [0]
  36. }
  37. },
  38. relatedRationSetting: {
  39. header: [{
  40. headerName: "编码",
  41. headerWidth: 100,
  42. dataCode: "code",
  43. dataType: "String"
  44. },
  45. {
  46. headerName: "名称",
  47. headerWidth: 180,
  48. dataCode: "name",
  49. dataType: "String"
  50. },
  51. {
  52. headerName: "单位",
  53. headerWidth: 50,
  54. dataCode: "unit",
  55. dataType: "String",
  56. hAlign: "center"
  57. },
  58. {
  59. headerName: "工程量",
  60. headerWidth: 65,
  61. dataCode: "quantity",
  62. dataType: "Number",
  63. hAlign: "right",
  64. decimalField: "ration.quantity"
  65. },
  66. {
  67. headerName: "单价",
  68. headerWidth: 65,
  69. dataCode: "feesIndex.common.unitFee",
  70. dataType: "Number",
  71. hAlign: "right",
  72. decimalField: "ration.unitPrice"
  73. }
  74. ],
  75. view: {
  76. lockColumns: [0, 1, 2, 3, 4] //,
  77. //colHeaderHeight:30
  78. }
  79. },
  80. materialTreeSetting: {
  81. "emptyRows": 0,
  82. "headRows": 1,
  83. "headRowHeight": [21],
  84. "defaultRowHeight": 21,
  85. "treeCol": 0,
  86. "cols": []
  87. },
  88. materialSetting: {
  89. header: [{
  90. headerName: "编码",
  91. headerWidth: 200,
  92. dataCode: "code",
  93. dataType: "String"
  94. },
  95. {
  96. headerName: "名称",
  97. headerWidth: 160,
  98. dataCode: "name",
  99. dataType: "String"
  100. },
  101. {
  102. headerName: "规格型号",
  103. headerWidth: 160,
  104. dataCode: "specs",
  105. hAlign: "left",
  106. dataType: "String"
  107. },
  108. {
  109. headerName: "单位",
  110. headerWidth: 45,
  111. dataCode: "unit",
  112. hAlign: "center",
  113. dataType: "String"
  114. },
  115. {
  116. headerName: "定额价",
  117. headerWidth: 70,
  118. dataCode: "basePrice",
  119. hAlign: "right",
  120. dataType: "Number",
  121. validator: "number"
  122. }, //,decimalField:'glj.unitPrice'
  123. {
  124. headerName: "市场价",
  125. headerWidth: 70,
  126. dataCode: "marketPrice",
  127. hAlign: "right",
  128. dataType: "Number",
  129. validator: "number"
  130. }, //,decimalField:"glj.unitPrice"
  131. {
  132. headerName: "总消耗量",
  133. headerWidth: 70,
  134. dataCode: "quantity",
  135. hAlign: "right",
  136. dataType: "Number",
  137. decimalField: 'glj.quantity'
  138. },
  139. {
  140. headerName: "三材系数",
  141. headerWidth: 70,
  142. dataCode: "materialCoe",
  143. hAlign: "right",
  144. dataType: "Number",
  145. validator: "number"
  146. }, //,decimalField:'material'
  147. {
  148. headerName: "三材量",
  149. headerWidth: 100,
  150. dataCode: "materialQuantity",
  151. hAlign: "right",
  152. dataType: "Number",
  153. decimalField: 'glj.quantity'
  154. },
  155. {
  156. headerName: "三材类别",
  157. headerWidth: 70,
  158. dataCode: "materialType",
  159. hAlign: "center",
  160. dataType: "String",
  161. cellType: 'comboBox',
  162. editorValueType: true,
  163. options: materialComboMap
  164. }
  165. ],
  166. view: {
  167. lockColumns: [0, 1, 2, 3, 6, 8]
  168. }
  169. },
  170. mixRatioSpread: null,
  171. mixRatioSheet: null,
  172. mixRatioData: [],
  173. subList: [], //定额工料机,添加组成物时临时保存组成物信息的位置
  174. usedTenderList: [],
  175. usedUnitPriceInfo: null,
  176. displayTypeMap: [{
  177. ID: 'LABOUR',
  178. text: '人工'
  179. },
  180. {
  181. ID: 'GENERAL_MATERIAL',
  182. text: '材料'
  183. },
  184. {
  185. ID: 'GENERAL_MACHINE',
  186. text: '机械'
  187. },
  188. {
  189. ID: 'MAIN_MATERIAL',
  190. text: '主材'
  191. },
  192. {
  193. ID: 'EQUIPMENT',
  194. text: '设备'
  195. }
  196. ],
  197. initInfoPriceSpread: function () {
  198. if (this.infoPriceSpread) return this.infoPriceSpread.refresh();
  199. this.infoPriceSpread = SheetDataHelper.createNewSpread($("#info_price_sheet")[0]);
  200. sheetCommonObj.spreadDefaultStyle(this.infoPriceSpread);
  201. this.infoPriceSheet = this.infoPriceSpread.getSheet(0);
  202. this.initSheet(this.infoPriceSheet, this.infoPriceSetting);
  203. this.infoPriceSheet.bind(GC.Spread.Sheets.Events.TopRowChanged, _.debounce(this.onInfoTopRowChanged, 100));
  204. this.infoPriceSheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onInfoPriceDoubleClick);
  205. this.infoPriceSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, this.infoPriceSelectionChange);
  206. this.infoPriceSheet.name('infoPriceSheet');
  207. this.infoPriceSheet.setRowCount(0);
  208. this.getInfoPriceOptions();
  209. if (projectReadOnly) {
  210. disableSpread(this.infoPriceSpread);
  211. } else {
  212. this.initInfoPriceRightClick();
  213. }
  214. },
  215. initInfoClassSpread: function () {
  216. if (this.infoClassSpread) return this.infoClassSpread.refresh();
  217. this.infoClassSpread = SheetDataHelper.createNewSpread($("#info_class_sheet")[0]);
  218. sheetCommonObj.spreadDefaultStyle(this.infoPriceSpread);
  219. this.infoClassSheet = this.infoClassSpread.getSheet(0);
  220. this.initSheet(this.infoClassSheet, this.infoClassSetting);
  221. this.infoClassSheet.name('infoClassSheet');
  222. this.infoClassSheet.setRowCount(0);
  223. this.infoClassSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, this.infoClassSelectionChange);
  224. if (projectReadOnly) {
  225. disableSpread(this.infoClassSpread);
  226. }
  227. },
  228. initSpreads: function () {
  229. if (this.projectGljSpread == null) this.initProjectGljSpread();
  230. //if(materialAdjustObj.spread == null) materialAdjustObj.initSpread();
  231. if (configMaterialObj.configSpread == null) configMaterialObj.initSpread();
  232. },
  233. initProjectGljSpread: function () {
  234. if (!this.projectGljSpread) {
  235. this.projectGljSpread = SheetDataHelper.createNewSpread($("#project_glj_sheet")[0], 2);
  236. sheetCommonObj.spreadDefaultStyle(this.projectGljSpread);
  237. }
  238. this.projectGljSpread.bind(GC.Spread.Sheets.Events.RangeChanged, this.onProjectGljRangeChange);
  239. this.initProjectGljSheet();
  240. this.initMaterialTreeSheet();
  241. disableRightMenu("project_glj_sheet", this.projectGljSpread, this.rightClickCallback);
  242. //打开别人分享的项目,只读
  243. if (projectReadOnly) {
  244. //锁定逻辑走disabledSpread里的
  245. if (this.projectGljSetting.view.lockColumns) {
  246. this.projectGljSetting.view.lockColumns = null;
  247. }
  248. disableSpread(this.projectGljSpread);
  249. }
  250. },
  251. initProjectGljSheet: function () {
  252. this.projectGljSheet = this.projectGljSpread.getSheet(0);
  253. this.initSheet(this.projectGljSheet, this.projectGljSetting);
  254. this.projectGljSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, this.onProjectGljSelectionChange);
  255. this.projectGljSheet.bind(GC.Spread.Sheets.Events.EditStarting, this.onProjectGljEditStarting);
  256. this.projectGljSheet.name('projectGljSheet');
  257. //this.projectGljSheet.setRowHeight(0, 36, 1);
  258. this.projectGljSheet.options.frozenlineColor = '#ababab';
  259. this.projectGljSheet.frozenColumnCount(this.projectGljSetting.frozenCols);
  260. },
  261. initMixRatio: function () {
  262. let me = projectGljObject;
  263. if (me.mixRatioSpread == null) {
  264. me.initMixRatioSpread();
  265. if (!projectReadOnly) {
  266. me.initRightClick();
  267. }
  268. }
  269. },
  270. initMixRatioSpread: function () {
  271. this.mixRatioSpread = SheetDataHelper.createNewSpread($("#mix_ratio_sheet")[0], 2);
  272. sheetCommonObj.spreadDefaultStyle(this.mixRatioSpread);
  273. this.mixRatioSheet = this.mixRatioSpread.getSheet(0);
  274. this.initSheet(this.mixRatioSheet, this.mixRatioSetting);
  275. this.mixRatioSheet.name('mixRatioSheet');
  276. this.mixRatioSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onMixRatioRangeChange);
  277. this.initRelatedRationSheet();
  278. if (projectReadOnly) {
  279. if (this.mixRatioSetting.view.lockColumns) {
  280. this.mixRatioSetting.view.lockColumns = null;
  281. }
  282. disableSpread(this.mixRatioSpread);
  283. }
  284. },
  285. initRelatedRationSheet: function () {
  286. this.relatedRationSheet = this.mixRatioSpread.getSheet(1);
  287. sheetCommonObj.initSheet(this.relatedRationSheet, this.relatedRationSetting, 30);
  288. this.relatedRationSheet.name('relatedRation');
  289. this.relatedRationSheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onRelatedRationDoubleClick);
  290. //this.mixRatioSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onMixRatioRangeChange);
  291. },
  292. initMaterialTreeSheet: function () {
  293. this.materialTreeSheet = this.projectGljSpread.getSheet(1);
  294. this.materialTreeSetting = this.createMaterialTreeSheetSetting();
  295. this.materialTree = cacheTree.createNew(this);
  296. this.materialTreeController = TREE_SHEET_CONTROLLER.createNew(this.materialTree, this.materialTreeSheet, this.materialTreeSetting);
  297. this.materialTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, this.onSelectionChange);
  298. this.materialTreeSheet.bind(GC.Spread.Sheets.Events.EditStarting, this.onProjectGljEditStarting);
  299. this.materialTreeSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onProjectGLJValueChange);
  300. this.materialTreeSheet.name('materialTreeSheet');
  301. if (projectReadOnly && this.materialSetting.view.lockColumns) {
  302. if (this.materialSetting.view.lockColumns) {
  303. this.materialSetting.view.lockColumns = null;
  304. }
  305. }
  306. },
  307. createMaterialTreeSheetSetting: function () {
  308. return sheetCommonObj.transferToTreeSetting(this.materialSetting, this.materialTreeSetting);
  309. },
  310. unitPriceFileInit: function () {
  311. let me = this;
  312. let projectGLJ = projectObj.project.projectGLJ;
  313. let data = projectGLJ.datas;
  314. me.usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
  315. me.usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ?
  316. data.constData.usedUnitPriceInfo : {};
  317. $("#current-name").text(me.usedUnitPriceInfo.name);
  318. let usedCount = me.usedTenderList.length <= 0 ? 1 : me.usedTenderList.length;
  319. $("#used-project-count").text(usedCount);
  320. $("#editUnitFile").attr("href", `/unitPrice/index/${me.usedUnitPriceInfo.id}`)
  321. },
  322. getUsedTenderInfo: function () {
  323. return "人材机单价的变化,将自动影响以下单位工程造价:<br>" + projectGljObject.usedTenderList.join("<br>");
  324. },
  325. // 获取选中人材机,添加组成物时,分页查询语句的扩展
  326. getQueryExtForMixRatio: function () {
  327. const extend = {};
  328. if (!this.selectedProjectGLJ) {
  329. return extend;
  330. }
  331. if (this.selectedProjectGLJ.type === gljType.MAIN_MATERIAL) { //对于主材,只显示没有组成物并且除了自已的主材
  332. extend['component.0'] = {
  333. $exists: false
  334. };
  335. extend.gljType = gljType.MAIN_MATERIAL;
  336. } else if (_.includes(gljUtil.hasCompMaterial, this.selectedProjectGLJ.type)) { //混凝土、砂浆、配合比
  337. extend.gljType = gljType.GENERAL_MATERIAL;
  338. } else if (_.includes(gljUtil.hasCompMachine, this.selectedProjectGLJ.type)) { //me.selectedProjectGLJ.type == gljType.GENERAL_MACHINE//机械中有组成物的类型
  339. extend.gljType = {
  340. $in: gljUtil.machineComposition
  341. };
  342. }
  343. return extend;
  344. },
  345. filterLibGLJForMixRatio: function () {
  346. let me = this;
  347. if (me.selectedProjectGLJ) {
  348. let showTypes = [];
  349. if (me.selectedProjectGLJ.type == gljType.MAIN_MATERIAL) { //对于主材,只显示没有组成物并且除了自已的主材
  350. showTypes = [gljType.MAIN_MATERIAL];
  351. } else if (_.includes(gljUtil.hasCompMaterial, me.selectedProjectGLJ.type)) { //混凝土、砂浆、配合比
  352. showTypes = [gljType.GENERAL_MATERIAL];
  353. } else if (_.includes(gljUtil.hasCompMachine, me.selectedProjectGLJ.type)) { //me.selectedProjectGLJ.type == gljType.GENERAL_MACHINE//机械中有组成物的类型
  354. showTypes = gljUtil.machineComposition;
  355. }
  356. gljOprObj.gljLibSheetData = _.filter(gljOprObj.gljLibSheetData, function (item) {
  357. if (me.selectedProjectGLJ.type == gljType.MAIN_MATERIAL) {
  358. let p_index = gljOprObj.getIndex(me.selectedProjectGLJ, gljKeyArray);
  359. let i_index = gljOprObj.getIndex(item, gljLibKeyArray);
  360. return item.gljType == gljType.MAIN_MATERIAL && item.component.length == 0 && p_index != i_index
  361. } else {
  362. return _.includes(showTypes, item.gljType);
  363. }
  364. });
  365. }
  366. },
  367. addMixRatio: async function () {
  368. let me = this,
  369. projectGLJ = projectObj.project.projectGLJ;
  370. let tdatas = me.mixRatioData;
  371. if (me.subList.length > 0) tdatas = me.subList;
  372. for (let mix of tdatas) {
  373. let m_key = gljOprObj.getIndex(mix, gljKeyArray);
  374. let t_index = gljOprObj.GLJSelection.indexOf(m_key);
  375. t_index != -1 ? gljOprObj.GLJSelection.splice(t_index, 1) : '';
  376. }
  377. await me.addMixRatioFromLib(gljOprObj.GLJSelection, () => {
  378. me.showMixRatioData(); //这里添加的组成物的消耗量默认都是0,所以对父工料机的价格不会有影响,不用触发计算
  379. projectGLJ.loadData(function () {
  380. me.showProjectGljData();
  381. gljOprObj.showRationGLJSheetData();
  382. me.onUnitFileChange(me.selectedProjectGLJ);
  383. });
  384. });
  385. },
  386. addMixRatioFromLib: async function (selections, callback) {
  387. let gljList = [],
  388. allGLJ = gljOprObj.AllRecode;
  389. let url = "/glj/add-ratio";
  390. let result = null;
  391. if (selections.length == 0) {
  392. return;
  393. }
  394. try {
  395. for (let glj of allGLJ) {
  396. let i_key = gljUtil.getIndex(glj, gljLibKeyArray);
  397. if (_.includes(selections, i_key)) {
  398. let pglj = {
  399. glj_id: glj.ID,
  400. name: glj.name,
  401. code: glj.code,
  402. original_code: glj.code,
  403. unit: glj.unit,
  404. specs: glj.specs,
  405. base_price: glj.basePrice,
  406. market_price: glj.basePrice,
  407. shortName: glj.shortName,
  408. type: glj.gljType,
  409. model: glj.model,
  410. adjCoe: glj.adjCoe,
  411. from: 'std',
  412. repositoryId: glj.repositoryId,
  413. materialType: glj.materialType,
  414. materialCoe: glj.materialCoe,
  415. grossWeightCoe: glj.grossWeightCoe,
  416. purchaseStorageRate: glj.purchaseStorageRate,
  417. offSiteTransportLossRate: glj.offSiteTransportLossRate,
  418. handlingLossRate: glj.handlingLossRate
  419. };
  420. if (typeof projectObj !== 'undefined') pglj.project_id = projectObj.project.ID();
  421. if (glj.hasOwnProperty("compilationId")) {
  422. pglj.from = "cpt";
  423. if (glj.code.indexOf('-') != -1) { //这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  424. pglj.original_code = glj.code.split('-')[0]; //取-前的编号作为原始编号
  425. }
  426. }
  427. gljList.push(pglj);
  428. }
  429. }
  430. gljList = _.sortByAll(gljList, ['type', 'code']);
  431. if (gljList.length == 0) return;
  432. let parentInfo = {};
  433. if (typeof unitPriceObj !== 'undefined') {
  434. url = "/unitPrice/addMixRatio";
  435. pdata = unitPriceObj.getSelectedUnitPrice();
  436. parentInfo = {
  437. unit_price_file_id: pdata.unit_price_file_id,
  438. connect_key: gljUtil.getIndex(pdata)
  439. };
  440. } else {
  441. parentInfo = {
  442. unit_price_file_id: projectObj.project.property.unitPriceFile.id,
  443. connect_key: gljOprObj.getIndex(projectGljObject.selectedProjectGLJ, gljKeyArray)
  444. };
  445. }
  446. $.bootstrapLoading.start();
  447. result = await ajaxPost(url, {
  448. gljList: gljList,
  449. parentInfo: parentInfo
  450. })
  451. if (callback) callback(result);
  452. } catch (error) {
  453. alert(error);
  454. console.log(error);
  455. }
  456. $.bootstrapLoading.end();
  457. return result;
  458. },
  459. showMixRatioData: function () {
  460. let me = this,
  461. gljId = null,
  462. gljType = null;
  463. if (!$('#mixRatio-nav').hasClass('active')) return;
  464. me.mixRatioSpread.setActiveSheetIndex(0);
  465. if (!me.projectGljSpread) return;
  466. let sheet = me.projectGljSpread.getActiveSheet();
  467. let oldSel = me.mixRatioSheet.getSelections()[0];
  468. if (sheet.name() == 'projectGljSheet') { //projectGljSheet/materialSheet 工料机汇总和三材汇总表
  469. let sel = me.projectGljSheet.getSelections()[0];
  470. let srow = sel.row == -1 || sel.row == "" ? 0 : sel.row;
  471. if (me.projectGljSheetData.length > srow) {
  472. gljId = me.projectGljSheetData[srow].id;
  473. gljType = me.projectGljSheetData[srow].type;
  474. }
  475. } else if (sheet.name() == 'materialTreeSheet') {
  476. if (this.materialTree.selected) {
  477. gljId = this.materialTree.selected.data.id;
  478. gljType = this.materialTree.selected.data.type;
  479. }
  480. }
  481. if (compositionTypes.indexOf(gljType) == -1) { //如果不是有组成物的类型,工料机id设置为空,组成物表设置为空
  482. gljId = null
  483. }
  484. projectObj.project.projectGLJ.getRatioData(gljId, function (data) {
  485. if (gljId !== projectObj.project.projectGLJ.getRatioId) { //两个id不一致说明不是最新的请求,不用往下执行。
  486. return;
  487. }
  488. let ratioList = [];
  489. for (let glj of data) {
  490. ratioList.push(me.getMixRatioSheetData(glj));
  491. }
  492. ratioList = gljUtil.sortRationGLJ(ratioList);
  493. me.mixRatioData = ratioList;
  494. me.mixRatioSheet.setRowCount(0);
  495. sheetCommonObj.showData(me.mixRatioSheet, me.mixRatioSetting, me.mixRatioData);
  496. me.mixRatioSheet.setRowCount(me.mixRatioData.length);
  497. me.mixRatioSheet.setSelection(oldSel.row == -1 ? 0 : oldSel.row, oldSel.col, oldSel.rowCount, oldSel.colCount);
  498. })
  499. },
  500. showRelatedRationDatas: function () {
  501. let me = this;
  502. if (!$('#ration-nav').hasClass('active')) return;
  503. me.mixRatioSpread.setActiveSheetIndex(1);
  504. let projectGLJData = me.getProjectGLJSelected();
  505. let rationIDMap = {};
  506. let rations = [];
  507. if (projectGLJData) {
  508. for (let rg of projectObj.project.ration_glj.datas) {
  509. if (rg.projectGLJID == projectGLJData.id) rationIDMap[rg.rationID] = true;
  510. }
  511. for (let r of projectObj.project.Ration.datas) {
  512. if (rationIDMap[r.ID] || (r.type == rationType.gljRation && r.projectGLJID == projectGLJData.id)) {
  513. rations.push(r);
  514. }
  515. }
  516. }
  517. this.relatedRationSheetData = rations;
  518. sheetCommonObj.showData(me.relatedRationSheet, me.relatedRationSetting, rations);
  519. me.relatedRationSheet.setRowCount(rations.length);
  520. },
  521. setInfoClassSelection:function(){
  522. let me = this;
  523. let priceRow = me.infoPriceSheet.getSelections()[0].row;
  524. let infoPrice = me.infoPriceData[priceRow];
  525. if(infoPrice && me.infoClassData.length > 0){
  526. const index = _.findIndex(me.infoClassData,{'ID':infoPrice.classID});
  527. me.infoClassSheet.setSelection(index,0,1,1);
  528. //me.infoClassSheet.clearSelection(); 清除焦点行
  529. me.infoClassSheet.showRow(index, GC.Spread.Sheets.VerticalPosition.center);
  530. }
  531. },
  532. showInforPriceData: function (datas) {
  533. let me = this;
  534. me.infoPriceData = datas;
  535. sheetCommonObj.showData(me.infoPriceSheet, me.infoPriceSetting, datas);
  536. me.infoPriceSheet.setRowCount(datas.length);
  537. if(datas.length > 0) me.setInfoClassSelection();
  538. },
  539. showInforClassData: function (datas) {
  540. let me = this;
  541. me.infoClassData = datas;
  542. for(let d of datas){
  543. d.collapsed = false;
  544. }
  545. sheetCommonObj.showTreeData(me.infoClassSheet, me.infoClassSetting, datas);
  546. },
  547. autoShowInfoPriceData: function () {
  548. if (!$('#info-nav').hasClass('active')) return;
  549. let projectGLJData = this.getProjectGLJSelected();
  550. if(projectGLJData){
  551. $('#info_search_name').val(projectGLJData.name);
  552. let code = projectGLJData.code.substr(0, 4);
  553. $('#info_glj_name').val(projectGLJData.name);
  554. $('#info_glj_code').val(code);
  555. this.searchInfoPrice(null);
  556. }
  557. },
  558. getMixRatioSheetData: function (glj) {
  559. let data = {
  560. id: glj.id,
  561. mix_ratio_id: glj.ratio_data.id,
  562. code: glj.code,
  563. name: glj.name,
  564. specs: glj.specs,
  565. unit: glj.unit,
  566. type: glj.type,
  567. short_name: projectObj.project.projectGLJ.getShortNameByID(glj.type),
  568. consumption: glj.ratio_data.consumption,
  569. unit_price: glj.unit_price,
  570. connect_key: glj.ratio_data.connect_key
  571. };
  572. gljOprObj.setGLJPrice(data, glj);
  573. return data;
  574. },
  575. onProjectGljEditStarting: function (sender, args) {
  576. let me = projectGljObject;
  577. let row = args.row;
  578. let col = args.col;
  579. if (me.projectGljEditChecking(row, col) == false) {
  580. args.cancel = true;
  581. }
  582. },
  583. projectGljEditChecking: function (row, col, isPaste = false) { //return false表示不能编辑
  584. let me = projectGljObject;
  585. let data = null,
  586. setting = null;
  587. let sheet = me.projectGljSpread.getActiveSheet();
  588. if (sheet.name() == 'projectGljSheet') {
  589. if (row >= me.projectGljSheetData.length) return false;
  590. data = me.projectGljSheetData[row];
  591. setting = me.projectGljSetting;
  592. } else if (sheet.name() == 'materialTreeSheet') {
  593. data = me.materialTree.selected.data;
  594. setting = me.materialSetting;
  595. let notEditId = ['GC', 'GJ', 'MC', 'SN', 'SZ'];
  596. if (notEditId.indexOf(data.id) != -1) {
  597. return false;
  598. }
  599. }
  600. let dataCode = setting.header[col].dataCode;
  601. let lockColumns = setting.view.lockColumns;
  602. if (lockColumns.indexOf(col) != -1) return false;
  603. if (isPaste == false && (dataCode == 'is_adjust_price' || dataCode == 'is_evaluate' || dataCode == 'is_main_material' || dataCode == 'is_eval_material' || dataCode == 'no_tax_eqp')) { //除了粘贴,拖动填充等操作,其它的都不能编辑
  604. return false;
  605. }
  606. if (dataCode == 'basePrice' || dataCode == 'marketPrice' || dataCode == 'supply') { //有组成物时,市场单价、定额价、供货方式不能修改
  607. if (data.ratio_data && data.ratio_data.length > 0) return false;
  608. if (dataCode == 'basePrice' && data.is_add != 1) return false; //如果不是新增,定额价不可修改。
  609. }
  610. if (dataCode == 'supply_quantity' && data.supply != 1) return false; // 如果为部分甲供则甲供数量需要可编辑,其它的都不能编辑
  611. if (dataCode == 'materialCoe') { //三材类别为空时,三材系数应只读,不允许输入。
  612. if (data.materialType == undefined || data.materialType == null || data.materialType == '') return false;
  613. }
  614. if (dataCode == 'taxRate') {
  615. //普通材料、商品混凝土、商品砂浆、机械组成物、主材、设备才能编辑
  616. if (!_.includes([gljType.GENERAL_MATERIAL, gljType.COMMERCIAL_CONCRETE, gljType.COMMERCIAL_MORTAR, gljType.MACHINE_COMPOSITION, gljType.MAIN_MATERIAL, gljType.EQUIPMENT], data.type)) {
  617. return false
  618. }
  619. }
  620. return true;
  621. },
  622. onSelectionChange: function () {
  623. let me = projectGljObject;
  624. me.showMixRatioData();
  625. me.materialTreeSheet.repaint();
  626. },
  627. onRelatedRationDoubleClick: function (sender, args) {
  628. let me = projectGljObject;
  629. let record = me.relatedRationSheetData[args.row];
  630. $("#tab_zaojiashu").click();
  631. locateObject.locateNode(record.ID);
  632. },
  633. onInfoPriceDoubleClick: function(sender, args) {
  634. projectGljObject.preApplyInfoPrice(args.row);
  635. },
  636. infoPriceSelectionChange:function(sender, args){
  637. projectGljObject.setInfoClassSelection();
  638. },
  639. infoClassSelectionChange:function(sender, args){
  640. let me = projectGljObject;
  641. let row = args.newSelections[0].row;
  642. let infoClass = me.infoClassData[row];
  643. if(infoClass){
  644. $("#info_class").val(infoClass.ID);
  645. $("#info_glj_name").val("")//清除工料机名字搜索项
  646. me.searchInfoPrice();
  647. }
  648. },
  649. onProjectGljSelectionChange: function (sender, args) {
  650. let me = projectGljObject;
  651. let newSel = args.newSelections[0];
  652. let oldSel = args.oldSelections ? args.oldSelections[0] : {};
  653. me.projectGljSheet.suspendPaint();
  654. me.projectGljSheet.suspendEvent();
  655. if (newSel.row != oldSel.row) {
  656. let style = gljOprObj.getSelStyle(true, {});
  657. me.projectGljSheet.setStyle(newSel.row, -1, style);
  658. let orow = oldSel.row == '' || oldSel.row == -1 ? 0 : oldSel.row;
  659. if (me.projectGljSheetData[orow]) {
  660. style = gljOprObj.getSelStyle(false, {}, me.projectGljSheetData[orow].bgColour);
  661. } else {
  662. style.backColor = "White";
  663. }
  664. me.projectGljSheet.setStyle(orow, -1, style);
  665. me.projectGljRowChang();
  666. } else {
  667. me.projectGljSheet.repaint();
  668. }
  669. me.projectGljSheet.resumeEvent();
  670. me.projectGljSheet.resumePaint();
  671. },
  672. projectGljRowChang: function (row) {
  673. let me = projectGljObject;
  674. let sel = me.mixRatioSheet.getSelections()[0];
  675. sel.row = -1;
  676. sel.col = 0;
  677. sel.rowCount = 1;
  678. sel.colCount = 1;
  679. me.showMixRatioData();
  680. me.showRelatedRationDatas();
  681. $("#info_class").val("");
  682. me.autoShowInfoPriceData();
  683. },
  684. rightClickCallback: function (row) {
  685. let me = projectGljObject;
  686. let sheet = me.projectGljSpread.getActiveSheet();
  687. if (sheet.name() == 'projectGljSheet') {
  688. me.projectGljRowChang(row);
  689. } else if (sheet.name() == 'materialTreeSheet') {
  690. me.materialTreeController.setTreeSelected(me.materialTreeController.tree.items[row]);
  691. }
  692. },
  693. onProjectGljRangeChange: function (sender, info) {
  694. let me = projectGljObject;
  695. let changeInfo = [];
  696. let canChange = true;
  697. if (info.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  698. if (me.projectGljEditChecking(info.row, info.col) == false) {
  699. canChange = false;
  700. } else {
  701. info.newValue = null;
  702. me.onProjectGLJValueChange(sender, info);
  703. return;
  704. }
  705. }
  706. for (let c of info.changedCells) {
  707. let value = info.sheet.getCell(c.row, c.col).text();
  708. changeInfo.push({
  709. row: c.row,
  710. col: c.col,
  711. value: value
  712. });
  713. if (me.projectGljEditChecking(c.row, c.col, true) == false) { //如果不能编辑
  714. canChange = false;
  715. break;
  716. }
  717. if (!me.checkData(c.col, me.projectGljSetting, value)) {
  718. alert('输入的数据类型不对,请重新输入!');
  719. canChange = false;
  720. break;
  721. }
  722. }
  723. if (canChange == false) { //恢复原来的值
  724. info.sheetName == "materialTreeSheet" ? me.showMaterialTreeData() : me.showProjectGljData();
  725. } else if (info.sheetName == "projectGljSheet") {
  726. me.batchUpdateProjectGLJ(changeInfo, info.sheetName);
  727. }
  728. },
  729. onMixRatioRangeChange: function (sender, info) {
  730. let me = projectGljObject;
  731. let canChange = true;
  732. let changeInfo = [];
  733. /* if (info.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  734. info.newValue = 0;
  735. me.onMixRatioValueChange(sender,info);
  736. info.sheet.getCell(info.row, info.col).text(0);
  737. return ;
  738. } */
  739. for (let c of info.changedCells) {
  740. let value = info.sheet.getCell(c.row, c.col).text();
  741. if (_.isEmpty(value)) value = 0;
  742. if (!me.checkData(c.col, me.mixRatioSetting, value)) {
  743. alert('输入的数据类型不对,请重新输入!');
  744. canChange = false;
  745. break;
  746. } else {
  747. changeInfo.push({
  748. row: c.row,
  749. col: c.col,
  750. value: value
  751. });
  752. }
  753. }
  754. if (canChange == false) me.showMixRatioData(); //数据类型不对
  755. if (changeInfo.length > 0) me.batchUpdateConsumption(changeInfo);
  756. },
  757. batchUpdateProjectGLJ: function (changeInfo, sheetName) {
  758. let projectGLJ = projectObj.project.projectGLJ;
  759. let me = projectGljObject;
  760. let propertyCells = [],
  761. priceCells = [];
  762. let setting = sheetName == "materialTreeSheet" ? me.materialSetting : me.projectGljSetting;
  763. for (let c of changeInfo) {
  764. c.dataCode = setting.header[c.col].dataCode;
  765. if (c.dataCode == 'basePrice' || c.dataCode == 'marketPrice') {
  766. priceCells.push(c);
  767. } else {
  768. propertyCells.push(c);
  769. }
  770. }
  771. me.batchUpdateGLJProperty(propertyCells, sheetName, function () {
  772. //价格属于单价文件表,如果与项目工料机的其它属性一起的话计算起来会比较复杂,同时出现价格与其它属性一起更新的情况也会比较少;
  773. projectGLJ.batchUpdatePrice(priceCells, sheetName);
  774. //me.refreshBySheetName(sheetName); 2020-07-27 改在projectGLJ里统一刷新了
  775. //gljOprObj.refreshView();
  776. });
  777. },
  778. refreshBySheetName: function (sheetName) {
  779. let me = projectGljObject;
  780. if (sheetName == "projectGljSheet") {
  781. me.showProjectGljData();
  782. } else if (sheetName == "materialTreeSheet") {
  783. me.showMaterialTreeData();
  784. }
  785. },
  786. batchUpdateGLJProperty: function (changeInfo, sheetName, callback) {
  787. let me = projectGljObject,
  788. updateMap = {};
  789. let projectGLJ = projectObj.project.projectGLJ;
  790. for (let c of changeInfo) {
  791. if (c.dataCode == 'is_evaluate') continue; //暂估,暂时跳过
  792. let recode = sheetName == "materialTreeSheet" ? me.materialTree.items[c.row].data : me.projectGljSheetData[c.row];
  793. if (recode[c.dataCode] == c.value) {
  794. continue;
  795. }
  796. me.getUpdateData(recode.id, c.value, c.dataCode, recode.quantity, updateMap);
  797. }
  798. if (_.isEmpty(updateMap)) {
  799. callback ? callback() : '';
  800. return;
  801. }
  802. projectGLJ.batchUpdateGLJProperty(updateMap, callback);
  803. },
  804. getUpdateData: function (id, value, dataCode, quantity, updateMap) {
  805. let me = projectGljObject;
  806. let supplyMap = {
  807. "自行采购": 0,
  808. "部分甲供": 1,
  809. "完全甲供": 2,
  810. "甲定乙供": 3
  811. };
  812. let materialMap = {
  813. "钢材": 1,
  814. "钢筋": 2,
  815. "木材": 3,
  816. "水泥": 4,
  817. "商品砼": 5,
  818. "商品砂浆": 6
  819. };
  820. let data = updateMap[id] ? updateMap[id] : {};
  821. //供货方式 和三材类型 粘贴和填充过来的数据,要做对应转换,因为这里value只是中文文本,并不是实际的值
  822. // 如果是供货方式则需要处理数据
  823. if (dataCode === 'supply') {
  824. if (supplyMap[value] !== undefined || supplyMap[value] !== null) {
  825. value = supplyMap[value];
  826. }
  827. data.supply_quantity = me.getSupplyQuantity(value, quantity);
  828. }
  829. if (dataCode === 'supply_quantity') { //修改数量需做4舍5入
  830. value = scMathUtil.roundForObj(value, getDecimal('glj.quantity'));
  831. }
  832. if (dataCode === 'is_evaluate' || dataCode === 'is_adjust_price' || dataCode === 'is_main_material') {
  833. value = value ? 1 : 0;
  834. }
  835. if (dataCode === 'materialType') { //三材类型要做对应转换,因为这里value只是中文文本,并不是实际的值
  836. if (materialMap[value] !== undefined || materialMap[value] !== null) {
  837. value = materialMap[value];
  838. }
  839. if (value == null || value == "") { //删除三材类别时,清空三材系数
  840. value = null;
  841. data.materialCoe = null;
  842. }
  843. }
  844. if (dataCode == 'materialCoe') {
  845. value = scMathUtil.roundForObj(value, getDecimal("material"));
  846. }
  847. data[dataCode] = value;
  848. updateMap[id] = data;
  849. },
  850. batchUpdateConsumption: function (changeInfo) {
  851. let projectGLJ = projectObj.project.projectGLJ;
  852. let me = projectGljObject;
  853. let updateMap = {},
  854. updateData = [],
  855. parentBasePrice = 0,
  856. parentMarketPrice = 0;
  857. let parentKey = '',
  858. unit_price_file_id = null;
  859. for (let c of changeInfo) {
  860. let record = me.mixRatioData[c.row];
  861. let value = scMathUtil.roundForObj(c.value, getDecimal("glj.quantity"));
  862. updateMap[record.mix_ratio_id] = {
  863. consumption: value,
  864. record: record
  865. };
  866. updateData.push({
  867. type: 'mix_ratio',
  868. query: {
  869. id: record.mix_ratio_id
  870. },
  871. doc: {
  872. consumption: value
  873. }
  874. });
  875. parentKey = record.connect_key;
  876. unit_price_file_id = record.unit_price.unit_price_file_id;
  877. }
  878. for (let sub of me.mixRatioData) {
  879. let marketPrice = scMathUtil.roundForObj(sub.unit_price.market_price, getDecimal("process"));
  880. let basePrice = scMathUtil.roundForObj(sub.unit_price.base_price, getDecimal("process"));
  881. let consumption = updateMap[sub.mix_ratio_id] ? updateMap[sub.mix_ratio_id].consumption : scMathUtil.roundForObj(sub.consumption, getDecimal("glj.quantity"));
  882. parentMarketPrice = scMathUtil.roundForObj(marketPrice * consumption + parentMarketPrice, getDecimal("process"));
  883. parentBasePrice = scMathUtil.roundForObj(basePrice * consumption + parentBasePrice, getDecimal("process"));
  884. }
  885. parentBasePrice = scMathUtil.roundForObj(parentBasePrice, getDecimal("glj.unitPrice"));
  886. parentMarketPrice = scMathUtil.roundForObj(parentMarketPrice, getDecimal("glj.unitPrice"));
  887. updateData.push({
  888. type: 'parent',
  889. connect_key: parentKey,
  890. base_price: parentBasePrice,
  891. market_price: parentMarketPrice,
  892. unit_price_file_id: unit_price_file_id
  893. });
  894. projectGLJ.batchUpdateConsumption(updateData, updateMap, function () {
  895. //更新人材机汇总表
  896. let parentSheet = me.projectGljSpread.getActiveSheet(); //三材汇总表和工料机汇总表
  897. let prow = parentSheet.getActiveRowIndex(); //取父机械或组成物的下标
  898. let prowData = parentSheet.name() == 'projectGljSheet' ? me.projectGljSheetData[prow] : me.materialTree.items[prow].data;
  899. me.refreshParentData(prow, prowData.id);
  900. me.onUnitFileChange(updateData);
  901. });
  902. },
  903. showProjectGljData: function () {
  904. if (!this.projectGljSpread) return;
  905. let me = this;
  906. this.projectGljSpread.setActiveSheetIndex(0);
  907. let sel = this.projectGljSheet.getSelections()[0];
  908. let oldData = sel.row < this.projectGljSheetData.length ? this.projectGljSheetData[sel.row] : "";
  909. let projectGljSheetData = [];
  910. let gljList = projectObj.project.projectGLJ.datas.gljList;
  911. gljList = this.filterProjectGLJ(gljList);
  912. gljList = sortProjectGLJ(gljList);
  913. for (let glj of gljList) {
  914. projectGljSheetData.push(this.getSheetDataByGLJ(glj));
  915. }
  916. this.projectGljSheetData = projectGljSheetData;
  917. sheetCommonObj.showData(this.projectGljSheet, this.projectGljSetting, this.projectGljSheetData, null, function () {
  918. me.projectGljSheet.setRowCount(me.projectGljSheetData.length);
  919. sel.row = oldData ? _.findIndex(me.projectGljSheetData, {
  920. 'id': oldData.id
  921. }) : -1;
  922. me.projectGljSheet.setSelection(sel.row == -1 ? 0 : sel.row, sel.col, sel.rowCount, sel.colCount);
  923. });
  924. },
  925. showMaterialTreeData: function () {
  926. this.projectGljSpread.setActiveSheetIndex(1);
  927. let sel = this.materialTreeSheet.getSelections()[0];
  928. let oldNodeID = this.materialTree.selected ? this.materialTree.selected.data.id : "";
  929. let gljList = projectObj.project.projectGLJ.datas.gljList;
  930. gljList = _.sortByAll(gljList, ['code']);
  931. this.createMaterialTree(gljList);
  932. this.materialTreeController.showTreeData();
  933. let newNode = this.materialTree.getNodeByID(oldNodeID);
  934. sel.row = newNode ? newNode.serialNo() : -1;
  935. this.materialTreeSheet.setSelection(sel.row == -1 ? 0 : sel.row, sel.col, sel.rowCount, sel.colCount);
  936. this.materialTreeController.setTreeSelected(this.materialTree.items[sel.row == -1 ? 0 : sel.row]);
  937. },
  938. initSheetViews: function () {
  939. let me = projectGljObject;
  940. if (me.displayType == filterType.AMAE || me.displayType == filterType.ZGCL || me.displayType == filterType.PBCL) {
  941. $('#adjustType').hide();
  942. if (me.displayType == filterType.AMAE) {
  943. let adjustType = projectObj.project.projectInfo.property.gljAdjustType || 'priceInfo';
  944. $('#adjustType').val(adjustType);
  945. $('#adjustType').show();
  946. }
  947. configMaterialObj.setNavLinkText(me.displayType);
  948. $('#material_adjust').hide();
  949. $('#project-glj-main').hide();
  950. $('#config_material').show();
  951. } else {
  952. $('#material_adjust').hide();
  953. $('#adjustType').hide();
  954. $('#config_material').hide();
  955. $('#project-glj-main').show();
  956. if (me.displayType == filterType.JGCL || me.displayType == filterType.SCHZ) {
  957. $("#projectGljResize").hide();
  958. $("#projectGljBottom").hide();
  959. } else {
  960. $("#projectGljResize").show();
  961. $("#projectGljBottom").show();
  962. }
  963. }
  964. },
  965. refreshViewsData: function () {
  966. let me = projectGljObject;
  967. if (me.displayType == filterType.AMAE) return materialAdjustObj.refreshSheetDatas();
  968. if (me.displayType == filterType.ZGCL || me.displayType == filterType.PBCL) return configMaterialObj.refreshSheetDatas();
  969. me.refreshDataSheet();
  970. },
  971. refreshDataSheet: function (refresh) { //refresh = true 的时候不用更新表头信息
  972. let me = projectGljObject;
  973. if (!refresh) {
  974. let quantityCol = _.findIndex(me.projectGljSetting.header, function (header) {
  975. return header.dataCode == 'quantity' || header.dataCode == 'techQuantity' || header.dataCode == 'subdivisionQuantity';
  976. });
  977. if (me.displayType == filterType.FBFX) { //分部分项人材机,将“总消耗量”替换显示为“分部分项总消耗量”。
  978. me.projectGljSetting.header[quantityCol].dataCode = 'subdivisionQuantity';
  979. me.projectGljSheet.setValue(0, quantityCol, "分部分项总消耗量", GC.Spread.Sheets.SheetArea.colHeader);
  980. } else if (me.displayType == filterType.TECH) { //措施项目人材机,将“总消耗量”替换显示为“措施项目总消耗量”。
  981. me.projectGljSetting.header[quantityCol].dataCode = 'techQuantity';
  982. me.projectGljSheet.setValue(0, quantityCol, "措施项目总消耗量", GC.Spread.Sheets.SheetArea.colHeader);
  983. } else {
  984. me.projectGljSetting.header[quantityCol].dataCode = 'quantity';
  985. me.projectGljSheet.setValue(0, quantityCol, "总消耗量", GC.Spread.Sheets.SheetArea.colHeader);
  986. }
  987. }
  988. if (me.displayType == filterType.SCHZ) { //三材汇总树节点
  989. me.showMaterialTreeData();
  990. } else {
  991. me.showProjectGljData();
  992. me.showMixRatioData();
  993. me.showRelatedRationDatas();
  994. }
  995. },
  996. createMaterialTree: function (gljList) {
  997. let me = projectGljObject;
  998. let q_decimal = getDecimal("glj.quantity");
  999. let GC = {
  1000. id: 'GC',
  1001. name: materialType[materialTypeMap.GC],
  1002. code: 'GC',
  1003. unit: 't',
  1004. ParentID: -1,
  1005. NextSiblingID: 'MC'
  1006. };
  1007. let GJ = {
  1008. id: 'GJ',
  1009. name: materialType[materialTypeMap.GJ],
  1010. code: 'GJ',
  1011. unit: 't',
  1012. ParentID: 'GC',
  1013. NextSiblingID: -1
  1014. };
  1015. let MC = {
  1016. id: 'MC',
  1017. name: materialType[materialTypeMap.MC],
  1018. code: 'MC',
  1019. unit: 'm3',
  1020. ParentID: -1,
  1021. NextSiblingID: 'SN'
  1022. };
  1023. let SN = {
  1024. id: 'SN',
  1025. name: materialType[materialTypeMap.SN],
  1026. code: 'SN',
  1027. unit: 't',
  1028. ParentID: -1,
  1029. NextSiblingID: 'ST'
  1030. };
  1031. let ST = {
  1032. id: 'ST',
  1033. name: materialType[materialTypeMap.ST],
  1034. code: 'SPT',
  1035. unit: 'm3',
  1036. ParentID: -1,
  1037. NextSiblingID: 'SS'
  1038. };
  1039. let SS = {
  1040. id: 'SS',
  1041. name: materialType[materialTypeMap.SS],
  1042. code: 'SPJS',
  1043. unit: 'm3',
  1044. ParentID: -1,
  1045. NextSiblingID: '-1'
  1046. };
  1047. let rootDatas = [GC, GJ, MC, SN, ST, SS];
  1048. let parentMap = {};
  1049. let sumMap = {};
  1050. this.materialTree.nodes = {}, this.materialTree.selected = null, this.materialTree.roots = [], this.materialTree.items = [];
  1051. for (let r of rootDatas) {
  1052. let baseNode = null;
  1053. if (r.id == 'GJ') {
  1054. baseNode = createMaterialNode(r, parentMap['GC'], null); //钢筋的父节点为钢材
  1055. } else {
  1056. baseNode = createMaterialNode(r, null, null);
  1057. }
  1058. parentMap[r.id] = baseNode;
  1059. }
  1060. for (let g of gljList) {
  1061. if (g.quantity !== 0 && g.quantity !== '0') {
  1062. if (g.materialType) {
  1063. let tem = me.getMaterialSheetDataByGLJ(g);
  1064. if (tem.materialQuantity) {
  1065. sumMap[g.materialType] = sumMap[g.materialType] ? sumMap[g.materialType] + tem.materialQuantity : tem.materialQuantity;
  1066. tem.materialQuantity = scMathUtil.roundToString(tem.materialQuantity, q_decimal); //转成string
  1067. }
  1068. if (g.materialType == materialTypeMap.GC) { //钢材的下一节点是钢筋
  1069. createMaterialNode(tem, parentMap['GC'], parentMap['GJ']);
  1070. } else {
  1071. createMaterialNode(tem, parentMap[materialTypeMap[g.materialType]]);
  1072. }
  1073. }
  1074. }
  1075. }
  1076. for (let mkey in sumMap) {
  1077. if (mkey == materialTypeMap.GC && sumMap[materialTypeMap.GJ]) { //钢材汇总要加上钢筋的总量
  1078. parentMap['GC'].data.materialQuantity = scMathUtil.roundToString(sumMap[mkey] + sumMap[materialTypeMap.GJ], q_decimal);
  1079. } else {
  1080. parentMap[materialTypeMap[mkey]].data.materialQuantity = scMathUtil.roundToString(sumMap[mkey], q_decimal);
  1081. }
  1082. }
  1083. this.materialTree.sortTreeItems();
  1084. function createMaterialNode(data, parent, next) {
  1085. let newNode = me.materialTree.addNode(parent, next, data.id);
  1086. newNode.data = data;
  1087. return newNode;
  1088. }
  1089. },
  1090. getMaterialSheetDataByGLJ: function (glj) {
  1091. let q_decimal = getDecimal("glj.quantity");
  1092. let m_decimal = getDecimal("material");
  1093. let p_decimal = getDecimal("glj.unitPrice");
  1094. let projectGLJ = projectObj.project.projectGLJ;
  1095. let data = {
  1096. id: glj.id,
  1097. code: glj.code,
  1098. name: glj.name,
  1099. specs: glj.specs,
  1100. unit: glj.unit,
  1101. type: glj.type,
  1102. short_name: projectGLJ.getShortNameByID(glj.type),
  1103. quantity: scMathUtil.roundToString(glj.quantity, q_decimal),
  1104. supply: glj.supply,
  1105. supply_quantity: glj.supply_quantity,
  1106. materialType: glj.materialType,
  1107. delivery: glj.delivery,
  1108. delivery_address: glj.delivery_address,
  1109. is_adjust_price: glj.is_adjust_price,
  1110. ratio_data: glj.ratio_data,
  1111. is_add: glj.unit_price.is_add,
  1112. bgColour: 'white'
  1113. };
  1114. if (glj.materialCoe) {
  1115. data.materialCoe = scMathUtil.roundForObj(glj.materialCoe, m_decimal);
  1116. data.materialQuantity = scMathUtil.roundForObj(glj.materialCoe * glj.quantity, q_decimal); //还要做汇总,汇总完再转成string
  1117. }
  1118. gljOprObj.setGLJPrice(data, glj);
  1119. data.basePrice = scMathUtil.roundToString(data.basePrice, p_decimal);
  1120. data.marketPrice = scMathUtil.roundToString(data.marketPrice, p_decimal);
  1121. return data;
  1122. },
  1123. filterProjectGLJ: function (gljList) {
  1124. let me = projectGljObject;
  1125. if (gljList.length > 0) {
  1126. gljList = _.filter(gljList, function (item) {
  1127. return me.displayTypeFilter(item);
  1128. });
  1129. }
  1130. return gljList;
  1131. },
  1132. displayTypeFilter: function (item) {
  1133. let me = this;
  1134. if (item.quantity !== 0 && item.quantity !== '0') { //过滤掉消耗量为0的工料机
  1135. if (me.displayType == filterType.ALL) { //所有工料机
  1136. return true;
  1137. } else if (filterTypeArray.indexOf(me.displayType) != -1) { //人工、材料、机械、主材、设备
  1138. let typeString = item.type + "";
  1139. return typeString.startsWith(me.displayType);
  1140. } else if (me.displayType == filterType.FBFX) { //“分部分项总消耗量”≠0的工料机行
  1141. return item.subdivisionQuantity !== 0 && item.subdivisionQuantity !== '0';
  1142. } else if (me.displayType == filterType.TECH) { //筛选“措施项目总消耗量”≠0的工料机行
  1143. return item.techQuantity !== 0 && item.techQuantity !== '0';
  1144. } else if (me.displayType == filterType.JGCL) { //筛选“供货方式”=“完全甲供”或“部分甲供”的工料机行
  1145. return item.supply == supplyType.WQJG || item.supply == supplyType.BFJG;
  1146. } else if (me.displayType == filterType.ZGCL) { //筛选“是否暂估”=“是”的工料机行。
  1147. return item.is_evaluate == 1;
  1148. } else if (me.displayType == filterType.ZYCL) { //筛选“主要材料”=“是”的工料机行。
  1149. return item.is_main_material == 1;
  1150. }
  1151. }
  1152. return false;
  1153. },
  1154. getSheetDataByGLJ: function (glj) {
  1155. let projectGLJ = projectObj.project.projectGLJ;
  1156. let materialIdList = projectGLJ.datas.constData.materialIdList;
  1157. let data = {
  1158. id: glj.id,
  1159. code: glj.code,
  1160. name: glj.name,
  1161. specs: glj.specs,
  1162. unit: glj.unit,
  1163. type: glj.type,
  1164. short_name: projectGLJ.getShortNameByID(glj.type),
  1165. quantity: glj.quantity,
  1166. tenderQuantity: glj.tenderQuantity,
  1167. supply: glj.supply,
  1168. supply_quantity: glj.supply_quantity,
  1169. materialType: glj.materialType,
  1170. materialCoe: glj.materialCoe,
  1171. delivery: glj.delivery,
  1172. delivery_address: glj.delivery_address,
  1173. is_adjust_price: glj.is_adjust_price,
  1174. ratio_data: glj.ratio_data,
  1175. is_add: glj.unit_price.is_add,
  1176. bgColour: 'white',
  1177. techQuantity: glj.techQuantity,
  1178. subdivisionQuantity: glj.subdivisionQuantity,
  1179. originPlace: glj.originPlace,
  1180. vender: glj.vender,
  1181. qualityGrace: glj.qualityGrace,
  1182. brand: glj.brand,
  1183. unitPriceID: glj.unit_price.id,
  1184. priceFrom: glj.unit_price.priceFrom,
  1185. remark: glj.remark
  1186. };
  1187. gljOprObj.setGLJPrice(data, glj);
  1188. data.is_main_material = glj.is_main_material == 1 ? 1 : 0;
  1189. //供货方式为完全甲供时设置甲供数量为总消耗量
  1190. if (data.supply == 2) data.supply_quantity = glj.quantity;
  1191. // 只有材料才显示是否暂估
  1192. if (materialIdList.indexOf(glj.type) >= 0) data.is_evaluate = glj.is_evaluate;
  1193. //是“材料”、“主材”、“设备”时显示评标材料
  1194. if (materialIdList.indexOf(glj.type) >= 0 || glj.type == gljType.MAIN_MATERIAL || glj.type == gljType.EQUIPMENT) data.is_eval_material = glj.is_eval_material ? glj.is_eval_material : 0;
  1195. //类型是“设备”时有效
  1196. if (glj.type == gljType.EQUIPMENT) data.no_tax_eqp = glj.no_tax_eqp ? glj.no_tax_eqp : 0;
  1197. if (glj.materialCoe !== null && glj.materialCoe !== undefined) {
  1198. data.materialCoe = scMathUtil.roundForObj(glj.materialCoe, getDecimal("material"));
  1199. }
  1200. //bgColour
  1201. if (data.basePrice == data.marketPrice) { //如果定额价等于市场价时,改底色。 优先度低于有组成物时的底色
  1202. data.bgColour = "#C4CAFB";
  1203. }
  1204. if (gljUtil.notEditType.indexOf(glj.type) >= 0) {
  1205. if (data.ratio_data && data.ratio_data.length > 0) { //有组成物时
  1206. //设置底色
  1207. data.bgColour = "#E0E0E0";
  1208. }
  1209. }
  1210. return data;
  1211. },
  1212. refreshProjectGljRow: function (row) {
  1213. let me = projectGljObject;
  1214. let rowData = me.projectGljSheetData[row];
  1215. let glj = projectObj.project.projectGLJ.getByID(rowData.id);
  1216. let newRow = null;
  1217. if (glj) {
  1218. newRow = me.getSheetDataByGLJ(glj);
  1219. }
  1220. if (me.displayTypeFilter(newRow) == true) {
  1221. me.projectGljSheetData[row] = newRow;
  1222. sheetCommonObj.showRowData(this.projectGljSheet, this.projectGljSetting, row, this.projectGljSheetData);
  1223. } else {
  1224. me.projectGljSheetData.splice(row, 1);
  1225. me.projectGljSheet.deleteRows(row, 1);
  1226. me.showMixRatioData();
  1227. me.showRelatedRationDatas();
  1228. }
  1229. //me.projectGljSheetData[row] = me.getSheetDataByGLJ(glj);
  1230. },
  1231. initSheet: function (sheet, setting) {
  1232. var me = this;
  1233. sheetCommonObj.initSheet(sheet, setting, 30);
  1234. sheet.bind(GC.Spread.Sheets.Events.ValueChanged, me.onSheetValueChange);
  1235. },
  1236. onSheetValueChange: function (e, info) {
  1237. let me = projectGljObject;
  1238. if (info.sheetName == 'projectGljSheet') {
  1239. me.onProjectGLJValueChange(e, info);
  1240. } else if (info.sheetName == 'mixRatioSheet') {
  1241. me.onMixRatioValueChange(e, info);
  1242. }
  1243. },
  1244. onMixRatioValueChange: function (e, info) {
  1245. let composition = projectObj.project.composition;
  1246. let me = projectGljObject,
  1247. row = info.row,
  1248. col = info.col;
  1249. let dataCode = me.mixRatioSetting.header[col].dataCode;
  1250. let recode = me.mixRatioData[row];
  1251. let value = info.newValue;
  1252. let parentSheet = me.projectGljSpread.getActiveSheet(); //三材汇总表和工料机汇总表
  1253. if (!me.checkData(col, me.mixRatioSetting, value)) {
  1254. alert('输入的数据类型不对,请重新输入!');
  1255. me.mixRatioSheet.setValue(row, col, info.oldValue);
  1256. return false;
  1257. }
  1258. value = scMathUtil.roundToString(value, getDecimal("glj.quantity"));
  1259. me.batchUpdateConsumption([{
  1260. row: row,
  1261. col: col,
  1262. value
  1263. }]);
  1264. },
  1265. refreshParentData: function (row, pid, sid) {
  1266. let me = this;
  1267. let sheet = me.projectGljSpread.getActiveSheet();
  1268. let parantData = null;
  1269. if (sheet.name() == 'projectGljSheet') {
  1270. me.showProjectGljData(); // me.refreshProjectGljRow(row) 这里原来是分开刷新的,现在整个统一刷新,先留着
  1271. //parantData = _.find(); //me.projectGljSheetData[row];
  1272. } else {
  1273. me.showMaterialTreeData();
  1274. //parantData = me.materialTree.items[row].data;
  1275. }
  1276. let pglj = _.find(projectObj.project.projectGLJ.datas.gljList, {
  1277. 'id': pid
  1278. });
  1279. parantData = pglj ? me.getSheetDataByGLJ(pglj) : null;
  1280. //projectObj.project.projectGLJ.datas.gljList
  1281. // 更新组成物缓存
  1282. projectObj.project.composition.loadData();
  1283. me.updateParentNodes(pid, parantData.marketPrice, sid);
  1284. },
  1285. updateParentNodes: function (pid, marketPrice, sid) {
  1286. //先查找使用了父项目工料机的定额工料机
  1287. let updateNodes = [];
  1288. let ration_gljs = _.filter(projectObj.project.ration_glj.datas, {
  1289. 'projectGLJID': pid
  1290. });
  1291. for (let rg of ration_gljs) {
  1292. let node = projectObj.project.mainTree.getNodeByID(rg.rationID);
  1293. if (node) {
  1294. updateNodes.push(node);
  1295. }
  1296. }
  1297. //或者是使用了父项目工料机的工料机类型的定额
  1298. let rations = _.filter(projectObj.project.Ration.datas, {
  1299. 'type': 3,
  1300. 'projectGLJID': pid
  1301. });
  1302. for (let r of rations) {
  1303. let r_node = projectObj.project.mainTree.getNodeByID(r.ID);
  1304. if (r_node) {
  1305. r_node.data.marketUnitFee = marketPrice; //parentMarketPrice;//这里用显示的价格
  1306. updateNodes.push(r_node);
  1307. }
  1308. }
  1309. if (sid) {
  1310. let subRations = calcTools.getRationsByProjectGLJ(sid);
  1311. updateNodes = updateNodes.concat(subRations);
  1312. }
  1313. if (updateNodes.length > 0) {
  1314. projectObj.project.calcProgram.calcNodesAndSave(updateNodes, async function () {
  1315. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  1316. installationFeeObj.calcInstallationFee(); //计算安装增加费
  1317. await OVER_HEIGHT.reCalcOverHeightFee();
  1318. await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(updateNodes);
  1319. });
  1320. }
  1321. gljOprObj.refreshView();
  1322. },
  1323. onUnitFileChange: function (data) {
  1324. projectObj.project.markUpdateProject({
  1325. projectID: projectObj.project.ID(),
  1326. 'unitFileID': socketObject.getUnitFileRoomID()
  1327. }, "unitFile", function () {
  1328. //socket.emit('unitFileChangeNotify', JSON.stringify(data));
  1329. socket.emit('unitFileChangeNotify', {
  1330. projectID: projectObj.project.ID(),
  1331. userID: userID,
  1332. 'unitFileID': socketObject.getUnitFileRoomID()
  1333. });
  1334. });
  1335. },
  1336. deleteMixRatio: function (row) {
  1337. let me = this,
  1338. deleteRecode = me.mixRatioData[row];
  1339. let consumption = deleteRecode.consumption;
  1340. let [parentMarketPrice, parentBasePrice] = me.getCompositionSumPrice('delete', row);
  1341. let parentSheet = me.projectGljSpread.getActiveSheet(); //三材汇总表和工料机汇总表
  1342. let prow = parentSheet.getActiveRowIndex(); //取父机械或组成物的下标
  1343. let prowData = parentSheet.name() == 'projectGljSheet' ? me.projectGljSheetData[prow] : me.materialTree.items[prow].data;
  1344. let updateData = {
  1345. id: deleteRecode.mix_ratio_id,
  1346. field: 'mix_ratio.consumption',
  1347. value: 0,
  1348. market_price: parentMarketPrice,
  1349. base_price: parentBasePrice
  1350. };
  1351. projectObj.project.composition.deleteComposition(updateData, deleteRecode, prowData.id, function () {
  1352. _.remove(me.mixRatioData, {
  1353. "mix_ratio_id": deleteRecode.mix_ratio_id
  1354. });
  1355. me.refreshParentData(prow, prowData.id);
  1356. me.mixRatioSheet.deleteRows(row, 1);
  1357. me.onUnitFileChange(deleteRecode);
  1358. });
  1359. },
  1360. getCompositionSumPrice: function (scene, affectRow, newValue = 0) {
  1361. let me = this;
  1362. let parentMarketPrice = 0;
  1363. let parentBasePrice = 0;
  1364. for (let i = 0; i < me.mixRatioData.length; i++) {
  1365. let ratio = me.mixRatioData[i];
  1366. let marketPrice = ratio.unit_price.market_price;
  1367. let basePrice = ratio.unit_price.base_price;
  1368. // 如果是删除则忽略即将被删除的行数据
  1369. if (scene === 'delete' && affectRow === i) {
  1370. continue;
  1371. }
  1372. let consumption = i === affectRow ? newValue : ratio.consumption;
  1373. parentMarketPrice += operationWithRound(consumption, marketPrice, "glj.unitPrice", "*");
  1374. parentBasePrice += operationWithRound(consumption, basePrice, "glj.unitPrice", "*");
  1375. }
  1376. parentMarketPrice = parentMarketPrice.toDecimal(getDecimal("glj.unitPrice"));
  1377. parentBasePrice = parentBasePrice.toDecimal(getDecimal("glj.unitPrice"));
  1378. return [parentMarketPrice, parentBasePrice];
  1379. },
  1380. onProjectGLJValueChange: function (e, info) { //me.projectGljSetting
  1381. let projectGLJ = projectObj.project.projectGLJ;
  1382. let me = projectGljObject,
  1383. row = info.row,
  1384. col = info.col;
  1385. let setting = info.sheetName == "materialTreeSheet" ? me.materialSetting : me.projectGljSetting;
  1386. let dataCode = setting.header[col].dataCode;
  1387. let recode = info.sheetName == "materialTreeSheet" ? me.materialTree.selected.data : me.projectGljSheetData[row];
  1388. let value = info.newValue;
  1389. if (info.newValue === undefined) {
  1390. return;
  1391. }
  1392. if (value && !me.checkData(col, setting, value)) {
  1393. alert('输入的数据类型不对,请重新输入!');
  1394. info.sheetName == "materialTreeSheet" ? me.materialTreeController.refreshTreeNode([me.materialTree.selected]) : me.refreshProjectGljRow(row);
  1395. return;
  1396. }
  1397. let callback = function (impactList) {
  1398. info.sheet.suspendPaint();
  1399. info.sheet.suspendEvent();
  1400. if (dataCode === 'is_adjust_price') {
  1401. projectGLJ.calcQuantity();
  1402. };
  1403. if (info.sheetName == "materialTreeSheet") {
  1404. me.showMaterialTreeData();
  1405. } else {
  1406. // me.refreshProjectGljRow(row);
  1407. me.showProjectGljData();
  1408. for (let g of impactList) {
  1409. me.refreshProjectGljRowByID(g.id, row);
  1410. }
  1411. }
  1412. info.sheet.resumeEvent();
  1413. info.sheet.resumePaint();
  1414. if (dataCode === 'supply' || dataCode === 'supply_quantity' || dataCode === 'is_adjust_price') { // basePrice、marketPrice 有自己的计算代码,无需走这里重复计算
  1415. let rations = calcTools.getRationsByProjectGLJ(recode.id);
  1416. projectObj.project.calcProgram.calcNodesAndSave(rations, function () {
  1417. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  1418. });
  1419. };
  1420. gljOprObj.refreshView();
  1421. };
  1422. if (dataCode == 'basePrice' || dataCode == 'marketPrice') { //修改市场价和修改定额价时需要重新记算很多受影响的树节点,现在改成与定字额工料机那里调相同的方法。
  1423. let editField = dataCode === 'basePrice' ? "base_price" : "market_price";
  1424. projectObj.project.projectGLJ.updatePrice(recode, editField, value, 'pg', null, callback);
  1425. } else {
  1426. let extend = {};
  1427. // 如果是供货方式则需要处理数据
  1428. if (dataCode === 'supply') {
  1429. extend.supply_quantity = me.getSupplyQuantity(value, recode.quantity);
  1430. }
  1431. if (dataCode === 'supply_quantity') { //修改数量需做4舍5入
  1432. value = scMathUtil.roundForObj(value, getDecimal('glj.quantity'));
  1433. }
  1434. if (dataCode === 'is_evaluate' || dataCode === 'is_adjust_price' || dataCode === 'is_main_material' || dataCode === 'no_tax_eqp' || dataCode == 'is_eval_material') {
  1435. value = value == true ? 1 : 0;
  1436. if (dataCode === 'is_evaluate' || dataCode == 'is_eval_material') {
  1437. configMaterialObj.updateConfigMaterial(dataCode, value, recode); //暂估材料,主要材料等新需求
  1438. return
  1439. }
  1440. }
  1441. if (dataCode === 'materialType' && (value == null || value == "")) { //删除三材类别时,清空三材系数
  1442. value = null;
  1443. extend.materialCoe = null;
  1444. }
  1445. if (dataCode == 'materialCoe') {
  1446. value = scMathUtil.roundForObj(value, getDecimal("material"));
  1447. }
  1448. if (dataCode == 'taxRate') value = scMathUtil.roundToString(value, 2);
  1449. extend = Object.keys(extend).length > 0 ? JSON.stringify(extend) : '';
  1450. if (recode[dataCode] == value) return;
  1451. let updateData = {
  1452. id: recode.id,
  1453. field: dataCode,
  1454. value: value,
  1455. extend: extend
  1456. };
  1457. projectGLJ.pGljUpdate(updateData, callback);
  1458. };
  1459. },
  1460. refreshProjectGljRowByID: function (ID, row) { //row 可以不传,如果row 和 index 相等就不刷新
  1461. let me = this;
  1462. let index = _.findIndex(me.projectGljSheetData, {
  1463. 'id': ID
  1464. });
  1465. if (index >= 0 && index != row) {
  1466. me.refreshProjectGljRow(index);
  1467. }
  1468. },
  1469. getSupplyQuantity: function (supplyType, quantity) {
  1470. // 自行采购和甲定乙供则把甲供数量设置为0,其余情况则设置为当前总消耗量
  1471. let supplyQuantity = supplyType == 0 || supplyType == 3 ? 0 : quantity;
  1472. supplyQuantity = parseFloat(supplyQuantity);
  1473. return supplyQuantity;
  1474. },
  1475. getSupplyQuantityByGlj: function (glj, tender) {
  1476. //{"自行采购":0,"部分甲供":1,"完全甲供":2,"甲定乙供":3};
  1477. let supply_quantity = glj.supply_quantity;
  1478. switch (glj.supply) {
  1479. case 0:
  1480. supply_quantity = 0;
  1481. break;
  1482. case 1:
  1483. break;
  1484. case 2:
  1485. supply_quantity = tender ? glj.tenderQuantity : glj.quantity;
  1486. break;
  1487. case 3:
  1488. supply_quantity = 0;
  1489. break;
  1490. }
  1491. return supply_quantity
  1492. },
  1493. checkData: function (col, setting, value) {
  1494. return sheetCommonObj.checkData(col, setting, value);
  1495. },
  1496. getProjectGLJSelected: function () {
  1497. let me = this,
  1498. data = null;
  1499. let sheet = me.projectGljSpread.getActiveSheet();
  1500. if (sheet.name() == 'projectGljSheet') { //projectGljSheet/materialSheet 工料机汇总和三材汇总表
  1501. let sel = me.projectGljSheet.getSelections()[0];
  1502. let srow = sel.row == -1 || sel.row == "" ? 0 : sel.row;
  1503. if (me.projectGljSheetData.length > srow) {
  1504. data = me.projectGljSheetData[srow];
  1505. }
  1506. } else if (sheet.name() == 'materialTreeSheet') {
  1507. if (this.materialTree.selected) {
  1508. data = this.materialTree.selected.data;
  1509. }
  1510. }
  1511. return data;
  1512. },
  1513. initInfoPriceRightClick: function () {
  1514. let me = this;
  1515. $.contextMenu({
  1516. selector: '#info_price_sheet',
  1517. build: function ($trigger, e) {
  1518. me.rightClickTarget = SheetDataHelper.safeRightClickSelection($trigger, e, me.infoPriceSpread);
  1519. return me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.viewport ||
  1520. me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1521. },
  1522. items: {
  1523. "apply": {
  1524. name: "确认套用(或双快速套用)",
  1525. icon: 'fa-sign-in',
  1526. disabled: function () {
  1527. return me.rightClickTarget.row === undefined;
  1528. },
  1529. callback: function (key, opt) {
  1530. let row = me.rightClickTarget.row;
  1531. me.preApplyInfoPrice(row);
  1532. }
  1533. }
  1534. }
  1535. });
  1536. },
  1537. initRightClick: function () {
  1538. let activeSheet = this.mixRatioSheet;
  1539. let me = this;
  1540. $.contextMenu({
  1541. selector: '#mix_ratio_sheet',
  1542. build: function ($trigger, e) {
  1543. me.rightClickTarget = SheetDataHelper.safeRightClickSelection($trigger, e, me.mixRatioSpread);
  1544. return me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.viewport ||
  1545. me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1546. },
  1547. items: {
  1548. "deleteMixRatio": {
  1549. name: "删除",
  1550. icon: 'fa-trash-o',
  1551. disabled: function () {
  1552. return me.rightClickTarget.row === undefined;
  1553. },
  1554. callback: function (key, opt) {
  1555. let row = me.rightClickTarget.row;
  1556. me.deleteMixRatio(row);
  1557. },
  1558. visible: function (key, opt) {
  1559. if (!$('#mixRatio-nav').hasClass('active')) return false;
  1560. return true;
  1561. }
  1562. },
  1563. "addMixRatio": {
  1564. name: '添加',
  1565. icon: 'fa-sign-in',
  1566. disabled: function () {
  1567. let projectGLJ = projectGljObject.getProjectGLJSelected();
  1568. return !_.includes(compositionTypes, projectGLJ.type);
  1569. },
  1570. callback: function (key, opt) {
  1571. me.selectedProjectGLJ = projectGljObject.getProjectGLJSelected();
  1572. getGLJData('addMix', null, true, null);
  1573. },
  1574. visible: function (key, opt) {
  1575. if (!$('#mixRatio-nav').hasClass('active')) return false;
  1576. return true;
  1577. }
  1578. }
  1579. }
  1580. });
  1581. },
  1582. changeFileCallback: function () {
  1583. projectGljObject.unitPriceFileInit();
  1584. projectGljObject.refreshViewsData();
  1585. gljOprObj.refreshView();
  1586. projectObj.project.calcProgram.calcAllNodesAndSave(calcAllType.catAll, function () {
  1587. if (socketObject.roomInfo) {
  1588. let data = {
  1589. projectID: projectObj.project.ID(),
  1590. oldRoom: socketObject.roomInfo.unitFile,
  1591. newRoom: socketObject.getUnitFileRoomID(),
  1592. userID: userID,
  1593. name: 'unitFile'
  1594. };
  1595. socket.emit('changeNewRoom', data);
  1596. socketObject.roomInfo.unitFile = socketObject.getUnitFileRoomID();
  1597. }
  1598. });
  1599. },
  1600. calcPartASupplyFeeByProjectGLJs: function (projectGLJsArr) {
  1601. for (let pGLJ of projectGLJsArr) {
  1602. if (pGLJ.supply == supplyType.BFJG) {
  1603. let rations = calcTools.getRationsByProjectGLJ(pGLJ.id);
  1604. projectObj.project.calcProgram.calcNodesAndSave(rations, function () {
  1605. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  1606. });
  1607. }
  1608. }
  1609. },
  1610. checkUnitFileName: function (name, callback) {
  1611. let projectGLJ = projectObj.project.projectGLJ;
  1612. projectGLJ.checkUnitFileName(name, function (data) {
  1613. if (data) {
  1614. $("#save-as-tips").text('已存在同名单价文件').show();
  1615. $('#save-as-confirm').attr("disabled", "disabled");
  1616. } else {
  1617. $("#save-as-tips").hide();
  1618. $('#save-as-confirm').removeAttr("disabled");
  1619. if (callback) callback();
  1620. }
  1621. });
  1622. },
  1623. initFilterTypeList: function () { //初始化人材机汇总工料机类型过滤列表
  1624. let htmlString = ' <ul class="nav flex-column">';
  1625. for (let t of this.displayTypeMap) {
  1626. htmlString += '<li class="nav-item "><a class="nav-link pl-4" href="javascript:void(0)" id="' + t.ID + '">' + t.text + '</a></li>';
  1627. }
  1628. htmlString += '</ul>';
  1629. $('#ALL').after(htmlString);
  1630. },
  1631. getInfoPriceOptions: async function () {
  1632. let options = await ajaxPost("/infoPrice/getOptions", {});
  1633. this.infoPriceOptions = options;
  1634. this.createSelectOptions($("#info_area"), options.areas, true);
  1635. let years = _.keysIn(options.periodMap);
  1636. this.createSelectOptions($("#info_year"), _.sortBy(years));
  1637. },
  1638. createSelectOptions: function (ele, opts, isArea) {
  1639. ele.empty();
  1640. let str = `<option value=""></option>`;
  1641. opts.sort((a, b) => a.serialNo - b.serialNo);
  1642. for (let o of opts) {
  1643. if (isArea == true) {
  1644. str += `<option value="${o.ID}">${o.name}</option>`
  1645. if (o.name == "通用") this.commonInfoPriceID = o.ID;
  1646. } else {
  1647. str += `<option value="${o}">${o}</option>`
  1648. }
  1649. }
  1650. ele.html(str);
  1651. },
  1652. onInfoTopRowChanged: function (sender, args) {
  1653. let me = projectGljObject;
  1654. const bottomRow = args.sheet.getViewportBottomRow(1);
  1655. if (me.infoPriceData >= me.infoPriceTotalSize) return;
  1656. if (me.infoPriceData.length - bottomRow < 20) {
  1657. if (projectGljObject.infoPriceLastLoadingRow == me.infoPriceData.length) { //如果最后一行已经加载过了,就不用再加载了,不然会重复加载
  1658. return;
  1659. }
  1660. me.infoPriceLastLoadingRow = me.infoPriceData.length;
  1661. //只有在空的搜索条件下才执行分页查询,其它情况无法分页
  1662. if ($('#info_search_name').val() == "") me.searchInfoPrice(me.infoPriceData[me.infoPriceData.length - 1]._id)
  1663. }
  1664. },
  1665. searchInfoClass:async function(){
  1666. let me = projectGljObject;
  1667. let areaID = $('#info_area').val();
  1668. let year = $('#info_year').val();
  1669. let month = $('#info_month').val();
  1670. let datas = [];
  1671. $('#info_class').val("");
  1672. try {
  1673. if (year != "" && month != "" && areaID != ""){
  1674. let period = year + "-" + month;
  1675. let condition = {areaID:areaID,period:period};
  1676. if (projectGljObject.addCommonInfoPriceID) projectGljObject.addCommonInfoPriceID(condition);
  1677. datas = await ajaxPost("/infoPrice/getClassByAreaID", condition);
  1678. }
  1679. me.showInforClassData(datas);
  1680. } catch (error) {
  1681. console.log(error)
  1682. }
  1683. },
  1684. searchInfoPrice: async function (objectID) {
  1685. let year = $('#info_year').val();
  1686. let month = $('#info_month').val();
  1687. let areaID = $('#info_area').val();
  1688. let keyWord = $('#info_search_name').val();
  1689. let name = $('#info_glj_name').val();
  1690. let code = $('#info_glj_code').val();
  1691. let classID = $("#info_class").val();
  1692. let me = projectGljObject;
  1693. try {
  1694. if (year != "" && month != "" && areaID != "") {
  1695. let condition = {
  1696. period: year + "-" + month,
  1697. areaID: areaID
  1698. }
  1699. if(classID!=""){
  1700. keyWord = "";
  1701. condition.classID = classID;
  1702. }
  1703. if (projectGljObject.addCommonInfoPriceID) projectGljObject.addCommonInfoPriceID(condition);
  1704. let data = {
  1705. condition: condition
  1706. };
  1707. if (keyWord != "") data.keyWord = keyWord;
  1708. if (name !="") data.keyWord = name;
  1709. if (objectID) data.lastID = objectID;
  1710. if (code !="" ) data.code = code;
  1711. let result = await ajaxPost("/infoPrice/getDataByCondition", data);
  1712. if (objectID) { //分页查询
  1713. sheetCommonObj.appendData(me.infoPriceSheet, me.infoPriceData.length, 0, me.infoPriceSetting, result.items);
  1714. me.infoPriceData.splice(me.infoPriceData.length, 0, ...result.items);
  1715. } else {
  1716. me.infoPriceTotalSize = result.totalSize;
  1717. me.infoPriceLastLoadingRow = 0;
  1718. me.showInforPriceData(result.items);
  1719. if (result.totalSize == 0) {
  1720. $("#info-warning").text("当前材料没有信息价! ");
  1721. } else {
  1722. $("#info-warning").text("");
  1723. }
  1724. }
  1725. } else { //当有任意一个为空时,都清空表格
  1726. me.infoPriceTotalSize = 0;
  1727. me.infoPriceLastLoadingRow = 0;
  1728. me.showInforPriceData([]);
  1729. }
  1730. } catch (error) {
  1731. console.log(error)
  1732. }
  1733. },
  1734. preApplyInfoPrice: function (row) {
  1735. let info = this.infoPriceData[row];
  1736. let projectGLJData = this.getProjectGLJSelected();
  1737. if(!projectGLJData) return;
  1738. if (projectGLJData.ratio_data && projectGLJData.ratio_data.length > 0) return;
  1739. let marketPrice = this.getInfoMarketPrice(info);
  1740. if (projectGLJData.unit == info.unit) {
  1741. this.applyInfoPrice(projectGLJData, marketPrice, 1);
  1742. } else if (_.includes(["t", "kg"], projectGLJData.unit) && _.includes(["t", "kg"], info.unit)) {
  1743. //遇到t和kg之间的转换,默认处理:1t=1000kg,不弹换算窗口
  1744. let coeMap = {
  1745. "t": 1,
  1746. "kg": 1000
  1747. };
  1748. let coe = coeMap[info.unit] / coeMap[projectGLJData.unit];
  1749. this.applyInfoPrice(projectGLJData, marketPrice, coe);
  1750. } else { //弹出单位转换窗口
  1751. $("#infoRow").val(row);
  1752. $("#applyGLJName").text(projectGLJData.name);
  1753. $("#applyGLJUnit").text(projectGLJData.unit);
  1754. $("#infoPriceCoe").val("");
  1755. $("#applyInfoUnit").text(info.unit);
  1756. $("#infoPriceCoeDiv").modal('show')
  1757. }
  1758. },
  1759. applyInfoPrice: function (projectGLJData, price, coe) {
  1760. let priceFrom = this.getPriceFrom();
  1761. projectObj.project.projectGLJ.updatePrice(projectGLJData, "market_price", price * coe, 'pg', {
  1762. "priceFrom": priceFrom
  1763. });
  1764. },
  1765. getPriceFrom: function () {
  1766. let area = "";
  1767. for (let o of this.infoPriceOptions.areas) {
  1768. if (o.ID == $("#info_area").val()) {
  1769. area = o.name;
  1770. break;
  1771. }
  1772. }
  1773. return `${area}信息价(${$("#info_year").val()}${$("#info_month").val()})`;
  1774. },
  1775. getInfoMarketPrice: function (info) {
  1776. let taxType = projectObj.project.property.taxType; //1: 一般计税 2: 简易计税
  1777. return gljUtil.getInfoMarketPrice(info, taxType);
  1778. },
  1779. refreshInfoPrice: function () {
  1780. this.setInfoDivHeight();
  1781. if ($('#info_price_sheet').is(':visible')){
  1782. this.initInfoPriceSpread();
  1783. this.initInfoClassSpread();
  1784. }
  1785. },
  1786. setInfoDivHeight:function(){
  1787. let info_height = $("#mix_ratio_sheet").height() - $("#infoToolDiv").height()-10;
  1788. $('#info_price_main').height(info_height);
  1789. $('#info_class_sheet').height(info_height);
  1790. $('#info_price_sheet').height(info_height);
  1791. }
  1792. };
  1793. function getProjectResizeEles() {
  1794. let pojGljResizeEles = {};
  1795. pojGljResizeEles.eleObj = {
  1796. module: 'projectGlj',
  1797. resize: $('#projectGljResize'),
  1798. top: $('#projectGljTop'),
  1799. topSpread: $('#project_glj_sheet'),
  1800. bottom: $('#projectGljBottom'),
  1801. bottomSpread: $('#mix_ratio_sheet')
  1802. };
  1803. pojGljResizeEles.limit = {
  1804. min: 150,
  1805. max: `$(window).height()-$('.header').height()-$('#projectGljToolsBar').height()-150-5`, //5: resize.height()
  1806. notTopSpread: 0,
  1807. notBottomSpread: 0,
  1808. totalHeight: `$(window).height()-$('.header').height()-$('#projectGljToolsBar').height()-5`
  1809. };
  1810. return pojGljResizeEles;
  1811. }
  1812. function getConficMaterialResizeEles() {
  1813. let conficMaterialResizeEles = {};
  1814. conficMaterialResizeEles.eleObj = {
  1815. module: 'conficMaterial',
  1816. resize: $('#configMaterialResize'),
  1817. top: $('#configMaterialTop'),
  1818. topSpread: $('#config_material_sheet'),
  1819. bottom: $('#configMaterialBottom'),
  1820. bottomSpread: $('#related_sheet')
  1821. };
  1822. conficMaterialResizeEles.limit = {
  1823. min: 150,
  1824. max: `$(window).height()-$('.header').height()-$('#projectGljToolsBar').height()-150-5`, //5: resize.height()
  1825. notTopSpread: 0,
  1826. notBottomSpread: 0,
  1827. totalHeight: `$(window).height()-$('.header').height()-$('#projectGljToolsBar').height()-5`,
  1828. bottomNav: `$('#configMaterialBottom ul').height() + $('#filterToolDiv').height()+10`
  1829. };
  1830. return conficMaterialResizeEles;
  1831. }
  1832. function loadProjectGljSize() {
  1833. if ($('#project-glj-main').is(':visible')) {
  1834. let me = projectGljObject;
  1835. let pojGljResizeEles = getProjectResizeEles();
  1836. if (!$("#projectGljBottom").is(':visible')) {
  1837. let total = $(window).height() - $('.header').height() - $('#projectGljToolsBar').height() + 3;
  1838. $("#projectGljTop").height(total);
  1839. $("#project_glj_sheet").height(total);
  1840. me.projectGljSpread ? me.projectGljSpread.refresh() : '';
  1841. } else {
  1842. SlideResize.loadVerticalHeight(pojGljResizeEles.eleObj.module, pojGljResizeEles.eleObj, pojGljResizeEles.limit, function () {
  1843. me.projectGljSpread ? me.projectGljSpread.refresh() : '';
  1844. me.mixRatioSpread ? me.mixRatioSpread.refresh() : '';
  1845. //信息价相关
  1846. me.refreshInfoPrice();
  1847. });
  1848. }
  1849. } else if ($('#material_adjust').is(':visible')) {
  1850. $('#material_adjust_sheet').height($(window).height() - $('.header').height() - $('#projectGljToolsBar').height() + 3);
  1851. if (materialAdjustObj.spread) materialAdjustObj.spread.refresh();
  1852. } else if ($('#config_material').is(':visible')) {
  1853. let configMaterialResizeEles = getConficMaterialResizeEles();
  1854. SlideResize.loadVerticalHeight(configMaterialResizeEles.eleObj.module, configMaterialResizeEles.eleObj, configMaterialResizeEles.limit, function () {
  1855. configMaterialObj.configSpread ? configMaterialObj.configSpread.refresh() : '';
  1856. configMaterialObj.relatedSpread ? configMaterialObj.relatedSpread.refresh() : '';
  1857. /*
  1858. me.mixRatioSpread?me.mixRatioSpread.refresh():'';*/
  1859. });
  1860. }
  1861. }
  1862. //从其他建设项目中复制中,建设项目的文件层次结构名称和顺序
  1863. function getFileHierarchyInfo(treeData) {
  1864. let tree = idTree.createNew({
  1865. id: 'ID',
  1866. pid: 'ParentID',
  1867. nid: 'NextSiblingID',
  1868. rootId: -1
  1869. });
  1870. tree.loadDatas(treeData);
  1871. let items = tree.items;
  1872. let rst = [];
  1873. function getFileHierarchyName(node) {
  1874. let nodeName = node.data.name;
  1875. let name = [];
  1876. while (node.parent) {
  1877. name.push(node.parent.data.name ? node.parent.data.name : '');
  1878. node = node.parent;
  1879. }
  1880. name = name.reverse();
  1881. name.push(nodeName);
  1882. return name.join('\\');
  1883. }
  1884. for (let node of items) {
  1885. if (node.children.length === 0) { //project
  1886. rst.push({
  1887. ID: node.data.ID,
  1888. fileHierarchyName: getFileHierarchyName(node)
  1889. })
  1890. }
  1891. }
  1892. return rst;
  1893. }
  1894. $(function () {
  1895. let pojGljResizeEles = getProjectResizeEles();
  1896. SlideResize.verticalSlide(pojGljResizeEles.eleObj, pojGljResizeEles.limit, function () {
  1897. projectGljObject.projectGljSpread.refresh();
  1898. projectGljObject.mixRatioSpread ? projectGljObject.mixRatioSpread.refresh() : '';
  1899. projectGljObject.refreshInfoPrice();
  1900. });
  1901. let tr = getConficMaterialResizeEles();
  1902. SlideResize.verticalSlide(tr.eleObj, tr.limit, function () {
  1903. configMaterialObj.configSpread ? configMaterialObj.configSpread.refresh() : '';
  1904. configMaterialObj.relatedSpread ? configMaterialObj.relatedSpread.refresh() : '';
  1905. });
  1906. $('#tab_project_glj').on('shown.bs.tab', function (e) {
  1907. sessionStorage.setItem('mainTab', '#tab_project_glj');
  1908. let me = projectGljObject;
  1909. $(e.relatedTarget.hash).removeClass('active');
  1910. if (me.projectGljSpread == null) {
  1911. me.initSpreads();
  1912. }
  1913. me.unitPriceFileInit();
  1914. me.initMixRatio();
  1915. me.initSheetViews();
  1916. //projectObj.project.projectGLJ.calcQuantity(); 在工程量有更新的地方调用
  1917. me.refreshViewsData();
  1918. loadProjectGljSize();
  1919. });
  1920. /* $('#ration_link').on('shown.bs.tab', function (e) {
  1921. let me = projectGljObject;
  1922. me.showTag='ration';
  1923. me.showProjectGljData();
  1924. });
  1925. $('#mix_ratio_link').on('shown.bs.tab', function (e) {
  1926. let me = projectGljObject;
  1927. me.showTag='mixRatio';
  1928. me.showProjectGljData();
  1929. me.initMixRatio();
  1930. });
  1931. $('#machine_ratio_link').on('shown.bs.tab', function (e) {
  1932. let me = projectGljObject;
  1933. me.showTag='machine';
  1934. me.showProjectGljData();
  1935. me.initMixRatio();
  1936. });*/
  1937. $('#pop-used-list').tooltip({
  1938. placement: "bottom",
  1939. html: true,
  1940. trigger: "hover | focus",
  1941. title: projectGljObject.getUsedTenderInfo
  1942. });
  1943. // 单价文件切换弹框
  1944. $('#change-unitFile').on('shown.bs.modal', function () {
  1945. let rootProjectID = projectObj.project.projectInfo.property.rootProjectID;
  1946. // 获取切换单价文件相关数据
  1947. $.ajax({
  1948. url: '/glj/get-project-info',
  1949. type: 'post',
  1950. data: {
  1951. project_id: scUrlUtil.GetQueryString('project'),
  1952. rootProjectID: rootProjectID
  1953. },
  1954. dataType: 'json',
  1955. success: function (response) {
  1956. if (response.err === 1) {
  1957. alert('数据传输错误!');
  1958. return false;
  1959. }
  1960. let data = response.data;
  1961. projectGljObject.changeInfo = data;
  1962. $("#current-project-name").text(data.currentProjectName);
  1963. // 本项目中的单价文件
  1964. if (data.self.length > 0) {
  1965. let selfFileHtml = '';
  1966. for (let tmp of data.self) {
  1967. let select = usedUnitPriceInfo === tmp.id ? ' selected="selected"' : '';
  1968. selfFileHtml += '<option' + select + ' value="' + tmp.id + '">' + tmp.name + '</option>';
  1969. }
  1970. $("#self-file").html(selfFileHtml);
  1971. }
  1972. // 其他建设项目数据
  1973. let newDataOther = [];
  1974. if (data.other.length > 0) {
  1975. //转换成按项目管理顺序,名称包含文件夹层次
  1976. let fileHierarchyDatas = getFileHierarchyInfo(data.treeData);
  1977. for (let fileHierarchyData of fileHierarchyDatas) {
  1978. let projData = _.find(data.other, {
  1979. ID: fileHierarchyData.ID
  1980. });
  1981. if (projData) {
  1982. projData.name = fileHierarchyData.fileHierarchyName;
  1983. newDataOther.push(projData);
  1984. }
  1985. }
  1986. data.other = newDataOther;
  1987. let otherProjectHtml = '';
  1988. let otherFileHtml = '';
  1989. for (let tmp of data.other) {
  1990. otherProjectHtml += '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  1991. otherFileData[tmp.ID] = tmp.unitPriceList;
  1992. if (otherFileHtml !== '') {
  1993. continue;
  1994. }
  1995. for (let unitPrice of tmp.unitPriceList) {
  1996. otherFileHtml += '<option value="' + unitPrice.id + '">' + unitPrice.name + '</option>';
  1997. }
  1998. }
  1999. $("#other-project").html(otherProjectHtml);
  2000. $("#other-file").html(otherFileHtml);
  2001. }
  2002. }
  2003. });
  2004. });
  2005. // 单价文件切换确认
  2006. $("#change-file-confirm").click(function () {
  2007. let type = $("input[name='change-type']:checked").val();
  2008. type = parseInt(type);
  2009. let changeUnitPriceId = 0;
  2010. $('#change-unitFile').modal("hide");
  2011. if (type === 0) {
  2012. // 从本项目中选择
  2013. changeUnitPriceId = $("#self-file").val();
  2014. if (!changeUnitPriceId) {
  2015. alert('单价文件不可为空');
  2016. return;
  2017. }
  2018. submitFileChange(changeUnitPriceId, type);
  2019. } else {
  2020. // 从其他项目中复制
  2021. changeUnitPriceId = $("#other-file").val();
  2022. let newName = $("#other-file").children("option:selected").text();
  2023. projectObj.project.projectGLJ.checkUnitFileName(newName, function (need_rename) {
  2024. if (need_rename) {
  2025. $("#rename-unitFile").modal({
  2026. show: true
  2027. });
  2028. $("#newUnitFileID").val(changeUnitPriceId);
  2029. $("#newUnitFileName").val(newName);
  2030. } else {
  2031. submitFileChange(changeUnitPriceId, type);
  2032. }
  2033. });
  2034. }
  2035. function submitFileChange(changeUnitPriceId, type) {
  2036. let data = {
  2037. project_id: scUrlUtil.GetQueryString('project'),
  2038. change_id: changeUnitPriceId,
  2039. type: type
  2040. };
  2041. projectObj.project.projectGLJ.changeFile(data, function () {
  2042. projectGljObject.changeFileCallback();
  2043. })
  2044. }
  2045. });
  2046. // 单价文件选项切换
  2047. $("input[name='change-type']").change(function () {
  2048. let type = $(this).val();
  2049. type = parseInt(type);
  2050. $("#change-unitFile .option").hide();
  2051. if (type === 0) {
  2052. $(".option.select").show();
  2053. } else {
  2054. $(".option.copy").show();
  2055. }
  2056. });
  2057. $("#unitFile-save-as").on('shown.bs.modal', function () {
  2058. // 获取当前建设项数据
  2059. $("#save-as-name").val(projectGljObject.usedUnitPriceInfo.name + '副本');
  2060. projectGljObject.checkUnitFileName(projectGljObject.usedUnitPriceInfo.name + '副本');
  2061. });
  2062. // 从其他建设项目中复制 选择建设项目
  2063. $("#other-project").change(function () {
  2064. let projectId = $(this).val();
  2065. if (otherFileData[projectId] === undefined) {
  2066. return false;
  2067. }
  2068. let otherFileHtml = '';
  2069. for (let unitPrice of otherFileData[projectId]) {
  2070. otherFileHtml += '<option value="' + unitPrice.id + '">' + unitPrice.name + '</option>';
  2071. }
  2072. $("#other-file").html(otherFileHtml);
  2073. });
  2074. $('#save-as-name').change(function () {
  2075. projectGljObject.checkUnitFileName(this.value);
  2076. });
  2077. $('#newUnitFileName').change(function () {
  2078. let projectGLJ = projectObj.project.projectGLJ;
  2079. projectGLJ.checkUnitFileName(this.value, function (data) {
  2080. if (data) {
  2081. $("#renameError_unitFile").text('已存在同名单价文件').show();
  2082. //$('#renameUnitFileConfirm').attr("disabled","disabled");
  2083. } else {
  2084. $("#renameError_unitFile").hide();
  2085. // $('#renameUnitFileConfirm').removeAttr("disabled");
  2086. }
  2087. });
  2088. });
  2089. $("#renameUnitFileConfirm").click(function () {
  2090. let projectGLJ = projectObj.project.projectGLJ;
  2091. let newName = $('#newUnitFileName').val();
  2092. let changeUnitPriceId = $('#newUnitFileID').val();
  2093. projectGLJ.checkUnitFileName(newName, function (data) {
  2094. if (data) {
  2095. $("#renameError_unitFile").text('已存在同名单价文件').show();
  2096. //$('#renameUnitFileConfirm').attr("disabled","disabled");
  2097. } else {
  2098. $("#renameError_unitFile").hide();
  2099. $('#rename-unitFile').modal('hide');
  2100. // $('#renameUnitFileConfirm').removeAttr("disabled");
  2101. let data = {
  2102. project_id: scUrlUtil.GetQueryString('project'),
  2103. change_id: changeUnitPriceId,
  2104. type: 1,
  2105. newName: newName
  2106. };
  2107. projectObj.project.projectGLJ.changeFile(data, function () {
  2108. projectGljObject.changeFileCallback();
  2109. })
  2110. }
  2111. });
  2112. });
  2113. // 单价文件另存为操作
  2114. $("#save-as-confirm").click(function () {
  2115. let projectGLJ = projectObj.project.projectGLJ;
  2116. let name = $("#save-as-name").val();
  2117. if (name === '') {
  2118. $("#save-as-tips").text('请填写单价文件名称').show();
  2119. return false;
  2120. }
  2121. let saveData = {
  2122. name: name,
  2123. project_id: scUrlUtil.GetQueryString('project')
  2124. };
  2125. projectGljObject.checkUnitFileName(name, function () {
  2126. projectGLJ.saveAs(saveData, function () {
  2127. projectGljObject.changeFileCallback();
  2128. $("#unitFile-save-as").modal("hide");
  2129. });
  2130. });
  2131. });
  2132. $("#filterType").on("click", "ul li a", function (e) {
  2133. let children = $('#filterType a');
  2134. for (let c of children) {
  2135. $(c).removeClass('active');
  2136. }
  2137. $(this).addClass('active');
  2138. let me = projectGljObject;
  2139. me.displayType = filterType[this.id];
  2140. me.initSheetViews();
  2141. me.refreshViewsData();
  2142. loadProjectGljSize();
  2143. });
  2144. $("#mixRatio-nav").on('shown.bs.tab', function () {
  2145. projectGljObject.mixRatioSpread.refresh();
  2146. projectGljObject.showMixRatioData();
  2147. });
  2148. $("#ration-nav").on('shown.bs.tab', function () {
  2149. projectGljObject.mixRatioSpread.refresh();
  2150. projectGljObject.showRelatedRationDatas();
  2151. });
  2152. $("#info-nav").on('shown.bs.tab', function () {
  2153. projectGljObject.refreshInfoPrice();
  2154. projectGljObject.autoShowInfoPriceData();
  2155. });
  2156. $('#info_year').change(async function () {
  2157. let periodMap = projectGljObject.infoPriceOptions.periodMap;
  2158. let year = $(this).val();
  2159. let month = $("#info_month").val();
  2160. let options = periodMap[year];
  2161. if (year == "") return projectGljObject.searchInfoPrice(); //为空的时候清空显示
  2162. projectGljObject.createSelectOptions($("#info_month"), periodMap[year]);
  2163. if (month != "") {
  2164. if (_.includes(options, month)) {
  2165. $("#info_month").val(month);
  2166. projectGljObject.searchInfoClass();
  2167. projectGljObject.searchInfoPrice();
  2168. }
  2169. }
  2170. });
  2171. $('#info_month').change(async function () {
  2172. await projectGljObject.searchInfoClass();
  2173. await projectGljObject.searchInfoPrice();
  2174. });
  2175. $('#info_area').change(async function () {
  2176. await projectGljObject.searchInfoClass()
  2177. await projectGljObject.searchInfoPrice();
  2178. });
  2179. $('#info_search_name').on('keypress', function (e) {
  2180. $("#info-warning").text("");
  2181. if (e.keyCode === 13) {
  2182. $('#info_glj_name').val("");
  2183. $('#info_glj_code').val("");
  2184. $('#info_class').val("");
  2185. projectGljObject.searchInfoPrice();
  2186. }
  2187. });
  2188. $('#info_search_btn').on('click', function (e) {
  2189. $('#info_glj_name').val("");
  2190. $('#info_glj_code').val("");
  2191. $('#info_class').val("");
  2192. projectGljObject.searchInfoPrice();
  2193. });
  2194. $('#infoPriceCoeConfirm').on('click', function (e) {
  2195. let me = projectGljObject;
  2196. let infoPriceCoe = $("#infoPriceCoe").val();
  2197. if (infoPriceCoe === "") return alert("请输入单位转换值!");
  2198. if (!(/^\d+(\.\d+)?$/.test(infoPriceCoe))) return alert("请输入数字!");
  2199. $("#infoPriceCoeDiv").modal('hide');
  2200. let pojectGLJData = me.getProjectGLJSelected();
  2201. let info = me.infoPriceData[parseInt($("#infoRow").val())];
  2202. let marketPrice = me.getInfoMarketPrice(info);
  2203. me.applyInfoPrice(pojectGLJData, marketPrice, parseFloat(infoPriceCoe));
  2204. });
  2205. $('#muti_apply_info').on('click', function (e) {
  2206. let year = $('#info_year').val();
  2207. let month = $('#info_month').val();
  2208. let areaID = $('#info_area').val();
  2209. if (year != "" && month != "" && areaID != "") {
  2210. $("#mutiApplyInfoPriceDiv").modal("show");
  2211. }
  2212. });
  2213. $('#mutiApplyinfoPriceConfirm').on('click', function (e) {
  2214. let typeMap = {};
  2215. let pgljMap = {};
  2216. let year = $('#info_year').val();
  2217. let month = $('#info_month').val();
  2218. let areaID = $('#info_area').val();
  2219. for (let e of $(".info_apply_type")) {
  2220. if ($(e).prop('checked') == true) {
  2221. typeMap[$(e).val()] = true;
  2222. }
  2223. }
  2224. for (let pglj of projectGljObject.projectGljSheetData) {
  2225. if (pglj.ratio_data && pglj.ratio_data.length > 0) continue; //有组成物时跳过
  2226. let typeString = pglj.type + "";
  2227. if (typeMap[typeString.charAt(0)]) {
  2228. let index = gljUtil.getIndex(pglj, ["name", "specs", "unit"]);
  2229. let obj = {
  2230. pgljID: pglj.id,
  2231. unitPriceID: pglj.unitPriceID,
  2232. fullIndex: gljUtil.getIndex(pglj)
  2233. };
  2234. pgljMap[index] ? pgljMap[index].push(obj) : pgljMap[index] = [obj]; //考虑到只用三个去匹配会有重复的工料机,所以这里用数组
  2235. }
  2236. }
  2237. if (_.isEmpty(pgljMap)) return;
  2238. let condition = {
  2239. period: year + "-" + month,
  2240. areaID: areaID
  2241. }
  2242. let priceFrom = '批量信息价';
  2243. projectObj.project.projectGLJ.mutiApplyInfoPrice(pgljMap, condition, priceFrom);
  2244. });
  2245. });