glj_view.js 62 KB

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