item_increase_fee_view.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /**
  2. * Created by zhang on 2020/1/17.
  3. */
  4. let itemBaseOptions = ["人工费","材料费","机械费","人工费+材料费","人工费+机械费","人工费+材料费","材料费+机械费","人工费+材料费+机械费"];
  5. let itemIncreaseFeeObj = {
  6. settingSpread:null,
  7. itemSetting:{
  8. header:[
  9. {headerName: "名称", headerWidth: 270, dataCode: "name", dataType: "String"},
  10. {headerName: "范围", headerWidth: 70, dataCode: "displayScope",hAlign: "center",dataType: "String",cellType:'cusButton',callback:'selectScope'},
  11. {headerName: "取费基数", headerWidth: 150, dataCode: "base", hAlign: "center", dataType: "String",cellType:'comboBox',options:itemBaseOptions},
  12. {headerName: "系数(%)", headerWidth: 55, dataCode: "coe", hAlign: "center", dataType: "Number",validator:"number"}
  13. ],
  14. view: {
  15. lockColumns: ["name","displayScope"],
  16. rowHeaderWidth:25,
  17. colHeaderHeight:36
  18. },
  19. autoFit:true,
  20. fitRow:['name'],
  21. callback:{
  22. selectScope:function (hitinfo) {
  23. $("#item_increase_scope").modal('show');
  24. }
  25. }
  26. },
  27. settingDatas:[],
  28. scopeSpread:null,
  29. scopeSetting:{
  30. header:[
  31. {headerName: "编码", headerWidth: 250, dataCode: "code", dataType: "String"},
  32. {headerName: "类别", headerWidth: 100, dataCode: "type",hAlign: "center",dataType: "String"},
  33. {headerName: "名称", headerWidth: 300, dataCode: "name", dataType: "String"},
  34. {headerName: "计取", headerWidth: 100, dataCode: "selected", hAlign: "center", dataType: "String",cellType:'checkBox'}
  35. ],
  36. view: {
  37. lockColumns: ["name","code","type","selected"],
  38. rowHeaderWidth:25,
  39. colHeaderHeight:36
  40. }
  41. },
  42. scopeDatas:[],
  43. initSpread:function () {
  44. if(this.settingSpread) return this.settingSpread.refresh();
  45. this.settingSpread = SheetDataHelper.createNewSpread($("#itemIncreaseFee_sheet")[0]);
  46. sheetCommonObj.spreadDefaultStyle(this.settingSpread);
  47. this.settingSheet = this.settingSpread.getSheet(0);
  48. sheetCommonObj.initSheet(this.settingSheet, this.itemSetting, 4);
  49. this.settingSheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onItemSelectionChange);
  50. this.settingSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onItemValueChange);
  51. this.settingSheet.name('itemIncreaseFee_sheet');
  52. if(projectReadOnly){
  53. disableSpread(this.settingSpread);
  54. }
  55. },
  56. initScopeSpread:function () {
  57. if(this.scopeSpread) return this.scopeSpread.refresh();
  58. this.scopeSpread = SheetDataHelper.createNewSpread($("#scopeSheet")[0]);
  59. sheetCommonObj.spreadDefaultStyle(this.scopeSpread);
  60. this.scopeSheet = this.scopeSpread.getSheet(0);
  61. sheetCommonObj.initSheet(this.scopeSheet, this.scopeSetting, 0);
  62. this.scopeSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, this.onScopeCheckBoxClick);
  63. this.scopeSheet.name('scopeSheet');
  64. if(projectReadOnly){
  65. disableSpread(this.scopeSpread);
  66. }
  67. },
  68. getSelectedItem:function () {
  69. let selectedItem = null;
  70. let sel = this.settingSheet.getSelections()[0];
  71. if(sel.row != -1 && this.settingDatas.length>sel.row){
  72. selectedItem = this.settingDatas[sel.row];
  73. }
  74. return selectedItem;
  75. },
  76. showScopeDatas:function () {
  77. let controller = projectObj.mainController, project = projectObj.project;
  78. let allNodes=[];
  79. this.scopeDatas=[];
  80. let selectedItem = this.getSelectedItem();
  81. let fbfcNode = project.Bills.getFBFXNode(controller).source;//分部分项节点
  82. if(fbfcNode){
  83. allNodes.push(fbfcNode);
  84. controller.tree.getAllSubNode(project.Bills.getFBFXNode(controller).source,allNodes);
  85. }
  86. let meaNode = project.Bills.getMeasureNode(controller).source;//措施项目节点
  87. if(meaNode){
  88. allNodes.push(meaNode);
  89. controller.tree.getAllSubNode(project.Bills.getMeasureNode(controller).source,allNodes);
  90. }
  91. for(let row=0;row<allNodes.length;row++){
  92. let node = allNodes[row];
  93. let tem = {
  94. ID:node.data.ID,
  95. ParentID:node.data.ParentID,
  96. code:node.data.code,
  97. name:node.data.name,
  98. type:billText[node.data.type],
  99. selected:0,
  100. collapsed:false,
  101. row:row
  102. };
  103. if(selectedItem && selectedItem.scope&&selectedItem.scope[tem.ID]) tem.selected = 1;
  104. this.scopeDatas.push(tem);
  105. }
  106. this.scopeSheet.setRowCount(this.scopeDatas.length);
  107. sheetCommonObj.showTreeData(this.scopeSheet, this.scopeSetting,this.scopeDatas);
  108. },
  109. onScopeCheckBoxClick:function (sender,args) {
  110. let me = itemIncreaseFeeObj;
  111. let checkboxValue = args.sheet.getCell(args.row, args.col).value();
  112. let newval = 0;
  113. checkboxValue?newval=0:newval=1;
  114. let record = me.scopeDatas[args.row];
  115. let dataMap= _.groupBy(me.scopeDatas,"ParentID");
  116. args.sheet.suspendPaint();
  117. args.sheet.suspendEvent();
  118. cascadeSelected(record,newval);
  119. args.sheet.resumeEvent();
  120. args.sheet.resumePaint();
  121. function cascadeSelected(parent,val) {
  122. args.sheet.getCell(parent.row, args.col).value(val);
  123. parent.selected = val;
  124. if(dataMap[parent.ID]){
  125. for(let c of dataMap[parent.ID]){
  126. cascadeSelected(c,val);
  127. }
  128. }
  129. }
  130. },
  131. onItemSelectionChange:function (sender,args) {
  132. args.sheet.repaint();
  133. },
  134. showDatas:function(datas){
  135. let sel = this.settingSheet.getSelections()[0];
  136. let oldData = sel.row<this.settingDatas.length?this.settingDatas[sel.row]:"";
  137. this.settingSheet.setRowCount(0);
  138. this.settingDatas = datas?datas:this.getItemSettingDatas();
  139. this.setItemForeStyle(this.settingDatas);
  140. sheetCommonObj.showData(this.settingSheet, this.itemSetting,this.settingDatas);
  141. this.settingSheet.setRowCount(this.settingDatas.length);
  142. sel.row = oldData?_.findIndex(this.settingDatas,{'name':oldData.name}):sel.row ;
  143. this.settingSheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
  144. },
  145. setItemForeStyle:function (datas) {
  146. for(let d of datas){
  147. if(_.isEmpty(d.scope)){
  148. d.foreColor = "#ff2a23";
  149. d.styleCol = 1;
  150. }else {
  151. delete d.foreColor;
  152. delete d.styleCol;
  153. }
  154. }
  155. },
  156. getItemSettingDatas:function () {
  157. let datas = [];
  158. if(projectObj.project.property.itemIncreaseSetting){
  159. for(let i of projectObj.project.property.itemIncreaseSetting.setting){
  160. let d = {name:i.name,displayScope:"范围",scope:i.scope,base:i.base,coe:i.coe};
  161. datas.push(d);
  162. }
  163. }
  164. return datas;
  165. },
  166. onItemValueChange:function (sender,args) {
  167. let me = itemIncreaseFeeObj;
  168. let dataCode = me.itemSetting.header[args.col].dataCode;
  169. let value = args.newValue;
  170. let tem = me.settingDatas[args.row];
  171. if (value&&!sheetCommonObj.checkData(args.col,me.itemSetting,value)) {
  172. alert('输入的数据类型不对,请重新输入!');
  173. return me.showDatas(me.settingDatas);
  174. }
  175. if(dataCode == 'coe') {
  176. if (value) value = scMathUtil.roundForObj(value, 2);
  177. }
  178. tem[dataCode] = value;
  179. me.showDatas(me.settingDatas);
  180. me.itemChange = true;
  181. },
  182. confirmScope:function(){
  183. let selectedItem = this.getSelectedItem();
  184. let scope = {};
  185. for(let n of this.scopeDatas){
  186. if(n.selected == 1) scope[n.ID] = true;
  187. }
  188. if(JSON.stringify(scope) != JSON.stringify(selectedItem.scope)) this.itemChange = true;//有改变的情况下才更新
  189. selectedItem.scope=scope;
  190. this.showDatas(this.settingDatas);
  191. },
  192. confirmItemIncreaseSetting:async function () {
  193. if(this.itemChange == true || projectObj.project.property.itemIncreaseSetting.isCalc == false){
  194. let datas = [];
  195. let itemIncreaseSetting = {
  196. isCalc : true,
  197. setting :[]
  198. };
  199. for(let d of this.settingDatas){
  200. itemIncreaseSetting.setting.push({name:d.name,scope:d.scope,base:d.base,coe:d.coe});
  201. }
  202. let tem ={
  203. type:'project',
  204. data:{ID:projectObj.project.ID(),"property.itemIncreaseSetting":itemIncreaseSetting}
  205. };
  206. datas.push(tem);
  207. let changeNodes = this.calcAllItemIncreaseFee(itemIncreaseSetting,datas);
  208. console.log(datas);
  209. let selectedNode = projectObj.project.mainTree.selected;
  210. //刷新缓存和树节点的插入删除
  211. let nodes = await projectObj.project.syncUpdateNodesAndRefresh(datas);
  212. //重新计算
  213. cbTools.refreshFormulaNodes();
  214. projectObj.project.calcProgram.calcNodesAndSave(changeNodes.concat(nodes));
  215. projectObj.mainController.setTreeSelection(selectedNode);
  216. }
  217. },
  218. calcItemIncreaseFeeByNodes:async function (nodes) {
  219. let itemIncreaseSetting = projectObj.project.property.itemIncreaseSetting;
  220. let datas = [];
  221. let refreshNodes=[];
  222. let rationGLJMap ={};
  223. let uniqMap={};
  224. if(!itemIncreaseSetting) return;
  225. if(itemIncreaseSetting.isCalc == false) return;
  226. for (n of nodes){
  227. if(n.sourceType == ModuleNames.ration) n = n.parent;
  228. if(uniqMap[n.data.ID]) continue;//去重复
  229. let newRefreshNodes = this.calcItemIncreasePerNode(n,itemIncreaseSetting,rationGLJMap,datas);
  230. if(newRefreshNodes.length > 0) refreshNodes = refreshNodes.concat(newRefreshNodes);
  231. uniqMap[n.data.ID] = true;
  232. }
  233. if(datas.length >0 || refreshNodes.length > 0){
  234. let nodes = await projectObj.project.syncUpdateNodesAndRefresh(datas);
  235. //重新计算
  236. cbTools.refreshFormulaNodes();
  237. projectObj.project.calcProgram.calcNodesAndSave(refreshNodes.concat(nodes));
  238. }
  239. },
  240. cancelItemIncreaseFee:async function () {
  241. let itemIncreaseSetting = projectObj.project.property.itemIncreaseSetting;
  242. let datas = [];
  243. let refreshNodes = [];
  244. if(itemIncreaseSetting && itemIncreaseSetting.isCalc == true){
  245. itemIncreaseSetting.isCalc = false;
  246. let billNodeMap = {};
  247. let tem ={
  248. type:'project',
  249. data:{ID:projectObj.project.ID(),"property.itemIncreaseSetting":itemIncreaseSetting}
  250. };
  251. datas.push(tem);
  252. for(let s of itemIncreaseSetting.setting){
  253. if(!_.isEmpty(s.scope)){
  254. for (let ID in s.scope){
  255. billNodeMap[ID] = true;//为了去重复
  256. }
  257. }
  258. }
  259. for(let cancelID in billNodeMap){
  260. let tnode = projectObj.project.mainTree.getNodeByID(cancelID);
  261. if(tnode){
  262. let cNode = this.cancelBillNode(tnode,datas);
  263. if(cNode) refreshNodes.push(cNode);
  264. }
  265. }
  266. let selectedNode = projectObj.project.mainTree.selected;
  267. //刷新缓存和树节点的插入删除
  268. await projectObj.project.syncUpdateNodesAndRefresh(datas);
  269. if(refreshNodes.length > 0){
  270. //重新计算
  271. cbTools.refreshFormulaNodes();
  272. projectObj.project.calcProgram.calcNodesAndSave(refreshNodes);
  273. projectObj.mainController.setTreeSelection(selectedNode);
  274. }
  275. }
  276. },
  277. getAllBillsIDMap:function () {
  278. let map = {};
  279. let itemIncreaseSetting = projectObj.project.property.itemIncreaseSetting;
  280. if(itemIncreaseSetting.isCalc == true){
  281. for(let s of itemIncreaseSetting.setting){
  282. if(!_.isEmpty(s.scope)){
  283. for (let ID in s.scope){
  284. map[ID] = true;
  285. }
  286. }
  287. }
  288. }
  289. return map;
  290. },
  291. calcAllItemIncreaseFee : function(setting,datas){
  292. let refreshNodes = [];
  293. let itemIncreaseSetting = setting?setting:projectObj.project.property.itemIncreaseSetting;
  294. let billNodeMap = {},rationGLJMap={};
  295. let cancelBillsIDMap = this.getAllBillsIDMap();
  296. if(itemIncreaseSetting && itemIncreaseSetting.isCalc == true){
  297. //为了不用循环所有节点,先挑出所有受影响的节点
  298. for(let s of itemIncreaseSetting.setting){
  299. if(!_.isEmpty(s.scope)){
  300. for (let ID in s.scope){
  301. billNodeMap[ID] = true;//为了去重复
  302. delete cancelBillsIDMap[ID];
  303. }
  304. }
  305. }
  306. for(let billsID in billNodeMap){
  307. let node = projectObj.project.mainTree.getNodeByID(billsID);
  308. let newRefreshNodes = this.calcItemIncreasePerNode(node,itemIncreaseSetting,rationGLJMap,datas);
  309. if(newRefreshNodes.length > 0) refreshNodes = refreshNodes.concat(newRefreshNodes);
  310. }
  311. //删除取消范围的清单下的子目定额
  312. for(let cancelID in cancelBillsIDMap){
  313. let tnode = projectObj.project.mainTree.getNodeByID(cancelID);
  314. let cNode = this.cancelBillNode(tnode,datas);
  315. if(cNode) refreshNodes.push(cNode);
  316. }
  317. }
  318. return refreshNodes;
  319. },
  320. cancelBillNode:function (node,datas) {
  321. if (node.children.length <= 0) return null;//如果没子项,不用计算
  322. if (node.source.children.length > 0) return null;//如果不是清单叶子节点,不用计算
  323. let isDelete = false;
  324. for(let rationNode of node.children){
  325. if(rationNode.data.code.indexOf("ZMZJF")!= -1){
  326. datas.push({type:ModuleNames.ration,data:{ID:rationNode.data.ID},action:"delete"});
  327. isDelete = true;
  328. }
  329. }
  330. return isDelete == true?node:null;
  331. },
  332. calcItemIncreasePerNode:function (node,setting,rationGLJMap,datas) {
  333. let itemIncreaseSetting = setting ? setting : projectObj.project.property.itemIncreaseSetting;
  334. let refreshNodes = [],rationCodeMap={},FeeMap={},updateDataIDMap={};
  335. if (node.children.length <= 0) return [];//如果没子项,不用计算
  336. if (node.source.children.length > 0) return [];//如果不是清单叶子节点,不用计算
  337. let labourTotal = 0,materialTotal=0,machineTotal=0;
  338. let process = getDecimal("process");
  339. let td = getDecimal("ration.totalPrice");
  340. let gd = getDecimal('glj.quantity');
  341. let preID="",serialNo=1;
  342. for(let rationNode of node.children){
  343. rationCodeMap[rationNode.data.code] = rationNode;
  344. if(rationNode.data.type == rationType.ration || rationNode.data.type == rationType.volumePrice ){//先只汇总定额和量价类型,不考虑自动生成的
  345. //计算人工费,材料费,机械费
  346. if(rationNode.data.feesIndex){
  347. let labour = rationNode.data.feesIndex.labour && rationNode.data.feesIndex.labour.totalFee?parseFloat(rationNode.data.feesIndex.labour.totalFee):0;
  348. let material = rationNode.data.feesIndex.material && rationNode.data.feesIndex.material.totalFee?parseFloat(rationNode.data.feesIndex.material.totalFee):0;
  349. let machine = rationNode.data.feesIndex.machine && rationNode.data.feesIndex.machine.totalFee?parseFloat(rationNode.data.feesIndex.machine.totalFee):0;
  350. labourTotal = scMathUtil.roundForObj(labourTotal + labour,getDecimal("process"));
  351. materialTotal = scMathUtil.roundForObj(materialTotal + material,getDecimal("process"));
  352. machineTotal = scMathUtil.roundForObj(machineTotal + machine,getDecimal("process"));
  353. }
  354. }
  355. if(rationNode.data.type != rationType.itemIncrease ){//计录除了子目增加节点外最后的节点ID,和nexeID
  356. preID = rationNode.data.ID;
  357. serialNo = rationNode.data.serialNo;
  358. }
  359. }
  360. FeeMap['人工费'] = labourTotal;
  361. FeeMap['材料费'] = materialTotal;
  362. FeeMap['机械费'] = machineTotal;
  363. //ZMZJF_1
  364. let s_in = 0;//序列号增长
  365. for(let i = 0; i < itemIncreaseSetting.setting.length;i++){
  366. let s = itemIncreaseSetting.setting[i];
  367. if(s.scope&&s.scope[node.data.ID]){
  368. let feeIndexArry = s.base.split("+");
  369. let total = 0;
  370. for(let index of feeIndexArry){
  371. total = scMathUtil.roundForObj(total + FeeMap[index],process);
  372. }
  373. total = scMathUtil.roundForObj(total,td);
  374. if(s.coe){
  375. let t = scMathUtil.roundForObj(total * s.coe/100,process);
  376. total = scMathUtil.roundForObj(total + t,gd);
  377. }
  378. let seq = i+1;
  379. let code = "ZMZJF_"+seq;
  380. let ZMZJFnode = rationCodeMap[code];
  381. if(total > 0) {
  382. if(ZMZJFnode){//存在的话更新其它人工费消耗量
  383. this.updateItemNode(ZMZJFnode,total,rationGLJMap,datas);
  384. if(s_in>0){
  385. datas.push({type:ModuleNames.ration,data:{ID:ZMZJFnode.data.ID,serialNo:ZMZJFnode.data.serialNo +1}});
  386. } else {//如果s_in>0时,ZMZJFnode会因为有更新而刷新,不用push到refreshNodes里
  387. refreshNodes.push(ZMZJFnode);
  388. }
  389. preID = ZMZJFnode.data.ID;
  390. serialNo = ZMZJFnode.data.serialNo;
  391. }else {//不存在的话插入新的节点
  392. s_in = s_in +1;
  393. serialNo = serialNo+1;
  394. let newRationData = this.inserNewItemNodes(node.data.ID,node.data.quantity,preID,serialNo,code,s.name,total,datas);
  395. preID = newRationData.ID;
  396. }
  397. }else { //如果total小于0,但又存在的话,删除定额(同时后端处理时记得要删除定额工料机)
  398. if(ZMZJFnode){
  399. datas.push({type:ModuleNames.ration,data:{ID:ZMZJFnode.data.ID},action:"delete"});
  400. if(refreshNodes.length == 0) refreshNodes.push(node);//删除时,如果清单下没有定额更新,则刷新清单节点就行
  401. }
  402. }
  403. }
  404. }
  405. return refreshNodes;
  406. },
  407. updateItemNode:function (node,total,rationGLJMap,datas) {
  408. if(_.isEmpty(rationGLJMap)) this.setRationGLJMap(rationGLJMap);
  409. if(rationGLJMap[node.data.ID] && rationGLJMap[node.data.ID].quantity != total){
  410. datas.push({type:ModuleNames.ration_glj,data:{ID:rationGLJMap[node.data.ID].ID,quantity:total}})
  411. }
  412. },
  413. setRationGLJMap:function (rationGLJMap) {
  414. let gljList = projectObj.project.ration_glj.datas;
  415. for (let g of gljList){
  416. if(g.code == 'QTRGF') rationGLJMap[g.rationID] = g;
  417. }
  418. },
  419. inserNewItemNodes:function (billsItemID,billsQuantity,preID,serialNo,code,name,total,datas) {
  420. let Ration = projectObj.project.Ration;
  421. let newRationData = Ration.getTempRationData(Ration.getNewRationID(), billsItemID, serialNo, rationType.itemIncrease);
  422. newRationData.code = code;
  423. newRationData.name=name;
  424. newRationData.unit = '元';
  425. newRationData.quantity = "1";
  426. if(billsQuantity) newRationData.contain = scMathUtil.roundForObj(1/parseFloat(billsQuantity),getDecimal("process"))+"";
  427. newRationData.quantityEXP = '1';
  428. datas.push({type:ModuleNames.ration,data:newRationData,preSiblingID:preID,action:"add",parentID:billsItemID});
  429. let newRationGLJ = {
  430. rationID:newRationData.ID,
  431. billsItemID:billsItemID,
  432. shortName:projectObj.project.projectGLJ.getShortNameByID(gljType.LABOUR),
  433. GLJID:-1,
  434. projectID:newRationData.projectID,
  435. code:'QTRGF',
  436. original_code:'QTRGF',
  437. name:'其它人工费',
  438. specs:'',
  439. unit:'元',
  440. type:gljType.LABOUR,
  441. basePrice:1,
  442. marketPrice:1,
  443. adjCoe:null,
  444. from:'std',
  445. repositoryId:-1,
  446. quantity:total+"",
  447. rationItemQuantity:total+""
  448. };
  449. datas.push({type:ModuleNames.ration_glj,data:newRationGLJ,action:"add"});
  450. return newRationData;
  451. }
  452. };
  453. $(function () {
  454. $('#itemIncreaseFeeDiv').on('shown.bs.modal', function (e) {
  455. itemIncreaseFeeObj.itemChange = false;
  456. itemIncreaseFeeObj.initSpread();
  457. itemIncreaseFeeObj.showDatas();
  458. });
  459. $('#item_increase_scope').on('shown.bs.modal', function (e) {
  460. itemIncreaseFeeObj.initScopeSpread();
  461. itemIncreaseFeeObj.showScopeDatas();
  462. });
  463. $("#select_scope_confirm").click(function () {
  464. itemIncreaseFeeObj.confirmScope();
  465. })
  466. $("#itemIncreaseFeeConfirm").click(function () {
  467. itemIncreaseFeeObj.confirmItemIncreaseSetting();
  468. })
  469. });