glj_view.js 71 KB

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