project_glj_view.js 86 KB

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