glj_view.js 73 KB

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