project_glj_view.js 88 KB

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