glj_view.js 62 KB

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