project_glj_view.js 82 KB

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