project_glj_view.js 81 KB

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