glj_view.js 71 KB

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