glj_view.js 81 KB

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