glj_view.js 70 KB

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