glj_view.js 88 KB

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