glj_view.js 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299
  1. /**
  2. * Created by CSL on 2017-05-12.
  3. */
  4. var gljOprObj = {
  5. sheet: null,
  6. libID: null,
  7. ration: null,
  8. sheetData: [],
  9. checkb: null,
  10. rationGljEditObj: null, //编辑定额工料机还没提交的缓存数据
  11. cancelUpdate: true,
  12. mainTreeSelectedChange: false,
  13. detailSheet: null,
  14. detailData: [],
  15. GLJSelection: [],
  16. selectedGLJClass: null,
  17. parentNodeIds: {},
  18. preActiveTab: "", //提升焦点变换性能 2019年4月15日
  19. activeTab: "#linkGLJ",
  20. rationTab: "#linkGLJ",
  21. billsTab: "#linkGCLMX",
  22. setting: {},
  23. detailSetting: {
  24. header: [
  25. {
  26. headerName: "名称",
  27. headerWidth: 100,
  28. dataCode: "name",
  29. dataType: "String",
  30. },
  31. {
  32. headerName: "计算式",
  33. headerWidth: 120,
  34. dataCode: "regex",
  35. dataType: "String",
  36. },
  37. {
  38. headerName: "结果(C)",
  39. headerWidth: 120,
  40. dataCode: "result",
  41. dataType: "Number",
  42. decimalField: "quantity_detail",
  43. },
  44. {
  45. headerName: "累加",
  46. headerWidth: 120,
  47. dataCode: "isSummation",
  48. dataType: "String",
  49. cellType: "checkBox",
  50. },
  51. {
  52. headerName: "图号及备注",
  53. headerWidth: 120,
  54. dataCode: "memo",
  55. dataType: "String",
  56. },
  57. ],
  58. view: {
  59. lockColumns: [2, 3],
  60. rowHeaderWidth: 25,
  61. },
  62. },
  63. gljTreeSetting: {
  64. view: {
  65. expandSpeed: "",
  66. selectedMulti: false,
  67. },
  68. edit: {
  69. enable: false,
  70. editNameSelectAll: true,
  71. showRemoveBtn: true,
  72. showRenameBtn: true,
  73. removeTitle: "删除节点",
  74. renameTitle: "更改名称",
  75. },
  76. data: {
  77. keep: {
  78. parent: true,
  79. leaf: true,
  80. },
  81. key: {
  82. children: "items",
  83. name: "Name",
  84. },
  85. simpleData: {
  86. enable: false,
  87. idKey: "ID",
  88. pIdKey: "ParentID",
  89. rootPId: -1,
  90. },
  91. },
  92. callback: {
  93. onClick: function (event, treeId, treeNode) {
  94. if (treeId == "gljTree") {
  95. let me = gljOprObj,
  96. gljTypeId = treeNode.ID;
  97. if (treeNode.ID) {
  98. me.gljCurTypeId = treeNode.ID;
  99. me.filterLibGLJSheetData();
  100. me.showLibGLJSheetData();
  101. gljOprObj.initSelection({
  102. row: me.gljLibSheet.getActiveRowIndex(),
  103. });
  104. }
  105. } else {
  106. if (treeNode.isParent) {
  107. $("#class_selected_conf").attr("disabled", "disabled");
  108. $("#selected_class").val("");
  109. } else {
  110. $("#class_selected_conf").removeAttr("disabled");
  111. $("#selected_class").val(treeNode.ID);
  112. }
  113. }
  114. },
  115. },
  116. },
  117. gljLibSheetSetting: {
  118. owner: "gljTree",
  119. header: [
  120. {
  121. headerName: "选择",
  122. headerWidth: 40,
  123. dataCode: "select",
  124. hAlign: "center",
  125. vAlign: "center",
  126. cellType: "checkBox",
  127. },
  128. {
  129. headerName: "编码",
  130. headerWidth: 80,
  131. dataCode: "code",
  132. dataType: "String",
  133. formatter: "@",
  134. hAlign: "left",
  135. vAlign: "center",
  136. },
  137. {
  138. headerName: "名称",
  139. headerWidth: 160,
  140. dataCode: "name",
  141. dataType: "String",
  142. hAlign: "left",
  143. vAlign: "center",
  144. },
  145. {
  146. headerName: "规格型号",
  147. headerWidth: 160,
  148. dataCode: "specs",
  149. dataType: "String",
  150. hAlign: "left",
  151. vAlign: "center",
  152. },
  153. {
  154. headerName: "单位",
  155. headerWidth: 40,
  156. dataCode: "unit",
  157. dataType: "String",
  158. hAlign: "center",
  159. vAlign: "center",
  160. },
  161. {
  162. headerName: "单价",
  163. headerWidth: 55,
  164. dataCode: "basePrice",
  165. dataType: "Number",
  166. formatter: "0.00",
  167. hAlign: "right",
  168. vAlign: "center",
  169. },
  170. {
  171. headerName: "类型",
  172. headerWidth: 60,
  173. dataCode: "gljType",
  174. dataType: "String",
  175. hAlign: "center",
  176. vAlign: "center",
  177. },
  178. {
  179. headerName: "新增",
  180. headerWidth: 40,
  181. dataCode: "isComplementary",
  182. dataType: "String",
  183. hAlign: "center",
  184. vAlign: "center",
  185. cellType: "checkBox",
  186. },
  187. ],
  188. view: {
  189. lockColumns: [0, 1, 2, 3, 4, 5, 6],
  190. },
  191. },
  192. gljLibSheet: null,
  193. scopeSetting: {},
  194. scopeSpread: null,
  195. scopeSheet: null,
  196. scopeDatas: [],
  197. scopeSelectedIDMap: {},
  198. initSheet: function (sheet, name = "ration_glj") {
  199. var me = this;
  200. me.sheet = sheet;
  201. sheetCommonObj.initSheet(me.sheet, me.setting, 30);
  202. sheet.name(name);
  203. me.bindSheetEvent(sheet);
  204. sheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, me.onCellDoubleClick);
  205. sheet.bind(GC.Spread.Sheets.Events.ClipboardChanged, me.onClipboardChanged);
  206. subSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClick);
  207. if (!projectReadOnly) {
  208. gljContextMenu.loadGLJSpreadContextMenu();
  209. me.bindGLJEnterKey(subSpread, sheet);
  210. }
  211. sheet.bind(
  212. GC.Spread.Sheets.Events.SelectionChanged,
  213. me.onRationGLJSelectionChange
  214. );
  215. sheet.bind(GC.Spread.Sheets.Events.CellClick, function () {
  216. //这里主要记录是否点击了sheet以外的地方,如果点击了sheet里的单元格,则将cancelUpdate设置为true不触发提交更新操作
  217. me.cancelUpdate = true; //取消延时任务由selection change 事件处理
  218. });
  219. },
  220. onRationGLJSelectionChange: function (sender, args) {
  221. let me = gljOprObj;
  222. let selected = args.newSelections[0]
  223. ? args.newSelections[0]
  224. : { row: 0, col: 0 };
  225. //这主要记录是否点击了sheet以外的地方,如果点击了sheet里的单元格,则将cancelUpdate设置为true不触发提交更新操作
  226. me.cancelUpdate = true; //取消延时任务由这里进行判断处理
  227. me.sheetInitSelection(selected);
  228. if (me.rationGljEditObj) {
  229. if (ifNeedUpdate(selected)) {
  230. me.updateGljFromCache();
  231. }
  232. }
  233. function ifNeedUpdate(selected) {
  234. let navigationRightCol = me.setting.navigationRightCol,
  235. fieldID = me.setting.header[selected.col].dataCode;
  236. if (
  237. me.rationGljEditObj.row == selected.row &&
  238. navigationRightCol.indexOf(fieldID) != -1
  239. ) {
  240. //如果换行或者超出了三个编辑列,则提交更新
  241. return false;
  242. }
  243. return true;
  244. }
  245. },
  246. updateGljFromCache: function () {
  247. let me = this;
  248. if (me.rationGljEditObj) {
  249. projectObj.project.ration_glj.submitChange(
  250. me.rationGljEditObj.recode,
  251. me.rationGljEditObj.doc
  252. );
  253. }
  254. me.rationGljEditObj = null;
  255. },
  256. bindGLJEnterKey: function (spread, sheet) {
  257. let me = this;
  258. subSpread.commandManager().register("myEnter", enterKeyAction);
  259. subSpread
  260. .commandManager()
  261. .setShortcutKey(
  262. null,
  263. GC.Spread.Commands.Key.enter,
  264. false,
  265. false,
  266. false,
  267. false
  268. );
  269. subSpread
  270. .commandManager()
  271. .setShortcutKey(
  272. "myEnter",
  273. GC.Spread.Commands.Key.enter,
  274. false,
  275. false,
  276. false,
  277. false
  278. );
  279. function enterKeyAction(spd, sheeName) {
  280. let editRow = sheet.getActiveRowIndex(),
  281. orgCol = sheet.getActiveColumnIndex();
  282. let fieldID = me.setting.header[orgCol].dataCode;
  283. if (
  284. sheeName == "ration_glj" &&
  285. me.setting.navigationRightCol.indexOf(fieldID) != -1
  286. ) {
  287. if (sheet.isEditing()) sheet.endEdit();
  288. GC.Spread.Sheets.Commands.navigationRight.execute(spd, sheeName);
  289. } else {
  290. GC.Spread.Sheets.Commands.commitInputNavigationDown.execute(
  291. spd,
  292. sheeName
  293. );
  294. }
  295. }
  296. },
  297. sheetInitSelection: function (selected) {
  298. let me = gljOprObj;
  299. let style = {};
  300. if (selected.row < me.sheetData.length) {
  301. if (me.setting.getStyle)
  302. style = me.setting.getStyle(me.sheetData[selected.row]);
  303. me.sheet.setStyle(selected.row, -1, me.getSelStyle(true, style));
  304. }
  305. me.sheet.repaint();
  306. if (me.preGljSelection && me.preGljSelection.row !== selected.row) {
  307. if (me.setting.getStyle && me.preGljSelection.row < me.sheetData.length)
  308. style = me.setting.getStyle(me.sheetData[me.preGljSelection.row]);
  309. me.sheet.setStyle(
  310. me.preGljSelection.row,
  311. -1,
  312. me.getSelStyle(false, style)
  313. );
  314. }
  315. me.preGljSelection = selected;
  316. },
  317. initDetailSheet: function (sheet) {
  318. var me = this;
  319. me.detailSheet = sheet;
  320. sheetCommonObj.initSheet(me.detailSheet, me.detailSetting, 30);
  321. // me.detailSheet.selectionUnit(0);//0 cell,1 row,2 col;
  322. sheet.name("quantity_detail");
  323. me.bindSheetEvent(sheet);
  324. },
  325. detailSheetReadonly: function () {
  326. let selected = projectObj.project.mainTree.selected;
  327. let Bills = projectObj.project.Bills;
  328. if (selected) {
  329. //清单锁定时只读
  330. if (
  331. selected.sourceType == ModuleNames.bills &&
  332. projectObj.project.isBillsLocked() &&
  333. projectObj.project.withinBillsLocked(selected)
  334. ) {
  335. return true;
  336. }
  337. //大项费用、分部节点层次时,工程量明细只读。
  338. if (
  339. indicativeInfoObj.isDXFY(selected) ||
  340. indicativeInfoObj.isFB(selected)
  341. ) {
  342. return true;
  343. }
  344. //是主材或者是设备时只读
  345. if (selected.sourceType == ModuleNames.ration_glj) {
  346. return true;
  347. } else if (gljOprObj.isInstallationNode(selected)) {
  348. //是补项或者是安装类型的定额时只读
  349. return true;
  350. }
  351. return false;
  352. }
  353. return true;
  354. },
  355. bindSheetEvent: function (sheet) {
  356. var me = this;
  357. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  358. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  359. sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  360. sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
  361. sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.startEditChecking);
  362. // sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  363. },
  364. onClipboardPasting: function (sender, args) {
  365. var me = gljOprObj;
  366. if (
  367. args.sheetName != "quantity_detail" &&
  368. (args.cellRange.rowCount != 1 || args.cellRange.colCount != 1)
  369. ) {
  370. //工程量明细做特殊处理
  371. args.cancel = true;
  372. }
  373. },
  374. onClipboardPasted: function (e, info) {
  375. var me = gljOprObj;
  376. console.log("past");
  377. // if (!me.ration) {return;};
  378. // your code...
  379. },
  380. startEditChecking: function (sender, args) {
  381. let me = gljOprObj;
  382. let selected = projectObj.project.mainTree.selected;
  383. if ($.bootstrapLoading.isLoading()) args.cancel = true;
  384. if (selected) {
  385. if (me.isInstallationNode(selected) == true) {
  386. args.cancel = true;
  387. } else {
  388. if (args.sheetName == "quantity_detail") {
  389. //工程量明细表
  390. if (me.detailSheetReadonly()) {
  391. args.cancel = true;
  392. } else {
  393. if (args.sheet.getValue(args.row, args.col) == null) {
  394. //这里是为了解决当单元格里的值是null的时候,在单元格里输入数据,按键盘箭头移动光标的时候,会直接结束编辑,跳到另外的单元格。
  395. args.sheet.setValue(args.row, args.col, "");
  396. }
  397. }
  398. }
  399. if (args.sheetName == "ration_glj") {
  400. //定额工料机表
  401. if (!me.rationGLJEditCheck(args)) args.cancel = true;
  402. }
  403. }
  404. } else {
  405. args.cancel = true;
  406. }
  407. },
  408. isInstallationNode: function (node) {
  409. if (
  410. node.sourceType == ModuleNames.ration &&
  411. node.data.type == rationType.install
  412. ) {
  413. //是定额安装费类型时只读,原先是补项的时候也是控制只读的||(node.sourceType == ModuleNames.bills&&node.data.type==billType.BX)){//是定额安装费类型或者补项
  414. return true;
  415. }
  416. return false;
  417. },
  418. onEditEnded: function (sender, args) {
  419. var me = gljOprObj;
  420. if (args.sheetName == "ration_glj") {
  421. me.onEditGLJSheet(args);
  422. }
  423. if (args.sheetName == "quantity_detail") {
  424. me.onEditDetailSheet(args);
  425. }
  426. },
  427. onEditDetailSheet: function (args, callback) {
  428. var me = gljOprObj;
  429. if (args.row > me.detailData.length) {
  430. return;
  431. }
  432. if (args.row == me.detailData.length && args.editingText == null) {
  433. return;
  434. }
  435. var selected = projectObj.project.mainTree.selected; //因为使用了延时方法,所以要先取得选中行;
  436. var detailList = me.detailData;
  437. if (args.editingText) {
  438. args.editingText = args.editingText.replace(/(/g, "("); //替换中文左右括号;
  439. args.editingText = args.editingText.replace(/)/g, ")");
  440. }
  441. if (args.row == detailList.length) {
  442. projectObj.project.quantity_detail.saveQuantityDetail(
  443. args,
  444. me.detailSetting.header[args.col].dataCode,
  445. selected,
  446. callback
  447. );
  448. }
  449. if (args.row < detailList.length) {
  450. projectObj.project.quantity_detail.updateQuantityDetail(
  451. args,
  452. me.detailSetting.header[args.col].dataCode,
  453. detailList[args.row],
  454. selected,
  455. callback
  456. );
  457. }
  458. },
  459. onEditGLJSheet: function (args) {
  460. var me = gljOprObj;
  461. if (args.row >= me.sheetData.length) {
  462. me.sheet.getCell(args.row, args.col).value(null);
  463. return;
  464. }
  465. me.updateRationGLJ(args);
  466. },
  467. onSelectionChanged: function (sender, args) {
  468. let me = gljOprObj;
  469. me.initSelection(
  470. args.newSelections.length > 0
  471. ? { row: args.newSelections[0].row }
  472. : { row: 0 }
  473. );
  474. },
  475. getSelStyle: function (selected, settingStyle, rcolor) {
  476. let style = new GC.Spread.Sheets.Style();
  477. if (settingStyle) {
  478. for (let key in settingStyle) {
  479. style[key] = settingStyle[key];
  480. }
  481. }
  482. style.borderLeft = new GC.Spread.Sheets.LineBorder(
  483. "#D4D4D4",
  484. GC.Spread.Sheets.LineStyle.thin
  485. );
  486. style.borderTop = new GC.Spread.Sheets.LineBorder(
  487. "#D4D4D4",
  488. GC.Spread.Sheets.LineStyle.thin
  489. );
  490. style.borderRight = new GC.Spread.Sheets.LineBorder(
  491. "#D4D4D4",
  492. GC.Spread.Sheets.LineStyle.thin
  493. );
  494. style.borderBottom = new GC.Spread.Sheets.LineBorder(
  495. "#D4D4D4",
  496. GC.Spread.Sheets.LineStyle.thin
  497. );
  498. let colorOpts = optionsOprObj.getOption(
  499. optionsOprObj.optionsTypes.COLOROPTS
  500. );
  501. if (!colorOpts) colorOpts = { SELECTED: { backColor: "#FFFACD" } };
  502. let selectedColor = colorOpts.SELECTED.backColor,
  503. recColor = rcolor ? rcolor : "White";
  504. style.backColor = selected ? selectedColor : recColor;
  505. return style;
  506. },
  507. initSelection: function (sel) {
  508. let me = gljOprObj;
  509. if (sel) {
  510. sel.row = !sel.row || sel.row == -1 ? 0 : sel.row;
  511. me.gljLibSheet.setStyle(sel.row, -1, me.getSelStyle(true));
  512. }
  513. if (me.preGljLibSelection && me.preGljLibSelection.row !== sel.row) {
  514. me.gljLibSheet.setStyle(
  515. me.preGljLibSelection.row,
  516. -1,
  517. me.getSelStyle(false)
  518. );
  519. }
  520. me.preGljLibSelection = sel;
  521. },
  522. onButtonClick: function (sender, args) {
  523. if (args.sheet.isEditing()) {
  524. args.sheet.endEdit();
  525. }
  526. var me = gljOprObj;
  527. var sheet = args.sheet,
  528. row = args.row,
  529. col = args.col;
  530. var cellType = sheet.getCellType(row, col);
  531. if (cellType instanceof GC.Spread.Sheets.CellTypes.Button) {
  532. if (args.sheetName == "rationInstallSheet") {
  533. installationFeeObj.onPositionButtonClick(sender, args);
  534. }
  535. } else {
  536. me.onCheckBoxClick(sender, args);
  537. }
  538. },
  539. onCheckBoxClick: function (sender, args) {
  540. if (typeof projectObj != "undefined") {
  541. let selected = projectObj.project.mainTree.selected;
  542. if (selected.sourceType == ModuleNames.ration_glj) {
  543. //选中的是工料机时不可编辑
  544. return;
  545. }
  546. if (gljOprObj.isInstallationNode(selected) == true) {
  547. return;
  548. }
  549. }
  550. let checkboxValue = args.sheet.getCell(args.row, args.col).value();
  551. if (args.sheetName == "rationInstallSheet" && checkboxValue) {
  552. return;
  553. }
  554. let newval = checkboxValue ? 0 : 1;
  555. args.sheet.getCell(args.row, args.col).value(newval);
  556. if (args.sheetName == "ration_glj") {
  557. gljOprObj.updateIsEstimate(args, newval);
  558. } else if (args.sheetName == "quantity_detail") {
  559. projectObj.project.quantity_detail.isSummationUpdate(
  560. args,
  561. gljOprObj.detailData,
  562. newval
  563. );
  564. } else if (args.sheetName == "glj_lib") {
  565. if (gljOprObj.gljLibSheetSetting.header[args.col].dataCode === "select") {
  566. gljOprObj.setGLJSelection(args, newval);
  567. }
  568. } else if (args.sheetName == "rationInstallSheet") {
  569. args.newValue = newval;
  570. installationFeeObj.onRationInstallValueChange(sender, args);
  571. }
  572. },
  573. onCellDoubleClick: function (sender, args) {
  574. // 含组成物的材料市场价改为只读,改为双击无反应不提示
  575. /* var me = gljOprObj;
  576. var header = me.setting.header;
  577. if (args.row >= me.sheetData.length) {
  578. return;
  579. }
  580. if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
  581. if(me.hasComposition(me.sheetData[args.row])){
  582. alert("当前工料机的市场价由组成物计算得出,不可直接修改。");
  583. }
  584. }
  585. if (header[args.col] && header[args.col].dataCode == 'basePrice') {
  586. var isAdd = me.sheetData[args.row].isAdd;
  587. if(isAdd==1){//是新增但没有组成物时允许修改定额价
  588. if(me.hasComposition(me.sheetData[args.row])){//如果有组成物,不可修改
  589. alert("当前工料机的定额价由组成物计算得出,不可直接修改。");
  590. }
  591. }
  592. }*/
  593. },
  594. onClipboardChanged: function (sender, info) {
  595. let cDatas = sheetCommonObj.getTableData(info.sheet, null);
  596. sheetCommonObj.copyTextToClipboard(cDatas);
  597. return;
  598. },
  599. rationGLJEditCheck: function (args) {
  600. //true 可以编辑,false 不能编辑
  601. let me = gljOprObj,
  602. header = me.setting.header;
  603. let dataCode =
  604. header[args.col] && header[args.col].dataCode
  605. ? header[args.col].dataCode
  606. : null,
  607. recode = me.sheetData[args.row];
  608. if (me.sheet.getTag(args.row, args.col) == "locked") return false; //如果是双击树节点编号里设置了锁定标记,不能编辑
  609. if (_.includes(me.setting.view.lockColumns, args.col)) return false; //如果是锁定的列,不能编辑
  610. if (recode != undefined) {
  611. if (recode.isMixRatio) {
  612. //对于组成物列
  613. return dataCode == "marketPrice"; //允许修改组成物市单价,其它的不可以
  614. } else {
  615. if (dataCode && dataCode == "marketPrice") {
  616. return !me.marketPriceReadOnly({ data: me.sheetData[args.row] });
  617. }
  618. if (dataCode && dataCode == "basePrice") {
  619. var isAdd = recode.isAdd;
  620. if (isAdd == 1) {
  621. //是新增但没有组成物时允许修改定额价
  622. return !me.marketPriceReadOnly({ data: recode }); //如果有组成物,不可修改
  623. } else {
  624. return false;
  625. }
  626. }
  627. if (
  628. me.isExtraType(recode.type) &&
  629. (dataCode == "name" || dataCode == "specs" || dataCode == "unit")
  630. ) {
  631. //人材机窗口中的“企业管理费”“利润”“一般风险费”的名称、规格、单位改为只读。
  632. return false;
  633. }
  634. return true;
  635. }
  636. } else {
  637. return false;
  638. }
  639. },
  640. hasComposition: function (ration_glj, isRationType) {
  641. //判断是否有组成物,有则返回true 现在主材类型的工料机也有可能有组成物。
  642. return gljUtil.hasComposition(ration_glj, isRationType);
  643. },
  644. onRangeChanged: function (sender, args) {
  645. var me = gljOprObj;
  646. if (args.sheetName == "quantity_detail") {
  647. me.batchUpdateQuantityDetail(args);
  648. } else {
  649. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  650. args.editingText = null;
  651. } else if (args.action == GC.Spread.Sheets.RangeChangedAction.paste) {
  652. args.editingText = args.sheet.getCell(args.row, args.col).value();
  653. } else {
  654. return;
  655. }
  656. if (args.sheetName == "ration_glj") {
  657. me.onEditGLJSheet(args);
  658. }
  659. }
  660. },
  661. batchUpdateQuantityDetail: function (args) {
  662. let me = gljOprObj;
  663. let updateArray = [];
  664. for (let i = 0; i < args.changedCells.length; i++) {
  665. let c = args.changedCells[i];
  666. let tem = {
  667. row: c.row,
  668. col: c.col,
  669. editingText: args.sheet.getCell(c.row, c.col).text(),
  670. sheet: args.sheet,
  671. sheetName: args.sheetName,
  672. index: i,
  673. };
  674. updateArray.push(tem);
  675. }
  676. if (updateArray.length > 0) {
  677. updateArray.length == 1
  678. ? me.onEditDetailSheet(updateArray[0])
  679. : me.onEditDetailSheet(updateArray[0], updateCallback);
  680. }
  681. function updateCallback(i_args) {
  682. let index = i_args.index;
  683. if (index < updateArray.length - 1) {
  684. let nextIndex = index + 1;
  685. updateArray[nextIndex].replace = i_args.replace;
  686. if (nextIndex == updateArray.length - 1) {
  687. //是最后一个,则不用调callback了
  688. me.onEditDetailSheet(updateArray[nextIndex]);
  689. } else {
  690. me.onEditDetailSheet(updateArray[nextIndex], updateCallback);
  691. }
  692. }
  693. }
  694. },
  695. showDataIfRationSelect: function (node, selectedNodeId) {
  696. this.sheet.suspendPaint();
  697. this.sheet.suspendEvent();
  698. var isShow = false;
  699. if (projectReadOnly && this.setting.view.lockColumns) {
  700. this.setting.view.lockColumns = null;
  701. }
  702. if (selectedNodeId) {
  703. this.selectedNodeId = selectedNodeId;
  704. }
  705. if (node) {
  706. if (this.selectedNodeId && this.selectedNodeId == node.getID()) {
  707. return;
  708. } else {
  709. //恢复底色
  710. this.sheet.setStyle(
  711. this.sheet.getActiveRowIndex(),
  712. -1,
  713. this.getSelStyle(false, this.setting.style)
  714. );
  715. this.selectedNodeId = node.getID();
  716. }
  717. if (node.sourceType == "ration") {
  718. if (node.data.type == rationType.gljRation) {
  719. if ($("#linkGLJ").hasClass("active")) this.showMixRatio(node);
  720. subObj.showGljSubTabData();
  721. } else {
  722. if ($("#linkGLJ").hasClass("active")) {
  723. this.showRationGLJData(node);
  724. subObj.showGljSubTabData();
  725. // MaterialController.showReplaceDiv(node);
  726. }
  727. if ($("#linkAZZJF").hasClass("active"))
  728. installationFeeObj.showRationInstallationData(node);
  729. if ($("#linkMBZM").hasClass("active")) mbzm_obj.showMBZMData(node);
  730. }
  731. isShow = true;
  732. }
  733. if (node.sourceType == ModuleNames.ration_glj) {
  734. if ($("#linkGLJ").hasClass("active")) this.showMixRatio(node);
  735. MaterialController.hideReplaceDiv();
  736. isShow = true;
  737. }
  738. if ($("#linkGCLMX").hasClass("active")) this.showQuantityDetailData(node);
  739. } else {
  740. this.selectedNodeId = null;
  741. }
  742. if (!isShow) {
  743. this.clearSheetData();
  744. MaterialController.hideReplaceDiv();
  745. }
  746. this.sheet.resumeEvent();
  747. this.sheet.resumePaint();
  748. },
  749. showMixRatio: function (node) {
  750. //显示组成物到定额工料机
  751. let mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  752. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  753. let indexArray =
  754. node.sourceType == ModuleNames.ration ? rationKeyArray : gljKeyArray;
  755. let connect_index = this.getIndex(node.data, indexArray);
  756. let gljList = [];
  757. if (mixRatioMap[connect_index]) {
  758. //说明是有组成物的类型
  759. gljList = this.getMixRationShowDatas(
  760. mixRatioMap[connect_index],
  761. projectGljs
  762. );
  763. }
  764. if (gljList.length > 0) {
  765. //计算总消耗量
  766. if (node.sourceType == ModuleNames.ration) {
  767. this.calcMixRationTotalQuantity(gljList, node.data.quantity);
  768. } else {
  769. let totalQuantity = this.getTotalQuantity(node.data);
  770. this.calcMixRationTotalQuantity(gljList, totalQuantity);
  771. }
  772. }
  773. this.sheetData = gljList;
  774. this.sheet.setRowCount(0);
  775. this.sheetData = gljUtil.sortRationGLJ(this.sheetData);
  776. this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType([]));
  777. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  778. //初始选择
  779. this.preGljSelection = null;
  780. this.sheetInitSelection({ row: this.sheet.getActiveRowIndex(), col: 0 });
  781. this.sheet.getRange(-1, 0, -1, this.setting.header.length).locked(true); //锁住定额工料机的所有列
  782. this.detailSheet
  783. .getRange(-1, 0, -1, this.detailSetting.header.length)
  784. .locked(true); //锁住工程量明细的所有列
  785. },
  786. showRationGLJData: function (node) {
  787. let gljList = [];
  788. let ration_glj = projectObj.project.ration_glj;
  789. node = node ? node : projectObj.project.mainTree.selected;
  790. if (node.sourceType == ModuleNames.ration) {
  791. if (node.data.type == rationType.gljRation) {
  792. this.showMixRatio(node);
  793. } else {
  794. let ration = node.data;
  795. gljList = this.filterGljByRation(ration, ration_glj.datas);
  796. this.showInSheet(gljList);
  797. }
  798. } else if (node.sourceType == ModuleNames.ration_glj) {
  799. this.showMixRatio(node);
  800. }
  801. },
  802. showRationGLJSheetData: function (init) {
  803. let me = this;
  804. let selected = this.sheet.getSelections();
  805. this.combineWithProjectGlj(this.sheetData);
  806. this.sheet.setRowCount(0);
  807. this.sheetData = gljUtil.sortRationGLJ(this.sheetData);
  808. this.sumQuantity(); //计算总消耗量
  809. this.addMixRatioToShow(); //显示组成物信息
  810. this.initRationTree(init, this.getUnitPriceCodeMap());
  811. sheetCommonObj.showData(
  812. this.sheet,
  813. this.setting,
  814. this.sheetData,
  815. null,
  816. function () {
  817. if (me.mainTreeSelectedChange == true) {
  818. me.sheet.setSelection(0, 1, 1, 1); //默认选中第一行,第二列(名称列)
  819. me.mainTreeSelectedChange = false;
  820. } else if (selected) {
  821. //定位光标到之前的位置
  822. me.sheet.setSelection(
  823. selected[0].row,
  824. selected[0].col,
  825. selected[0].rowCount,
  826. selected[0].colCount
  827. );
  828. }
  829. //初始选择
  830. me.preGljSelection = null;
  831. me.sheetInitSelection({
  832. row: me.sheet.getActiveRowIndex(),
  833. col: me.sheet.getActiveColumnIndex(),
  834. });
  835. }
  836. );
  837. },
  838. getSelectedRationGlj: function () {
  839. let selected = this.sheet.getSelections()[0];
  840. let ration_glj = this.sheetData[selected.row];
  841. return ration_glj;
  842. },
  843. getUnitPriceCodeMap: function () {
  844. //取单价文件中,编码前缀一样的映射表
  845. let codeMap = {};
  846. let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;
  847. if (priceMap) {
  848. for (let connectKey in priceMap) {
  849. let code = priceMap[connectKey].code;
  850. let name = priceMap[connectKey].name;
  851. let specs = priceMap[connectKey].specs;
  852. if (code) {
  853. let displayText = code + " " + name + " " + specs;
  854. let preCode = code.split("-")[0];
  855. if (codeMap[preCode]) {
  856. codeMap[preCode].push({ text: displayText, value: connectKey });
  857. } else {
  858. codeMap[preCode] = [{ text: displayText, value: connectKey }];
  859. }
  860. }
  861. }
  862. }
  863. return codeMap;
  864. },
  865. initRationTree: function (init, codeMap) {
  866. this.sheet.suspendPaint();
  867. this.sheet.suspendEvent();
  868. this.sheet.setRowCount(
  869. this.sheetData.length > 30 ? this.sheetData.length : 30
  870. );
  871. for (var i = 0; i < this.sheetData.length; i++) {
  872. let options = this.getCodeOptions(this.sheetData[i], codeMap);
  873. this.sheet.setCellType(
  874. i,
  875. 0,
  876. this.getTreeNodeCellType(this.sheetData, options),
  877. GC.Spread.Sheets.SheetArea.viewport
  878. );
  879. if (this.sheetData[i].hasOwnProperty("subList")) {
  880. var collapsed =
  881. this.sheetData[i].collapsed == undefined
  882. ? true
  883. : this.sheetData[i].collapsed;
  884. if (collapsed == true) {
  885. this.sheet
  886. .getRange(i + 1, -1, this.sheetData[i].subList.length, -1)
  887. .visible(false);
  888. }
  889. }
  890. }
  891. this.sheet.resumeEvent();
  892. this.sheet.resumePaint();
  893. },
  894. getCodeOptions: function (recode, codeMap) {
  895. let options = [];
  896. if (recode.isMixRatio === true) {
  897. return null;
  898. }
  899. let code = recode.code;
  900. if (code) {
  901. let preCode = code.split("-")[0];
  902. if (codeMap[preCode]) options = codeMap[preCode];
  903. if (options.length > 0)
  904. _.remove(options, { value: gljOprObj.getIndex(recode, gljKeyArray) }); //去掉本身
  905. }
  906. return _.sortBy(options, "text");
  907. },
  908. filterGljByRation: function (ration, datas) {
  909. var gljList = [];
  910. if (datas && datas.length > 0) {
  911. gljList = _.filter(datas, { rationID: ration.ID });
  912. }
  913. return gljList;
  914. },
  915. showInSheet: function (gljList) {
  916. this.sheetData = gljList;
  917. this.showRationGLJSheetData(true);
  918. },
  919. sumQuantity: function (node) {
  920. if (this.sheetData.length > 0) {
  921. node = node ? node : projectObj.project.mainTree.selected;
  922. let ration = node.data;
  923. for (let glj of this.sheetData) {
  924. glj.totalQuantity = this.getTotalQuantity(glj, ration);
  925. }
  926. }
  927. },
  928. getTotalQuantity: function (glj, ration) {
  929. if (glj.isMixRatio == true) return; //如果是用于显示的组成物,则不用计算,跳过
  930. ration = ration
  931. ? ration
  932. : _.find(projectObj.project.Ration.datas, { ID: glj.rationID });
  933. glj.totalQuantity = gljUtil.getTotalQuantity(
  934. glj,
  935. ration,
  936. getDecimal("ration.quantity"),
  937. getDecimal("glj.quantity")
  938. );
  939. if (glj.hasOwnProperty("subList")) {
  940. //需要计算glj下挂的组成物的总消耗量
  941. this.calcMixRationTotalQuantity(glj.subList, glj.totalQuantity);
  942. }
  943. return glj.totalQuantity;
  944. },
  945. calcMixRationTotalQuantity(mList, pTotal) {
  946. //计算组成物的总消耗量
  947. for (let subG of mList) {
  948. subG.rationItemQuantity = scMathUtil.roundForObj(
  949. subG.rationItemQuantity,
  950. getDecimal("glj.quantity")
  951. );
  952. subG.totalQuantity =
  953. scMathUtil.roundForObj(
  954. subG.rationItemQuantity * pTotal,
  955. getDecimal("glj.quantity")
  956. ) + "";
  957. }
  958. },
  959. addMixRatioToShow: function () {
  960. var newList = [];
  961. _.remove(this.sheetData, { isMixRatio: true });
  962. for (var i = 0; i < this.sheetData.length; i++) {
  963. newList.push(this.sheetData[i]);
  964. if (this.sheetData[i].hasOwnProperty("subList")) {
  965. newList = newList.concat(this.sheetData[i].subList);
  966. }
  967. }
  968. this.sheetData = newList;
  969. },
  970. combineWithProjectGlj: function (
  971. ration_gljs,
  972. needRatio = true,
  973. ration,
  974. p_gljMap
  975. ) {
  976. let projectGLJData = projectObj.project.projectGLJ.datas;
  977. let projectGljs = projectGLJData.gljList;
  978. let mixRatioMap = projectGLJData.mixRatioMap;
  979. if (
  980. ration_gljs &&
  981. ration_gljs.length > 0 &&
  982. projectGljs &&
  983. projectGljs.length > 0
  984. ) {
  985. let pgljMap = p_gljMap ? p_gljMap : _.indexBy(projectGljs, "id");
  986. for (let i = 0; i < ration_gljs.length; i++) {
  987. let glj = pgljMap[ration_gljs[i].projectGLJID];
  988. if (glj) {
  989. if (
  990. projectObj.project.projectGLJ.isEstimateType(ration_gljs[i].type)
  991. ) {
  992. ration_gljs[i].isEstimate = glj.is_evaluate;
  993. }
  994. ration_gljs[i].shortName =
  995. projectObj.project.projectGLJ.getShortNameByID(ration_gljs[i].type);
  996. ration_gljs[i].isAdd = glj.unit_price.is_add;
  997. ration_gljs[i] = this.setGLJPrice(ration_gljs[i], glj, false); //设置工料机价格
  998. let connect_index = this.getIndex(glj, gljKeyArray);
  999. if (needRatio == true && mixRatioMap.hasOwnProperty(connect_index)) {
  1000. let mixRatios = this.getMixRationShowDatas(
  1001. mixRatioMap[connect_index],
  1002. projectGljs
  1003. );
  1004. ration_gljs[i].subList = mixRatios;
  1005. }
  1006. if (needRatio == false) {
  1007. //不需要组成物的情况,目前应该是复制整块那里用到,这里加上毛重系数等信息,一起复制
  1008. ration_gljs[i].grossWeightCoe = glj.unit_price.grossWeightCoe;
  1009. ration_gljs[i].purchaseStorageRate =
  1010. glj.unit_price.purchaseStorageRate;
  1011. ration_gljs[i].offSiteTransportLossRate =
  1012. glj.unit_price.offSiteTransportLossRate;
  1013. ration_gljs[i].handlingLossRate = glj.unit_price.handlingLossRate;
  1014. }
  1015. if (ration) gljOprObj.getTotalQuantity(ration_gljs[i], ration);
  1016. } else {
  1017. //计算程序中量价也会放到这里进来,量价是没有对应的项目工料机的
  1018. //if(ration_gljs[i].type != rationType.volumePrice) console.log("没有找到工料机:"+ration_gljs[i].name)
  1019. }
  1020. }
  1021. }
  1022. return ration_gljs;
  1023. },
  1024. setGLJPrice: function (data, glj, isRadio = false, ext) {
  1025. //isRadio 标记是否算组成物的价格
  1026. let proGLJ = projectObj.project.projectGLJ;
  1027. let calcOptions = projectObj.project.projectInfo.property.calcOptions;
  1028. let decimalObj = projectObj.project.projectInfo.property.decimal;
  1029. let labourCoeDatas = projectObj.project.labourCoe.datas;
  1030. glj = glj ? glj : _.find(proGLJ.datas.gljList, { id: data.projectGLJID });
  1031. if (glj) {
  1032. let tenderCoe = projectObj.project.projectGLJ.getTenderPriceCoe(glj);
  1033. let result = gljUtil.getGLJPrice(
  1034. glj,
  1035. proGLJ.datas,
  1036. calcOptions,
  1037. labourCoeDatas,
  1038. decimalObj,
  1039. isRadio,
  1040. _,
  1041. scMathUtil,
  1042. ext,
  1043. tenderCoe
  1044. );
  1045. data.marketPrice = result.marketPrice;
  1046. data.basePrice = result.basePrice;
  1047. data.adjustPrice = result.adjustPrice;
  1048. data.marketUnitFee = data.marketPrice; //更新树节点市场单价列的值
  1049. data.tenderPrice = result.tenderPrice;
  1050. }
  1051. return data;
  1052. },
  1053. getBasePrice: function (treeNode) {
  1054. //造价书中的工料机修改的节点要用到
  1055. let proGLJ = projectObj.project.projectGLJ;
  1056. let glj = _.find(proGLJ.datas.gljList, { id: treeNode.data.projectGLJID });
  1057. if (this.calcPriceDiff(glj) == true) {
  1058. return proGLJ.getBasePrice(glj);
  1059. } else {
  1060. return scMathUtil.roundForObj(
  1061. treeNode.data.marketUnitFee,
  1062. getDecimal("glj.unitPrice")
  1063. );
  1064. }
  1065. },
  1066. getMarketPrice: function (treeNode) {
  1067. //造价书中的工料机修改的节点要用到
  1068. let proGLJ = projectObj.project.projectGLJ;
  1069. let glj = _.find(proGLJ.datas.gljList, { id: treeNode.data.projectGLJID });
  1070. return proGLJ.getMarketPrice(glj);
  1071. },
  1072. calcPriceDiff: function (glj) {
  1073. let calcOptions = projectObj.project.projectInfo.property.calcOptions;
  1074. return gljUtil.calcPriceDiff(glj, calcOptions);
  1075. },
  1076. getIndex(obj, pops) {
  1077. return gljUtil.getIndex(obj, pops);
  1078. },
  1079. getConditionByKey(conKey) {
  1080. //将连接字符串转换成对象
  1081. let valueArray = conKey.split("|-|");
  1082. let obj = {};
  1083. for (let i = 0; i < valueArray.length; i++) {
  1084. if (valueArray[i] != "null") {
  1085. if (gljKeyArray[i] == "type") {
  1086. valueArray[i] = parseInt(valueArray[i]);
  1087. }
  1088. obj[gljKeyArray[i]] = valueArray[i];
  1089. }
  1090. }
  1091. return obj;
  1092. },
  1093. getMixRationShowDatas: function (mixRatioList, projectGljs) {
  1094. var temRationGLJs = [];
  1095. for (var i = 0; i < mixRatioList.length; i++) {
  1096. let mIndex = gljOprObj.getIndex(mixRatioList[i], gljKeyArray);
  1097. let pgljMap = projectObj.project.projectGLJ.datas.gljMap;
  1098. let pg = null;
  1099. if (pgljMap) {
  1100. pg = pgljMap[mIndex];
  1101. }
  1102. if (!pg) {
  1103. pg = _.find(projectGljs, function (item) {
  1104. return gljOprObj.getIndex(item, gljKeyArray) == mIndex;
  1105. }); //改关联关系
  1106. }
  1107. if (pg) {
  1108. let tem = {
  1109. projectGLJID: pg.id,
  1110. code: pg.code,
  1111. name: pg.name,
  1112. specs: pg.specs,
  1113. unit: pg.unit,
  1114. type: mixRatioList[i].type,
  1115. shortName: projectObj.project.projectGLJ.getShortNameByID(
  1116. mixRatioList[i].type
  1117. ),
  1118. consumption: mixRatioList[i].consumption,
  1119. rationItemQuantity: mixRatioList[i].consumption,
  1120. // quantity:mixRatioList[i].consumption,
  1121. /* basePrice: pg.unit_price.base_price,
  1122. marketPrice: pg.unit_price.market_price,
  1123. adjustPrice: pg.adjust_price,*/
  1124. //isEstimate: pg.is_evaluate,
  1125. isMixRatio: true,
  1126. isAdd: pg.unit_price.is_add,
  1127. GLJID: pg.glj_id,
  1128. };
  1129. if (projectObj.project.projectGLJ.isEstimateType(pg.type)) {
  1130. tem.isEstimate = pg.is_evaluate;
  1131. }
  1132. this.setGLJPrice(tem, pg);
  1133. temRationGLJs.push(tem);
  1134. } else {
  1135. console.log("没有找到工料机:" + mIndex);
  1136. }
  1137. }
  1138. temRationGLJs = gljUtil.sortMixRatio(temRationGLJs);
  1139. return temRationGLJs;
  1140. },
  1141. showQuantityDetailData: function (node) {
  1142. node = node ? node : projectObj.project.mainTree.selected;
  1143. var quantity_detail = projectObj.project.quantity_detail;
  1144. let field = node.sourceType == ModuleNames.ration ? "rationID" : "billID";
  1145. let details = quantity_detail.getListByID(node.data.ID, field);
  1146. sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
  1147. this.detailData = details;
  1148. if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
  1149. this.detailSheet
  1150. .getRange(-1, 0, -1, this.detailSetting.header.length)
  1151. .locked(true);
  1152. }
  1153. },
  1154. clearSheetData: function () {
  1155. if ($("#linkGLJ").hasClass("active")) {
  1156. sheetCommonObj.showData(this.sheet, this.setting, []);
  1157. }
  1158. if ($("#linkAZZJF").hasClass("active")) {
  1159. installationFeeObj.rationInstallSheet.setRowCount(0); //清除combobox cell
  1160. sheetCommonObj.showData(
  1161. installationFeeObj.rationInstallSheet,
  1162. installationFeeObj.rationInstallSetting,
  1163. []
  1164. );
  1165. }
  1166. // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
  1167. this.sheetData = [];
  1168. installationFeeObj.rationInstallData = [];
  1169. //this.detailData=[];
  1170. },
  1171. updateRationGLJ: function (args) {
  1172. var me = this;
  1173. var updateField = me.setting.header[args.col].dataCode;
  1174. var recode = me.sheetData[args.row];
  1175. var newval;
  1176. if (!me.rationGLJEditCheck(args)) {
  1177. recode
  1178. ? me.sheet.getCell(args.row, args.col).value(recode[updateField])
  1179. : me.sheet.getCell(args.row, args.col).value(null);
  1180. return;
  1181. }
  1182. if (args.editingText) {
  1183. args.editingText = args.editingText.replace(/[\r\n]/g, ""); //去掉回车换行等字符;
  1184. me.sheet.getCell(args.row, args.col).value(args.editingText);
  1185. }
  1186. if (
  1187. updateField == "marketPrice" ||
  1188. updateField == "customQuantity" ||
  1189. updateField == "basePrice"
  1190. ) {
  1191. if (args.editingText == null) {
  1192. updateField == "marketPrice" ? (newval = 0) : (newval = "");
  1193. } else {
  1194. var decimal =
  1195. updateField == "customQuantity" ? getDecimal("glj.quantity") : 6; //对于市场价和定额价,这里只是中间的小数位数,后面更新前会根据有没有组成物再取值
  1196. newval = number_util.checkNumberValue(args.editingText, decimal);
  1197. if (newval == null) {
  1198. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  1199. return;
  1200. }
  1201. }
  1202. } else {
  1203. if (updateField == "name" || updateField == "unit") {
  1204. if (args.editingText === null) {
  1205. alert(me.setting.header[args.col].headerName + "不能为空!");
  1206. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  1207. return;
  1208. }
  1209. }
  1210. if (updateField == "code") {
  1211. if (
  1212. !gljUtil.isDef(args.editingText) ||
  1213. args.editingText == "" ||
  1214. args.editingText.indexOf("|-|") === -1 ||
  1215. this.isRationGLJExit(args.editingText)
  1216. ) {
  1217. //说明是选中自已,或者是已存在的工料机
  1218. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  1219. return;
  1220. }
  1221. }
  1222. newval = args.editingText == null ? "" : args.editingText;
  1223. }
  1224. if (newval === recode[updateField]) {
  1225. //如果值完全相等,则不需要更新
  1226. return;
  1227. }
  1228. if (updateField == "marketPrice" || updateField == "basePrice") {
  1229. projectObj.project.projectGLJ.updatePriceFromRG(
  1230. recode,
  1231. updateField,
  1232. newval
  1233. );
  1234. } else if (updateField == "code") {
  1235. //替换单价文件中已经有的工料机
  1236. projectObj.project.ration_glj.updateRationGLJByChangeCode(
  1237. recode,
  1238. updateField,
  1239. newval
  1240. );
  1241. } else if (me.setting.navigationRightCol.indexOf(updateField) != -1) {
  1242. //对于名称、规格、单位先跳到下一列,保存至缓存
  1243. me.setToEditCache(recode, updateField, newval, args);
  1244. } else {
  1245. projectObj.project.ration_glj.updateRationGLJByEdit(
  1246. recode,
  1247. updateField,
  1248. newval
  1249. );
  1250. }
  1251. },
  1252. setToEditCache: function (recode, updateField, value, args) {
  1253. let me = this;
  1254. if (me.rationGljEditObj == null) {
  1255. me.rationGljEditObj = {
  1256. recode: recode,
  1257. doc: {},
  1258. row: args.row,
  1259. };
  1260. me.rationGljEditObj.doc[updateField] = value;
  1261. } else {
  1262. if (me.rationGljEditObj.recode.ID == recode.ID) {
  1263. //确保编辑的是同一条数据
  1264. me.rationGljEditObj.doc[updateField] = value;
  1265. }
  1266. }
  1267. },
  1268. isRationGLJExit: function (connectKey) {
  1269. for (let rg of gljOprObj.sheetData) {
  1270. if (rg.isMixRatio == true) {
  1271. continue;
  1272. }
  1273. if (gljOprObj.getIndex(rg, gljKeyArray) == connectKey) {
  1274. //存在一样的工料机
  1275. return true;
  1276. }
  1277. }
  1278. return false;
  1279. },
  1280. updateRationTypeGLJ: function (value, node, fieldName, editingText) {
  1281. let newval;
  1282. let updatePrice = false;
  1283. if (
  1284. fieldName == "marketUnitFee" ||
  1285. fieldName == "feesIndex.common.unitFee"
  1286. ) {
  1287. updatePrice = true;
  1288. if (value == null) {
  1289. newval = 0;
  1290. } else {
  1291. var decimal = getDecimal("glj.unitPrice");
  1292. newval = number_util.checkNumberValue(value, decimal);
  1293. }
  1294. } else {
  1295. if (value != null) {
  1296. projectObj.project.projectGLJ.updatePropertyFromMainSpread(
  1297. node,
  1298. fieldName,
  1299. value,
  1300. editingText
  1301. );
  1302. return;
  1303. }
  1304. }
  1305. if (newval && updatePrice == true) {
  1306. projectObj.project.projectGLJ.updatePriceFromRG(
  1307. node.data,
  1308. "marketPrice",
  1309. newval
  1310. );
  1311. return;
  1312. }
  1313. projectObj.mainController.refreshTreeNode([node]);
  1314. },
  1315. updateIsEstimate: function (args, newval) {
  1316. var me = gljOprObj;
  1317. if (me.setting.header[args.col].dataCode == "isEstimate") {
  1318. var pspread = new ProjectGLJSpread();
  1319. var recode = me.sheetData[args.row];
  1320. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  1321. let glj = _.find(projectGljs, { id: recode.projectGLJID });
  1322. if (glj) {
  1323. glj["is_evaluate"] = newval;
  1324. args.fromRG = true;
  1325. pspread.postUpdate(
  1326. recode.projectGLJID,
  1327. "is_evaluate",
  1328. newval,
  1329. args,
  1330. null,
  1331. successTrigger
  1332. );
  1333. }
  1334. }
  1335. },
  1336. showLibGLJSheetData: function () {
  1337. //this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
  1338. sheetCommonObj.showData(
  1339. this.gljLibSheet,
  1340. this.gljLibSheetSetting,
  1341. this.gljLibSheetData,
  1342. gljOprObj.distTypeTree
  1343. );
  1344. this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
  1345. },
  1346. filterLibGLJSheetData: function () {
  1347. let me = this;
  1348. const selectLibID = $("#glj-lib-select").val();
  1349. const cptLibReg = new RegExp(commonConstants.COMPLEMENTARY_LIB);
  1350. me.gljLibSheetData = cptLibReg.test(selectLibID)
  1351. ? me.complementaryGLJs
  1352. : me.stdGLJ;
  1353. if (
  1354. $("#actionType").val() == "replace" ||
  1355. $("#actionType").val() == "m_replace"
  1356. ) {
  1357. me.filterLibGLJByType();
  1358. } else if (
  1359. $("#actionType").val() == "addMix" ||
  1360. $("#actionType").val() == "unitPriceAddMix"
  1361. ) {
  1362. projectGljObject.filterLibGLJForMixRatio();
  1363. }
  1364. //文本筛选
  1365. let searchStr = $("#gljSearchKeyword").val();
  1366. if (searchStr && searchStr.trim() != "") {
  1367. let reg = new RegExp(searchStr);
  1368. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  1369. return reg.test(data.code) || reg.test(data.name);
  1370. });
  1371. }
  1372. if (me.gljCurTypeId == undefined) {
  1373. return;
  1374. }
  1375. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  1376. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  1377. return _.includes(
  1378. me.parentNodeIds["_pNodeId_" + me.gljCurTypeId],
  1379. n.gljClass
  1380. );
  1381. });
  1382. } else {
  1383. me.gljLibSheetData = _.filter(me.gljLibSheetData, {
  1384. gljClass: me.gljCurTypeId,
  1385. });
  1386. }
  1387. },
  1388. setGLJSelection: function (args, newVal) {
  1389. if (
  1390. $("#actionType").val() == "add" ||
  1391. $("#actionType").val() == "insert" ||
  1392. $("#actionType").val() == "insertEquipment" ||
  1393. $("#actionType").val() == "addMix" ||
  1394. $("#actionType").val() == "unitPriceAddMix"
  1395. ) {
  1396. this.addGLJsSelection(args, newVal);
  1397. } else {
  1398. this.replaceGLJSelection(args, newVal);
  1399. }
  1400. },
  1401. addGLJsSelection: function (args, newVal) {
  1402. var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
  1403. if (newVal == 1) {
  1404. this.GLJSelection.push(con_key);
  1405. this.gljLibSheetData[args.row].select = 1;
  1406. } else if (newVal == 0) {
  1407. _.pull(this.GLJSelection, con_key);
  1408. this.gljLibSheetData[args.row].select = 0;
  1409. }
  1410. },
  1411. replaceGLJSelection: function (args, newVal) {
  1412. var me = this;
  1413. var oldSelection = this.GLJSelection[0];
  1414. if (newVal == 0) {
  1415. args.sheet.getCell(args.row, args.col).value(1);
  1416. return;
  1417. }
  1418. this.GLJSelection = [
  1419. me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray),
  1420. ];
  1421. this.gljLibSheetData[args.row].select = 1;
  1422. var oindex = _.findIndex(this.gljLibSheetData, function (item) {
  1423. var i_key = me.getIndex(item, gljLibKeyArray);
  1424. return oldSelection == i_key;
  1425. });
  1426. if (oindex != -1) {
  1427. args.sheet.getCell(oindex, args.col).value(0);
  1428. this.gljLibSheetData[oindex].select = 0;
  1429. } else {
  1430. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  1431. var i_key = me.getIndex(item, gljLibKeyArray);
  1432. return oldSelection == i_key;
  1433. });
  1434. oldData ? (oldData.select = 0) : "";
  1435. }
  1436. },
  1437. filterLibGLJByType: function () {
  1438. var me = this;
  1439. var selected = me.sheetData[gljContextMenu.selectedRow];
  1440. let materialTypes = [
  1441. gljType.CONCRETE,
  1442. gljType.MORTAR,
  1443. gljType.MIX_RATIO,
  1444. gljType.COMMERCIAL_CONCRETE,
  1445. gljType.COMMERCIAL_MORTAR,
  1446. ]; //混凝土、砂浆、配合比、商品混凝土、商品砂浆
  1447. let normalTypes = [
  1448. gljType.GENERAL_MATERIAL,
  1449. gljType.PURCHASE_COMPONENT,
  1450. gljType.GREEN_SEEDLING,
  1451. ]; //普通材料、外购砼构件、绿化苗木;
  1452. let filterTypes = [selected.type];
  1453. //当前人材机类型是“混凝土、砂浆、配合比、商品混凝土、商品砂浆”时,筛选的可替换的人材机类型应是“混凝土、或砂浆、或配合比、或商品混凝土、或商品砂浆”。
  1454. if (materialTypes.includes(selected.type)) filterTypes = materialTypes;
  1455. //当前人材机类型是普通材料、外购砼构件、绿化苗木
  1456. if (normalTypes.includes(selected.type)) filterTypes = normalTypes;
  1457. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  1458. return filterTypes.includes(data.gljType);
  1459. });
  1460. },
  1461. getComboData: function (gljDistType) {
  1462. let me = this;
  1463. let distType;
  1464. let distTypeTree = {
  1465. prefix: "gljType",
  1466. distTypes: {},
  1467. comboDatas: [],
  1468. distTypesArr: [],
  1469. };
  1470. gljDistType.forEach(function (typeData) {
  1471. let typeObj = {
  1472. data: typeData,
  1473. children: [],
  1474. parent: null,
  1475. };
  1476. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  1477. distTypeTree.distTypesArr.push(typeObj);
  1478. });
  1479. gljDistType.forEach(function (typeData) {
  1480. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  1481. let parent =
  1482. distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  1483. if (parent) {
  1484. distType.parent = parent;
  1485. parent.children.push(distType);
  1486. }
  1487. });
  1488. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  1489. if (
  1490. distTypeObj.data.fullName !== "材料" &&
  1491. distTypeObj.data.fullName !== "机械"
  1492. ) {
  1493. distTypeTree.comboDatas.push({
  1494. text: distTypeObj.data.fullName,
  1495. value: distTypeObj.data.ID,
  1496. });
  1497. }
  1498. });
  1499. return distTypeTree;
  1500. },
  1501. doInsertGLJ: function (insertType) {
  1502. var me = this;
  1503. var selected = projectObj.project.mainTree.selected;
  1504. var project = projectObj.project;
  1505. if (me.GLJSelection.length <= 0) {
  1506. return;
  1507. }
  1508. $.bootstrapLoading.start();
  1509. project.ration_glj.insertGLJAsRation(
  1510. me.GLJSelection,
  1511. selected,
  1512. insertType,
  1513. function (parentNodeID, nextNodeID, data) {
  1514. let newNode = null;
  1515. for (let r_glj of data) {
  1516. r_glj.quantity = r_glj.quantity + "";
  1517. project.Ration.datas.push(r_glj);
  1518. } //要先更新树节点工程量,加载项目工料机并计算消耗量才有值
  1519. project.projectGLJ.loadData(function () {
  1520. for (let r_glj of data) {
  1521. r_glj = me.setGLJPrice(r_glj); //设置工料机价格
  1522. newNode = project.mainTree.insert(
  1523. parentNodeID,
  1524. nextNodeID,
  1525. r_glj.ID
  1526. );
  1527. newNode.source = r_glj;
  1528. newNode.sourceType = project.Ration.getSourceType();
  1529. newNode.data = r_glj;
  1530. ProjectController.syncDisplayNewNode(
  1531. projectObj.mainController,
  1532. newNode
  1533. );
  1534. }
  1535. project.calcProgram.calcLeafAndSave(newNode.parent); //计算父级清单的所有子节点
  1536. projectObj.mainController.refreshTreeNode([newNode]);
  1537. if (me.hasComposition(newNode.data, true)) {
  1538. me.showMixRatio(newNode);
  1539. } else {
  1540. me.showRationGLJSheetData();
  1541. }
  1542. projectObj.refreshBaseActn(project.mainTree);
  1543. $.bootstrapLoading.end();
  1544. });
  1545. }
  1546. );
  1547. },
  1548. doAddGLJ: function () {
  1549. var selected = projectObj.project.mainTree.selected;
  1550. var project = projectObj.project;
  1551. gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
  1552. var rg = _.find(gljOprObj.sheetData, function (item) {
  1553. if (item.isMixRatio == true) {
  1554. return false;
  1555. }
  1556. var i_key = gljOprObj.getIndex(item, gljKeyArray);
  1557. return n == i_key;
  1558. });
  1559. return rg ? false : true;
  1560. });
  1561. if (
  1562. gljOprObj.GLJSelection.length > 0 &&
  1563. selected &&
  1564. selected.sourceType == ModuleNames.ration
  1565. ) {
  1566. project.ration_glj.addGLJByLib(
  1567. gljOprObj.GLJSelection,
  1568. selected.data,
  1569. function (result) {
  1570. if (result) {
  1571. selected.data.adjustState = result.adjustState;
  1572. project.ration_glj.datas = project.ration_glj.datas.concat(
  1573. result.newRecodes
  1574. ); //显示和缓存统一,这样的话就不用更新两个位置了
  1575. //project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
  1576. //gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
  1577. project.projectGLJ.loadNewProjectGLJToCaches(
  1578. result.projectGLJList,
  1579. true
  1580. );
  1581. project.ration_glj.addToMainTree(result.showData); //组成物不会显示到造价书页面
  1582. project.calcProgram.calcAndSave(selected);
  1583. projectObj.mainController.refreshTreeNode([selected]);
  1584. gljOprObj.refreshView();
  1585. $.bootstrapLoading.end();
  1586. }
  1587. }
  1588. ); //doc.rationID=selected.data.ID;
  1589. }
  1590. },
  1591. concreteTypeReplaceChecking: function (selectCode, oldData, selected) {
  1592. //selected为空,表示批量替换 混凝土替换前的检查,是否给出确认提示
  1593. let allGLJ = gljOprObj.AllRecode;
  1594. let glj = _.find(allGLJ, function (item) {
  1595. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  1596. return i_key == selectCode;
  1597. });
  1598. if (!glj) return false;
  1599. if (gljUtil.isConcreteToCommercialConcrete(oldData.type, glj.gljType)) {
  1600. //被替换的是混凝土,替换成商品砼或商品砂浆
  1601. if (selected) {
  1602. //如果有选中的,说明是替换,还要判断是否有辅助定额, 批量替换不用判断
  1603. return selected.data.rationAssList &&
  1604. selected.data.rationAssList.length > 0
  1605. ? true
  1606. : false;
  1607. }
  1608. return true;
  1609. }
  1610. return false;
  1611. },
  1612. replaceGLJConfirm: function (mreplace = false) {
  1613. let me = this;
  1614. let oldData = me.sheetData[gljContextMenu.selectedRow];
  1615. let selectCode = gljOprObj.GLJSelection[0];
  1616. let selected =
  1617. mreplace == true ? null : projectObj.project.mainTree.selected;
  1618. if (me.concreteTypeReplaceChecking(selectCode, oldData, selected)) {
  1619. hintBox.infoBox(
  1620. "操作确认",
  1621. "请先调整厚度,再替换商品砼。确定要继续吗?",
  1622. 2,
  1623. function () {
  1624. mreplace == true
  1625. ? $("#mreplace_next_div").modal("show")
  1626. : me.doReplaceGLJ(selectCode, oldData, selected);
  1627. },
  1628. null,
  1629. ["确定", "取消"],
  1630. false
  1631. );
  1632. } else {
  1633. mreplace == true
  1634. ? $("#mreplace_next_div").modal("show")
  1635. : me.doReplaceGLJ(selectCode, oldData, selected);
  1636. }
  1637. },
  1638. doReplaceGLJ: function (selectCode, oldData, selected, is) {
  1639. let me = this;
  1640. let project = projectObj.project;
  1641. let oldType = oldData.type;
  1642. project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
  1643. if (result) {
  1644. //result.adjustState;
  1645. project.ration_glj.setDatasAfterReplace(result);
  1646. let data = result.data;
  1647. let nodes = [selected];
  1648. let node = project.ration_glj.updateGLJNodeAfterReplace(data);
  1649. if (node) nodes.push(node);
  1650. /*if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  1651. var node = project.ration_glj.findGLJNodeByID(data.ID);
  1652. if (node) {
  1653. project.ration_glj.transferToNodeData(data);
  1654. node.source = data;
  1655. node.data = data;
  1656. }
  1657. node ? nodes.push(node) : "";
  1658. }*/
  1659. //project.ration_glj.addToMainTree(data);
  1660. selected.data.adjustState = result.adjustState;
  1661. selected.data.name = result.name;
  1662. projectObj.mainController.refreshTreeNode(nodes);
  1663. project.calcProgram.calcAndSave(selected, function () {
  1664. me.replaceProgramInfo(oldType, result.projectGLJ.type);
  1665. });
  1666. gljOprObj.refreshView();
  1667. $.bootstrapLoading.end();
  1668. }
  1669. });
  1670. },
  1671. replaceProgramInfo: function (oldType, newType) {
  1672. //检查是否由混凝土替换为商品砼或者商品砂浆
  1673. if (gljUtil.isConcreteToCommercialConcrete(oldType, newType)) {
  1674. const showCompilations1 = [
  1675. "浙江养护(2005)",
  1676. "内蒙古养护(2019)",
  1677. "内蒙古高速公路养护(2022)",
  1678. "安徽养护(2018)",
  1679. "山东养护(2016/2024)",
  1680. ];
  1681. const showMsg1 = "请手动修改取费类别为构造物III";
  1682. const showCompilations2 = ["广西养护(2020)", "广西日常养护(2020)"];
  1683. const showMsg2 = "请手动修改取费类别为商混及外构件";
  1684. const showCompilations3 = ["河南养护(2022)", "河南日常养护(2022)"];
  1685. const showMsg3 = "请手动修改取费类别为商品混凝土及外构件";
  1686. if (showCompilations1.includes(compilationName)) {
  1687. // 隐藏,不显示
  1688. } else if (showCompilations2.includes(compilationName)) {
  1689. setTimeout(() => {
  1690. alert(showMsg2);
  1691. }, 300);
  1692. } else if (showCompilations3.includes(compilationName)) {
  1693. setTimeout(() => {
  1694. alert(showMsg3);
  1695. }, 300);
  1696. } else {
  1697. setTimeout(() => {
  1698. alert(showMsg1);
  1699. }, 300);
  1700. }
  1701. }
  1702. },
  1703. doMReplaceGLJ: function () {
  1704. let me = this;
  1705. let project = projectObj.project;
  1706. let oldData = me.sheetData[gljContextMenu.selectedRow];
  1707. let selectCode = gljOprObj.GLJSelection[0];
  1708. let oldType = oldData.type;
  1709. project.ration_glj.mReplaceGLJ(
  1710. selectCode,
  1711. oldData,
  1712. function (result, updateMap) {
  1713. if (result == null) {
  1714. return;
  1715. }
  1716. let data = result.data;
  1717. let stateList = result.stateList;
  1718. //let n_index = me.getIndex(data.query, gljKeyArray);
  1719. let nodes = [];
  1720. let quantityMap = {};
  1721. for (let gr of result.glj_result) {
  1722. quantityMap[gr.query.ID] = gr.doc;
  1723. }
  1724. //添加\删除混凝土组成物定额工料机
  1725. project.ration_glj.addAndDeleteDatas(
  1726. result.newRecodes,
  1727. result.deleteList
  1728. );
  1729. _.forEach(project.ration_glj.datas, function (t) {
  1730. // let t_index = me.getIndex(t, gljKeyArray);
  1731. if (updateMap[t.ID]) {
  1732. if (updateMap[t.ID].code) me.updateProperty(t, data.doc); //说明这条不是只更新自定义消耗量的,才要更新项目工料机
  1733. me.updateProperty(t, updateMap[t.ID]);
  1734. if (project.ration_glj.needShowToTree(t)) {
  1735. //如果是造价书中的树节点,则也须刷新
  1736. project.ration_glj.transferToNodeData(t);
  1737. var node = project.ration_glj.findGLJNodeByID(t.ID);
  1738. node ? nodes.push(node) : "";
  1739. }
  1740. }
  1741. if (quantityMap[t.ID]) {
  1742. //更新消耗量
  1743. me.updateProperty(t, quantityMap[t.ID]);
  1744. }
  1745. });
  1746. project.projectGLJ.loadNewProjectGLJToCaches([result.projectGLJ], true);
  1747. var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
  1748. project.calcProgram.calcNodesAndSave(rationNodes, function () {
  1749. me.replaceProgramInfo(oldType, result.projectGLJ.type);
  1750. });
  1751. me.refreshView();
  1752. $.bootstrapLoading.end();
  1753. }
  1754. );
  1755. },
  1756. updateProperty: function (obj, doc) {
  1757. gljUtil.updateProperty(obj, doc);
  1758. },
  1759. refreshStateAfterMreplace: function (stateList, gljNodes) {
  1760. let nodes = [];
  1761. let rationNodes = [];
  1762. _.forEach(stateList, function (s) {
  1763. let node = _.find(projectObj.project.mainTree.items, function (n) {
  1764. return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
  1765. });
  1766. if (node) {
  1767. node.data.adjustState = s.adjustState;
  1768. node.data.name = s.name;
  1769. nodes.push(node);
  1770. rationNodes.push(node);
  1771. }
  1772. });
  1773. gljNodes.length > 0 ? (nodes = nodes.concat(gljNodes)) : "";
  1774. projectObj.mainController.refreshTreeNode(nodes);
  1775. return rationNodes;
  1776. },
  1777. refreshView: function () {
  1778. let node = projectObj.project.mainTree.selected;
  1779. this.showDataIfRationSelect(node, "111111");
  1780. },
  1781. refreshTreeNode: function (obj) {
  1782. if (!obj) {
  1783. return;
  1784. }
  1785. let objectArray = [];
  1786. let nodes = [];
  1787. if (obj instanceof Array) {
  1788. objectArray.concat(obj);
  1789. } else {
  1790. objectArray.push(obj);
  1791. }
  1792. for (let o of objectArray) {
  1793. let node = this.updateDataNodeProperty(o.ID, o.data);
  1794. if (node) {
  1795. nodes.push(node);
  1796. }
  1797. }
  1798. projectObj.mainController.refreshTreeNode(nodes);
  1799. return nodes;
  1800. },
  1801. updateDataNodeProperty: function (nodeID, data) {
  1802. let node = projectObj.project.mainTree.findNode(nodeID);
  1803. if (node) {
  1804. for (let k in data) {
  1805. node.data[k] = data[k];
  1806. }
  1807. }
  1808. return node;
  1809. },
  1810. getTreeNodeCellType: function (data, comboboxOptions) {
  1811. let ns = GC.Spread.Sheets;
  1812. let rectW = 10;
  1813. let rectH = 10;
  1814. let margin = 3;
  1815. function TreeNodeCellType() {
  1816. this.ctx = null;
  1817. }
  1818. TreeNodeCellType.prototype = comboboxOptions
  1819. ? sheetCommonObj.getDynamicCombo()
  1820. : new ns.CellTypes.Text();
  1821. TreeNodeCellType.prototype.paint = function (
  1822. ctx,
  1823. value,
  1824. x,
  1825. y,
  1826. w,
  1827. h,
  1828. style,
  1829. options
  1830. ) {
  1831. this.ctx = ctx;
  1832. if (style.backColor) {
  1833. //先画背景色
  1834. ctx.save();
  1835. ctx.fillStyle = style.backColor;
  1836. ctx.fillRect(x, y, w, h);
  1837. ctx.restore();
  1838. } else {
  1839. ctx.clearRect(x, y, w, h);
  1840. }
  1841. if (value != null) {
  1842. let offset = margin + rectW + 6;
  1843. let recode = data[options.row];
  1844. if (recode && recode.hasOwnProperty("subList")) {
  1845. sheetCommonObj.drowRect(ctx, x, y, w, h, rectW, rectH, margin);
  1846. let collapsed =
  1847. recode.collapsed == undefined ? true : recode.collapsed; //options.sheet.getTag(options.row,options.col);
  1848. sheetCommonObj.drowSymbol(
  1849. ctx,
  1850. x,
  1851. y,
  1852. w,
  1853. h,
  1854. rectW,
  1855. rectH,
  1856. margin,
  1857. collapsed
  1858. );
  1859. } else if (recode && recode.isMixRatio) {
  1860. let hasNext =
  1861. data[options.row + 1] && data[options.row + 1].isMixRatio;
  1862. offset = sheetCommonObj.drowSubItem(ctx, x, y, w, h, offset, hasNext);
  1863. offset += 1;
  1864. }
  1865. arguments[2] = x + offset;
  1866. arguments[4] = w - offset;
  1867. //x = x + offset;
  1868. //w = w - offset;
  1869. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1870. }
  1871. };
  1872. TreeNodeCellType.prototype.getHitInfo = function (
  1873. x,
  1874. y,
  1875. cellStyle,
  1876. cellRect,
  1877. context
  1878. ) {
  1879. if (x < cellRect.x + cellRect.width - 15) {
  1880. //这里要判断点击的位置来决定return的内容,不能直接用combobox的方法
  1881. return {
  1882. x: x,
  1883. y: y,
  1884. row: context.row,
  1885. col: context.col,
  1886. cellStyle: cellStyle,
  1887. cellRect: cellRect,
  1888. sheetArea: context.sheetArea,
  1889. };
  1890. } else {
  1891. return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(
  1892. this,
  1893. arguments
  1894. );
  1895. }
  1896. };
  1897. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1898. let recode = data[hitinfo.row];
  1899. if (hitinfo.x < hitinfo.cellRect.x + hitinfo.cellRect.width - 15) {
  1900. hitinfo.sheet.setTag(hitinfo.row, hitinfo.col, "locked"); //通过这个来控制除了点击下拉框的三角形,点击其它地方不充许进入编辑状态,不然不好控制下拉框超出页面后调整滚动条
  1901. }
  1902. if (recode && recode.hasOwnProperty("subList")) {
  1903. let hoffset = hitinfo.cellRect.x + 3;
  1904. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1905. let collapsed =
  1906. recode.collapsed == undefined ? true : recode.collapsed;
  1907. collapsed = !collapsed;
  1908. recode.collapsed = collapsed;
  1909. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1910. hitinfo.sheet
  1911. .getRange(hitinfo.row + 1, -1, recode.subList.length, -1)
  1912. .visible(!collapsed);
  1913. hitinfo.sheet.invalidateLayout();
  1914. hitinfo.sheet.repaint();
  1915. return;
  1916. }
  1917. }
  1918. if (
  1919. comboboxOptions &&
  1920. hitinfo.x > hitinfo.cellRect.x + hitinfo.cellRect.width - 15
  1921. ) {
  1922. //点击了下拉框按钮,这里要判断下拉框是否会被挡住,从而决定是否自动调整滚动条
  1923. hitinfo.sheet.setTag(hitinfo.row, hitinfo.col, "");
  1924. sheetCommonObj.scrollSheetForOption(
  1925. hitinfo.sheet,
  1926. this.ctx,
  1927. hitinfo.cellRect,
  1928. hitinfo.row,
  1929. comboboxOptions
  1930. ); //下拉框超出显示后自动调整滚动条
  1931. GC.Spread.Sheets.CellTypes.ComboBox.prototype.processMouseDown.apply(
  1932. this,
  1933. arguments
  1934. );
  1935. }
  1936. };
  1937. let cellType = new TreeNodeCellType();
  1938. if (comboboxOptions) {
  1939. cellType.editorValueType(
  1940. GC.Spread.Sheets.CellTypes.EditorValueType.value
  1941. );
  1942. cellType.itemHeight(comboboxOptions.length).items(comboboxOptions);
  1943. }
  1944. return cellType;
  1945. },
  1946. marketPriceReadOnly: function (node) {
  1947. let isRationType =
  1948. node.sourceType == ModuleNames.ration &&
  1949. node.data.type == rationType.gljRation;
  1950. let type = isRationType == true ? node.data.subType : node.data.type;
  1951. if (gljUtil.isConcreteType(type)) return true;
  1952. return this.hasComposition(node.data, isRationType); //2018-9-14 需求变更暂估工料机也能修改市场价原语句:return hasCom|| node.data.isEstimate == 1
  1953. },
  1954. locateZTree: function (ID) {
  1955. let zTree = $.fn.zTree.getZTreeObj("gljTree");
  1956. let node = null;
  1957. if (ID) node = zTree.getNodesByParam("ID", ID, null)[0];
  1958. if (!node) {
  1959. node = zTree.getNodeByTId("gljTree_1");
  1960. ID = node.ID;
  1961. }
  1962. zTree.selectNode(node);
  1963. gljOprObj.gljCurTypeId = ID;
  1964. gljOprObj.filterLibGLJSheetData();
  1965. gljOprObj.showLibGLJSheetData();
  1966. },
  1967. isExtraType: function (type) {
  1968. return _.includes(gljUtil.extraType, type);
  1969. },
  1970. setNodeShowTab: function () {
  1971. let node = projectObj.project.mainTree.selected;
  1972. if (node && node.sourceType == ModuleNames.ration) {
  1973. gljOprObj.rationTab = gljOprObj.activeTab;
  1974. } else {
  1975. gljOprObj.billsTab = gljOprObj.activeTab;
  1976. }
  1977. },
  1978. //初始化分类树
  1979. //@param {String}type(标准或补充) {Array}treeData(树数据)
  1980. initClassTree: function (type, treeData, initSel = false) {
  1981. let me = this;
  1982. if (me.treeObj) {
  1983. me.treeObj.destroy();
  1984. me.parentNodeIds = {};
  1985. }
  1986. zTreeHelper.createTree(treeData, me.gljTreeSetting, "gljTree", me);
  1987. if (initSel) {
  1988. let rootNode = me.treeObj.getNodes()[0];
  1989. if (rootNode && rootNode.isParent && rootNode.isFirstNode) {
  1990. me.rootNode = rootNode;
  1991. }
  1992. if (me.rootNode) {
  1993. me.treeObj.selectNode(me.rootNode);
  1994. me.gljTreeSetting.callback.onClick(null, "gljTree", me.rootNode);
  1995. }
  1996. }
  1997. },
  1998. initScopeSpread: function () {
  1999. if (this.scopeSpread) return this.scopeSpread.repaint();
  2000. this.scopeSpread = SheetDataHelper.createNewSpread($("#scopeSpread")[0]);
  2001. sheetCommonObj.spreadDefaultStyle(this.scopeSpread);
  2002. this.scopeTree = idTree.createNew({
  2003. id: "ID",
  2004. pid: "ParentID",
  2005. nid: "NextSiblingID",
  2006. rootId: -1,
  2007. autoUpdate: false,
  2008. });
  2009. this.scopeTreeController = TREE_SHEET_CONTROLLER.createNew(
  2010. this.scopeTree,
  2011. this.scopeSpread.getActiveSheet(),
  2012. this.scopeSetting
  2013. );
  2014. this.scopeSheet = this.scopeSpread.getActiveSheet();
  2015. this.scopeSpread.bind(
  2016. GC.Spread.Sheets.Events.ButtonClicked,
  2017. this.onScopeChecked
  2018. );
  2019. },
  2020. showScopeDatas: function () {
  2021. this.initScopeSpread();
  2022. this.scopeDatas = this.getScopeDatas();
  2023. this.scopeTree.loadDatas(this.scopeDatas);
  2024. this.scopeTreeController.showTreeData();
  2025. },
  2026. getScopeDatas: function () {
  2027. let controller = projectObj.mainController,
  2028. project = projectObj.project;
  2029. let allNodes = [],
  2030. datas = [];
  2031. for (let rootNode of controller.tree.roots) {
  2032. allNodes.push(rootNode);
  2033. controller.tree.getAllSubNode(rootNode.source, allNodes);
  2034. }
  2035. for (let n of allNodes) {
  2036. let temData = {
  2037. ID: n.data.ID,
  2038. NextSiblingID: n.data.NextSiblingID,
  2039. ParentID: n.data.ParentID,
  2040. unit: n.data.unit,
  2041. code: n.data.code,
  2042. selected: 0,
  2043. name: n.data.name,
  2044. quantity: calcTools.uiNodeQty(n) ? calcTools.uiNodeQty(n) : "",
  2045. };
  2046. if (n.data.feesIndex && n.data.feesIndex.common) {
  2047. temData.unitPrice = n.data.feesIndex.common.unitFee;
  2048. temData.totalPrice = n.data.feesIndex.common.totalFee;
  2049. }
  2050. datas.push(temData);
  2051. }
  2052. return datas;
  2053. },
  2054. onScopeChecked: function (e, args) {
  2055. let me = gljOprObj,
  2056. nodes = [];
  2057. var checkboxValue = args.sheet.getCell(args.row, args.col).value();
  2058. var newval = checkboxValue ? 0 : 1;
  2059. let node = me.scopeTree.items[args.row];
  2060. setNodeAndChildreSelected(node, newval, nodes);
  2061. me.scopeTreeController.refreshTreeNode(nodes);
  2062. function setNodeAndChildreSelected(n, val, arr) {
  2063. n.data.selected = val;
  2064. nodes.push(n);
  2065. for (let c of n.children) {
  2066. setNodeAndChildreSelected(c, val, arr);
  2067. }
  2068. }
  2069. },
  2070. setScopeSelection: function () {
  2071. for (let node of this.scopeTree.items) {
  2072. //挑出选中数,过滤父节点
  2073. if (node.data.selected == 1 && node.children.length == 0)
  2074. this.scopeSelectedIDMap[node.data.ID] = true;
  2075. }
  2076. },
  2077. };
  2078. $(function () {
  2079. $("#glj_tree_div").on("shown.bs.modal", function (e) {
  2080. gljContextMenu.initGLJSelectView();
  2081. });
  2082. $("#mreplace_next_div").on("shown.bs.modal", function (e) {
  2083. gljOprObj.scopeSelectedIDMap = {};
  2084. gljOprObj.showScopeDatas();
  2085. });
  2086. $("#glj_tree_div").on("hidden.bs.modal", function () {
  2087. $("#gljSearchKeyword").val("");
  2088. });
  2089. $(".glj-radio").change(function () {
  2090. let val = $("input[name='glj']:checked").val();
  2091. if (val == "allGljs") {
  2092. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  2093. gljOprObj.filterLibGLJSheetData();
  2094. gljOprObj.showLibGLJSheetData();
  2095. } else {
  2096. if (val === "stdGLJ") {
  2097. gljOprObj.initClassTree("std", gljOprObj.treeData.std, true);
  2098. } else {
  2099. gljOprObj.initClassTree("comple", gljOprObj.treeData.comple, true);
  2100. }
  2101. gljOprObj.initSelection({ row: 0 });
  2102. }
  2103. });
  2104. // 更改选择库
  2105. $("#glj-lib-select").change(function () {
  2106. let getLibFun = null;
  2107. if (typeof unitPriceObj != "undefined")
  2108. getLibFun = unitPriceObj.getGLJLibData;
  2109. getGLJData("change", false, getLibFun);
  2110. });
  2111. /* //工料机搜索
  2112. $('#gljSearchKeyword').change(function () {
  2113. gljOprObj.filterLibGLJSheetData();
  2114. gljOprObj.showLibGLJSheetData();
  2115. });
  2116. $('#gljSearchKeyword').bind('keypress', function (e) {
  2117. if(e.keyCode === 13){
  2118. alert('2');
  2119. $(this).blur();
  2120. return false;
  2121. }
  2122. });*/
  2123. $("#gljSearchKeyword").bind("keyup", function (e) {
  2124. gljOprObj.filterLibGLJSheetData();
  2125. gljOprObj.showLibGLJSheetData();
  2126. gljOprObj.initSelection({ row: 0 });
  2127. });
  2128. $("#glj_selected_conf").click(function () {
  2129. if (gljOprObj.GLJSelection.length < 1) {
  2130. return;
  2131. }
  2132. if (["insert", "insertEquipment"].includes($("#actionType").val())) {
  2133. //造价书页面中插入定额类型的工料机
  2134. gljOprObj.doInsertGLJ($("#actionType").val());
  2135. } else if ($("#actionType").val() == "add") {
  2136. //添加工料机
  2137. gljOprObj.doAddGLJ();
  2138. } else if ($("#actionType").val() == "replace") {
  2139. //替换工料机
  2140. gljOprObj.replaceGLJConfirm(false);
  2141. } else if ($("#actionType").val() == "m_replace") {
  2142. //批量替换工料机
  2143. gljOprObj.replaceGLJConfirm(true);
  2144. } else if ($("#actionType").val() == "addMix") {
  2145. projectGljObject.addMixRatio();
  2146. } else if ($("#actionType").val() == "unitPriceAddMix") {
  2147. unitPriceObj.addMixRatio();
  2148. }
  2149. $("#glj_tree_div").modal("hide");
  2150. });
  2151. $("#scope_position_confirm").click(function () {
  2152. gljOprObj.setScopeSelection();
  2153. gljOprObj.doMReplaceGLJ();
  2154. });
  2155. $("#replace_next_btn").click(function () {
  2156. $("#glj_tree_div").modal("hide");
  2157. gljOprObj.replaceGLJConfirm(true);
  2158. });
  2159. $("#class_selected_conf").click(function () {
  2160. var gljClass = $("#selected_class").val();
  2161. var glj = gljOprObj.selectedGLJClass;
  2162. if (glj && gljClass && gljClass != "") {
  2163. //保存到我的工料机库
  2164. /*1 检查是否有组成物
  2165. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  2166. * 3 保存
  2167. * */
  2168. var newItem = {
  2169. code: glj.code,
  2170. name: glj.name,
  2171. specs: glj.specs,
  2172. unit: glj.unit,
  2173. basePrice: glj.basePrice,
  2174. gljType: glj.type,
  2175. shortName: glj.shortName,
  2176. component: [],
  2177. gljClass: gljClass,
  2178. };
  2179. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {
  2180. //有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  2181. for (var i = 0; i < glj.subList.length; i++) {
  2182. let tem = {
  2183. ID: glj.subList[i].GLJID,
  2184. consumeAmt: glj.rationItemQuantity,
  2185. isStd: true,
  2186. };
  2187. newItem.component.push(tem);
  2188. }
  2189. }
  2190. var data = getcmpUpdateData([newItem]);
  2191. $.bootstrapLoading.start();
  2192. var callback = function (data) {
  2193. $("#glj_class_div").modal("hide");
  2194. $.bootstrapLoading.end();
  2195. };
  2196. CommonAjax.post(
  2197. "complementartGlj/api/mixUpdateGljItems",
  2198. data,
  2199. callback,
  2200. function () {
  2201. $.bootstrapLoading.end();
  2202. }
  2203. );
  2204. }
  2205. });
  2206. $("#glj_class_div").on("hidden.bs.modal", function (e) {
  2207. gljOprObj.selectedGLJClass = null;
  2208. $("#class_selected_conf").attr("disabled", "disabled");
  2209. $("#selected_class").val("");
  2210. });
  2211. $("#subSpread").focusout(function (e) {
  2212. //当本身或子元素失去焦点时这个事件都会发生,而且不好判断点击的是哪里。
  2213. if (gljOprObj.rationGljEditObj) {
  2214. gljOprObj.cancelUpdate = false;
  2215. gljOprObj.timeStamp = e.timeStamp; //设置时间戳,有可能用户在表格上乱点,这个事件被触发多次
  2216. setTimeout(function () {
  2217. //延时执行提交操作,如果点击的是spread里的地方,会把cancelUpdate改成true,这样的话就不执行提交操作
  2218. if (
  2219. gljOprObj.timeStamp == e.timeStamp &&
  2220. gljOprObj.cancelUpdate !== true
  2221. ) {
  2222. //时间戳要相同
  2223. gljOprObj.updateGljFromCache();
  2224. }
  2225. }, 200);
  2226. }
  2227. });
  2228. function getcmpUpdateData(items) {
  2229. var data = {
  2230. updateItems: [],
  2231. removeIds: [],
  2232. };
  2233. data.addItems = items;
  2234. return data;
  2235. }
  2236. });
  2237. function operationWithRound(value1, value2, field, symble) {
  2238. let decimal = getDecimal(field);
  2239. value1 = scMathUtil.roundForObj(value1, decimal);
  2240. value2 = scMathUtil.roundForObj(value2, decimal);
  2241. let result;
  2242. switch (symble) {
  2243. case "+":
  2244. result = scMathUtil.roundForObj(value1 + value2, decimal);
  2245. break;
  2246. case "-":
  2247. result = scMathUtil.roundForObj(value1 - value2, decimal);
  2248. break;
  2249. case "*":
  2250. result = scMathUtil.roundForObj(value1 * value2, decimal);
  2251. break;
  2252. case "/":
  2253. result = scMathUtil.roundForObj(value1 / value2, decimal);
  2254. break;
  2255. }
  2256. return result;
  2257. }
  2258. function getDecimal(fieldID, node) {
  2259. if (node) {
  2260. return decimalObj.decimal(fieldID, node);
  2261. } else if (fieldID.indexOf(".") != -1) {
  2262. var keyArray = fieldID.split(".");
  2263. return decimalObj[keyArray[0]][keyArray[1]];
  2264. } else {
  2265. return decimalObj.decimal(fieldID);
  2266. }
  2267. }
  2268. function compareRationGLJ(a, b) {
  2269. if (a.type + "" < b.type + "") {
  2270. return true;
  2271. }
  2272. if (a.type + "" == b.type + "") {
  2273. if (a.code < b.code) {
  2274. return true;
  2275. }
  2276. }
  2277. return false;
  2278. }