glj_view.js 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  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. delete ration_gljs[i].subList; //置空,再设置
  717. let connect_index = this.getIndex(glj, gljKeyArray);
  718. if (needRatio==true&&mixRatioMap.hasOwnProperty(connect_index)) {
  719. let mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  720. ration_gljs[i].subList = mixRatios;
  721. }
  722. }
  723. }
  724. }
  725. return ration_gljs;
  726. },
  727. setGLJPrice:function (data,glj,isRadio = false) {//isRadio 标记是否算组成物的价格
  728. let proGLJ = projectObj.project.projectGLJ;
  729. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  730. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  731. let labourCoeDatas = projectObj.project.labourCoe.datas;
  732. glj = glj?glj:_.find(proGLJ.datas.gljList, {'id': data.projectGLJID});
  733. if(glj){
  734. let result = gljUtil.getGLJPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  735. data.marketPrice = result.marketPrice;
  736. data.basePrice = result.basePrice;
  737. data.adjustPrice = result.adjustPrice;
  738. data.marketUnitFee = data.marketPrice;//更新树节点市场单价列的值
  739. }
  740. return data;
  741. },
  742. getBasePrice:function (treeNode) {//造价书中的工料机修改的节点要用到
  743. let proGLJ = projectObj.project.projectGLJ;
  744. let glj =_.find(proGLJ.datas.gljList, {'id': treeNode.data.projectGLJID});
  745. if(this.calcPriceDiff(glj)==true){
  746. return proGLJ.getBasePrice(glj);
  747. }else {
  748. return scMathUtil.roundForObj(treeNode.data.marketUnitFee,getDecimal("glj.unitPrice"));
  749. }
  750. },
  751. getMarketPrice:function (treeNode) {//造价书中的工料机修改的节点要用到
  752. let proGLJ = projectObj.project.projectGLJ;
  753. let glj =_.find(proGLJ.datas.gljList, {'id': treeNode.data.projectGLJID});
  754. return proGLJ.getMarketPrice(glj);
  755. },
  756. calcPriceDiff:function (glj) {
  757. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  758. return gljUtil.calcPriceDiff(glj,calcOptions);
  759. },
  760. getIndex(obj, pops){
  761. return gljUtil.getIndex(obj,pops);
  762. },
  763. getConditionByKey(conKey){//将连接字符串转换成对象
  764. let valueArray = conKey.split("|-|");
  765. let obj ={};
  766. for(let i = 0;i<valueArray.length;i++){
  767. if(valueArray[i]!='null'){
  768. if(gljKeyArray[i]=='type'){
  769. valueArray[i] = parseInt(valueArray[i]);
  770. }
  771. obj[gljKeyArray[i]]=valueArray[i];
  772. }
  773. }
  774. return obj;
  775. },
  776. getMixRationShowDatas: function (mixRatioList, projectGljs) {
  777. var temRationGLJs = [];
  778. for (var i = 0; i < mixRatioList.length; i++) {
  779. let mIndex = gljOprObj.getIndex(mixRatioList[i],gljKeyArray);
  780. var pg = _.find(projectGljs, function (item) {
  781. return gljOprObj.getIndex(item,gljKeyArray) == mIndex
  782. });//改关联关系
  783. if(pg){
  784. var tem = {
  785. projectGLJID: pg.id,
  786. code: pg.code,
  787. name: pg.name,
  788. specs: pg.specs,
  789. unit: pg.unit,
  790. type:mixRatioList[i].type,
  791. shortName: projectObj.project.projectGLJ.getShortNameByID(mixRatioList[i].type),
  792. consumption:mixRatioList[i].consumption,
  793. rationItemQuantity: mixRatioList[i].consumption,
  794. // quantity:mixRatioList[i].consumption,
  795. /* basePrice: pg.unit_price.base_price,
  796. marketPrice: pg.unit_price.market_price,
  797. adjustPrice: pg.adjust_price,*/
  798. //isEstimate: pg.is_evaluate,
  799. isMixRatio: true,
  800. isAdd: pg.unit_price.is_add,
  801. GLJID: pg.glj_id
  802. };
  803. if(projectObj.project.projectGLJ.isEstimateType(pg.type)){
  804. tem.isEstimate = pg.is_evaluate;
  805. }
  806. this.setGLJPrice(tem,pg);
  807. }
  808. temRationGLJs.push(tem);
  809. }
  810. temRationGLJs = gljUtil.sortMixRatio(temRationGLJs);
  811. return temRationGLJs;
  812. },
  813. showQuantityDetailData: function (node) {
  814. node = node ? node : projectObj.project.mainTree.selected;
  815. var quantity_detail = projectObj.project.quantity_detail;
  816. let field = node.sourceType == ModuleNames.ration?'rationID':'billID';
  817. let details = quantity_detail.getListByID(node.data.ID,field);
  818. sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
  819. this.detailData = details;
  820. if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
  821. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
  822. }
  823. },
  824. clearSheetData: function () {
  825. if($('#linkGLJ').hasClass('active')){
  826. sheetCommonObj.showData(this.sheet, this.setting, []);
  827. }
  828. if($('#linkAZZJF').hasClass('active')){
  829. installationFeeObj.rationInstallSheet.setRowCount(0);//清除combobox cell
  830. sheetCommonObj.showData(installationFeeObj.rationInstallSheet, installationFeeObj.rationInstallSetting, []);
  831. }
  832. // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
  833. this.sheetData = [];
  834. installationFeeObj.rationInstallData = [];
  835. //this.detailData=[];
  836. },
  837. updateRationGLJ: function (args) {
  838. var me = this;
  839. var updateField = me.setting.header[args.col].dataCode;
  840. var recode = me.sheetData[args.row];
  841. var newval;
  842. if(!me.rationGLJEditCheck(args)){
  843. recode? me.sheet.getCell(args.row, args.col).value(recode[updateField]): me.sheet.getCell(args.row, args.col).value(null);
  844. return;
  845. }
  846. if(args.editingText){
  847. args.editingText = args.editingText.replace(/[\r\n]/g, "");//去掉回车换行等字符;
  848. me.sheet.getCell(args.row, args.col).value(args.editingText);
  849. }
  850. if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
  851. if (args.editingText == null) {
  852. updateField == 'marketPrice' ? newval = 0 : newval = "";
  853. } else {
  854. var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : 6;//对于市场价和定额价,这里只是中间的小数位数,后面更新前会根据有没有组成物再取值
  855. newval = number_util.checkNumberValue(args.editingText, decimal);
  856. if (newval == null) {
  857. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  858. return;
  859. }
  860. }
  861. } else {
  862. if (updateField == 'name' || updateField == 'unit') {
  863. if (args.editingText === null) {
  864. alert(me.setting.header[args.col].headerName + '不能为空!');
  865. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  866. return;
  867. }
  868. }
  869. if(updateField == 'code'){
  870. if (!gljUtil.isDef(args.editingText)||args.editingText==''||args.editingText.indexOf('|-|') === -1||this.isRationGLJExit(args.editingText)) {//说明是选中自已,或者是已存在的工料机
  871. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  872. return;
  873. }
  874. }
  875. newval = args.editingText == null ? "" : args.editingText;
  876. }
  877. if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
  878. return
  879. }
  880. if (updateField == 'marketPrice' || updateField == 'basePrice') {
  881. projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
  882. }else if(updateField == 'code'){//替换单价文件中已经有的工料机
  883. projectObj.project.ration_glj.updateRationGLJByChangeCode(recode, updateField, newval);
  884. }else if(me.setting.navigationRightCol.indexOf(updateField) != -1){//对于名称、规格、单位先跳到下一列,保存至缓存
  885. me.setToEditCache(recode,updateField, newval,args);
  886. } else {
  887. projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
  888. }
  889. },
  890. setToEditCache:function(recode,updateField,value,args){
  891. let me = this;
  892. if(me.rationGljEditObj == null){
  893. me.rationGljEditObj = {
  894. recode:recode,
  895. doc:{},
  896. row:args.row
  897. }
  898. me.rationGljEditObj.doc[updateField] = value;
  899. }else {
  900. if(me.rationGljEditObj.recode.ID == recode.ID){//确保编辑的是同一条数据
  901. me.rationGljEditObj.doc[updateField] = value;
  902. }
  903. }
  904. },
  905. isRationGLJExit:function (connectKey) {
  906. for(let rg of gljOprObj.sheetData){
  907. if(rg.isMixRatio == true){
  908. continue;
  909. }
  910. if(gljOprObj.getIndex(rg, gljKeyArray) == connectKey){//存在一样的工料机
  911. return true;
  912. }
  913. }
  914. return false;
  915. },
  916. updateRationTypeGLJ: function (value, node, fieldName,editingText) {
  917. let newval;
  918. let updatePrice = false;
  919. if (fieldName == "marketUnitFee" || fieldName == "feesIndex.common.unitFee") {
  920. updatePrice = true;
  921. if (value == null) {
  922. newval = 0;
  923. } else {
  924. var decimal = getDecimal("glj.unitPrice");
  925. newval = number_util.checkNumberValue(value, decimal);
  926. }
  927. }
  928. else {
  929. if (value != null) {
  930. projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value,editingText);
  931. return;
  932. }
  933. }
  934. if (newval && updatePrice == true) {
  935. projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
  936. return
  937. }
  938. projectObj.mainController.refreshTreeNode([node]);
  939. },
  940. updateIsEstimate:function (args, newval) {
  941. var me = gljOprObj;
  942. if(me.setting.header[args.col].dataCode=="isEstimate"){
  943. var pspread= new ProjectGLJSpread();
  944. var recode = me.sheetData[args.row];
  945. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  946. let glj = _.find(projectGljs, {'id': recode.projectGLJID});
  947. if(glj){
  948. glj["is_evaluate"]=newval;
  949. args.fromRG=true;
  950. pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
  951. }
  952. }
  953. },
  954. showLibGLJSheetData: function () {
  955. this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
  956. sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
  957. this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
  958. },
  959. filterLibGLJSheetData: function () {
  960. let me = this;
  961. let val = $("input[name='glj']:checked").val();
  962. if (val == 'allGljs') {
  963. me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
  964. } else {
  965. me.gljLibSheetData = me[val];
  966. }
  967. if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
  968. me.filterLibGLJByType();
  969. }else if($('#actionType').val() == 'addMix'){
  970. projectGljObject.filterLibGLJForMixRatio();
  971. }
  972. //文本筛选
  973. let searchStr = $('#gljSearchKeyword').val();
  974. if(searchStr && searchStr.trim() != ''){
  975. let reg = new RegExp(searchStr);
  976. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  977. return reg.test(data.code) || reg.test(data.name);
  978. });
  979. }
  980. if (me.gljCurTypeId == undefined) {
  981. return;
  982. }
  983. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  984. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  985. return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
  986. });
  987. } else {
  988. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
  989. }
  990. },
  991. setGLJSelection: function (args, newVal) {
  992. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert'|| $('#actionType').val() == 'insertEquipment' || $('#actionType').val() == 'addMix') {
  993. this.addGLJsSelection(args, newVal);
  994. } else {
  995. this.replaceGLJSelection(args, newVal);
  996. }
  997. },
  998. addGLJsSelection: function (args, newVal) {
  999. var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
  1000. if (newVal == 1) {
  1001. this.GLJSelection.push(con_key);
  1002. this.gljLibSheetData[args.row].select = 1;
  1003. } else if (newVal == 0) {
  1004. _.pull(this.GLJSelection, con_key);
  1005. this.gljLibSheetData[args.row].select = 0;
  1006. }
  1007. },
  1008. replaceGLJSelection: function (args, newVal) {
  1009. var me = this;
  1010. var oldSelection = this.GLJSelection[0];
  1011. if (newVal == 0) {
  1012. args.sheet.getCell(args.row, args.col).value(1);
  1013. return;
  1014. }
  1015. this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
  1016. this.gljLibSheetData[args.row].select = 1;
  1017. var oindex = _.findIndex(this.gljLibSheetData, function (item) {
  1018. var i_key = me.getIndex(item, gljLibKeyArray);
  1019. return oldSelection == i_key;
  1020. });
  1021. if (oindex != -1) {
  1022. args.sheet.getCell(oindex, args.col).value(0);
  1023. this.gljLibSheetData[oindex].select = 0;
  1024. } else {
  1025. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  1026. var i_key = me.getIndex(item, gljLibKeyArray);
  1027. return oldSelection == i_key;
  1028. });
  1029. oldData ? oldData.select = 0 : "";
  1030. }
  1031. },
  1032. filterLibGLJByType: function () {
  1033. var me = this;
  1034. var selected = me.sheetData[gljContextMenu.selectedRow];
  1035. //当前人材机类型是“混凝土、砂浆、配合比、商品混凝土、商品砂浆”时,筛选的可替换的人材机类型应是“混凝土、或砂浆、或配合比、或商品混凝土、或商品砂浆”。
  1036. let materialTypes = [202, 203, 204, 205, 206];//除了普通材料
  1037. let filterTypes = materialTypes.includes(selected.type) ? materialTypes : [selected.type];
  1038. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  1039. return filterTypes.includes(data.gljType);
  1040. });
  1041. },
  1042. getComboData: function (gljDistType) {
  1043. let me = this;
  1044. let distType;
  1045. let distTypeTree = {
  1046. prefix: 'gljType',
  1047. distTypes: {},
  1048. comboDatas: [],
  1049. distTypesArr: []
  1050. };
  1051. gljDistType.forEach(function (typeData) {
  1052. let typeObj = {
  1053. data: typeData,
  1054. children: [],
  1055. parent: null
  1056. }
  1057. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  1058. distTypeTree.distTypesArr.push(typeObj);
  1059. });
  1060. gljDistType.forEach(function (typeData) {
  1061. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  1062. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  1063. if (parent) {
  1064. distType.parent = parent;
  1065. parent.children.push(distType);
  1066. }
  1067. });
  1068. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  1069. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  1070. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  1071. }
  1072. });
  1073. console.log(distTypeTree);
  1074. return distTypeTree;
  1075. },
  1076. doInsertGLJ: function () {
  1077. var me = this;
  1078. var selected = projectObj.project.mainTree.selected;
  1079. var project = projectObj.project;
  1080. if (me.GLJSelection.length <= 0) {
  1081. return;
  1082. }
  1083. $("#glj_tree_div").modal('hide');
  1084. $.bootstrapLoading.start();
  1085. project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (parentNodeID,nextNodeID,data) {
  1086. let newNode=null;
  1087. for (let r_glj of data) {
  1088. r_glj.quantity = r_glj.quantity + "";
  1089. project.Ration.datas.push(r_glj);
  1090. }//要先更新树节点工程量,加载项目工料机并计算消耗量才有值
  1091. project.projectGLJ.loadData(function () {
  1092. for(let r_glj of data){
  1093. r_glj = me.setGLJPrice(r_glj);//设置工料机价格
  1094. newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
  1095. newNode.source = r_glj;
  1096. newNode.sourceType = project.Ration.getSourceType();
  1097. newNode.data = r_glj;
  1098. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  1099. }
  1100. project.calcProgram.calcLeafAndSave(newNode.parent);//计算父级清单的所有子节点
  1101. projectObj.mainController.refreshTreeNode([newNode]);
  1102. if(me.hasComposition(newNode.data,true)){
  1103. me.showMixRatio(newNode);
  1104. }else {
  1105. me.showRationGLJSheetData();
  1106. }
  1107. $.bootstrapLoading.end();
  1108. });
  1109. })
  1110. },
  1111. doAddGLJ: function () {
  1112. var selected = projectObj.project.mainTree.selected;
  1113. var project = projectObj.project;
  1114. gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
  1115. var rg = _.find(gljOprObj.sheetData, function (item) {
  1116. if(item.isMixRatio == true){
  1117. return false;
  1118. }
  1119. var i_key = gljOprObj.getIndex(item, gljKeyArray);
  1120. return n == i_key
  1121. });
  1122. return rg ? false : true;
  1123. })
  1124. if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
  1125. $("#glj_tree_div").modal('hide');
  1126. project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
  1127. if (result) {
  1128. selected.data.adjustState = result.adjustState;
  1129. project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
  1130. //project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
  1131. //gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
  1132. project.projectGLJ.loadData(function () {
  1133. project.ration_glj.addToMainTree(result.showData);//组成物不会显示到造价书页面
  1134. gljOprObj.refreshView();
  1135. project.calcProgram.calcAndSave(selected);
  1136. projectObj.mainController.refreshTreeNode([selected]);
  1137. $.bootstrapLoading.end();
  1138. });
  1139. }
  1140. });//doc.rationID=selected.data.ID;
  1141. } else {
  1142. $("#glj_tree_div").modal('hide');
  1143. }
  1144. },
  1145. doReplaceGLJ: function () {
  1146. let me = this;
  1147. let oldData = me.sheetData[gljContextMenu.selectedRow];
  1148. let project = projectObj.project;
  1149. let selectCode = gljOprObj.GLJSelection[0];
  1150. let selected = projectObj.project.mainTree.selected;
  1151. $("#glj_tree_div").modal('hide');
  1152. project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
  1153. if (result) {
  1154. //result.adjustState;
  1155. project.ration_glj.setDatasAfterReplace(result);
  1156. let data = result.data;
  1157. let nodes = [selected];
  1158. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  1159. gljOprObj.refreshView();
  1160. let node = project.ration_glj.updateGLJNodeAfterReplace(data);
  1161. if(node) nodes.push(node);
  1162. /*if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  1163. var node = project.ration_glj.findGLJNodeByID(data.ID);
  1164. if (node) {
  1165. project.ration_glj.transferToNodeData(data);
  1166. node.source = data;
  1167. node.data = data;
  1168. }
  1169. node ? nodes.push(node) : "";
  1170. }*/
  1171. //project.ration_glj.addToMainTree(data);
  1172. selected.data.adjustState = result.adjustState;
  1173. selected.data.name = result.name;
  1174. projectObj.mainController.refreshTreeNode(nodes);
  1175. project.calcProgram.calcAndSave(selected);
  1176. $.bootstrapLoading.end();
  1177. });
  1178. }
  1179. })
  1180. },
  1181. doMReplaceGLJ: function () {
  1182. let me = this;
  1183. let oldData = me.sheetData[gljContextMenu.selectedRow];
  1184. let project = projectObj.project;
  1185. let selectCode = me.GLJSelection[0];
  1186. $("#glj_tree_div").modal('hide');
  1187. project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result,updateMap) {
  1188. if(result == null){
  1189. return;
  1190. }
  1191. let data = result.data;
  1192. let stateList = result.stateList;
  1193. //let n_index = me.getIndex(data.query, gljKeyArray);
  1194. let nodes = [];
  1195. let quantityMap = {};
  1196. for(let gr of result.glj_result){
  1197. quantityMap[gr.query.ID] = gr.doc;
  1198. }
  1199. //添加\删除混凝土组成物定额工料机
  1200. project.ration_glj.addAndDeleteDatas(result.newRecodes,result.deleteList);
  1201. _.forEach(project.ration_glj.datas, function (t) {
  1202. // let t_index = me.getIndex(t, gljKeyArray);
  1203. if (updateMap[t.ID]) {
  1204. me.updateProperty(t, data.doc);
  1205. me.updateProperty(t, updateMap[t.ID]);
  1206. if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
  1207. project.ration_glj.transferToNodeData(t);
  1208. var node = project.ration_glj.findGLJNodeByID(t.ID);
  1209. node ? nodes.push(node):'';
  1210. }
  1211. }
  1212. if(quantityMap[t.ID]){//更新消耗量
  1213. me.updateProperty(t,quantityMap[t.ID]);
  1214. }
  1215. })
  1216. project.projectGLJ.loadData(function () {
  1217. me.refreshView();
  1218. var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
  1219. project.calcProgram.calcNodesAndSave(rationNodes);
  1220. $.bootstrapLoading.end();
  1221. });
  1222. })
  1223. },
  1224. updateProperty: function (obj, doc) {
  1225. _.forEach(doc, function (n, key) {
  1226. obj[key] = n;
  1227. });
  1228. },
  1229. refreshStateAfterMreplace: function (stateList, gljNodes) {
  1230. let nodes = [];
  1231. let rationNodes = [];
  1232. _.forEach(stateList, function (s) {
  1233. let node = _.find(projectObj.project.mainTree.items, function (n) {
  1234. return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
  1235. })
  1236. if (node) {
  1237. node.data.adjustState = s.adjustState;
  1238. node.data.name = s.name;
  1239. nodes.push(node);
  1240. rationNodes.push(node);
  1241. }
  1242. });
  1243. gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
  1244. projectObj.mainController.refreshTreeNode(nodes);
  1245. return rationNodes;
  1246. },
  1247. refreshView: function () {
  1248. let node = projectObj.project.mainTree.selected;
  1249. this.showDataIfRationSelect(node,"111111");
  1250. },
  1251. refreshTreeNode: function (obj) {
  1252. if (!obj) {
  1253. return;
  1254. }
  1255. let objectArray = [];
  1256. let nodes = [];
  1257. if (obj instanceof Array) {
  1258. objectArray.concat(obj);
  1259. } else {
  1260. objectArray.push(obj);
  1261. }
  1262. for (let o of objectArray) {
  1263. let node = this.updateDataNodeProperty(o.ID,o.data);
  1264. if (node) {
  1265. nodes.push(node);
  1266. }
  1267. }
  1268. projectObj.mainController.refreshTreeNode(nodes);
  1269. return nodes;
  1270. },
  1271. updateDataNodeProperty:function(nodeID,data){
  1272. let node = projectObj.project.mainTree.findNode(nodeID);
  1273. if (node) {
  1274. for (let k in data) {
  1275. node.data[k] = data[k];
  1276. }
  1277. }
  1278. return node;
  1279. },
  1280. getTreeNodeCellType: function (data,comboboxOptions) {
  1281. let ns = GC.Spread.Sheets;
  1282. let rectW = 10;
  1283. let rectH = 10;
  1284. let margin = 3;
  1285. function TreeNodeCellType() {
  1286. this.ctx = null;
  1287. }
  1288. TreeNodeCellType.prototype = comboboxOptions?sheetCommonObj.getDynamicCombo():new ns.CellTypes.Text();
  1289. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  1290. this.ctx= ctx;
  1291. if (style.backColor) {//先画背景色
  1292. ctx.save();
  1293. ctx.fillStyle = style.backColor;
  1294. ctx.fillRect(x, y, w, h);
  1295. ctx.restore();
  1296. } else {
  1297. ctx.clearRect(x, y, w, h);
  1298. }
  1299. if (value != null) {
  1300. let offset = margin + rectW + 6;
  1301. let recode = data[options.row];
  1302. if (recode && recode.hasOwnProperty('subList')) {
  1303. sheetCommonObj.drowRect(ctx, x, y, w, h,rectW,rectH,margin);
  1304. let collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
  1305. sheetCommonObj.drowSymbol(ctx, x, y, w, h,rectW,rectH,margin, collapsed);
  1306. } else if (recode && recode.isMixRatio) {
  1307. let hasNext = data[options.row + 1] && data[options.row + 1].isMixRatio;
  1308. offset = sheetCommonObj.drowSubItem(ctx, x, y, w, h, offset,hasNext);
  1309. offset += 1;
  1310. }
  1311. arguments[2] = x + offset;
  1312. arguments[4] = w - offset;
  1313. //x = x + offset;
  1314. //w = w - offset;
  1315. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1316. }
  1317. };
  1318. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1319. if(x < cellRect.x+cellRect.width -15){//这里要判断点击的位置来决定return的内容,不能直接用combobox的方法
  1320. return {
  1321. x: x,
  1322. y: y,
  1323. row: context.row,
  1324. col: context.col,
  1325. cellStyle: cellStyle,
  1326. cellRect: cellRect,
  1327. sheetArea: context.sheetArea
  1328. };
  1329. }else {
  1330. return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(this, arguments);
  1331. }
  1332. };
  1333. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1334. let recode = data[hitinfo.row];
  1335. if(hitinfo.x < hitinfo.cellRect.x+hitinfo.cellRect.width -15){
  1336. hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,"locked")//通过这个来控制除了点击下拉框的三角形,点击其它地方不充许进入编辑状态,不然不好控制下拉框超出页面后调整滚动条
  1337. }
  1338. if (recode && recode.hasOwnProperty('subList')) {
  1339. let hoffset = hitinfo.cellRect.x + 3;
  1340. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1341. let collapsed = recode.collapsed == undefined ? true : recode.collapsed;
  1342. collapsed = !collapsed
  1343. recode.collapsed = collapsed;
  1344. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1345. hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
  1346. hitinfo.sheet.invalidateLayout();
  1347. hitinfo.sheet.repaint();
  1348. return;
  1349. }
  1350. }
  1351. if(comboboxOptions&&hitinfo.x > hitinfo.cellRect.x+hitinfo.cellRect.width -15){//点击了下拉框按钮,这里要判断下拉框是否会被挡住,从而决定是否自动调整滚动条
  1352. hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,"");
  1353. sheetCommonObj.scrollSheetForOption(hitinfo.sheet,this.ctx,hitinfo.cellRect,hitinfo.row,comboboxOptions);//下拉框超出显示后自动调整滚动条
  1354. GC.Spread.Sheets.CellTypes.ComboBox.prototype.processMouseDown.apply(this, arguments);
  1355. }
  1356. };
  1357. let cellType = new TreeNodeCellType();
  1358. if(comboboxOptions){
  1359. cellType.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  1360. cellType.itemHeight(comboboxOptions.length).items(comboboxOptions);
  1361. }
  1362. return cellType;
  1363. },
  1364. marketPriceReadOnly: function (node) {
  1365. let isRationType = node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation;
  1366. let type = isRationType==true? node.data.subType:node.data.type;
  1367. if(gljUtil.isConcreteType(type)) return true;
  1368. return this.hasComposition(node.data,isRationType); //2018-9-14 需求变更暂估工料机也能修改市场价原语句:return hasCom|| node.data.isEstimate == 1
  1369. },
  1370. locateZTree: function(ID) {
  1371. let zTree = $.fn.zTree.getZTreeObj("gljTree");
  1372. let node = null;
  1373. if (ID) node = zTree.getNodesByParam('ID', ID, null)[0];
  1374. if (!node) node = zTree.getNodeByTId('gljTree_1');
  1375. zTree.selectNode(node);
  1376. gljOprObj.gljCurTypeId = ID;
  1377. gljOprObj.filterLibGLJSheetData();
  1378. gljOprObj.showLibGLJSheetData();
  1379. },
  1380. isExtraType:function (type) {
  1381. return _.includes(gljUtil.extraType,type)
  1382. },
  1383. setNodeShowTab:function () {
  1384. let node = projectObj.project.mainTree.selected;
  1385. if(node && node.sourceType==ModuleNames.ration){
  1386. gljOprObj.rationTab = gljOprObj.activeTab;
  1387. }else {
  1388. gljOprObj.billsTab = gljOprObj.activeTab;
  1389. }
  1390. },
  1391. //初始化分类树
  1392. //@param {String}type(标准或补充) {Array}treeData(树数据)
  1393. initClassTree: function (type, treeData, initSel = false) {
  1394. let me = this;
  1395. if (me.treeObj) {
  1396. me.treeObj.destroy();
  1397. me.parentNodeIds = {};
  1398. }
  1399. zTreeHelper.createTree(treeData, me.gljTreeSetting, "gljTree", me);
  1400. if (initSel) {
  1401. let rootNode = me.treeObj.getNodes()[0];
  1402. if(rootNode && rootNode.isParent && rootNode.isFirstNode){
  1403. me.rootNode = rootNode;
  1404. }
  1405. if(me.rootNode){
  1406. me.treeObj.selectNode(me.rootNode);
  1407. me.gljTreeSetting.callback.onClick(null, 'gljTree', me.rootNode);
  1408. }
  1409. }
  1410. }
  1411. }
  1412. $(function () {
  1413. $('#glj_tree_div').on('shown.bs.modal', function (e) {
  1414. if (gljOprObj.gljLibSpresd == undefined) {
  1415. gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
  1416. sheetCommonObj.spreadDefaultStyle(gljOprObj.gljLibSpresd);
  1417. gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
  1418. gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
  1419. gljOprObj.gljLibSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, gljOprObj.onSelectionChanged);
  1420. gljOprObj.gljLibSheet.setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  1421. gljOprObj.gljLibSheet.options.isProtected = true;
  1422. gljOprObj.gljLibSheet.name('glj_lib');
  1423. }
  1424. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1425. let gljClass = 0, selectMap = {};
  1426. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert' || $('#actionType').val() == 'insertEquipment') {//插入,添加
  1427. gljOprObj.GLJSelection = [];
  1428. } else if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){//替换、批量替换
  1429. let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1430. let connect_key = gljOprObj.getIndex(selected, gljKeyArray);
  1431. gljOprObj.GLJSelection = [connect_key];
  1432. selectMap[connect_key] = true;
  1433. gljOprObj.filterLibGLJByType();
  1434. }else if($('#actionType').val() =='addMix'){//添加组成物
  1435. gljOprObj.GLJSelection = [];
  1436. projectGljObject.filterLibGLJForMixRatio();
  1437. /*selections = projectGljObject.mixRatioData; 添加组成物的时候先不选中
  1438. gljOprObj.GLJSelection = [];
  1439. for(let s of selections){
  1440. let s_key = gljOprObj.getIndex(s, gljKeyArray);
  1441. selectMap[s_key] = true;
  1442. gljOprObj.GLJSelection.push(s_key);
  1443. }*/
  1444. }
  1445. for(let item of gljOprObj.gljLibSheetData){
  1446. let item_key = gljOprObj.getIndex(item, gljLibKeyArray);
  1447. if(selectMap[item_key]){
  1448. item.select = 1 ;
  1449. gljClass = item.gljClass;
  1450. }
  1451. }
  1452. //替换,焦点定位至当前选中人材机
  1453. if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){
  1454. gljOprObj.locateZTree(gljClass);
  1455. let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1456. let index = _.findIndex(gljOprObj.gljLibSheetData, {code: selected.code});
  1457. gljOprObj.gljLibSheet.showRow(index, GC.Spread.Sheets.VerticalPosition.center);
  1458. gljOprObj.gljLibSheet.setActiveCell(index, 0);
  1459. gljOprObj.initSelection({row: index});
  1460. gljOprObj.gljLibSpresd.focus(true);
  1461. } else if ($('#actionType').val() === 'insertEquipment') {//右键插入设备,人材机选择窗口,应默认固定到分类"养护管理设备"。
  1462. let locateClass = gljOprObj.treeData.std.find(function (stdClass) {
  1463. return stdClass.Name === '养护管理设备';
  1464. });
  1465. if (locateClass) {
  1466. gljClass = locateClass.ID;
  1467. gljOprObj.locateZTree(gljClass);
  1468. gljOprObj.gljLibSheet.showRow(0, GC.Spread.Sheets.VerticalPosition.top);
  1469. gljOprObj.gljLibSheet.setActiveCell(0, 0);
  1470. gljOprObj.initSelection({row: 0});
  1471. }
  1472. } else if ($('#actionType').val() === 'add') {
  1473. gljOprObj.locateZTree(null);
  1474. gljOprObj.gljLibSheet.showRow(0, GC.Spread.Sheets.VerticalPosition.top);
  1475. gljOprObj.gljLibSheet.setActiveCell(0, 0);
  1476. gljOprObj.initSelection({row: 0});
  1477. } else {
  1478. gljOprObj.showLibGLJSheetData();
  1479. }
  1480. });
  1481. $('#glj_tree_div').on('hidden.bs.modal', function () {
  1482. $('#gljSearchKeyword').val('');
  1483. });
  1484. $('.glj-radio').change(function () {
  1485. let val = $("input[name='glj']:checked").val();
  1486. if (val == 'allGljs') {
  1487. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1488. gljOprObj.filterLibGLJSheetData();
  1489. gljOprObj.showLibGLJSheetData();
  1490. } else {
  1491. if(val === 'stdGLJ') {
  1492. gljOprObj.initClassTree('std', gljOprObj.treeData.std, true);
  1493. } else {
  1494. gljOprObj.initClassTree('comple', gljOprObj.treeData.comple, true);
  1495. }
  1496. gljOprObj.initSelection({row: 0});
  1497. //gljOprObj.gljLibSheetData = gljOprObj[val];
  1498. /*gljOprObj.filterLibGLJSheetData();
  1499. gljOprObj.showLibGLJSheetData();*/
  1500. }
  1501. });
  1502. /* //工料机搜索
  1503. $('#gljSearchKeyword').change(function () {
  1504. gljOprObj.filterLibGLJSheetData();
  1505. gljOprObj.showLibGLJSheetData();
  1506. });
  1507. $('#gljSearchKeyword').bind('keypress', function (e) {
  1508. if(e.keyCode === 13){
  1509. alert('2');
  1510. $(this).blur();
  1511. return false;
  1512. }
  1513. });*/
  1514. $('#gljSearchKeyword').bind('keyup', function (e) {
  1515. gljOprObj.filterLibGLJSheetData();
  1516. gljOprObj.showLibGLJSheetData();
  1517. gljOprObj.initSelection({row: 0});
  1518. });
  1519. $('#glj_selected_conf').click(function () {
  1520. if (gljOprObj.GLJSelection.length < 1) {
  1521. return;
  1522. }
  1523. if (['insert', 'insertEquipment'].includes($('#actionType').val())) { //造价书页面中插入定额类型的工料机
  1524. gljOprObj.doInsertGLJ();
  1525. } else if ($('#actionType').val() == 'add') { //添加工料机
  1526. gljOprObj.doAddGLJ();
  1527. } else if ($('#actionType').val() == 'replace') {//替换工料机
  1528. gljOprObj.doReplaceGLJ();
  1529. } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
  1530. gljOprObj.doMReplaceGLJ();
  1531. }else if($('#actionType').val() == 'addMix'){
  1532. projectGljObject.addMixRatio();
  1533. }
  1534. })
  1535. $('#class_selected_conf').click(function () {
  1536. var gljClass = $('#selected_class').val();
  1537. var glj = gljOprObj.selectedGLJClass;
  1538. if (glj && gljClass && gljClass != "") {
  1539. //保存到我的工料机库
  1540. /*1 检查是否有组成物
  1541. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  1542. * 3 保存
  1543. * */
  1544. var newItem = {
  1545. code: glj.code,
  1546. name: glj.name,
  1547. specs: glj.specs,
  1548. unit: glj.unit,
  1549. basePrice: glj.basePrice,
  1550. gljType: glj.type,
  1551. shortName: glj.shortName,
  1552. component: [],
  1553. gljClass: gljClass
  1554. };
  1555. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  1556. for (var i = 0; i < glj.subList.length; i++) {
  1557. let tem = {
  1558. ID: glj.subList[i].GLJID,
  1559. consumeAmt: glj.rationItemQuantity,
  1560. isStd: true
  1561. }
  1562. newItem.component.push(tem);
  1563. }
  1564. }
  1565. var data = getcmpUpdateData([newItem]);
  1566. $.bootstrapLoading.start();
  1567. var callback = function (data) {
  1568. $("#glj_class_div").modal('hide');
  1569. $.bootstrapLoading.end();
  1570. }
  1571. CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
  1572. $.bootstrapLoading.end();
  1573. });
  1574. }
  1575. })
  1576. $('#glj_class_div').on('hidden.bs.modal', function (e) {
  1577. gljOprObj.selectedGLJClass = null;
  1578. $('#class_selected_conf').attr("disabled", "disabled");
  1579. $('#selected_class').val("");
  1580. })
  1581. $("#subSpread").focusout(function(e){//当本身或子元素失去焦点时这个事件都会发生,而且不好判断点击的是哪里。
  1582. if(gljOprObj.rationGljEditObj){
  1583. gljOprObj.cancelUpdate = false;
  1584. gljOprObj.timeStamp = e.timeStamp;//设置时间戳,有可能用户在表格上乱点,这个事件被触发多次
  1585. setTimeout(function () {//延时执行提交操作,如果点击的是spread里的地方,会把cancelUpdate改成true,这样的话就不执行提交操作
  1586. if(gljOprObj.timeStamp == e.timeStamp && gljOprObj.cancelUpdate !== true){//时间戳要相同
  1587. gljOprObj.updateGljFromCache();
  1588. }
  1589. },200)
  1590. }
  1591. });
  1592. function getcmpUpdateData(items) {
  1593. var data = {
  1594. "updateItems": [],
  1595. "removeIds": []
  1596. }
  1597. data.addItems = items;
  1598. return data;
  1599. }
  1600. })
  1601. function operationWithRound(value1,value2,field,symble) {
  1602. let decimal = getDecimal(field);
  1603. value1 = scMathUtil.roundForObj(value1,decimal);
  1604. value2 = scMathUtil.roundForObj(value2,decimal);
  1605. let result;
  1606. switch (symble){
  1607. case "+" :
  1608. result=scMathUtil.roundForObj(value1 + value2,decimal);
  1609. break;
  1610. case "-":
  1611. result=scMathUtil.roundForObj(value1 - value2,decimal);
  1612. break;
  1613. case "*":
  1614. result=scMathUtil.roundForObj(value1 * value2,decimal);
  1615. break;
  1616. case "/":
  1617. result=scMathUtil.roundForObj(value1 / value2,decimal);
  1618. break
  1619. }
  1620. return result;
  1621. }
  1622. function getDecimal(fieldID, node) {
  1623. if (node) {
  1624. return decimalObj.decimal(fieldID, node);
  1625. } else if (fieldID.indexOf(".") != -1) {
  1626. var keyArray = fieldID.split(".");
  1627. return decimalObj[keyArray[0]][keyArray[1]];
  1628. } else {
  1629. return decimalObj.decimal(fieldID);
  1630. }
  1631. }
  1632. function compareRationGLJ(a, b) {
  1633. if ((a.type + "") < (b.type + "")) {
  1634. return true
  1635. }
  1636. if ((a.type + "") == (b.type + "")) {
  1637. if (a.code < b.code) {
  1638. return true
  1639. }
  1640. }
  1641. return false;
  1642. }