glj_view.js 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555
  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. }, 200);
  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. data.marketUnitFee = data.marketPrice;//更新树节点市场单价列的值
  746. return data;
  747. },
  748. getBasePrice:function (treeNode) {//造价书中的工料机修改的节点要用到
  749. let proGLJ = projectObj.project.projectGLJ;
  750. let glj =_.find(proGLJ.datas.gljList, {'id': treeNode.data.projectGLJID});
  751. if(this.calcPriceDiff(glj)==true){
  752. return proGLJ.getBasePrice(glj);
  753. }else {
  754. return scMathUtil.roundForObj(treeNode.data.marketUnitFee,getDecimal("glj.unitPrice"));
  755. }
  756. },
  757. calcPriceDiff:function (glj) {
  758. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  759. return gljUtil.calcPriceDiff(glj,calcOptions);
  760. },
  761. getIndex(obj, pops){
  762. let t_index = '';
  763. let k_arr = [];
  764. for (let p of pops) {
  765. let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
  766. k_arr.push(tmpK);
  767. }
  768. t_index = k_arr.join("|-|");
  769. return t_index;
  770. },
  771. getConditionByKey(conKey){//将连接字符串转换成对象
  772. let valueArray = conKey.split("|-|");
  773. let obj ={};
  774. for(let i = 0;i<valueArray.length;i++){
  775. if(valueArray[i]!='null'){
  776. if(gljKeyArray[i]=='type'){
  777. valueArray[i] = parseInt(valueArray[i]);
  778. }
  779. obj[gljKeyArray[i]]=valueArray[i];
  780. }
  781. }
  782. return obj;
  783. },
  784. getMixRationShowDatas: function (mixRatioList, projectGljs) {
  785. var temRationGLJs = [];
  786. for (var i = 0; i < mixRatioList.length; i++) {
  787. var pg = _.find(projectGljs, {
  788. 'code': mixRatioList[i].code,
  789. 'name': mixRatioList[i].name,
  790. 'specs': mixRatioList[i].specs,
  791. 'type': mixRatioList[i].type,
  792. 'unit': mixRatioList[i].unit
  793. });//改关联关系
  794. var tem = {
  795. projectGLJID: pg.id,
  796. code: pg.code,
  797. name: pg.name,
  798. specs: pg.specs,
  799. unit: pg.unit,
  800. type:mixRatioList[i].type,
  801. shortName: projectObj.project.projectGLJ.getShortNameByID(mixRatioList[i].type),
  802. consumption:mixRatioList[i].consumption,
  803. rationItemQuantity: mixRatioList[i].consumption,
  804. // quantity:mixRatioList[i].consumption,
  805. /* basePrice: pg.unit_price.base_price,
  806. marketPrice: pg.unit_price.market_price,
  807. adjustPrice: pg.adjust_price,*/
  808. //isEstimate: pg.is_evaluate,
  809. isMixRatio: true,
  810. isAdd: pg.unit_price.is_add,
  811. GLJID: pg.glj_id
  812. };
  813. if(projectObj.project.projectGLJ.isEstimateType(pg.type)){
  814. tem.isEstimate = pg.is_evaluate;
  815. }
  816. this.setGLJPrice(tem,pg);
  817. temRationGLJs.push(tem);
  818. }
  819. temRationGLJs = _.sortBy(temRationGLJs, 'code');
  820. return temRationGLJs;
  821. },
  822. showQuantityDetailData: function (node) {
  823. var details = [];
  824. node = node ? node : projectObj.project.mainTree.selected;
  825. var quantity_detail = projectObj.project.quantity_detail;
  826. if (node.sourceType == ModuleNames.ration) {
  827. details = _.filter(quantity_detail.datas, {'rationID': node.data.ID});
  828. } else if (node.sourceType == ModuleNames.bills) {
  829. details = _.filter(quantity_detail.datas, {'billID': node.data.ID});
  830. }
  831. details = _.sortBy(details, 'seq');
  832. sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
  833. this.detailData = details;
  834. if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
  835. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
  836. }
  837. },
  838. clearSheetData: function () {
  839. sheetCommonObj.showData(this.sheet, this.setting, []);
  840. installationFeeObj.rationInstallSheet.setRowCount(0);//清除combobox cell
  841. sheetCommonObj.showData(installationFeeObj.rationInstallSheet, installationFeeObj.rationInstallSetting, []);
  842. // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
  843. this.sheetData = [];
  844. installationFeeObj.rationInstallData = [];
  845. //this.detailData=[];
  846. },
  847. updateRationGLJ: function (args) {
  848. var me = this;
  849. var updateField = me.setting.header[args.col].dataCode;
  850. var recode = me.sheetData[args.row];
  851. var newval;
  852. if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
  853. if (args.editingText == null) {
  854. updateField == 'marketPrice' ? newval = 0 : newval = "";
  855. } else {
  856. var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : getDecimal("glj.unitPrice");
  857. newval = number_util.checkNumberValue(args.editingText, decimal);
  858. if (newval == null) {
  859. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  860. return;
  861. }
  862. }
  863. } else {
  864. if (updateField == 'name' || updateField == 'unit') {
  865. if (args.editingText === null) {
  866. alert(me.setting.header[args.col].headerName + '不能为空!');
  867. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  868. return;
  869. }
  870. }
  871. newval = args.editingText == null ? "" : args.editingText;
  872. }
  873. if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
  874. return
  875. }
  876. if (updateField == 'marketPrice' || updateField == 'basePrice') {
  877. projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
  878. } else {
  879. projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
  880. }
  881. },
  882. updateRationTypeGLJ: function (value, node, fieldName,editingText) {
  883. let newval;
  884. let updatePrice = false;
  885. if (fieldName == "marketUnitFee") {
  886. updatePrice = true;
  887. if (value == null) {
  888. newval = 0;
  889. } else {
  890. var decimal = getDecimal("glj.unitPrice");
  891. newval = number_util.checkNumberValue(value, decimal);
  892. }
  893. } else {
  894. if (value != null) {
  895. projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value,editingText);
  896. return;
  897. //update
  898. }
  899. }
  900. if (newval && updatePrice == true) {
  901. projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
  902. return
  903. }
  904. projectObj.mainController.refreshTreeNode([node]);
  905. },
  906. updateIsEstimate:function (args, newval) {
  907. var me = gljOprObj;
  908. if(me.setting.header[args.col].dataCode=="isEstimate"){
  909. var pspread= new ProjectGLJSpread();
  910. var recode = me.sheetData[args.row];
  911. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  912. let glj = _.find(projectGljs, {'id': recode.projectGLJID});
  913. if(glj){
  914. glj["is_evaluate"]=newval;
  915. args.fromRG=true;
  916. pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
  917. }
  918. }
  919. },
  920. showLibGLJSheetData: function () {
  921. this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
  922. sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
  923. this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
  924. },
  925. filterLibGLJSheetData: function () {
  926. let me = this;
  927. let val = $("input[name='glj']:checked").val();
  928. if (val == 'allGljs') {
  929. me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
  930. } else {
  931. me.gljLibSheetData = me[val];
  932. }
  933. if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
  934. me.filterLibGLJByType();
  935. }else if($('#actionType').val() == 'addMix'){
  936. projectGljObject.filterLibGLJForMixRatio();
  937. }
  938. //文本筛选
  939. let searchStr = $('#gljSearchKeyword').val();
  940. if(searchStr && searchStr.trim() != ''){
  941. let reg = new RegExp(searchStr);
  942. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  943. return reg.test(data.code) || reg.test(data.name);
  944. });
  945. }
  946. if (me.gljCurTypeId == undefined) {
  947. return;
  948. }
  949. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  950. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  951. return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
  952. });
  953. } else {
  954. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
  955. }
  956. },
  957. setGLJSelection: function (args, newVal) {
  958. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert'|| $('#actionType').val() == 'addMix') {
  959. this.addGLJsSelection(args, newVal);
  960. } else {
  961. this.replaceGLJSelection(args, newVal);
  962. }
  963. },
  964. addGLJsSelection: function (args, newVal) {
  965. var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
  966. if (newVal == 1) {
  967. this.GLJSelection.push(con_key);
  968. this.gljLibSheetData[args.row].select = 1;
  969. } else if (newVal == 0) {
  970. _.pull(this.GLJSelection, con_key);
  971. this.gljLibSheetData[args.row].select = 0;
  972. }
  973. },
  974. replaceGLJSelection: function (args, newVal) {
  975. var me = this;
  976. var oldSelection = this.GLJSelection[0];
  977. if (newVal == 0) {
  978. args.sheet.getCell(args.row, args.col).value(1);
  979. return;
  980. }
  981. this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
  982. this.gljLibSheetData[args.row].select = 1;
  983. var oindex = _.findIndex(this.gljLibSheetData, function (item) {
  984. var i_key = me.getIndex(item, gljLibKeyArray);
  985. return oldSelection == i_key;
  986. });
  987. if (oindex != -1) {
  988. args.sheet.getCell(oindex, args.col).value(0);
  989. this.gljLibSheetData[oindex].select = 0;
  990. } else {
  991. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  992. var i_key = me.getIndex(item, gljLibKeyArray);
  993. return oldSelection == i_key;
  994. });
  995. oldData ? oldData.select = 0 : "";
  996. }
  997. },
  998. filterLibGLJByType: function () {
  999. var me = this;
  1000. var selected = me.sheetData[gljContextMenu.selectedRow];
  1001. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljType': selected.type});
  1002. },
  1003. getComboData: function (gljDistType) {
  1004. let me = this;
  1005. let distType;
  1006. let distTypeTree = {
  1007. prefix: 'gljType',
  1008. distTypes: {},
  1009. comboDatas: [],
  1010. distTypesArr: []
  1011. };
  1012. gljDistType.forEach(function (typeData) {
  1013. let typeObj = {
  1014. data: typeData,
  1015. children: [],
  1016. parent: null
  1017. }
  1018. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  1019. distTypeTree.distTypesArr.push(typeObj);
  1020. });
  1021. gljDistType.forEach(function (typeData) {
  1022. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  1023. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  1024. if (parent) {
  1025. distType.parent = parent;
  1026. parent.children.push(distType);
  1027. }
  1028. });
  1029. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  1030. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  1031. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  1032. }
  1033. });
  1034. return distTypeTree;
  1035. },
  1036. doInsertGLJ: function () {
  1037. var me = this;
  1038. var selected = projectObj.project.mainTree.selected;
  1039. var project = projectObj.project;
  1040. if (me.GLJSelection.length <= 0) {
  1041. return;
  1042. }
  1043. $("#glj_tree_div").modal('hide');
  1044. $.bootstrapLoading.start();
  1045. project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (parentNodeID,nextNodeID,data) {
  1046. let newNode=null;
  1047. for (let r_glj of data) {
  1048. r_glj.quantity = r_glj.quantity + "";
  1049. project.Ration.datas.push(r_glj);
  1050. }//要先更新树节点工程量,加载项目工料机并计算消耗量才有值
  1051. project.projectGLJ.loadData(function () {
  1052. for(let r_glj of data){
  1053. r_glj = me.setGLJPrice(r_glj);//设置工料机价格
  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.calcNodesAndSave(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. x = x + offset;
  1295. w = w - offset;
  1296. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1297. }
  1298. };
  1299. // override getHitInfo to allow cell type get mouse messages
  1300. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1301. return {
  1302. x: x,
  1303. y: y,
  1304. row: context.row,
  1305. col: context.col,
  1306. cellStyle: cellStyle,
  1307. cellRect: cellRect,
  1308. sheetArea: context.sheetArea
  1309. };
  1310. };
  1311. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1312. var recode = data[hitinfo.row];
  1313. if (recode && recode.hasOwnProperty('subList')) {
  1314. var hoffset = hitinfo.cellRect.x + 3;
  1315. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1316. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;
  1317. collapsed = !collapsed
  1318. recode.collapsed = collapsed;
  1319. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1320. hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
  1321. hitinfo.sheet.invalidateLayout();
  1322. hitinfo.sheet.repaint();
  1323. }
  1324. }
  1325. };
  1326. return new TreeNodeCellType()
  1327. },
  1328. marketPriceReadOnly: function (node) {
  1329. let hasCom = false;
  1330. if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
  1331. hasCom = this.hasComposition(node.data,true);
  1332. }else {
  1333. hasCom = this.hasComposition(node.data);
  1334. }
  1335. return hasCom|| node.data.isEstimate == 1;
  1336. }
  1337. }
  1338. $(function () {
  1339. $('#glj_tree_div').on('shown.bs.modal', function (e) {
  1340. if (gljOprObj.gljLibSpresd == undefined) {
  1341. gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
  1342. gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
  1343. gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
  1344. gljOprObj.gljLibSheet.options.isProtected = true;
  1345. gljOprObj.gljLibSheet.name('glj_lib');
  1346. }
  1347. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1348. let selections = [],selectMap = {};
  1349. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {//插入,添加
  1350. gljOprObj.GLJSelection = [];
  1351. } else if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){//替换、批量替换
  1352. let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1353. var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
  1354. gljOprObj.GLJSelection = [connect_key];
  1355. selectMap[connect_key] = true;
  1356. gljOprObj.filterLibGLJByType();
  1357. }else if($('#actionType').val() =='addMix'){//添加组成物
  1358. gljOprObj.GLJSelection = [];
  1359. projectGljObject.filterLibGLJForMixRatio();
  1360. /*selections = projectGljObject.mixRatioData; 添加组成物的时候先不选中
  1361. gljOprObj.GLJSelection = [];
  1362. for(let s of selections){
  1363. let s_key = gljOprObj.getIndex(s, gljKeyArray);
  1364. selectMap[s_key] = true;
  1365. gljOprObj.GLJSelection.push(s_key);
  1366. }*/
  1367. }
  1368. for(let item of gljOprObj.gljLibSheetData){
  1369. let item_key = gljOprObj.getIndex(item, gljLibKeyArray);
  1370. if(selectMap[item_key]){
  1371. item.select = 1 ;
  1372. }
  1373. }
  1374. gljOprObj.showLibGLJSheetData();
  1375. });
  1376. $('#glj_tree_div').on('hidden.bs.modal', function () {
  1377. $('#gljSearchKeyword').val('');
  1378. });
  1379. $('.glj-radio').change(function () {
  1380. let val = $("input[name='glj']:checked").val();
  1381. if (val == 'allGljs') {
  1382. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1383. gljOprObj.filterLibGLJSheetData();
  1384. gljOprObj.showLibGLJSheetData();
  1385. } else {
  1386. gljOprObj.gljLibSheetData = gljOprObj[val];
  1387. gljOprObj.filterLibGLJSheetData();
  1388. gljOprObj.showLibGLJSheetData();
  1389. }
  1390. })
  1391. //工料机搜索
  1392. $('#gljSearchKeyword').change(function () {
  1393. gljOprObj.filterLibGLJSheetData();
  1394. gljOprObj.showLibGLJSheetData();
  1395. });
  1396. $('#gljSearchKeyword').bind('keypress', function (e) {
  1397. if(e.keyCode === 13){
  1398. $(this).blur();
  1399. return false;
  1400. }
  1401. });
  1402. $('#glj_selected_conf').click(function () {
  1403. if (gljOprObj.GLJSelection.length < 1) {
  1404. return;
  1405. }
  1406. if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
  1407. gljOprObj.doInsertGLJ();
  1408. } else if ($('#actionType').val() == 'add') { //添加工料机
  1409. gljOprObj.doAddGLJ();
  1410. } else if ($('#actionType').val() == 'replace') {//替换工料机
  1411. gljOprObj.doReplaceGLJ();
  1412. } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
  1413. gljOprObj.doMReplaceGLJ();
  1414. }else if($('#actionType').val() == 'addMix'){
  1415. projectGljObject.addMixRatio();
  1416. }
  1417. })
  1418. $('#class_selected_conf').click(function () {
  1419. var gljClass = $('#selected_class').val();
  1420. var glj = gljOprObj.selectedGLJClass;
  1421. if (glj && gljClass && gljClass != "") {
  1422. //保存到我的工料机库
  1423. /*1 检查是否有组成物
  1424. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  1425. * 3 保存
  1426. * */
  1427. var newItem = {
  1428. code: glj.code,
  1429. name: glj.name,
  1430. specs: glj.specs,
  1431. unit: glj.unit,
  1432. basePrice: glj.basePrice,
  1433. gljType: glj.type,
  1434. shortName: glj.shortName,
  1435. component: [],
  1436. gljClass: gljClass
  1437. };
  1438. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  1439. for (var i = 0; i < glj.subList.length; i++) {
  1440. let tem = {
  1441. ID: glj.subList[i].GLJID,
  1442. consumeAmt: glj.rationItemQuantity,
  1443. isStd: true
  1444. }
  1445. newItem.component.push(tem);
  1446. }
  1447. }
  1448. var data = getcmpUpdateData([newItem]);
  1449. $.bootstrapLoading.start();
  1450. var callback = function (data) {
  1451. $("#glj_class_div").modal('hide');
  1452. $.bootstrapLoading.end();
  1453. }
  1454. CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
  1455. $.bootstrapLoading.end();
  1456. });
  1457. }
  1458. })
  1459. $('#glj_class_div').on('hidden.bs.modal', function (e) {
  1460. gljOprObj.selectedGLJClass = null;
  1461. $('#class_selected_conf').attr("disabled", "disabled");
  1462. $('#selected_class').val("");
  1463. })
  1464. function getcmpUpdateData(items) {
  1465. var data = {
  1466. "updateItems": [],
  1467. "removeIds": []
  1468. }
  1469. data.addItems = items;
  1470. return data;
  1471. }
  1472. })
  1473. function operationWithRound(value1,value2,field,symble) {
  1474. let decimal = getDecimal(field);
  1475. value1 = scMathUtil.roundForObj(value1,decimal);
  1476. value2 = scMathUtil.roundForObj(value2,decimal);
  1477. let result;
  1478. switch (symble){
  1479. case "+" :
  1480. result=scMathUtil.roundForObj(value1 + value2,decimal);
  1481. break;
  1482. case "-":
  1483. result=scMathUtil.roundForObj(value1 - value2,decimal);
  1484. break;
  1485. case "*":
  1486. result=scMathUtil.roundForObj(value1 * value2,decimal);
  1487. break;
  1488. case "/":
  1489. result=scMathUtil.roundForObj(value1 / value2,decimal);
  1490. break
  1491. }
  1492. return result;
  1493. }
  1494. function getDecimal(fieldID, node) {
  1495. if (node) {
  1496. return decimalObj.decimal(fieldID, node);
  1497. } else if (fieldID.indexOf(".") != -1) {
  1498. var keyArray = fieldID.split(".");
  1499. return decimalObj[keyArray[0]][keyArray[1]];
  1500. } else {
  1501. return decimalObj.decimal(fieldID);
  1502. }
  1503. }
  1504. function sortRationGLJ(list) {
  1505. list = _.sortByAll(list, [function (item) {
  1506. return item.type + "";
  1507. }, "code"])
  1508. return list;
  1509. }
  1510. function compareRationGLJ(a, b) {
  1511. if ((a.type + "") < (b.type + "")) {
  1512. return true
  1513. }
  1514. if ((a.type + "") == (b.type + "")) {
  1515. if (a.code < b.code) {
  1516. return true
  1517. }
  1518. }
  1519. return false;
  1520. }