glj_view.js 82 KB

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