glj_view.js 82 KB

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