glj_view.js 77 KB

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