project_glj_view.js 75 KB

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