glj_view.js 71 KB

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