glj_view.js 74 KB

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