glj_view.js 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537
  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. }
  935. //文本筛选
  936. let searchStr = $('#gljSearchKeyword').val();
  937. if(searchStr && searchStr.trim() != ''){
  938. let reg = new RegExp(searchStr);
  939. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  940. return reg.test(data.code) || reg.test(data.name);
  941. });
  942. }
  943. if (me.gljCurTypeId == undefined) {
  944. return;
  945. }
  946. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  947. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  948. return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
  949. });
  950. } else {
  951. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
  952. }
  953. },
  954. setGLJSelection: function (args, newVal) {
  955. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {
  956. this.addGLJsSelection(args, newVal);
  957. } else {
  958. this.replaceGLJSelection(args, newVal);
  959. }
  960. },
  961. addGLJsSelection: function (args, newVal) {
  962. var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
  963. if (newVal == 1) {
  964. this.GLJSelection.push(con_key);
  965. this.gljLibSheetData[args.row].select = 1;
  966. } else if (newVal == 0) {
  967. _.pull(this.GLJSelection, con_key);
  968. this.gljLibSheetData[args.row].select = 0;
  969. }
  970. },
  971. replaceGLJSelection: function (args, newVal) {
  972. var me = this;
  973. var oldSelection = this.GLJSelection[0];
  974. if (newVal == 0) {
  975. args.sheet.getCell(args.row, args.col).value(1);
  976. return;
  977. }
  978. this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
  979. this.gljLibSheetData[args.row].select = 1;
  980. var oindex = _.findIndex(this.gljLibSheetData, function (item) {
  981. var i_key = me.getIndex(item, gljLibKeyArray);
  982. return oldSelection == i_key;
  983. });
  984. if (oindex != -1) {
  985. args.sheet.getCell(oindex, args.col).value(0);
  986. this.gljLibSheetData[oindex].select = 0;
  987. } else {
  988. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  989. var i_key = me.getIndex(item, gljLibKeyArray);
  990. return oldSelection == i_key;
  991. });
  992. oldData ? oldData.select = 0 : "";
  993. }
  994. },
  995. filterLibGLJByType: function () {
  996. var me = this;
  997. var selected = me.sheetData[gljContextMenu.selectedRow];
  998. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljType': selected.type});
  999. },
  1000. getComboData: function (gljDistType) {
  1001. let me = this;
  1002. let distType;
  1003. let distTypeTree = {
  1004. prefix: 'gljType',
  1005. distTypes: {},
  1006. comboDatas: [],
  1007. distTypesArr: []
  1008. };
  1009. gljDistType.forEach(function (typeData) {
  1010. let typeObj = {
  1011. data: typeData,
  1012. children: [],
  1013. parent: null
  1014. }
  1015. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  1016. distTypeTree.distTypesArr.push(typeObj);
  1017. });
  1018. gljDistType.forEach(function (typeData) {
  1019. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  1020. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  1021. if (parent) {
  1022. distType.parent = parent;
  1023. parent.children.push(distType);
  1024. }
  1025. });
  1026. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  1027. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  1028. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  1029. }
  1030. });
  1031. return distTypeTree;
  1032. },
  1033. doInsertGLJ: function () {
  1034. var me = this;
  1035. var selected = projectObj.project.mainTree.selected;
  1036. var project = projectObj.project;
  1037. if (me.GLJSelection.length <= 0) {
  1038. return;
  1039. }
  1040. $("#glj_tree_div").modal('hide');
  1041. $.bootstrapLoading.start();
  1042. project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (parentNodeID,nextNodeID,data) {
  1043. let newNode=null;
  1044. for (let r_glj of data) {
  1045. r_glj.quantity = r_glj.quantity + "";
  1046. project.Ration.datas.push(r_glj);
  1047. }//要先更新树节点工程量,加载项目工料机并计算消耗量才有值
  1048. project.projectGLJ.loadData(function () {
  1049. for(let r_glj of data){
  1050. r_glj = me.setGLJPrice(r_glj);//设置工料机价格
  1051. r_glj.marketUnitFee = r_glj.marketPrice;
  1052. newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
  1053. newNode.source = r_glj;
  1054. newNode.sourceType = project.Ration.getSourceType();
  1055. newNode.data = r_glj;
  1056. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  1057. }
  1058. project.calcProgram.calcLeafAndSave(newNode.parent);//计算父级清单的所有子节点
  1059. projectObj.mainController.refreshTreeNode([newNode]);
  1060. if(me.hasComposition(newNode.data,true)){
  1061. me.showMixRatio(newNode);
  1062. }else {
  1063. me.showRationGLJSheetData();
  1064. }
  1065. $.bootstrapLoading.end();
  1066. });
  1067. })
  1068. },
  1069. doAddGLJ: function () {
  1070. var selected = projectObj.project.mainTree.selected;
  1071. var project = projectObj.project;
  1072. gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
  1073. var rg = _.find(gljOprObj.sheetData, function (item) {
  1074. var i_key = gljOprObj.getIndex(item, gljKeyArray);
  1075. return n == i_key
  1076. })
  1077. return rg ? false : true;
  1078. })
  1079. if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
  1080. $("#glj_tree_div").modal('hide');
  1081. project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
  1082. if (result) {
  1083. selected.data.adjustState = result.adjustState;
  1084. //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
  1085. project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
  1086. gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
  1087. project.projectGLJ.loadData(function () {
  1088. project.ration_glj.addToMainTree(result.showData);
  1089. gljOprObj.showRationGLJSheetData();
  1090. project.calcProgram.calcAndSave(selected);
  1091. projectObj.mainController.refreshTreeNode([selected]);
  1092. $.bootstrapLoading.end();
  1093. });
  1094. }
  1095. });//doc.rationID=selected.data.ID;
  1096. } else {
  1097. $("#glj_tree_div").modal('hide');
  1098. }
  1099. },
  1100. doReplaceGLJ: function () {
  1101. var me = this;
  1102. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1103. var project = projectObj.project;
  1104. var selectCode = gljOprObj.GLJSelection[0];
  1105. var selected = projectObj.project.mainTree.selected;
  1106. $("#glj_tree_div").modal('hide');
  1107. project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
  1108. if (result) {
  1109. //result.adjustState;
  1110. var glj_list = projectObj.project.ration_glj.datas;
  1111. var data = result.data;
  1112. var index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
  1113. var list_index = _.findIndex(glj_list, {'ID': data.ID});
  1114. var nodes = [selected];
  1115. gljOprObj.sheetData[index] = data;
  1116. glj_list[list_index] = data;
  1117. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  1118. gljOprObj.showRationGLJSheetData();
  1119. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  1120. var node = project.ration_glj.findGLJNodeByID(data.ID);
  1121. if (node) {
  1122. project.ration_glj.transferToNodeData(data);
  1123. node.source = data;
  1124. node.data = data;
  1125. }
  1126. node ? nodes.push(node) : "";
  1127. }
  1128. //project.ration_glj.addToMainTree(data);
  1129. selected.data.adjustState = result.adjustState;
  1130. projectObj.mainController.refreshTreeNode(nodes);
  1131. project.calcProgram.calcAndSave(selected);
  1132. $.bootstrapLoading.end();
  1133. });
  1134. }
  1135. })
  1136. },
  1137. doMReplaceGLJ: function () {
  1138. var me = this;
  1139. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1140. var project = projectObj.project;
  1141. var selectCode = me.GLJSelection[0];
  1142. $("#glj_tree_div").modal('hide');
  1143. project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result) {
  1144. var data = result.data;
  1145. var stateList = result.stateList;
  1146. var n_index = me.getIndex(data.query, gljKeyArray);
  1147. var nodes = [];
  1148. _.forEach(project.ration_glj.datas, function (t) {
  1149. var t_index = me.getIndex(t, gljKeyArray);
  1150. if (n_index == t_index) {
  1151. me.updateProperty(t, data.doc);
  1152. if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
  1153. project.ration_glj.transferToNodeData(t);
  1154. var node = project.ration_glj.findGLJNodeByID(t.ID);
  1155. node ? nodes.push(node):'';
  1156. }
  1157. }
  1158. })
  1159. project.projectGLJ.loadData(function () {
  1160. me.showRationGLJSheetData();
  1161. var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
  1162. project.calcProgram.calcRationsAndSave(rationNodes);
  1163. $.bootstrapLoading.end();
  1164. });
  1165. })
  1166. },
  1167. updateProperty: function (obj, doc) {
  1168. _.forEach(doc, function (n, key) {
  1169. obj[key] = n;
  1170. });
  1171. },
  1172. refreshStateAfterMreplace: function (stateList, gljNodes) {
  1173. var nodes = [];
  1174. var rationNodes = [];
  1175. _.forEach(stateList, function (s) {
  1176. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1177. return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
  1178. })
  1179. if (node) {
  1180. node.data.adjustState = s.adjustState;
  1181. nodes.push(node);
  1182. rationNodes.push(node);
  1183. }
  1184. });
  1185. gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
  1186. projectObj.mainController.refreshTreeNode(nodes);
  1187. return rationNodes;
  1188. },
  1189. refreshView: function () {
  1190. this.showRationGLJData();
  1191. },
  1192. //
  1193. refreshTreeNode: function (obj) {
  1194. if (!obj) {
  1195. return;
  1196. }
  1197. var objectArray = [];
  1198. var nodes = [];
  1199. if (obj instanceof Array) {
  1200. objectArray.concat(obj);
  1201. } else {
  1202. objectArray.push(obj);
  1203. }
  1204. for (let o of objectArray) {
  1205. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1206. return n.sourceType == o.type && n.data.ID == o.ID;
  1207. })
  1208. if (node) {
  1209. for (var k in o.data) {
  1210. node.data[k] = o.data[k];
  1211. }
  1212. nodes.push(node);
  1213. }
  1214. }
  1215. projectObj.mainController.refreshTreeNode(nodes);
  1216. return nodes;
  1217. },
  1218. getTreeNodeCellType: function (data) {
  1219. var ns = GC.Spread.Sheets;
  1220. var rectW = 10;
  1221. var rectH = 10;
  1222. var margin = 3;
  1223. function TreeNodeCellType() {
  1224. }
  1225. function drowRect(ctx, x, y, w, h) {
  1226. ctx.save();
  1227. ctx.strokeStyle = "gray";
  1228. ctx.translate(0.5, 0.5);
  1229. ctx.beginPath();
  1230. var rectX = x + margin;
  1231. var rectY = y + Math.round(h / 2) - rectH / 2;
  1232. ctx.moveTo(rectX, rectY);
  1233. ctx.lineTo(rectX, rectY + rectH);
  1234. ctx.lineTo(rectX + rectW, rectY + rectH);
  1235. ctx.lineTo(rectX + rectW, rectY);
  1236. ctx.lineTo(rectX, rectY);
  1237. ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
  1238. ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
  1239. ctx.stroke();
  1240. ctx.restore();
  1241. }
  1242. function drowSymbol(ctx, x, y, w, h, collapsed) {
  1243. ctx.save();
  1244. ctx.strokeStyle = "#000000";
  1245. ctx.translate(0.5, 0.5);
  1246. ctx.beginPath();
  1247. ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
  1248. ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
  1249. var rectY = y + Math.round(h / 2) - rectH / 2;
  1250. if (collapsed) {
  1251. ctx.moveTo(x + margin + rectW / 2, rectY + 2);
  1252. ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
  1253. }
  1254. ctx.stroke();
  1255. ctx.restore();
  1256. }
  1257. function drowSubItem(ctx, x, y, w, h, offset, nextItem) {
  1258. offset += 6;
  1259. ctx.save();
  1260. ctx.strokeStyle = "gray";
  1261. ctx.translate(0.5, 0.5);
  1262. ctx.beginPath();
  1263. ctx.moveTo(x + offset, y);
  1264. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1265. offset += 9;
  1266. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1267. if (nextItem && nextItem.isMixRatio) {
  1268. ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
  1269. ctx.lineTo(x + offset - 9, y + h);
  1270. }
  1271. ctx.stroke();
  1272. ctx.restore();
  1273. return offset;
  1274. }
  1275. TreeNodeCellType.prototype = new ns.CellTypes.Text();
  1276. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  1277. if (value != null) {
  1278. var offset = margin + rectW + 6;
  1279. var recode = data[options.row];
  1280. if (recode && recode.hasOwnProperty('subList')) {
  1281. drowRect(ctx, x, y, w, h);
  1282. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
  1283. drowSymbol(ctx, x, y, w, h, collapsed);
  1284. } else if (recode && recode.isMixRatio) {
  1285. offset = drowSubItem(ctx, x, y, w, h, offset, data[options.row + 1]);
  1286. offset += 1;
  1287. }
  1288. ctx.fillText(value, x + offset + ctx.measureText(value).width, y + h - 5);
  1289. }
  1290. };
  1291. // override getHitInfo to allow cell type get mouse messages
  1292. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1293. return {
  1294. x: x,
  1295. y: y,
  1296. row: context.row,
  1297. col: context.col,
  1298. cellStyle: cellStyle,
  1299. cellRect: cellRect,
  1300. sheetArea: context.sheetArea
  1301. };
  1302. };
  1303. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1304. var recode = data[hitinfo.row];
  1305. if (recode && recode.hasOwnProperty('subList')) {
  1306. var hoffset = hitinfo.cellRect.x + 3;
  1307. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1308. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;
  1309. collapsed = !collapsed
  1310. recode.collapsed = collapsed;
  1311. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1312. hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
  1313. hitinfo.sheet.invalidateLayout();
  1314. hitinfo.sheet.repaint();
  1315. }
  1316. }
  1317. };
  1318. return new TreeNodeCellType()
  1319. },
  1320. marketPriceReadOnly: function (node) {
  1321. let hasCom = false;
  1322. if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
  1323. hasCom = this.hasComposition(node.data,true);
  1324. }else {
  1325. hasCom = this.hasComposition(node.data);
  1326. }
  1327. return hasCom|| node.data.isEstimate == 1;
  1328. }
  1329. }
  1330. $(function () {
  1331. $('#glj_tree_div').on('shown.bs.modal', function (e) {
  1332. if (gljOprObj.gljLibSpresd == undefined) {
  1333. gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
  1334. gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
  1335. gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
  1336. gljOprObj.gljLibSheet.options.isProtected = true;
  1337. gljOprObj.gljLibSheet.name('glj_lib');
  1338. }
  1339. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1340. var selected = null;
  1341. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {
  1342. gljOprObj.GLJSelection = [];
  1343. } else {
  1344. selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1345. var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
  1346. gljOprObj.GLJSelection = [connect_key];
  1347. gljOprObj.filterLibGLJByType();
  1348. }
  1349. if (selected != null) {
  1350. var s_key = gljOprObj.getIndex(selected, gljLibKeyArray);
  1351. var r = _.find(gljOprObj.gljLibSheetData, function (item) {
  1352. var item_key = gljOprObj.getIndex(item, gljKeyArray);
  1353. return s_key == item_key;
  1354. });
  1355. r ? r.select = 1 : "";
  1356. }
  1357. gljOprObj.showLibGLJSheetData();
  1358. });
  1359. $('#glj_tree_div').on('hidden.bs.modal', function () {
  1360. $('#gljSearchKeyword').val('');
  1361. });
  1362. $('.glj-radio').change(function () {
  1363. let val = $("input[name='glj']:checked").val();
  1364. if (val == 'allGljs') {
  1365. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1366. gljOprObj.filterLibGLJSheetData();
  1367. gljOprObj.showLibGLJSheetData();
  1368. } else {
  1369. gljOprObj.gljLibSheetData = gljOprObj[val];
  1370. gljOprObj.filterLibGLJSheetData();
  1371. gljOprObj.showLibGLJSheetData();
  1372. }
  1373. })
  1374. //工料机搜索
  1375. $('#gljSearchKeyword').change(function () {
  1376. gljOprObj.filterLibGLJSheetData();
  1377. gljOprObj.showLibGLJSheetData();
  1378. });
  1379. $('#gljSearchKeyword').bind('keypress', function (e) {
  1380. if(e.keyCode === 13){
  1381. $(this).blur();
  1382. return false;
  1383. }
  1384. });
  1385. $('#glj_selected_conf').click(function () {
  1386. if (gljOprObj.GLJSelection.length < 1) {
  1387. return;
  1388. }
  1389. if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
  1390. gljOprObj.doInsertGLJ();
  1391. } else if ($('#actionType').val() == 'add') { //添加工料机
  1392. gljOprObj.doAddGLJ();
  1393. } else if ($('#actionType').val() == 'replace') {//替换工料机
  1394. gljOprObj.doReplaceGLJ();
  1395. } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
  1396. gljOprObj.doMReplaceGLJ();
  1397. }
  1398. })
  1399. $('#class_selected_conf').click(function () {
  1400. var gljClass = $('#selected_class').val();
  1401. var glj = gljOprObj.selectedGLJClass;
  1402. if (glj && gljClass && gljClass != "") {
  1403. //保存到我的工料机库
  1404. /*1 检查是否有组成物
  1405. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  1406. * 3 保存
  1407. * */
  1408. var newItem = {
  1409. code: glj.code,
  1410. name: glj.name,
  1411. specs: glj.specs,
  1412. unit: glj.unit,
  1413. basePrice: glj.basePrice,
  1414. gljType: glj.type,
  1415. shortName: glj.shortName,
  1416. component: [],
  1417. gljClass: gljClass
  1418. };
  1419. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  1420. for (var i = 0; i < glj.subList.length; i++) {
  1421. let tem = {
  1422. ID: glj.subList[i].GLJID,
  1423. consumeAmt: glj.rationItemQuantity,
  1424. isStd: true
  1425. }
  1426. newItem.component.push(tem);
  1427. }
  1428. }
  1429. var data = getcmpUpdateData([newItem]);
  1430. $.bootstrapLoading.start();
  1431. var callback = function (data) {
  1432. $("#glj_class_div").modal('hide');
  1433. $.bootstrapLoading.end();
  1434. }
  1435. CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
  1436. $.bootstrapLoading.end();
  1437. });
  1438. }
  1439. })
  1440. $('#glj_class_div').on('hidden.bs.modal', function (e) {
  1441. gljOprObj.selectedGLJClass = null;
  1442. $('#class_selected_conf').attr("disabled", "disabled");
  1443. $('#selected_class').val("");
  1444. })
  1445. function getcmpUpdateData(items) {
  1446. var data = {
  1447. "updateItems": [],
  1448. "removeIds": []
  1449. }
  1450. data.addItems = items;
  1451. return data;
  1452. }
  1453. })
  1454. function operationWithRound(value1,value2,field,symble) {
  1455. let decimal = getDecimal(field);
  1456. value1 = scMathUtil.roundForObj(value1,decimal);
  1457. value2 = scMathUtil.roundForObj(value2,decimal);
  1458. let result;
  1459. switch (symble){
  1460. case "+" :
  1461. result=scMathUtil.roundForObj(value1 + value2,decimal);
  1462. break;
  1463. case "-":
  1464. result=scMathUtil.roundForObj(value1 - value2,decimal);
  1465. break;
  1466. case "*":
  1467. result=scMathUtil.roundForObj(value1 * value2,decimal);
  1468. break;
  1469. case "/":
  1470. result=scMathUtil.roundForObj(value1 / value2,decimal);
  1471. break
  1472. }
  1473. return result;
  1474. }
  1475. function getDecimal(fieldID, node) {
  1476. if (node) {
  1477. return decimalObj.decimal(fieldID, node);
  1478. } else if (fieldID.indexOf(".") != -1) {
  1479. var keyArray = fieldID.split(".");
  1480. return decimalObj[keyArray[0]][keyArray[1]];
  1481. } else {
  1482. return decimalObj.decimal(fieldID);
  1483. }
  1484. }
  1485. function sortRationGLJ(list) {
  1486. list = _.sortByAll(list, [function (item) {
  1487. return item.type + "";
  1488. }, "code"])
  1489. return list;
  1490. }
  1491. function compareRationGLJ(a, b) {
  1492. if ((a.type + "") < (b.type + "")) {
  1493. return true
  1494. }
  1495. if ((a.type + "") == (b.type + "")) {
  1496. if (a.code < b.code) {
  1497. return true
  1498. }
  1499. }
  1500. return false;
  1501. }