glj_view.js 72 KB

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