project_glj_view.js 87 KB

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