glj_view.js 74 KB

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