glj_view.js 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999
  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. }else {
  560. if($('#linkGLJ').hasClass('active')){
  561. this.showRationGLJData(node);
  562. subObj.showGljSubTabData();
  563. // MaterialController.showReplaceDiv(node);
  564. }
  565. if($('#linkAZZJF').hasClass('active')) installationFeeObj.showRationInstallationData(node);
  566. if($('#linkMBZM').hasClass('active')) mbzm_obj.showMBZMData(node);
  567. }
  568. isShow = true;
  569. }
  570. if(node.sourceType == ModuleNames.ration_glj){
  571. if($('#linkGLJ').hasClass('active')) this.showMixRatio(node);
  572. MaterialController.hideReplaceDiv();
  573. isShow = true;
  574. }
  575. if($('#linkGCLMX').hasClass('active')) this.showQuantityDetailData(node);
  576. } else {
  577. this.selectedNodeId = null;
  578. }
  579. if (!isShow) {
  580. this.clearSheetData();
  581. MaterialController.hideReplaceDiv();
  582. }
  583. this.sheet.resumeEvent();
  584. this.sheet.resumePaint();
  585. //子目换算
  586. //zmhs_obj.showZMHSData(node);
  587. // $('#dropdown').hide();
  588. },
  589. showMixRatio:function (node) {//显示组成物到定额工料机
  590. let mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  591. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  592. let indexArray =node.sourceType==ModuleNames.ration?rationKeyArray:gljKeyArray;
  593. let connect_index = this.getIndex(node.data,indexArray);
  594. let gljList=[];
  595. if(mixRatioMap[connect_index]){ //说明是有组成物的类型
  596. gljList = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  597. }
  598. if(gljList.length>0){//计算总消耗量
  599. if(node.sourceType==ModuleNames.ration){
  600. this.calcMixRationTotalQuantity(gljList,node.data.quantity);
  601. }else {
  602. let totalQuantity = this.getTotalQuantity(node.data);
  603. this.calcMixRationTotalQuantity(gljList,totalQuantity)
  604. }
  605. }
  606. this.sheetData = gljList;
  607. this.sheet.setRowCount(0);
  608. this.sheetData = gljUtil.sortRationGLJ(this.sheetData);
  609. this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType([]));
  610. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  611. //初始选择
  612. this.preGljSelection = null;
  613. this.sheetInitSelection({row: this.sheet.getActiveRowIndex(), col: 0});
  614. this.sheet.getRange(-1, 0, -1, this.setting.header.length).locked(true);//锁住定额工料机的所有列
  615. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);//锁住工程量明细的所有列
  616. },
  617. showRationGLJData: function (node) {
  618. let startTime = +new Date();
  619. let gljList = [];
  620. let ration_glj = projectObj.project.ration_glj;
  621. node = node ? node : projectObj.project.mainTree.selected;
  622. if (node.sourceType == ModuleNames.ration) {
  623. if(node.data.type==rationType.gljRation){
  624. this.showMixRatio(node);
  625. }else {
  626. let ration = node.data;
  627. gljList = this.filterGljByRation(ration, ration_glj.datas);
  628. this.showInSheet(gljList);
  629. }
  630. }else if(node.sourceType == ModuleNames.ration_glj){
  631. this.showMixRatio(node);
  632. }
  633. },
  634. showRationGLJSheetData: function (init) {
  635. let me = this;
  636. let selected = this.sheet.getSelections();
  637. this.combineWithProjectGlj(this.sheetData);
  638. this.sheet.setRowCount(0);
  639. this.sheetData = gljUtil.sortRationGLJ(this.sheetData);
  640. this.sumQuantity();//计算总消耗量
  641. this.addMixRatioToShow();//显示组成物信息
  642. let itreeTime = +new Date();
  643. this.initRationTree(init,this.getUnitPriceCodeMap());
  644. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData,null,function () {
  645. if(me.mainTreeSelectedChange == true){
  646. me.sheet.setSelection(0,1,1,1);//默认选中第一行,第二列(名称列)
  647. me.mainTreeSelectedChange = false;
  648. }else if(selected){//定位光标到之前的位置
  649. me.sheet.setSelection(selected[0].row,selected[0].col,selected[0].rowCount,selected[0].colCount);
  650. }
  651. //初始选择
  652. me.preGljSelection = null;
  653. me.sheetInitSelection({row: me.sheet.getActiveRowIndex(), col: me.sheet.getActiveColumnIndex()});
  654. });
  655. },
  656. getSelectedRationGlj:function () {
  657. let selected = this.sheet.getSelections()[0];
  658. let ration_glj = this.sheetData[selected.row];
  659. return ration_glj;
  660. },
  661. getUnitPriceCodeMap : function () {//取单价文件中,编码前缀一样的映射表
  662. let codeMap = {};
  663. let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;
  664. if(priceMap){
  665. for(let connectKey in priceMap){
  666. let code = priceMap[connectKey].code;
  667. let name = priceMap[connectKey].name;
  668. let specs = priceMap[connectKey].specs;
  669. if(code){
  670. let displayText = code +" "+name +" "+specs;
  671. let preCode = code.split("-")[0];
  672. if(codeMap[preCode]) {
  673. codeMap[preCode].push({text:displayText,value:connectKey});
  674. }else {
  675. codeMap[preCode]=[{text:displayText ,value:connectKey}];
  676. }
  677. }
  678. }
  679. }
  680. return codeMap;
  681. },
  682. initRationTree: function (init,codeMap) {
  683. this.sheet.suspendPaint();
  684. this.sheet.suspendEvent();
  685. this.sheet.setRowCount(this.sheetData.length >30?this.sheetData.length:30);
  686. for (var i = 0; i < this.sheetData.length; i++) {
  687. let options = this.getCodeOptions(this.sheetData[i],codeMap);
  688. this.sheet.setCellType(i, 0,this.getTreeNodeCellType(this.sheetData,options),GC.Spread.Sheets.SheetArea.viewport);
  689. if (this.sheetData[i].hasOwnProperty('subList')) {
  690. var collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
  691. if (collapsed == true) {
  692. this.sheet.getRange(i + 1, -1, this.sheetData[i].subList.length, -1).visible(false);
  693. }
  694. }
  695. }
  696. this.sheet.resumeEvent();
  697. this.sheet.resumePaint();
  698. },
  699. getCodeOptions:function (recode,codeMap) {
  700. let options = [];
  701. if(recode.isMixRatio ===true){
  702. return null;
  703. }
  704. let code = recode.code;
  705. if(code) {
  706. let preCode = code.split("-")[0];
  707. if( codeMap[preCode]) options = codeMap[preCode];
  708. if(options.length>0) _.remove(options,{'value':gljOprObj.getIndex(recode, gljKeyArray)})//去掉本身
  709. }
  710. return _.sortBy(options,'text');
  711. },
  712. filterGljByRation: function (ration, datas) {
  713. var gljList = [];
  714. if (datas && datas.length > 0) {
  715. gljList = _.filter(datas, {'rationID': ration.ID})
  716. }
  717. return gljList;
  718. },
  719. showInSheet: function (gljList) {
  720. this.sheetData = gljList;
  721. this.showRationGLJSheetData(true);
  722. },
  723. sumQuantity: function (node) {
  724. if (this.sheetData.length > 0) {
  725. node = node ? node : projectObj.project.mainTree.selected;
  726. let ration = node.data;
  727. let quantity = ration.quantity;
  728. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  729. for (let glj of this.sheetData) {
  730. glj.totalQuantity= this.getTotalQuantity(glj,ration);
  731. }
  732. }
  733. },
  734. getTotalQuantity:function(glj,ration){
  735. if (glj.isMixRatio == true) return;//如果是用于显示的组成物,则不用计算,跳过
  736. ration=ration?ration: _.find(projectObj.project.Ration.datas,{"ID":glj.rationID});
  737. glj.totalQuantity = gljUtil.getTotalQuantity(glj,ration,getDecimal("ration.quantity"),getDecimal("glj.quantity"));
  738. if (glj.hasOwnProperty('subList')) {//需要计算glj下挂的组成物的总消耗量
  739. this.calcMixRationTotalQuantity(glj.subList,glj.totalQuantity);
  740. }
  741. return glj.totalQuantity;
  742. },
  743. calcMixRationTotalQuantity(mList,pTotal){ //计算组成物的总消耗量
  744. for (let subG of mList) {
  745. subG.rationItemQuantity = scMathUtil.roundForObj(subG.rationItemQuantity, getDecimal("glj.quantity"));
  746. subG.totalQuantity = scMathUtil.roundForObj(subG.rationItemQuantity * pTotal, getDecimal("glj.quantity"))+'';
  747. }
  748. },
  749. addMixRatioToShow: function () {
  750. var newList = [];
  751. _.remove(this.sheetData, {'isMixRatio': true});
  752. for (var i = 0; i < this.sheetData.length; i++) {
  753. newList.push(this.sheetData[i]);
  754. if (this.sheetData[i].hasOwnProperty('subList')) {
  755. newList = newList.concat(this.sheetData[i].subList);
  756. }
  757. }
  758. this.sheetData = newList;
  759. },
  760. combineWithProjectGlj: function (ration_gljs,needRatio=true,ration,p_gljMap) {
  761. let projectGLJData = projectObj.project.projectGLJ.datas;
  762. let projectGljs = projectGLJData.gljList;
  763. let mixRatioMap = projectGLJData.mixRatioMap;
  764. if (ration_gljs && ration_gljs.length > 0 && projectGljs && projectGljs.length > 0) {
  765. let pgljMap = p_gljMap?p_gljMap:_.indexBy(projectGljs, 'id');
  766. for (let i = 0; i < ration_gljs.length; i++) {
  767. let glj = pgljMap[ration_gljs[i].projectGLJID];
  768. if (glj) {
  769. if(projectObj.project.projectGLJ.isEstimateType(ration_gljs[i].type )){
  770. ration_gljs[i].isEstimate = glj.is_evaluate;
  771. }
  772. ration_gljs[i].shortName =projectObj.project.projectGLJ.getShortNameByID(ration_gljs[i].type);
  773. ration_gljs[i].isAdd = glj.unit_price.is_add;
  774. ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
  775. let connect_index = this.getIndex(glj, gljKeyArray);
  776. if (needRatio==true) {
  777. delete ration_gljs[i].subList;//先清空,再赋值
  778. if(mixRatioMap.hasOwnProperty(connect_index)){
  779. let mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs,glj);
  780. ration_gljs[i].subList = mixRatios;
  781. }
  782. }
  783. if(ration) gljOprObj.getTotalQuantity(ration_gljs[i], ration);
  784. // if(ration) ration_gljs[i].tenderQuantity = gljUtil.getRationGLJTenderQuantity(ration_gljs[i], ration,getDecimal("glj.quantity"),scMathUtil,glj);
  785. }else {
  786. console.log("没有找到工料机:"+ration_gljs[i].name)
  787. }
  788. }
  789. }
  790. return ration_gljs;
  791. },
  792. setGLJPrice:function (data,glj,isRadio = false) {//isRadio 标记是否算组成物的价格
  793. let proGLJ = projectObj.project.projectGLJ;
  794. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  795. let decimalObj = projectObj.project.projectInfo.property.decimal;
  796. let labourCoeDatas = projectObj.project.labourCoe.datas;
  797. glj = glj?glj:_.find(proGLJ.datas.gljList, {'id': data.projectGLJID});
  798. if(glj){
  799. let tenderCoe = projectObj.project.projectGLJ.getTenderPriceCoe(glj);
  800. let result = gljUtil.getGLJPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe);
  801. data.marketPrice = result.marketPrice;
  802. data.tenderPrice = result.tenderPrice;
  803. data.basePrice = result.basePrice;
  804. data.adjustPrice = result.adjustPrice;
  805. data.marketUnitFee = data.marketPrice;//更新树节点市场单价列的值
  806. data.taxRate = glj.unit_price.taxRate;//税率
  807. }
  808. return data;
  809. },
  810. getBasePrice:function (treeNode) {//造价书中的工料机修改的节点要用到
  811. let proGLJ = projectObj.project.projectGLJ;
  812. let glj =_.find(proGLJ.datas.gljList, {'id': treeNode.data.projectGLJID});
  813. if(this.calcPriceDiff(glj)==true){
  814. return proGLJ.getBasePrice(glj);
  815. }else {
  816. return scMathUtil.roundForObj(treeNode.data.marketUnitFee,getDecimal("glj.unitPrice"));
  817. }
  818. },
  819. calcPriceDiff:function (glj) {
  820. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  821. return gljUtil.calcPriceDiff(glj,calcOptions);
  822. },
  823. getIndex(obj, pops){
  824. return gljUtil.getIndex(obj,pops);
  825. /* let t_index = '';
  826. let k_arr = [];
  827. for (let p of pops) {
  828. let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
  829. k_arr.push(tmpK);
  830. }
  831. t_index = k_arr.join("|-|");
  832. return t_index;*/
  833. },
  834. getConditionByKey(conKey){//将连接字符串转换成对象
  835. let valueArray = conKey.split("|-|");
  836. let obj ={};
  837. for(let i = 0;i<valueArray.length;i++){
  838. if(valueArray[i]!='null'){
  839. if(gljKeyArray[i]=='type'){
  840. valueArray[i] = parseInt(valueArray[i]);
  841. }
  842. obj[gljKeyArray[i]]=valueArray[i];
  843. }
  844. }
  845. return obj;
  846. },
  847. getMixRationShowDatas: function (mixRatioList, projectGljs,parentGLJ) {
  848. var temRationGLJs = [];
  849. for (var i = 0; i < mixRatioList.length; i++) {
  850. let mIndex = gljOprObj.getIndex(mixRatioList[i],gljKeyArray);
  851. let pgljMap = projectObj.project.projectGLJ.datas.gljMap;
  852. let pg = null;
  853. if(pgljMap){
  854. pg = pgljMap[mIndex];
  855. }
  856. if(!pg){//兼容旧数据,以防万一
  857. pg = _.find(projectGljs, function (item) {
  858. return gljOprObj.getIndex(item,gljKeyArray) == mIndex
  859. });//改关联关系
  860. }
  861. if(pg){
  862. let tem = {
  863. mixRatioId:mixRatioList[i].id,
  864. projectGLJID: pg.id,
  865. code: pg.code,
  866. name: pg.name,
  867. specs: pg.specs,
  868. unit: pg.unit,
  869. type:mixRatioList[i].type,
  870. shortName: projectObj.project.projectGLJ.getShortNameByID(mixRatioList[i].type),
  871. consumption:mixRatioList[i].consumption,
  872. rationItemQuantity: mixRatioList[i].consumption,
  873. // quantity:mixRatioList[i].consumption,
  874. /* basePrice: pg.unit_price.base_price,
  875. marketPrice: pg.unit_price.market_price,
  876. adjustPrice: pg.adjust_price,*/
  877. //isEstimate: pg.is_evaluate,
  878. isMixRatio: true,
  879. isAdd: pg.unit_price.is_add,
  880. GLJID: pg.glj_id,
  881. parentGLJ:parentGLJ
  882. };
  883. if(projectObj.project.projectGLJ.isEstimateType(pg.type)){
  884. tem.isEstimate = pg.is_evaluate;
  885. }
  886. this.setGLJPrice(tem,pg);
  887. temRationGLJs.push(tem);
  888. }else {
  889. console.log("没有找到工料机:"+mIndex)
  890. }
  891. }
  892. temRationGLJs = gljUtil.sortRationGLJ(temRationGLJs);
  893. return temRationGLJs;
  894. },
  895. showQuantityDetailData: function (node) {
  896. node = node ? node : projectObj.project.mainTree.selected;
  897. var quantity_detail = projectObj.project.quantity_detail;
  898. let field = node.sourceType == ModuleNames.ration?'rationID':'billID';
  899. let details = quantity_detail.getListByID(node.data.ID,field);
  900. sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
  901. this.detailData = details;
  902. if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
  903. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
  904. }
  905. },
  906. clearSheetData: function () {
  907. if($('#linkGLJ').hasClass('active')){
  908. sheetCommonObj.showData(this.sheet, this.setting, []);
  909. }
  910. if($('#linkAZZJF').hasClass('active')){
  911. installationFeeObj.rationInstallSheet.setRowCount(0);//清除combobox cell
  912. sheetCommonObj.showData(installationFeeObj.rationInstallSheet, installationFeeObj.rationInstallSetting, []);
  913. }
  914. // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
  915. this.sheetData = [];
  916. installationFeeObj.rationInstallData = [];
  917. //this.detailData=[];
  918. },
  919. updateRationGLJ: function (args) {
  920. var me = this;
  921. var updateField = me.setting.header[args.col].dataCode;
  922. var recode = me.sheetData[args.row];
  923. var newval;
  924. if(!me.rationGLJEditCheck(args)){
  925. recode? me.sheet.getCell(args.row, args.col).value(recode[updateField]): me.sheet.getCell(args.row, args.col).value(null);
  926. return;
  927. }
  928. if(args.editingText){
  929. args.editingText = args.editingText+"";
  930. args.editingText = args.editingText.replace(/[\r\n]/g, "");//去掉回车换行等字符;
  931. me.sheet.getCell(args.row, args.col).value(args.editingText);
  932. }
  933. if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
  934. if (args.editingText == null) {
  935. updateField == 'marketPrice' ? newval = 0 : newval = "";
  936. } else {
  937. var decimal = updateField == 'customQuantity'||updateField == 'rationItemQuantity' ? getDecimal("glj.quantity") : 6;//对于市场价和定额价,这里只是中间的小数位数,后面更新前会根据有没有组成物再取值
  938. newval = number_util.checkNumberValue(args.editingText, decimal);
  939. if (newval == null) {
  940. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  941. return;
  942. }
  943. }
  944. } else {
  945. if (updateField == 'name' || updateField == 'unit') {
  946. if (args.editingText === null) {
  947. alert(me.setting.header[args.col].headerName + '不能为空!');
  948. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  949. return;
  950. }
  951. }
  952. if(updateField == 'code'){
  953. if (!gljUtil.isDef(args.editingText)||args.editingText==''||args.editingText.indexOf('|-|') === -1||this.isRationGLJExit(args.editingText)) {//说明是选中自已,或者是已存在的工料机
  954. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  955. return;
  956. }
  957. }
  958. newval = args.editingText == null ? "" : args.editingText;
  959. }
  960. if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
  961. return
  962. }
  963. if (updateField == 'marketPrice' || updateField == 'basePrice') {
  964. projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
  965. }else if(updateField == 'code'){//替换单价文件中已经有的工料机
  966. projectObj.project.ration_glj.updateRationGLJByChangeCode(recode, updateField, newval);
  967. }else if(me.setting.navigationRightCol.indexOf(updateField) != -1){//对于名称、规格、单位先跳到下一列,保存至缓存
  968. me.setToEditCache(recode,updateField, newval,args);
  969. }else if(updateField == 'rationItemQuantity'){//修改组成物的消耗量
  970. me.updateRatio(recode,{consumption:newval})
  971. console.log(recode);
  972. } else {
  973. projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
  974. }
  975. },
  976. setToEditCache:function(recode,updateField,value,args){
  977. let me = this;
  978. if(me.rationGljEditObj == null){
  979. me.rationGljEditObj = {
  980. recode:recode,
  981. doc:{},
  982. row:args.row
  983. }
  984. me.rationGljEditObj.doc[updateField] = value;
  985. }else {
  986. if(me.rationGljEditObj.recode.ID == recode.ID){//确保编辑的是同一条数据
  987. me.rationGljEditObj.doc[updateField] = value;
  988. }
  989. }
  990. },
  991. isRationGLJExit:function (connectKey) {
  992. for(let rg of gljOprObj.sheetData){
  993. if(rg.isMixRatio == true){
  994. continue;
  995. }
  996. if(gljOprObj.getIndex(rg, gljKeyArray) == connectKey){//存在一样的工料机
  997. return true;
  998. }
  999. }
  1000. return false;
  1001. },
  1002. getParentPrice:function(subList,value,radio,type = 'modify'){
  1003. let marketPrice = 0,basePrice=0;
  1004. let decimal = getDecimal('glj.unitPrice');
  1005. for(let s of subList){
  1006. let c = parseFloat(s.consumption);
  1007. if(s.mixRatioId == radio.mixRatioId) c = value;
  1008. if(type == 'delete' && s.mixRatioId == radio.mixRatioId) continue;
  1009. let m = scMathUtil.roundForObj(s.marketPrice * c,decimal);
  1010. let b = scMathUtil.roundForObj(s.basePrice * c,decimal);
  1011. marketPrice += m;
  1012. basePrice +=b;
  1013. }
  1014. return [scMathUtil.roundForObj(marketPrice,decimal),scMathUtil.roundForObj(basePrice,decimal)]
  1015. },
  1016. deleteRatio:async function(row){
  1017. let ratio = this.sheetData[row];
  1018. let pgljData = projectObj.project.projectGLJ.datas;
  1019. for(let rg of this.sheetData){
  1020. if(rg.projectGLJID == ratio.parentGLJ.id) {
  1021. subList = rg.subList;
  1022. break;
  1023. }
  1024. }
  1025. let [marketPrice,basePrice] = this.getParentPrice(subList,0,ratio,"delete");
  1026. try {
  1027. $.bootstrapLoading.start()
  1028. projectData = await ajaxPost('/glj/updateRatio', {id: ratio.mixRatioId,type:'delete',pid:ratio.parentGLJ.unit_price.id,market_price: marketPrice,base_price: basePrice});
  1029. //更新缓存
  1030. let pk = gljUtil.getIndex(ratio.parentGLJ);
  1031. if(pgljData.mixRatioMap && pgljData.mixRatioMap[pk]){
  1032. _.remove(pgljData.mixRatioMap[pk],{"id":ratio.mixRatioId});
  1033. }
  1034. for(let r of ratio.parentGLJ.ratio_data){
  1035. _.remove(ratio.parentGLJ.ratio_data,{"id":ratio.mixRatioId});
  1036. }
  1037. ratio.parentGLJ.unit_price.market_price = marketPrice;
  1038. ratio.parentGLJ.unit_price.base_price = basePrice;
  1039. //重新计算消耗量
  1040. projectObj.project.projectGLJ.calcQuantity();
  1041. let priceData = {};
  1042. priceData =this.setGLJPrice(priceData,ratio.parentGLJ);
  1043. projectGljObject.updateParentNodes(ratio.parentGLJ.id,priceData.marketPrice);
  1044. projectGljObject.onUnitFileChange(ratio);
  1045. } catch (error) {
  1046. console.log(error)
  1047. }finally{
  1048. $.bootstrapLoading.end()
  1049. }
  1050. },
  1051. updateRatio:async function(ratio,doc){
  1052. let pgljData = projectObj.project.projectGLJ.datas;
  1053. let subList = [];
  1054. for(let rg of this.sheetData){
  1055. if(rg.projectGLJID == ratio.parentGLJ.id) {
  1056. subList = rg.subList;
  1057. break;
  1058. }
  1059. }
  1060. let [marketPrice,basePrice] = this.getParentPrice(subList,doc.consumption,ratio);
  1061. try {
  1062. $.bootstrapLoading.start()
  1063. projectData = await ajaxPost('/glj/updateRatio', {id: ratio.mixRatioId, doc:doc,pid:ratio.parentGLJ.unit_price.id,market_price: marketPrice,base_price: basePrice});
  1064. //更新缓存
  1065. let pk = gljUtil.getIndex(ratio.parentGLJ);
  1066. if(pgljData.mixRatioMap && pgljData.mixRatioMap[pk]){
  1067. for(let m of pgljData.mixRatioMap[pk]){
  1068. if(m.id == ratio.mixRatioId) gljUtil.setProperty(m,doc);
  1069. }
  1070. }
  1071. for(let r of ratio.parentGLJ.ratio_data){
  1072. if(r.id == ratio.mixRatioId) gljUtil.setProperty(r,doc);
  1073. }
  1074. ratio.parentGLJ.unit_price.market_price = marketPrice;
  1075. ratio.parentGLJ.unit_price.base_price = basePrice;
  1076. //重新计算消耗量
  1077. projectObj.project.projectGLJ.calcQuantity();
  1078. let priceData = {};
  1079. priceData =this.setGLJPrice(priceData,ratio.parentGLJ);
  1080. projectGljObject.updateParentNodes(ratio.parentGLJ.id,priceData.marketPrice);
  1081. projectGljObject.onUnitFileChange(ratio);
  1082. } catch (error) {
  1083. console.log(error)
  1084. }finally{
  1085. $.bootstrapLoading.end()
  1086. }
  1087. },
  1088. updateRationTypeGLJ: function (value, node, fieldName,editingText) {
  1089. let newval;
  1090. let updatePrice = false;
  1091. if (fieldName == "marketUnitFee"|| fieldName == "feesIndex.common.unitFee") {
  1092. updatePrice = true;
  1093. if (value == null) {
  1094. newval = 0;
  1095. } else {
  1096. var decimal = getDecimal("glj.unitPrice");
  1097. newval = number_util.checkNumberValue(value, decimal);
  1098. }
  1099. } else {
  1100. if (value != null) {
  1101. projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value,editingText);
  1102. return;
  1103. }
  1104. }
  1105. if (newval && updatePrice == true) {
  1106. projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
  1107. return
  1108. }
  1109. projectObj.mainController.refreshTreeNode([node]);
  1110. },
  1111. updateIsEstimate:function (args, newval) {
  1112. var me = gljOprObj;
  1113. if(me.setting.header[args.col].dataCode=="isEstimate"){
  1114. var pspread= new ProjectGLJSpread();
  1115. var recode = me.sheetData[args.row];
  1116. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  1117. let glj = _.find(projectGljs, {'id': recode.projectGLJID});
  1118. if(glj){
  1119. configMaterialObj.updateConfigMaterial("is_evaluate",newval,glj);
  1120. }
  1121. }
  1122. },
  1123. showLibGLJSheetData: function () {
  1124. this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
  1125. sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
  1126. this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
  1127. },
  1128. // 根据人材机类型,设置人材机类型显示名称
  1129. setTypeName: function (distTypeData, data) {
  1130. data.forEach(item => {
  1131. let typeData = distTypeData.find(typeItem => typeItem.value === item.gljType);
  1132. if (typeData) {
  1133. item.typeName = typeData.text;
  1134. }
  1135. });
  1136. },
  1137. /*
  1138. * 获取分页查询所需要的条件数据
  1139. * @param {Boolean}init 是否是初始化
  1140. * {Boolean}reset 是否重置数据 (点击分类树等)
  1141. * {Boolean}location 是否定位(替换初始化)
  1142. * {Number}index 下一页数据开始索引,根据这个值获取上次分页最大的编码数据(不用skip进行分页,skip跳过大量数据会降低性能,用$gt: data.code)
  1143. * {Boolean}initLibs 是否初始化库列表
  1144. * {String||Null}gljLibID 选中的人材机库
  1145. * @return {Object}
  1146. * */
  1147. getPagingCondition: function (init, reset, location, index, initLibs, gljLibID) {
  1148. // 上一次分页的最末人材机编码,index为0时,code为空
  1149. const code = gljOprObj.AllRecode && gljOprObj.AllRecode[index - 1] ? gljOprObj.AllRecode[index - 1].code : '';
  1150. // 初始化情况下的条件
  1151. let condition = {
  1152. code,
  1153. // 是否重置数据
  1154. reset,
  1155. // 是否定位
  1156. location,
  1157. index,
  1158. // 限制条数
  1159. limit: 50,
  1160. // 初始化
  1161. init: init,
  1162. initLibs,
  1163. // 所在部分(标准、补充)
  1164. type: this.pagingType.stdGLJ,
  1165. // 替换数据,替换操作下有数据:编码、名称、规格、单位、类型
  1166. replace: null,
  1167. // 添加组成物的查询扩展
  1168. queryExtend: {},
  1169. // 所在分类节点
  1170. classList: [],
  1171. // 搜索文本
  1172. search: ''
  1173. };
  1174. const cptLibReg = new RegExp(commonConstants.COMPLEMENTARY_LIB);
  1175. // 触发入口(添加、替换、批量替换)
  1176. const actionType = $('#actionType').val();
  1177. const replaceActions = ['replace', 'm_replace'];
  1178. // 替换相关
  1179. if (replaceActions.includes(actionType)) {
  1180. // 定额人材机界面选中的人材机
  1181. const selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1182. condition.replace = {
  1183. code: selected.code,
  1184. name: selected.name,
  1185. specs: selected.specs,
  1186. unit: selected.unit,
  1187. gljType: selected.type
  1188. };
  1189. } else if (actionType === 'addMix'|| actionType === 'unitPriceAddMix') {
  1190. condition.queryExtend = projectGljObject.getQueryExtForMixRatio();
  1191. }
  1192. if (gljLibID) {
  1193. condition.gljLibID = gljLibID;
  1194. } else {
  1195. if (condition.replace) {
  1196. const selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1197. const cptLibID = selected.fromUser && selected.fromUser !== userID ? `${commonConstants.COMPLEMENTARY_LIB}*${selected.fromUser}` : commonConstants.COMPLEMENTARY_LIB;
  1198. condition.gljLibID = selected.from === 'cpt' || !selected.repositoryId ? cptLibID : selected.repositoryId;
  1199. } else {
  1200. condition.gljLibID = initLibs ? null : $('#glj-lib-select').val();
  1201. }
  1202. }
  1203. if (cptLibReg.test(condition.gljLibID)) {
  1204. condition.type = this.pagingType.complementaryGLJs;
  1205. }
  1206. if (init) {
  1207. return condition;
  1208. }
  1209. condition.init = false;
  1210. // 选中的分类
  1211. if (this.treeObj) {
  1212. let selNode = this.treeObj.getNodeByParam('ID', this.gljCurTypeId);
  1213. // 不为最顶层节点时,才赋值给withinClass
  1214. if (selNode && selNode.ParentID !== -1) {
  1215. const classList = this.parentNodeIds['_pNodeId_' + this.gljCurTypeId];
  1216. condition.classList = classList ? classList : [this.gljCurTypeId];
  1217. }
  1218. }
  1219. // 搜索文本
  1220. let searchStr = $('#gljSearchKeyword').val().trim();
  1221. if(searchStr){
  1222. condition.search = searchStr;
  1223. }
  1224. return condition;
  1225. },
  1226. filterLibGLJSheetData: function () {
  1227. let me = this;
  1228. const selectLibID = $('#glj-lib-select').val();
  1229. me.gljLibSheetData = selectLibID === commonConstants.COMPLEMENTARY_LIB
  1230. ? me.complementaryGLJs
  1231. : me.stdGLJ;
  1232. if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
  1233. me.filterLibGLJByType();
  1234. }else if($('#actionType').val() == 'addMix' || $('#actionType').val() == 'unitPriceAddMix'){
  1235. projectGljObject.filterLibGLJForMixRatio();
  1236. }
  1237. //文本筛选
  1238. let searchStr = $('#gljSearchKeyword').val();
  1239. if(searchStr && searchStr.trim() != ''){
  1240. let reg = new RegExp(searchStr);
  1241. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  1242. return reg.test(data.code) || reg.test(data.name);
  1243. });
  1244. }
  1245. if (me.gljCurTypeId == undefined) {
  1246. return;
  1247. }
  1248. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  1249. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  1250. return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
  1251. });
  1252. } else {
  1253. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
  1254. }
  1255. },
  1256. setGLJSelection: function (args, newVal) {
  1257. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert'|| $('#actionType').val() == 'addMix'|| $('#actionType').val() == 'unitPriceAddMix') {
  1258. this.addGLJsSelection(args, newVal);
  1259. } else {
  1260. this.replaceGLJSelection(args, newVal);
  1261. }
  1262. },
  1263. addGLJsSelection: function (args, newVal) {
  1264. const curGLJ = this.AllRecode[args.row];
  1265. const con_key = this.getIndex(curGLJ, gljLibKeyArray);
  1266. if (newVal == 1) {
  1267. this.GLJSelection.push(con_key);
  1268. } else if (newVal == 0) {
  1269. _.pull(this.GLJSelection, con_key);
  1270. }
  1271. },
  1272. replaceGLJSelection: function (args, newVal) {
  1273. var me = this;
  1274. var oldSelection = this.GLJSelection[0];
  1275. if (newVal == 0) {
  1276. args.sheet.getCell(args.row, args.col).value(1);
  1277. return;
  1278. }
  1279. const curGLJ = this.AllRecode[args.row];
  1280. const connectKey = this.getIndex(curGLJ, gljLibKeyArray);
  1281. this.GLJSelection = [connectKey];
  1282. var oindex = _.findIndex(this.AllRecode, function (item) {
  1283. var i_key = me.getIndex(item, gljLibKeyArray);
  1284. return oldSelection == i_key;
  1285. });
  1286. if (oindex != -1) {
  1287. args.sheet.getCell(oindex, args.col).value(0);
  1288. } else {
  1289. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  1290. var i_key = me.getIndex(item, gljLibKeyArray);
  1291. return oldSelection == i_key;
  1292. });
  1293. }
  1294. },
  1295. filterLibGLJByType: function () {
  1296. var me = this;
  1297. var selected = me.sheetData[gljContextMenu.selectedRow];
  1298. //当前人材机类型是“混凝土、砂浆、配合比、商品混凝土、商品砂浆”时,筛选的可替换的人材机类型应是“混凝土、或砂浆、或配合比、或商品混凝土、或商品砂浆”。
  1299. let materialTypes = [202, 203, 204, 205, 206];//除了普通材料
  1300. let filterTypes = materialTypes.includes(selected.type) ? materialTypes : [selected.type];
  1301. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  1302. return filterTypes.includes(data.gljType);
  1303. });
  1304. },
  1305. getComboData: function (gljDistType) {
  1306. let me = this;
  1307. let distType;
  1308. let distTypeTree = {
  1309. prefix: 'gljType',
  1310. distTypes: {},
  1311. comboDatas: [],
  1312. distTypesArr: []
  1313. };
  1314. gljDistType.forEach(function (typeData) {
  1315. let typeObj = {
  1316. data: typeData,
  1317. children: [],
  1318. parent: null
  1319. }
  1320. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  1321. distTypeTree.distTypesArr.push(typeObj);
  1322. });
  1323. gljDistType.forEach(function (typeData) {
  1324. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  1325. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  1326. if (parent) {
  1327. distType.parent = parent;
  1328. parent.children.push(distType);
  1329. }
  1330. });
  1331. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  1332. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  1333. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  1334. }
  1335. });
  1336. return distTypeTree;
  1337. },
  1338. doInsertGLJ: function () {
  1339. var me = this;
  1340. var selected = projectObj.project.mainTree.selected;
  1341. var project = projectObj.project;
  1342. if (me.GLJSelection.length <= 0) {
  1343. return;
  1344. }
  1345. $.bootstrapLoading.start();
  1346. project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (parentNodeID,nextNodeID,data) {
  1347. let newNode=null;
  1348. for (let r_glj of data) {
  1349. r_glj.quantity = r_glj.quantity + "";
  1350. project.Ration.datas.push(r_glj);
  1351. }//要先更新树节点工程量,加载项目工料机并计算消耗量才有值
  1352. project.projectGLJ.loadData(function () {
  1353. for(let r_glj of data){
  1354. r_glj = me.setGLJPrice(r_glj);//设置工料机价格
  1355. newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
  1356. newNode.source = r_glj;
  1357. newNode.sourceType = project.Ration.getSourceType();
  1358. newNode.data = r_glj;
  1359. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  1360. }
  1361. project.calcProgram.calcLeafAndSave(newNode.parent);//计算父级清单的所有子节点
  1362. projectObj.mainController.refreshTreeNode([newNode]);
  1363. if(me.hasComposition(newNode.data,true)){
  1364. me.showMixRatio(newNode);
  1365. }else {
  1366. me.showRationGLJSheetData();
  1367. }
  1368. $.bootstrapLoading.end();
  1369. });
  1370. })
  1371. },
  1372. doAddGLJ: function () {
  1373. var selected = projectObj.project.mainTree.selected;
  1374. var project = projectObj.project;
  1375. gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
  1376. var rg = _.find(gljOprObj.sheetData, function (item) {
  1377. if(item.isMixRatio == true){
  1378. return false;
  1379. }
  1380. var i_key = gljOprObj.getIndex(item, gljKeyArray);
  1381. return n == i_key
  1382. });
  1383. return rg ? false : true;
  1384. })
  1385. if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
  1386. project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
  1387. if (result) {
  1388. selected.data.adjustState = result.adjustState;
  1389. //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
  1390. project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
  1391. gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
  1392. project.projectGLJ.loadNewProjectGLJToCaches(result.projectGLJList,true);
  1393. project.ration_glj.addToMainTree(result.showData);
  1394. gljOprObj.showRationGLJSheetData();
  1395. project.calcProgram.calcAndSave(selected);
  1396. projectObj.mainController.refreshTreeNode([selected]);
  1397. $.bootstrapLoading.end();
  1398. }
  1399. });//doc.rationID=selected.data.ID;
  1400. }
  1401. },
  1402. doReplaceGLJ: function () {
  1403. let me = this;
  1404. let oldData = me.sheetData[gljContextMenu.selectedRow];
  1405. let project = projectObj.project;
  1406. let selectCode = gljOprObj.GLJSelection[0];
  1407. let selected = projectObj.project.mainTree.selected;
  1408. project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
  1409. if (result) {
  1410. //result.adjustState;
  1411. let glj_list = projectObj.project.ration_glj.datas;
  1412. let data = result.data;
  1413. let index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
  1414. let list_index = _.findIndex(glj_list, {'ID': data.ID});
  1415. let nodes = [selected];
  1416. gljOprObj.sheetData[index] = data;
  1417. glj_list[list_index] = data;
  1418. project.projectGLJ.loadNewProjectGLJToCaches([result.projectGLJ],true);
  1419. gljOprObj.refreshView();
  1420. let node = project.ration_glj.updateGLJNodeAfterReplace(data);
  1421. if(node) nodes.push(node);
  1422. /*if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  1423. var node = project.ration_glj.findGLJNodeByID(data.ID);
  1424. if (node) {
  1425. project.ration_glj.transferToNodeData(data);
  1426. node.source = data;
  1427. node.data = data;
  1428. }
  1429. node ? nodes.push(node) : "";
  1430. }*/
  1431. //project.ration_glj.addToMainTree(data);
  1432. selected.data.adjustState = result.adjustState;
  1433. selected.data.name = result.name;
  1434. projectObj.mainController.refreshTreeNode(nodes);
  1435. project.calcProgram.calcAndSave(selected, async function () {
  1436. await OVER_HEIGHT.reCalcOverHeightFee();
  1437. await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes([selected]);
  1438. });
  1439. $.bootstrapLoading.end();
  1440. }
  1441. })
  1442. },
  1443. doMReplaceGLJ: function () {
  1444. let me = this;
  1445. let oldData = me.sheetData[gljContextMenu.selectedRow];
  1446. let project = projectObj.project;
  1447. let selectCode = me.GLJSelection[0];
  1448. project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result,updateMap) {
  1449. if(result == null){
  1450. return;
  1451. }
  1452. let data = result.data;
  1453. let stateList = result.stateList;
  1454. //let n_index = me.getIndex(data.query, gljKeyArray);
  1455. let nodes = [];
  1456. _.forEach(project.ration_glj.datas, function (t) {
  1457. // let t_index = me.getIndex(t, gljKeyArray);
  1458. if (updateMap[t.ID]) {
  1459. me.updateProperty(t, data.doc);
  1460. me.updateProperty(t, updateMap[t.ID]);
  1461. if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
  1462. project.ration_glj.transferToNodeData(t);
  1463. var node = project.ration_glj.findGLJNodeByID(t.ID);
  1464. node ? nodes.push(node):'';
  1465. }
  1466. }
  1467. })
  1468. project.projectGLJ.loadNewProjectGLJToCaches([result.projectGLJ],true);
  1469. me.refreshView();
  1470. var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
  1471. project.calcProgram.calcNodesAndSave(rationNodes, async function () {
  1472. await OVER_HEIGHT.reCalcOverHeightFee();
  1473. await await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(rationNodes);
  1474. });
  1475. $.bootstrapLoading.end();
  1476. })
  1477. },
  1478. updateProperty: function (obj, doc) {
  1479. _.forEach(doc, function (n, key) {
  1480. obj[key] = n;
  1481. });
  1482. },
  1483. refreshStateAfterMreplace: function (stateList, gljNodes) {
  1484. let nodes = [];
  1485. let rationNodes = [];
  1486. _.forEach(stateList, function (s) {
  1487. let node = _.find(projectObj.project.mainTree.items, function (n) {
  1488. return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
  1489. })
  1490. if (node) {
  1491. node.data.adjustState = s.adjustState;
  1492. node.data.name = s.name;
  1493. nodes.push(node);
  1494. rationNodes.push(node);
  1495. }
  1496. });
  1497. gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
  1498. projectObj.mainController.refreshTreeNode(nodes);
  1499. return rationNodes;
  1500. },
  1501. refreshView: function () {
  1502. let node = projectObj.project.mainTree.selected;
  1503. this.showDataIfRationSelect(node,"111111");
  1504. },
  1505. refreshTreeNode: function (obj) {
  1506. if (!obj) {
  1507. return;
  1508. }
  1509. let objectArray = [];
  1510. let nodes = [];
  1511. if (obj instanceof Array) {
  1512. objectArray.concat(obj);
  1513. } else {
  1514. objectArray.push(obj);
  1515. }
  1516. for (let o of objectArray) {
  1517. let node = this.updateDataNodeProperty(o.ID,o.data);
  1518. if (node) {
  1519. nodes.push(node);
  1520. }
  1521. }
  1522. projectObj.mainController.refreshTreeNode(nodes);
  1523. return nodes;
  1524. },
  1525. updateDataNodeProperty:function(nodeID,data){
  1526. let node = projectObj.project.mainTree.findNode(nodeID);
  1527. if (node) {
  1528. for (let k in data) {
  1529. node.data[k] = data[k];
  1530. }
  1531. }
  1532. return node;
  1533. },
  1534. getTreeNodeCellType: function (data,comboboxOptions) {
  1535. let ns = GC.Spread.Sheets;
  1536. let rectW = 10;
  1537. let rectH = 10;
  1538. let margin = 3;
  1539. function TreeNodeCellType() {
  1540. this.ctx = null;
  1541. }
  1542. TreeNodeCellType.prototype = comboboxOptions?sheetCommonObj.getDynamicCombo():new ns.CellTypes.Text();
  1543. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  1544. this.ctx= ctx;
  1545. if (style.backColor) {//先画背景色
  1546. ctx.save();
  1547. ctx.fillStyle = style.backColor;
  1548. ctx.fillRect(x, y, w, h);
  1549. ctx.restore();
  1550. } else {
  1551. ctx.clearRect(x, y, w, h);
  1552. }
  1553. if (value != null) {
  1554. let offset = margin + rectW + 6;
  1555. let recode = data[options.row];
  1556. if (recode && recode.hasOwnProperty('subList')) {
  1557. sheetCommonObj.drowRect(ctx, x, y, w, h,rectW,rectH,margin);
  1558. let collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
  1559. sheetCommonObj.drowSymbol(ctx, x, y, w, h,rectW,rectH,margin, collapsed);
  1560. } else if (recode && recode.isMixRatio) {
  1561. let hasNext = data[options.row + 1] && data[options.row + 1].isMixRatio;
  1562. offset = sheetCommonObj.drowSubItem(ctx, x, y, w, h, offset,hasNext);
  1563. offset += 1;
  1564. }
  1565. arguments[2] = x + offset;
  1566. arguments[4] = w - offset;
  1567. //x = x + offset;
  1568. //w = w - offset;
  1569. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1570. }
  1571. };
  1572. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1573. if(x < cellRect.x+cellRect.width -15){//这里要判断点击的位置来决定return的内容,不能直接用combobox的方法
  1574. return {
  1575. x: x,
  1576. y: y,
  1577. row: context.row,
  1578. col: context.col,
  1579. cellStyle: cellStyle,
  1580. cellRect: cellRect,
  1581. sheetArea: context.sheetArea
  1582. };
  1583. }else {
  1584. return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(this, arguments);
  1585. }
  1586. };
  1587. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1588. let recode = data[hitinfo.row];
  1589. if(hitinfo.x < hitinfo.cellRect.x+hitinfo.cellRect.width -15){
  1590. hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,"locked")//通过这个来控制除了点击下拉框的三角形,点击其它地方不充许进入编辑状态,不然不好控制下拉框超出页面后调整滚动条
  1591. }
  1592. if (recode && recode.hasOwnProperty('subList')) {
  1593. let hoffset = hitinfo.cellRect.x + 3;
  1594. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1595. let collapsed = recode.collapsed == undefined ? true : recode.collapsed;
  1596. collapsed = !collapsed
  1597. recode.collapsed = collapsed;
  1598. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1599. hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
  1600. hitinfo.sheet.invalidateLayout();
  1601. hitinfo.sheet.repaint();
  1602. return;
  1603. }
  1604. }
  1605. if(comboboxOptions&&hitinfo.x > hitinfo.cellRect.x+hitinfo.cellRect.width -15){//点击了下拉框按钮,这里要判断下拉框是否会被挡住,从而决定是否自动调整滚动条
  1606. hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,"");
  1607. sheetCommonObj.scrollSheetForOption(hitinfo.sheet,this.ctx,hitinfo.cellRect,hitinfo.row,comboboxOptions);//下拉框超出显示后自动调整滚动条
  1608. GC.Spread.Sheets.CellTypes.ComboBox.prototype.processMouseDown.apply(this, arguments);
  1609. }
  1610. };
  1611. let cellType = new TreeNodeCellType();
  1612. if(comboboxOptions){
  1613. cellType.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  1614. cellType.itemHeight(comboboxOptions.length).items(comboboxOptions);
  1615. }
  1616. return cellType;
  1617. },
  1618. marketPriceReadOnly: function (node) {
  1619. let hasCom = false;
  1620. if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
  1621. hasCom = this.hasComposition(node.data,true);
  1622. }else {
  1623. hasCom = this.hasComposition(node.data);
  1624. }
  1625. return hasCom;//2018-9-14 需求变更暂估工料机也能修改市场价原语句:return hasCom|| node.data.isEstimate == 1
  1626. },
  1627. locateZTree: function(ID) {
  1628. let zTree = $.fn.zTree.getZTreeObj("gljTree");
  1629. let node = null;
  1630. if (ID) node = zTree.getNodesByParam('ID', ID, null)[0];
  1631. if (!node) {
  1632. node = zTree.getNodeByTId('gljTree_1');
  1633. ID = node.ID;
  1634. }
  1635. zTree.selectNode(node);
  1636. gljOprObj.gljCurTypeId = ID;
  1637. //--gljOprObj.filterLibGLJSheetData();
  1638. //--gljOprObj.showLibGLJSheetData();
  1639. },
  1640. isExtraType:function (type) {
  1641. return _.includes(gljUtil.extraType,type)
  1642. },
  1643. setNodeShowTab:function () {
  1644. let node = projectObj.project.mainTree.selected;
  1645. if(node && node.sourceType==ModuleNames.ration){
  1646. gljOprObj.rationTab = gljOprObj.activeTab;
  1647. }else {
  1648. gljOprObj.billsTab = gljOprObj.activeTab;
  1649. }
  1650. },
  1651. //初始化分类树
  1652. //@param {Array}treeData(树数据)
  1653. initClassTree: function (treeData, initSel = false) {
  1654. let me = this;
  1655. if (me.treeObj) {
  1656. me.treeObj.destroy();
  1657. me.parentNodeIds = {};
  1658. }
  1659. zTreeHelper.createTree(treeData, me.gljTreeSetting, "gljTree", me);
  1660. if (initSel) {
  1661. let rootNode = me.treeObj.getNodes()[0];
  1662. if(rootNode && rootNode.isParent && rootNode.isFirstNode){
  1663. me.rootNode = rootNode;
  1664. }
  1665. if(me.rootNode){
  1666. me.treeObj.selectNode(me.rootNode);
  1667. me.gljTreeSetting.callback.onClick(null, 'gljTree', me.rootNode);
  1668. }
  1669. }
  1670. },
  1671. initScopeSpread:function() {
  1672. if (this.scopeSpread) return this.scopeSpread.repaint();
  1673. this.scopeSpread = SheetDataHelper.createNewSpread($('#scopeSpread')[0]);
  1674. sheetCommonObj.spreadDefaultStyle(this.scopeSpread);
  1675. this.scopeTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: false});
  1676. this.scopeTreeController = TREE_SHEET_CONTROLLER.createNew(this.scopeTree, this.scopeSpread.getActiveSheet(), this.scopeSetting);
  1677. this.scopeSheet = this.scopeSpread.getActiveSheet();
  1678. this.scopeSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, this.onScopeChecked);
  1679. },
  1680. showScopeDatas:function () {
  1681. this.initScopeSpread();
  1682. this.scopeDatas =this.getScopeDatas();
  1683. this.scopeTree.loadDatas(this.scopeDatas);
  1684. this.scopeTreeController.showTreeData();
  1685. },
  1686. getScopeDatas:function () {
  1687. let controller = projectObj.mainController, project = projectObj.project;
  1688. let allNodes = [],datas = []
  1689. for(let rootNode of controller.tree.roots){
  1690. allNodes.push(rootNode);
  1691. controller.tree.getAllSubNode(rootNode.source,allNodes);
  1692. }
  1693. for(let n of allNodes){
  1694. let temData = {
  1695. ID:n.data.ID,
  1696. NextSiblingID:n.data.NextSiblingID,
  1697. ParentID:n.data.ParentID,
  1698. unit : n.data.unit,
  1699. code : n.data.code,
  1700. selected:0,
  1701. name : n.data.name,
  1702. quantity:calcTools.uiNodeQty(n)?calcTools.uiNodeQty(n):"",
  1703. };
  1704. if(n.data.feesIndex && n.data.feesIndex.common){
  1705. temData.unitPrice = n.data.feesIndex.common.unitFee;
  1706. temData.totalPrice = n.data.feesIndex.common.totalFee;
  1707. }
  1708. datas.push(temData);
  1709. }
  1710. return datas;
  1711. },
  1712. onScopeChecked:function (e,args) {
  1713. let me = gljOprObj,nodes = [];
  1714. var checkboxValue = args.sheet.getCell(args.row, args.col).value();
  1715. var newval = checkboxValue?0:1;
  1716. let node = me.scopeTree.items[args.row];
  1717. setNodeAndChildreSelected(node,newval,nodes);
  1718. me.scopeTreeController.refreshTreeNode(nodes);
  1719. function setNodeAndChildreSelected(n,val,arr){
  1720. n.data.selected = val;
  1721. nodes.push(n);
  1722. for(let c of n.children){
  1723. setNodeAndChildreSelected(c,val,arr)
  1724. }
  1725. }
  1726. },
  1727. setScopeSelection:function () {
  1728. for(let node of this.scopeTree.items){
  1729. //挑出选中数,过滤父节点
  1730. if(node.data.selected == 1 && node.children.length == 0) this.scopeSelectedIDMap[node.data.ID] = true
  1731. }
  1732. }
  1733. }
  1734. // 人材机选择界面的功能进行了适合分页的重构
  1735. // 重构时,只有添加、替换、批量替换的入口。因此只对这三个入口相关的地方进行重构,其他入口的代码没有变更
  1736. // 若以后放开其他入口,需要将其他入口的相应方法进行重构
  1737. $(function () {
  1738. $('#glj_tree_div').on('hidden.bs.modal', function () {
  1739. // 清空搜索框
  1740. $('#gljSearchKeyword').val('');
  1741. projectGljObject.subList = [];
  1742. });
  1743. $('#glj_tree_div').on('shown.bs.modal', function (e) {
  1744. gljContextMenu.initGLJSelectView();
  1745. /* if (gljOprObj.gljLibSpresd == undefined) {
  1746. gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
  1747. sheetCommonObj.spreadDefaultStyle(gljOprObj.gljLibSpresd);
  1748. gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
  1749. gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
  1750. gljOprObj.gljLibSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, gljOprObj.onSelectionChanged);
  1751. gljOprObj.gljLibSheet.bind(GC.Spread.Sheets.Events.TopRowChanged, _.debounce(gljOprObj.onTopRowChanged, 100));
  1752. gljOprObj.gljLibSheet.setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  1753. gljOprObj.gljLibSheet.options.isProtected = true;
  1754. gljOprObj.gljLibSheet.name('glj_lib');
  1755. sheetCommonObj.setSheetBySetting(gljOprObj.gljLibSheet, gljOprObj.gljLibSheetSetting);
  1756. }
  1757. let gljClass = 0,
  1758. selected,
  1759. connect_key;
  1760. const actionType = $('#actionType').val();
  1761. const addActions = ['add', 'insert', 'addMix','unitPriceAddMix'];
  1762. const replaceActions = ['m_replace', 'replace'];
  1763. if (addActions.includes(actionType)) {//插入,添加,添加组成物(项目人材机页面)
  1764. gljOprObj.GLJSelection = [];
  1765. } else if(replaceActions.includes(actionType)){//替换、批量替换
  1766. selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1767. connect_key = gljOprObj.getIndex(selected, gljKeyArray);
  1768. gljOprObj.GLJSelection = [connect_key];
  1769. // 找到定位的分类树
  1770. const locatedItem = gljOprObj.AllRecode.find(item => gljOprObj.getIndex(item, gljLibKeyArray) === connect_key);
  1771. if (locatedItem) {
  1772. gljClass = locatedItem.gljClass;
  1773. locatedItem.select = 1;
  1774. }
  1775. }
  1776. //替换,焦点定位至当前选中人材机
  1777. if (replaceActions.includes(actionType)) {
  1778. gljOprObj.locateZTree(gljClass);
  1779. sheetCommonObj.appendData(gljOprObj.gljLibSheet, 0, 0, gljOprObj.gljLibSheetSetting, gljOprObj.AllRecode);
  1780. const index = gljOprObj.AllRecode.findIndex(item => gljOprObj.getIndex(item, gljLibKeyArray) === connect_key);
  1781. gljOprObj.gljLibSheet.showRow(index, GC.Spread.Sheets.VerticalPosition.center);
  1782. gljOprObj.gljLibSheet.setActiveCell(index, 0);
  1783. gljOprObj.initSelection({row: index});
  1784. gljOprObj.gljLibSpresd.focus(true);
  1785. } else if (actionType === 'add' || actionType === 'addMix'|| actionType === 'unitPriceAddMix') {
  1786. debugger;
  1787. gljOprObj.locateZTree(null);
  1788. sheetCommonObj.appendData(gljOprObj.gljLibSheet, 0, 0, gljOprObj.gljLibSheetSetting, gljOprObj.AllRecode);
  1789. gljOprObj.gljLibSheet.showRow(0, GC.Spread.Sheets.VerticalPosition.top);
  1790. gljOprObj.gljLibSheet.setActiveCell(0, 0);
  1791. gljOprObj.initSelection({row: 0});
  1792. } else {
  1793. gljOprObj.showLibGLJSheetData();
  1794. } */
  1795. });
  1796. $('#mreplace_next_div').on('shown.bs.modal', function (e) {
  1797. gljOprObj.scopeSelectedIDMap = {};
  1798. gljOprObj.showScopeDatas();
  1799. });
  1800. // 人材机选择界面标准、补充单选
  1801. $('.glj-radio').change(function () {
  1802. const val = $("input[name='glj']:checked").val();
  1803. if (val === 'stdGLJ') {
  1804. gljOprObj.initClassTree('std', gljOprObj.treeData.std, true);
  1805. } else {
  1806. gljOprObj.initClassTree('comple', gljOprObj.treeData.comple, true);
  1807. }
  1808. gljOprObj.initSelection({row: 0});
  1809. });
  1810. $('#glj-lib-select').change(function () {
  1811. let getLibFun = null;
  1812. if (typeof unitPriceObj !='undefined') {
  1813. getLibFun = unitPriceObj.getGLJDataPaging;
  1814. }
  1815. const gljLibID = $(this).val();
  1816. getGLJData('change', getLibFun, false, gljLibID);
  1817. })
  1818. // 人材机选择页面搜索框
  1819. $('#gljSearchKeyword').bind('keyup', _.debounce(function() {
  1820. gljOprObj.loadPageData(gljOprObj.gljLibSheet, true, 0);
  1821. }, 500));
  1822. $('#glj_selected_conf').click(function () {
  1823. if (gljOprObj.GLJSelection.length < 1) {
  1824. return;
  1825. }
  1826. if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
  1827. gljOprObj.doInsertGLJ();
  1828. } else if ($('#actionType').val() == 'add') { //添加工料机
  1829. gljOprObj.doAddGLJ();
  1830. } else if ($('#actionType').val() == 'replace') {//替换工料机
  1831. gljOprObj.doReplaceGLJ();
  1832. } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
  1833. gljOprObj.doMReplaceGLJ();
  1834. }else if($('#actionType').val() == 'addMix'){
  1835. projectGljObject.addMixRatio();
  1836. }else if($('#actionType').val() == 'unitPriceAddMix'){
  1837. unitPriceObj.addMixRatio();
  1838. }
  1839. $("#glj_tree_div").modal('hide');
  1840. })
  1841. $('#scope_position_confirm').click(function () {
  1842. gljOprObj.setScopeSelection();
  1843. gljOprObj.doMReplaceGLJ();
  1844. });
  1845. $('#replace_next_btn').click(function () {
  1846. $("#glj_tree_div").modal('hide');
  1847. $("#mreplace_next_div").modal('show');
  1848. });
  1849. $('#class_selected_conf').click(function () {
  1850. var gljClass = $('#selected_class').val();
  1851. var glj = gljOprObj.selectedGLJClass;
  1852. if (glj && gljClass && gljClass != "") {
  1853. //保存到我的工料机库
  1854. /*1 检查是否有组成物
  1855. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  1856. * 3 保存
  1857. * */
  1858. var newItem = {
  1859. code: glj.code,
  1860. name: glj.name,
  1861. specs: glj.specs,
  1862. unit: glj.unit,
  1863. basePrice: glj.basePrice,
  1864. gljType: glj.type,
  1865. shortName: glj.shortName,
  1866. component: [],
  1867. gljClass: gljClass
  1868. };
  1869. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  1870. for (var i = 0; i < glj.subList.length; i++) {
  1871. let tem = {
  1872. ID: glj.subList[i].GLJID,
  1873. consumeAmt: glj.rationItemQuantity,
  1874. isStd: true
  1875. }
  1876. newItem.component.push(tem);
  1877. }
  1878. }
  1879. var data = getcmpUpdateData([newItem]);
  1880. $.bootstrapLoading.start();
  1881. var callback = function (data) {
  1882. $("#glj_class_div").modal('hide');
  1883. $.bootstrapLoading.end();
  1884. }
  1885. CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
  1886. $.bootstrapLoading.end();
  1887. });
  1888. }
  1889. })
  1890. $('#glj_class_div').on('hidden.bs.modal', function (e) {
  1891. gljOprObj.selectedGLJClass = null;
  1892. $('#class_selected_conf').attr("disabled", "disabled");
  1893. $('#selected_class').val("");
  1894. })
  1895. $("#subSpread").focusout(function(e){//当本身或子元素失去焦点时这个事件都会发生,而且不好判断点击的是哪里。
  1896. if(gljOprObj.rationGljEditObj){
  1897. gljOprObj.cancelUpdate = false;
  1898. gljOprObj.timeStamp = e.timeStamp;//设置时间戳,有可能用户在表格上乱点,这个事件被触发多次
  1899. setTimeout(function () {//延时执行提交操作,如果点击的是spread里的地方,会把cancelUpdate改成true,这样的话就不执行提交操作
  1900. if(gljOprObj.timeStamp == e.timeStamp && gljOprObj.cancelUpdate !== true){//时间戳要相同
  1901. gljOprObj.updateGljFromCache();
  1902. }
  1903. },200)
  1904. }
  1905. });
  1906. function getcmpUpdateData(items) {
  1907. var data = {
  1908. "updateItems": [],
  1909. "removeIds": []
  1910. }
  1911. data.addItems = items;
  1912. return data;
  1913. }
  1914. })
  1915. function operationWithRound(value1,value2,field,symble) {
  1916. let decimal = getDecimal(field);
  1917. value1 = scMathUtil.roundForObj(value1,decimal);
  1918. value2 = scMathUtil.roundForObj(value2,decimal);
  1919. let result;
  1920. switch (symble){
  1921. case "+" :
  1922. result=scMathUtil.roundForObj(value1 + value2,decimal);
  1923. break;
  1924. case "-":
  1925. result=scMathUtil.roundForObj(value1 - value2,decimal);
  1926. break;
  1927. case "*":
  1928. result=scMathUtil.roundForObj(value1 * value2,decimal);
  1929. break;
  1930. case "/":
  1931. result=scMathUtil.roundForObj(value1 / value2,decimal);
  1932. break
  1933. }
  1934. return result;
  1935. }
  1936. function getDecimal(fieldID, node) {
  1937. if (node) {
  1938. return decimalObj.decimal(fieldID, node);
  1939. } else if (fieldID.indexOf(".") != -1) {
  1940. var keyArray = fieldID.split(".");
  1941. return decimalObj[keyArray[0]][keyArray[1]];
  1942. } else {
  1943. return decimalObj.decimal(fieldID);
  1944. }
  1945. }
  1946. function compareRationGLJ(a, b) {
  1947. if ((a.type + "") < (b.type + "")) {
  1948. return true
  1949. }
  1950. if ((a.type + "") == (b.type + "")) {
  1951. if (a.code < b.code) {
  1952. return true
  1953. }
  1954. }
  1955. return false;
  1956. }