item_increase_fee_view.js 22 KB

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