project_glj_view.js 86 KB

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