item_increase_fee_view.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. for (n of nodes){
  226. if(n.sourceType == ModuleNames.ration) n = n.parent;
  227. if(uniqMap[n.data.ID]) continue;//去重复
  228. let newRefreshNodes = this.calcItemIncreasePerNode(n,itemIncreaseSetting,rationGLJMap,datas);
  229. if(newRefreshNodes.length > 0) refreshNodes = refreshNodes.concat(newRefreshNodes);
  230. uniqMap[n.data.ID] = true;
  231. }
  232. if(datas || refreshNodes.length > 0){
  233. let nodes = await projectObj.project.syncUpdateNodesAndRefresh(datas);
  234. //重新计算
  235. cbTools.refreshFormulaNodes();
  236. projectObj.project.calcProgram.calcNodesAndSave(refreshNodes.concat(nodes));
  237. }
  238. },
  239. cancelItemIncreaseFee:async function () {
  240. let itemIncreaseSetting = projectObj.project.property.itemIncreaseSetting;
  241. let datas = [];
  242. let refreshNodes = [];
  243. if(itemIncreaseSetting && itemIncreaseSetting.isCalc == true){
  244. itemIncreaseSetting.isCalc = false;
  245. let billNodeMap = {};
  246. let tem ={
  247. type:'project',
  248. data:{ID:projectObj.project.ID(),"property.itemIncreaseSetting":itemIncreaseSetting}
  249. };
  250. datas.push(tem);
  251. for(let s of itemIncreaseSetting.setting){
  252. if(!_.isEmpty(s.scope)){
  253. for (let ID in s.scope){
  254. billNodeMap[ID] = true;//为了去重复
  255. }
  256. }
  257. }
  258. for(let cancelID in billNodeMap){
  259. let tnode = projectObj.project.mainTree.getNodeByID(cancelID);
  260. if(tnode){
  261. let cNode = this.cancelBillNode(tnode,datas);
  262. if(cNode) refreshNodes.push(cNode);
  263. }
  264. }
  265. let selectedNode = projectObj.project.mainTree.selected;
  266. //刷新缓存和树节点的插入删除
  267. await projectObj.project.syncUpdateNodesAndRefresh(datas);
  268. if(refreshNodes.length > 0){
  269. //重新计算
  270. cbTools.refreshFormulaNodes();
  271. projectObj.project.calcProgram.calcNodesAndSave(refreshNodes);
  272. projectObj.mainController.setTreeSelection(selectedNode);
  273. }
  274. }
  275. },
  276. getAllBillsIDMap:function () {
  277. let map = {};
  278. let itemIncreaseSetting = projectObj.project.property.itemIncreaseSetting;
  279. if(itemIncreaseSetting.isCalc == true){
  280. for(let s of itemIncreaseSetting.setting){
  281. if(!_.isEmpty(s.scope)){
  282. for (let ID in s.scope){
  283. map[ID] = true;
  284. }
  285. }
  286. }
  287. }
  288. return map;
  289. },
  290. calcAllItemIncreaseFee : function(setting,datas){
  291. let refreshNodes = [];
  292. let itemIncreaseSetting = setting?setting:projectObj.project.property.itemIncreaseSetting;
  293. let billNodeMap = {},rationGLJMap={};
  294. let cancelBillsIDMap = this.getAllBillsIDMap();
  295. if(itemIncreaseSetting && itemIncreaseSetting.isCalc == true){
  296. //为了不用循环所有节点,先挑出所有受影响的节点
  297. for(let s of itemIncreaseSetting.setting){
  298. if(!_.isEmpty(s.scope)){
  299. for (let ID in s.scope){
  300. billNodeMap[ID] = true;//为了去重复
  301. delete cancelBillsIDMap[ID];
  302. }
  303. }
  304. }
  305. for(let billsID in billNodeMap){
  306. let node = projectObj.project.mainTree.getNodeByID(billsID);
  307. let newRefreshNodes = this.calcItemIncreasePerNode(node,itemIncreaseSetting,rationGLJMap,datas);
  308. if(newRefreshNodes.length > 0) refreshNodes = refreshNodes.concat(newRefreshNodes);
  309. }
  310. //删除取消范围的清单下的子目定额
  311. for(let cancelID in cancelBillsIDMap){
  312. let tnode = projectObj.project.mainTree.getNodeByID(cancelID);
  313. let cNode = this.cancelBillNode(tnode,datas);
  314. if(cNode) refreshNodes.push(cNode);
  315. }
  316. }
  317. return refreshNodes;
  318. },
  319. cancelBillNode:function (node,datas) {
  320. if (node.children.length <= 0) return null;//如果没子项,不用计算
  321. if (node.source.children.length > 0) return null;//如果不是清单叶子节点,不用计算
  322. let isDelete = false;
  323. for(let rationNode of node.children){
  324. if(rationNode.data.code.indexOf("ZMZJF")!= -1){
  325. datas.push({type:ModuleNames.ration,data:{ID:rationNode.data.ID},action:"delete"});
  326. isDelete = true;
  327. }
  328. }
  329. return isDelete == true?node:null;
  330. },
  331. calcItemIncreasePerNode:function (node,setting,rationGLJMap,datas) {
  332. let itemIncreaseSetting = setting ? setting : projectObj.project.property.itemIncreaseSetting;
  333. let refreshNodes = [],rationCodeMap={},FeeMap={},updateDataIDMap={};
  334. if (node.children.length <= 0) return [];//如果没子项,不用计算
  335. if (node.source.children.length > 0) return [];//如果不是清单叶子节点,不用计算
  336. let labourTotal = 0,materialTotal=0,machineTotal=0;
  337. let process = getDecimal("process");
  338. let td = getDecimal("ration.totalPrice");
  339. let gd = getDecimal('glj.quantity');
  340. let preID="",serialNo=1;
  341. for(let rationNode of node.children){
  342. rationCodeMap[rationNode.data.code] = rationNode;
  343. if(rationNode.data.type == rationType.ration || rationNode.data.type == rationType.volumePrice ){//先只汇总定额和量价类型,不考虑自动生成的
  344. //计算人工费,材料费,机械费
  345. if(rationNode.data.feesIndex){
  346. let labour = rationNode.data.feesIndex.labour && rationNode.data.feesIndex.labour.totalFee?parseFloat(rationNode.data.feesIndex.labour.totalFee):0;
  347. let material = rationNode.data.feesIndex.material && rationNode.data.feesIndex.material.totalFee?parseFloat(rationNode.data.feesIndex.material.totalFee):0;
  348. let machine = rationNode.data.feesIndex.machine && rationNode.data.feesIndex.machine.totalFee?parseFloat(rationNode.data.feesIndex.machine.totalFee):0;
  349. labourTotal = scMathUtil.roundForObj(labourTotal + labour,getDecimal("process"));
  350. materialTotal = scMathUtil.roundForObj(materialTotal + material,getDecimal("process"));
  351. machineTotal = scMathUtil.roundForObj(machineTotal + machine,getDecimal("process"));
  352. }
  353. }
  354. if(rationNode.data.type != rationType.itemIncrease ){//计录除了子目增加节点外最后的节点ID,和nexeID
  355. preID = rationNode.data.ID;
  356. serialNo = rationNode.data.serialNo;
  357. }
  358. }
  359. FeeMap['人工费'] = labourTotal;
  360. FeeMap['材料费'] = materialTotal;
  361. FeeMap['机械费'] = machineTotal;
  362. //ZMZJF_1
  363. let s_in = 0;//序列号增长
  364. for(let i = 0; i < itemIncreaseSetting.setting.length;i++){
  365. let s = itemIncreaseSetting.setting[i];
  366. if(s.scope&&s.scope[node.data.ID]){
  367. let feeIndexArry = s.base.split("+");
  368. let total = 0;
  369. for(let index of feeIndexArry){
  370. total = scMathUtil.roundForObj(total + FeeMap[index],process);
  371. }
  372. total = scMathUtil.roundForObj(total,td);
  373. if(s.coe){
  374. let t = scMathUtil.roundForObj(total * s.coe/100,process);
  375. total = scMathUtil.roundForObj(total + t,gd);
  376. }
  377. let seq = i+1;
  378. let code = "ZMZJF_"+seq;
  379. let ZMZJFnode = rationCodeMap[code];
  380. if(total > 0) {
  381. if(ZMZJFnode){//存在的话更新其它人工费消耗量
  382. this.updateItemNode(ZMZJFnode,total,rationGLJMap,datas);
  383. if(s_in>0){
  384. datas.push({type:ModuleNames.ration,data:{ID:ZMZJFnode.data.ID,serialNo:ZMZJFnode.data.serialNo +1}});
  385. } else {//如果s_in>0时,ZMZJFnode会因为有更新而刷新,不用push到refreshNodes里
  386. refreshNodes.push(ZMZJFnode);
  387. }
  388. preID = ZMZJFnode.data.ID;
  389. serialNo = ZMZJFnode.data.serialNo;
  390. }else {//不存在的话插入新的节点
  391. s_in = s_in +1;
  392. serialNo = serialNo+1;
  393. let newRationData = this.inserNewItemNodes(node.data.ID,node.data.quantity,preID,serialNo,code,s.name,total,datas);
  394. preID = newRationData.ID;
  395. }
  396. }else { //如果total小于0,但又存在的话,删除定额(同时后端处理时记得要删除定额工料机)
  397. if(ZMZJFnode){
  398. datas.push({type:ModuleNames.ration,data:{ID:ZMZJFnode.data.ID},action:"delete"});
  399. if(refreshNodes.length == 0) refreshNodes.push(node);//删除时,如果清单下没有定额更新,则刷新清单节点就行
  400. }
  401. }
  402. }
  403. }
  404. return refreshNodes;
  405. },
  406. updateItemNode:function (node,total,rationGLJMap,datas) {
  407. if(_.isEmpty(rationGLJMap)) this.setRationGLJMap(rationGLJMap);
  408. if(rationGLJMap[node.data.ID] && rationGLJMap[node.data.ID].quantity != total){
  409. datas.push({type:ModuleNames.ration_glj,data:{ID:rationGLJMap[node.data.ID].ID,quantity:total}})
  410. }
  411. },
  412. setRationGLJMap:function (rationGLJMap) {
  413. let gljList = projectObj.project.ration_glj.datas;
  414. for (let g of gljList){
  415. if(g.code == 'QTRGF') rationGLJMap[g.rationID] = g;
  416. }
  417. },
  418. inserNewItemNodes:function (billsItemID,billsQuantity,preID,serialNo,code,name,total,datas) {
  419. let Ration = projectObj.project.Ration;
  420. let newRationData = Ration.getTempRationData(Ration.getNewRationID(), billsItemID, serialNo, rationType.itemIncrease);
  421. newRationData.code = code;
  422. newRationData.name=name;
  423. newRationData.unit = '元';
  424. newRationData.quantity = "1";
  425. if(billsQuantity) newRationData.contain = scMathUtil.roundForObj(1/parseFloat(billsQuantity),getDecimal("process"))+"";
  426. newRationData.quantityEXP = '1';
  427. datas.push({type:ModuleNames.ration,data:newRationData,preSiblingID:preID,action:"add",parentID:billsItemID});
  428. let newRationGLJ = {
  429. rationID:newRationData.ID,
  430. billsItemID:billsItemID,
  431. shortName:projectObj.project.projectGLJ.getShortNameByID(gljType.LABOUR),
  432. GLJID:-1,
  433. projectID:newRationData.projectID,
  434. code:'QTRGF',
  435. original_code:'QTRGF',
  436. name:'其它人工费',
  437. specs:'',
  438. unit:'元',
  439. type:gljType.LABOUR,
  440. basePrice:1,
  441. marketPrice:1,
  442. adjCoe:null,
  443. from:'std',
  444. repositoryId:-1,
  445. quantity:total+"",
  446. rationItemQuantity:total+""
  447. };
  448. datas.push({type:ModuleNames.ration_glj,data:newRationGLJ,action:"add"});
  449. return newRationData;
  450. }
  451. };
  452. $(function () {
  453. $('#itemIncreaseFeeDiv').on('shown.bs.modal', function (e) {
  454. itemIncreaseFeeObj.itemChange = false;
  455. itemIncreaseFeeObj.initSpread();
  456. itemIncreaseFeeObj.showDatas();
  457. });
  458. $('#item_increase_scope').on('shown.bs.modal', function (e) {
  459. itemIncreaseFeeObj.initScopeSpread();
  460. itemIncreaseFeeObj.showScopeDatas();
  461. });
  462. $("#select_scope_confirm").click(function () {
  463. itemIncreaseFeeObj.confirmScope();
  464. })
  465. $("#itemIncreaseFeeConfirm").click(function () {
  466. itemIncreaseFeeObj.confirmItemIncreaseSetting();
  467. })
  468. });