project_glj_view.js 88 KB

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