glj_view.js 72 KB

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