project_glj_view.js 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227
  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. for (let o of opts) {
  1614. if (isArea == true) {
  1615. str += `<option value="${o.ID}">${o.name}</option>`
  1616. if (o.name == "通用") this.commonInfoPriceID = o.ID;
  1617. } else {
  1618. str += `<option value="${o}">${o}</option>`
  1619. }
  1620. }
  1621. ele.html(str);
  1622. },
  1623. onInfoTopRowChanged: function (sender, args) {
  1624. let me = projectGljObject;
  1625. const bottomRow = args.sheet.getViewportBottomRow(1);
  1626. if (me.infoPriceData >= me.infoPriceTotalSize) return;
  1627. if (me.infoPriceData.length - bottomRow < 20) {
  1628. if (projectGljObject.infoPriceLastLoadingRow == me.infoPriceData.length) { //如果最后一行已经加载过了,就不用再加载了,不然会重复加载
  1629. return;
  1630. }
  1631. console.log(bottomRow);
  1632. me.infoPriceLastLoadingRow = me.infoPriceData.length;
  1633. //只有在空的搜索条件下才执行分页查询,其它情况无法分页
  1634. if ($('#info_search_name').val() == "") me.searchInfoPrice(me.infoPriceData[me.infoPriceData.length - 1]._id)
  1635. }
  1636. },
  1637. searchInfoPrice: async function (objectID) {
  1638. let year = $('#info_year').val();
  1639. let month = $('#info_month').val();
  1640. let areaID = $('#info_area').val();
  1641. let keyWord = $('#info_search_name').val();
  1642. let name = $('#info_glj_name').val();
  1643. let code = $('#info_glj_code').val();
  1644. let me = projectGljObject;
  1645. try {
  1646. if (year != "" && month != "" && areaID != "") {
  1647. let condition = {
  1648. period: year + "-" + month,
  1649. areaID: areaID
  1650. }
  1651. if (projectGljObject.addCommonInfoPriceID) projectGljObject.addCommonInfoPriceID(condition);
  1652. let data = {
  1653. condition: condition
  1654. };
  1655. if (keyWord != "") data.keyWord = keyWord;
  1656. if (name !="") data.keyWord = name;
  1657. if (objectID) data.lastID = objectID;
  1658. if (code !="" ) data.code = code;
  1659. let result = await ajaxPost("/infoPrice/getDataByCondition", data);
  1660. if (objectID) { //分页查询
  1661. sheetCommonObj.appendData(me.infoPriceSheet, me.infoPriceData.length, 0, me.infoPriceSetting, result.items);
  1662. me.infoPriceData.splice(me.infoPriceData.length, 0, ...result.items);
  1663. } else {
  1664. me.infoPriceTotalSize = result.totalSize;
  1665. me.infoPriceLastLoadingRow = 0;
  1666. me.showInforPriceData(result.items);
  1667. if (result.totalSize == 0) {
  1668. $("#info-warning").text("当前材料没有信息价! ");
  1669. } else {
  1670. $("#info-warning").text("");
  1671. }
  1672. }
  1673. } else { //当有任意一个为空时,都清空表格
  1674. me.infoPriceTotalSize = 0;
  1675. me.infoPriceLastLoadingRow = 0;
  1676. me.showInforPriceData([]);
  1677. }
  1678. } catch (error) {
  1679. console.log(error)
  1680. }
  1681. },
  1682. preApplyInfoPrice: function (row) {
  1683. let info = this.infoPriceData[row];
  1684. let projectGLJData = this.getProjectGLJSelected();
  1685. if (projectGLJData.ratio_data && projectGLJData.ratio_data.length > 0) return;
  1686. let marketPrice = this.getInfoMarketPrice(info);
  1687. if (projectGLJData.unit == info.unit) {
  1688. this.applyInfoPrice(projectGLJData, marketPrice, 1);
  1689. } else if (_.includes(["t", "kg"], projectGLJData.unit) && _.includes(["t", "kg"], info.unit)) {
  1690. //遇到t和kg之间的转换,默认处理:1t=1000kg,不弹换算窗口
  1691. let coeMap = {
  1692. "t": 1,
  1693. "kg": 1000
  1694. };
  1695. let coe = coeMap[info.unit] / coeMap[projectGLJData.unit];
  1696. this.applyInfoPrice(projectGLJData, marketPrice, coe);
  1697. } else { //弹出单位转换窗口
  1698. $("#infoRow").val(row);
  1699. $("#applyGLJName").text(projectGLJData.name);
  1700. $("#applyGLJUnit").text(projectGLJData.unit);
  1701. $("#infoPriceCoe").val("");
  1702. $("#applyInfoUnit").text(info.unit);
  1703. $("#infoPriceCoeDiv").modal('show')
  1704. }
  1705. },
  1706. applyInfoPrice: function (projectGLJData, price, coe) {
  1707. let priceFrom = this.getPriceFrom();
  1708. projectObj.project.projectGLJ.updatePrice(projectGLJData, "market_price", price * coe, 'pg', {
  1709. "priceFrom": priceFrom
  1710. });
  1711. },
  1712. getPriceFrom: function () {
  1713. let area = "";
  1714. for (let o of this.infoPriceOptions.areas) {
  1715. if (o.ID == $("#info_area").val()) {
  1716. area = o.name;
  1717. break;
  1718. }
  1719. }
  1720. return `${area}信息价(${$("#info_year").val()}${$("#info_month").val()})`;
  1721. },
  1722. getInfoMarketPrice: function (info) {
  1723. let taxType = projectObj.project.property.taxType; //1: 一般计税 2: 简易计税
  1724. return gljUtil.getInfoMarketPrice(info, taxType);
  1725. },
  1726. refreshInfoPrice: function () {
  1727. $('#info_price_sheet').height($("#mix_ratio_sheet").height() - $("#infoToolDiv").height()-10);
  1728. projectGljObject.initInfoPriceSpread();
  1729. }
  1730. };
  1731. function getProjectResizeEles() {
  1732. let pojGljResizeEles = {};
  1733. pojGljResizeEles.eleObj = {
  1734. module: 'projectGlj',
  1735. resize: $('#projectGljResize'),
  1736. top: $('#projectGljTop'),
  1737. topSpread: $('#project_glj_sheet'),
  1738. bottom: $('#projectGljBottom'),
  1739. bottomSpread: $('#mix_ratio_sheet')
  1740. };
  1741. pojGljResizeEles.limit = {
  1742. min: 150,
  1743. max: `$(window).height()-$('.header').height()-$('#projectGljToolsBar').height()-150-5`, //5: resize.height()
  1744. notTopSpread: 0,
  1745. notBottomSpread: 0,
  1746. totalHeight: `$(window).height()-$('.header').height()-$('#projectGljToolsBar').height()-5`
  1747. };
  1748. return pojGljResizeEles;
  1749. }
  1750. function getConficMaterialResizeEles() {
  1751. let conficMaterialResizeEles = {};
  1752. conficMaterialResizeEles.eleObj = {
  1753. module: 'conficMaterial',
  1754. resize: $('#configMaterialResize'),
  1755. top: $('#configMaterialTop'),
  1756. topSpread: $('#config_material_sheet'),
  1757. bottom: $('#configMaterialBottom'),
  1758. bottomSpread: $('#related_sheet')
  1759. };
  1760. conficMaterialResizeEles.limit = {
  1761. min: 150,
  1762. max: `$(window).height()-$('.header').height()-$('#projectGljToolsBar').height()-150-5`, //5: resize.height()
  1763. notTopSpread: 0,
  1764. notBottomSpread: 0,
  1765. totalHeight: `$(window).height()-$('.header').height()-$('#projectGljToolsBar').height()-5`,
  1766. bottomNav: `$('#configMaterialBottom ul').height() + $('#filterToolDiv').height()+10`
  1767. };
  1768. return conficMaterialResizeEles;
  1769. }
  1770. function loadProjectGljSize() {
  1771. if ($('#project-glj-main').is(':visible')) {
  1772. let me = projectGljObject;
  1773. let pojGljResizeEles = getProjectResizeEles();
  1774. if (!$("#projectGljBottom").is(':visible')) {
  1775. let total = $(window).height() - $('.header').height() - $('#projectGljToolsBar').height() + 3;
  1776. $("#projectGljTop").height(total);
  1777. $("#project_glj_sheet").height(total);
  1778. me.projectGljSpread ? me.projectGljSpread.refresh() : '';
  1779. } else {
  1780. SlideResize.loadVerticalHeight(pojGljResizeEles.eleObj.module, pojGljResizeEles.eleObj, pojGljResizeEles.limit, function () {
  1781. me.projectGljSpread ? me.projectGljSpread.refresh() : '';
  1782. me.mixRatioSpread ? me.mixRatioSpread.refresh() : '';
  1783. //信息价相关
  1784. $('#info_price_sheet').height($("#mix_ratio_sheet").height() - $("#infoToolDiv").height());
  1785. if ($('#info_price_sheet').is(':visible')) me.initInfoPriceSpread();
  1786. });
  1787. }
  1788. } else if ($('#material_adjust').is(':visible')) {
  1789. $('#material_adjust_sheet').height($(window).height() - $('.header').height() - $('#projectGljToolsBar').height() + 3);
  1790. if (materialAdjustObj.spread) materialAdjustObj.spread.refresh();
  1791. } else if ($('#config_material').is(':visible')) {
  1792. let configMaterialResizeEles = getConficMaterialResizeEles();
  1793. SlideResize.loadVerticalHeight(configMaterialResizeEles.eleObj.module, configMaterialResizeEles.eleObj, configMaterialResizeEles.limit, function () {
  1794. configMaterialObj.configSpread ? configMaterialObj.configSpread.refresh() : '';
  1795. configMaterialObj.relatedSpread ? configMaterialObj.relatedSpread.refresh() : '';
  1796. /*
  1797. me.mixRatioSpread?me.mixRatioSpread.refresh():'';*/
  1798. });
  1799. }
  1800. }
  1801. //从其他建设项目中复制中,建设项目的文件层次结构名称和顺序
  1802. function getFileHierarchyInfo(treeData) {
  1803. let tree = idTree.createNew({
  1804. id: 'ID',
  1805. pid: 'ParentID',
  1806. nid: 'NextSiblingID',
  1807. rootId: -1
  1808. });
  1809. tree.loadDatas(treeData);
  1810. let items = tree.items;
  1811. let rst = [];
  1812. function getFileHierarchyName(node) {
  1813. let nodeName = node.data.name;
  1814. let name = [];
  1815. while (node.parent) {
  1816. name.push(node.parent.data.name ? node.parent.data.name : '');
  1817. node = node.parent;
  1818. }
  1819. name = name.reverse();
  1820. name.push(nodeName);
  1821. return name.join('\\');
  1822. }
  1823. for (let node of items) {
  1824. if (node.children.length === 0) { //project
  1825. rst.push({
  1826. ID: node.data.ID,
  1827. fileHierarchyName: getFileHierarchyName(node)
  1828. })
  1829. }
  1830. }
  1831. return rst;
  1832. }
  1833. $(function () {
  1834. let pojGljResizeEles = getProjectResizeEles();
  1835. SlideResize.verticalSlide(pojGljResizeEles.eleObj, pojGljResizeEles.limit, function () {
  1836. projectGljObject.projectGljSpread.refresh();
  1837. projectGljObject.mixRatioSpread ? projectGljObject.mixRatioSpread.refresh() : '';
  1838. projectGljObject.refreshInfoPrice();
  1839. });
  1840. let tr = getConficMaterialResizeEles();
  1841. SlideResize.verticalSlide(tr.eleObj, tr.limit, function () {
  1842. configMaterialObj.configSpread ? configMaterialObj.configSpread.refresh() : '';
  1843. configMaterialObj.relatedSpread ? configMaterialObj.relatedSpread.refresh() : '';
  1844. });
  1845. $('#tab_project_glj').on('shown.bs.tab', function (e) {
  1846. sessionStorage.setItem('mainTab', '#tab_project_glj');
  1847. let me = projectGljObject;
  1848. $(e.relatedTarget.hash).removeClass('active');
  1849. if (me.projectGljSpread == null) {
  1850. me.initSpreads();
  1851. }
  1852. me.unitPriceFileInit();
  1853. me.initMixRatio();
  1854. me.initSheetViews();
  1855. //projectObj.project.projectGLJ.calcQuantity(); 在工程量有更新的地方调用
  1856. me.refreshViewsData();
  1857. loadProjectGljSize();
  1858. });
  1859. /* $('#ration_link').on('shown.bs.tab', function (e) {
  1860. let me = projectGljObject;
  1861. me.showTag='ration';
  1862. me.showProjectGljData();
  1863. });
  1864. $('#mix_ratio_link').on('shown.bs.tab', function (e) {
  1865. let me = projectGljObject;
  1866. me.showTag='mixRatio';
  1867. me.showProjectGljData();
  1868. me.initMixRatio();
  1869. });
  1870. $('#machine_ratio_link').on('shown.bs.tab', function (e) {
  1871. let me = projectGljObject;
  1872. me.showTag='machine';
  1873. me.showProjectGljData();
  1874. me.initMixRatio();
  1875. });*/
  1876. $('#pop-used-list').tooltip({
  1877. placement: "bottom",
  1878. html: true,
  1879. trigger: "hover | focus",
  1880. title: projectGljObject.getUsedTenderInfo
  1881. });
  1882. // 单价文件切换弹框
  1883. $('#change-unitFile').on('shown.bs.modal', function () {
  1884. let rootProjectID = projectObj.project.projectInfo.property.rootProjectID;
  1885. // 获取切换单价文件相关数据
  1886. $.ajax({
  1887. url: '/glj/get-project-info',
  1888. type: 'post',
  1889. data: {
  1890. project_id: scUrlUtil.GetQueryString('project'),
  1891. rootProjectID: rootProjectID
  1892. },
  1893. dataType: 'json',
  1894. success: function (response) {
  1895. if (response.err === 1) {
  1896. alert('数据传输错误!');
  1897. return false;
  1898. }
  1899. let data = response.data;
  1900. projectGljObject.changeInfo = data;
  1901. $("#current-project-name").text(data.currentProjectName);
  1902. // 本项目中的单价文件
  1903. if (data.self.length > 0) {
  1904. let selfFileHtml = '';
  1905. for (let tmp of data.self) {
  1906. let select = usedUnitPriceInfo === tmp.id ? ' selected="selected"' : '';
  1907. selfFileHtml += '<option' + select + ' value="' + tmp.id + '">' + tmp.name + '</option>';
  1908. }
  1909. $("#self-file").html(selfFileHtml);
  1910. }
  1911. // 其他建设项目数据
  1912. let newDataOther = [];
  1913. if (data.other.length > 0) {
  1914. //转换成按项目管理顺序,名称包含文件夹层次
  1915. let fileHierarchyDatas = getFileHierarchyInfo(data.treeData);
  1916. for (let fileHierarchyData of fileHierarchyDatas) {
  1917. let projData = _.find(data.other, {
  1918. ID: fileHierarchyData.ID
  1919. });
  1920. if (projData) {
  1921. projData.name = fileHierarchyData.fileHierarchyName;
  1922. newDataOther.push(projData);
  1923. }
  1924. }
  1925. data.other = newDataOther;
  1926. let otherProjectHtml = '';
  1927. let otherFileHtml = '';
  1928. for (let tmp of data.other) {
  1929. otherProjectHtml += '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  1930. otherFileData[tmp.ID] = tmp.unitPriceList;
  1931. if (otherFileHtml !== '') {
  1932. continue;
  1933. }
  1934. for (let unitPrice of tmp.unitPriceList) {
  1935. otherFileHtml += '<option value="' + unitPrice.id + '">' + unitPrice.name + '</option>';
  1936. }
  1937. }
  1938. $("#other-project").html(otherProjectHtml);
  1939. $("#other-file").html(otherFileHtml);
  1940. }
  1941. }
  1942. });
  1943. });
  1944. // 单价文件切换确认
  1945. $("#change-file-confirm").click(function () {
  1946. let type = $("input[name='change-type']:checked").val();
  1947. type = parseInt(type);
  1948. let changeUnitPriceId = 0;
  1949. $('#change-unitFile').modal("hide");
  1950. if (type === 0) {
  1951. // 从本项目中选择
  1952. changeUnitPriceId = $("#self-file").val();
  1953. if (!changeUnitPriceId) {
  1954. alert('单价文件不可为空');
  1955. return;
  1956. }
  1957. submitFileChange(changeUnitPriceId, type);
  1958. } else {
  1959. // 从其他项目中复制
  1960. changeUnitPriceId = $("#other-file").val();
  1961. let newName = $("#other-file").children("option:selected").text();
  1962. projectObj.project.projectGLJ.checkUnitFileName(newName, function (need_rename) {
  1963. if (need_rename) {
  1964. $("#rename-unitFile").modal({
  1965. show: true
  1966. });
  1967. $("#newUnitFileID").val(changeUnitPriceId);
  1968. $("#newUnitFileName").val(newName);
  1969. } else {
  1970. submitFileChange(changeUnitPriceId, type);
  1971. }
  1972. });
  1973. }
  1974. function submitFileChange(changeUnitPriceId, type) {
  1975. let data = {
  1976. project_id: scUrlUtil.GetQueryString('project'),
  1977. change_id: changeUnitPriceId,
  1978. type: type
  1979. };
  1980. projectObj.project.projectGLJ.changeFile(data, function () {
  1981. projectGljObject.changeFileCallback();
  1982. })
  1983. }
  1984. });
  1985. // 单价文件选项切换
  1986. $("input[name='change-type']").change(function () {
  1987. let type = $(this).val();
  1988. type = parseInt(type);
  1989. $("#change-unitFile .option").hide();
  1990. if (type === 0) {
  1991. $(".option.select").show();
  1992. } else {
  1993. $(".option.copy").show();
  1994. }
  1995. });
  1996. $("#unitFile-save-as").on('shown.bs.modal', function () {
  1997. // 获取当前建设项数据
  1998. $("#save-as-name").val(projectGljObject.usedUnitPriceInfo.name + '副本');
  1999. projectGljObject.checkUnitFileName(projectGljObject.usedUnitPriceInfo.name + '副本');
  2000. });
  2001. // 从其他建设项目中复制 选择建设项目
  2002. $("#other-project").change(function () {
  2003. let projectId = $(this).val();
  2004. if (otherFileData[projectId] === undefined) {
  2005. return false;
  2006. }
  2007. let otherFileHtml = '';
  2008. for (let unitPrice of otherFileData[projectId]) {
  2009. otherFileHtml += '<option value="' + unitPrice.id + '">' + unitPrice.name + '</option>';
  2010. }
  2011. $("#other-file").html(otherFileHtml);
  2012. });
  2013. $('#save-as-name').change(function () {
  2014. projectGljObject.checkUnitFileName(this.value);
  2015. });
  2016. $('#newUnitFileName').change(function () {
  2017. let projectGLJ = projectObj.project.projectGLJ;
  2018. projectGLJ.checkUnitFileName(this.value, function (data) {
  2019. if (data) {
  2020. $("#renameError_unitFile").text('已存在同名单价文件').show();
  2021. //$('#renameUnitFileConfirm').attr("disabled","disabled");
  2022. } else {
  2023. $("#renameError_unitFile").hide();
  2024. // $('#renameUnitFileConfirm').removeAttr("disabled");
  2025. }
  2026. });
  2027. });
  2028. $("#renameUnitFileConfirm").click(function () {
  2029. let projectGLJ = projectObj.project.projectGLJ;
  2030. let newName = $('#newUnitFileName').val();
  2031. let changeUnitPriceId = $('#newUnitFileID').val();
  2032. projectGLJ.checkUnitFileName(newName, function (data) {
  2033. if (data) {
  2034. $("#renameError_unitFile").text('已存在同名单价文件').show();
  2035. //$('#renameUnitFileConfirm').attr("disabled","disabled");
  2036. } else {
  2037. $("#renameError_unitFile").hide();
  2038. $('#rename-unitFile').modal('hide');
  2039. // $('#renameUnitFileConfirm').removeAttr("disabled");
  2040. let data = {
  2041. project_id: scUrlUtil.GetQueryString('project'),
  2042. change_id: changeUnitPriceId,
  2043. type: 1,
  2044. newName: newName
  2045. };
  2046. projectObj.project.projectGLJ.changeFile(data, function () {
  2047. projectGljObject.changeFileCallback();
  2048. })
  2049. }
  2050. });
  2051. });
  2052. // 单价文件另存为操作
  2053. $("#save-as-confirm").click(function () {
  2054. let projectGLJ = projectObj.project.projectGLJ;
  2055. let name = $("#save-as-name").val();
  2056. if (name === '') {
  2057. $("#save-as-tips").text('请填写单价文件名称').show();
  2058. return false;
  2059. }
  2060. let saveData = {
  2061. name: name,
  2062. project_id: scUrlUtil.GetQueryString('project')
  2063. };
  2064. projectGljObject.checkUnitFileName(name, function () {
  2065. projectGLJ.saveAs(saveData, function () {
  2066. projectGljObject.changeFileCallback();
  2067. $("#unitFile-save-as").modal("hide");
  2068. });
  2069. });
  2070. });
  2071. $("#filterType").on("click", "ul li a", function (e) {
  2072. let children = $('#filterType a');
  2073. for (let c of children) {
  2074. $(c).removeClass('active');
  2075. }
  2076. $(this).addClass('active');
  2077. let me = projectGljObject;
  2078. me.displayType = filterType[this.id];
  2079. me.initSheetViews();
  2080. me.refreshViewsData();
  2081. loadProjectGljSize();
  2082. });
  2083. $("#mixRatio-nav").on('shown.bs.tab', function () {
  2084. projectGljObject.mixRatioSpread.refresh();
  2085. projectGljObject.showMixRatioData();
  2086. });
  2087. $("#ration-nav").on('shown.bs.tab', function () {
  2088. projectGljObject.mixRatioSpread.refresh();
  2089. projectGljObject.showRelatedRationDatas();
  2090. });
  2091. $("#info-nav").on('shown.bs.tab', function () {
  2092. projectGljObject.refreshInfoPrice();
  2093. projectGljObject.autoShowInfoPriceData();
  2094. });
  2095. $('#info_year').change(function () {
  2096. let periodMap = projectGljObject.infoPriceOptions.periodMap;
  2097. let year = $(this).val();
  2098. let month = $("#info_month").val();
  2099. let options = periodMap[year];
  2100. if (year == "") return projectGljObject.searchInfoPrice(); //为空的时候清空显示
  2101. projectGljObject.createSelectOptions($("#info_month"), periodMap[year]);
  2102. if (month != "") {
  2103. if (_.includes(options, month)) {
  2104. $("#info_month").val(month);
  2105. projectGljObject.searchInfoPrice();
  2106. }
  2107. }
  2108. });
  2109. $('#info_month').change(function () {
  2110. projectGljObject.searchInfoPrice();
  2111. });
  2112. $('#info_area').change(function () {
  2113. projectGljObject.searchInfoPrice();
  2114. });
  2115. $('#info_search_name').on('keypress', function (e) {
  2116. $("#info-warning").text("");
  2117. if (e.keyCode === 13) {
  2118. $('#info_glj_name').val("");
  2119. $('#info_glj_code').val("");
  2120. projectGljObject.searchInfoPrice();
  2121. }
  2122. });
  2123. $('#info_search_btn').on('click', function (e) {
  2124. $('#info_glj_name').val("");
  2125. $('#info_glj_code').val("");
  2126. projectGljObject.searchInfoPrice();
  2127. });
  2128. $('#infoPriceCoeConfirm').on('click', function (e) {
  2129. let me = projectGljObject;
  2130. let infoPriceCoe = $("#infoPriceCoe").val();
  2131. if (infoPriceCoe === "") return alert("请输入单位转换值!");
  2132. if (!(/^\d+(\.\d+)?$/.test(infoPriceCoe))) return alert("请输入数字!");
  2133. $("#infoPriceCoeDiv").modal('hide');
  2134. let pojectGLJData = me.getProjectGLJSelected();
  2135. let info = me.infoPriceData[parseInt($("#infoRow").val())];
  2136. let marketPrice = me.getInfoMarketPrice(info);
  2137. me.applyInfoPrice(pojectGLJData, marketPrice, parseFloat(infoPriceCoe));
  2138. });
  2139. $('#muti_apply_info').on('click', function (e) {
  2140. let year = $('#info_year').val();
  2141. let month = $('#info_month').val();
  2142. let areaID = $('#info_area').val();
  2143. if (year != "" && month != "" && areaID != "") {
  2144. $("#mutiApplyInfoPriceDiv").modal("show");
  2145. }
  2146. });
  2147. $('#mutiApplyinfoPriceConfirm').on('click', function (e) {
  2148. let typeMap = {};
  2149. let pgljMap = {};
  2150. let year = $('#info_year').val();
  2151. let month = $('#info_month').val();
  2152. let areaID = $('#info_area').val();
  2153. for (let e of $(".info_apply_type")) {
  2154. if ($(e).prop('checked') == true) {
  2155. typeMap[$(e).val()] = true;
  2156. }
  2157. }
  2158. for (let pglj of projectGljObject.projectGljSheetData) {
  2159. if (pglj.ratio_data && pglj.ratio_data.length > 0) continue; //有组成物时跳过
  2160. let typeString = pglj.type + "";
  2161. if (typeMap[typeString.charAt(0)]) {
  2162. let index = gljUtil.getIndex(pglj, ["name", "specs", "unit"]);
  2163. let obj = {
  2164. pgljID: pglj.id,
  2165. unitPriceID: pglj.unitPriceID,
  2166. fullIndex: gljUtil.getIndex(pglj)
  2167. };
  2168. pgljMap[index] ? pgljMap[index].push(obj) : pgljMap[index] = [obj]; //考虑到只用三个去匹配会有重复的工料机,所以这里用数组
  2169. }
  2170. }
  2171. if (_.isEmpty(pgljMap)) return;
  2172. let condition = {
  2173. period: year + "-" + month,
  2174. areaID: areaID
  2175. }
  2176. let priceFrom = '批量信息价';
  2177. projectObj.project.projectGLJ.mutiApplyInfoPrice(pgljMap, condition, priceFrom);
  2178. });
  2179. });