glj_view.js 71 KB

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