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