project_glj_view.js 86 KB

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