project_glj_view.js 85 KB

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