glj_view.js 71 KB

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