electrovalence_view.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /**
  2. * Created by zhang on 2019/12/12.
  3. */
  4. let electrovalenceObj = {
  5. setting:{
  6. header:[
  7. {headerName: "代号", headerWidth: 70, dataCode: "code", dataType: "String"},
  8. {headerName: "名称", headerWidth: 150, dataCode: "displayName",dataType: "String"},
  9. {headerName: "规格", headerWidth: 70, dataCode: "specs", dataType: "Number",validator:"number"},
  10. {headerName: "预算价", headerWidth: 75, dataCode: "electPrice", hAlign: "right", dataType: "Number",validator:"number"},
  11. {headerName: "加权系数", headerWidth: 80, dataCode: "coe", hAlign: "right", dataType: "Number",validator:"number"}
  12. ],
  13. view: {
  14. lockColumns: ["code","specs"],
  15. rowHeaderWidth:25,
  16. colHeaderHeight:36
  17. }
  18. },
  19. spread:null,
  20. sheet:null,
  21. datas:[],
  22. total:0,
  23. options:[
  24. {code:"3005003",name:"电网电",specs:"",unit:"kW·h",type:"201"},
  25. {code:"8017001",name:"5kW以内柴油发电机组",specs:"5GF1",unit:"台班",type:"301"},
  26. {code:"8017002",name:"15kW以内柴油发电机组",specs:"12GF1",unit:"台班",type:"301"},
  27. {code:"8017003",name:"30kW以内柴油发电机组",specs:"30GFY-2",unit:"台班",type:"301"},
  28. {code:"8017004",name:"50kW以内柴油发电机组",specs:"50GFY-2",unit:"台班",type:"301"},
  29. {code:"8017005",name:"75kW以内柴油发电机组",specs:"75GFY-4",unit:"台班",type:"301"},
  30. {code:"8017006",name:"100kW以内柴油发电机组",specs:"90GFZ",unit:"台班",type:"301"},
  31. {code:"8017007",name:"120kW以内柴油发电机组",specs:"120GFY-4",unit:"台班",type:"301"},
  32. {code:"8017008",name:"160kW以内柴油发电机组",specs:"160GF",unit:"台班",type:"301"},
  33. {code:"8017009",name:"200kW以内柴油发电机组",specs:"200GF",unit:"台班",type:"301"},
  34. {code:"8017010",name:"250kW以内柴油发电机组",specs:"250GF4-4",unit:"台班",type:"301"},
  35. {code:"8017011",name:"320kW以内柴油发电机组",specs:"320GF-2",unit:"台班",type:"301"}
  36. ],
  37. initSpread:function () {
  38. if(this.spread) return this.spread.refresh();
  39. this.spread = SheetDataHelper.createNewSpread($("#electrovalence_sheet")[0]);
  40. sheetCommonObj.spreadDefaultStyle(this.spread);
  41. this.sheet = this.spread.getSheet(0);
  42. sheetCommonObj.initSheet(this.sheet, this.setting, 30);
  43. this.sheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onElectrovalenceSelectionChange);
  44. this.sheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onElectrovalenceValueChange);
  45. this.sheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onElectrovalenceEditStarting);
  46. /*
  47. ;*/
  48. this.sheet.name('electrovalence_sheet');
  49. if(projectReadOnly){
  50. disableSpread(this.spread);
  51. }
  52. },
  53. showDatas:function (datas) {
  54. let sel = this.sheet.getSelections()[0];
  55. let oldData = sel.row<this.datas.length?this.datas[sel.row]:"";
  56. this.sheet.setRowCount(0);
  57. this.datas = datas?datas:this.getElectrovalenceDatas();
  58. this.calcPertElectrovalenceMarketPrice(this.datas);
  59. sheetCommonObj.showData(this.sheet, this.setting,this.datas);
  60. this.sheet.setRowCount(this.datas.length+1);
  61. let nameCol = _.findIndex(this.setting.header,{'dataCode':'displayName'});
  62. let nameOptions = this.getElectrovalenceOptions();
  63. sheetCommonObj.setComboBox(-1,nameCol,this.sheet,nameOptions,false,false,5);
  64. sel.row = oldData?_.findIndex(this.datas,{'ID':oldData.ID}):sel.row ;
  65. this.sheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
  66. },
  67. getElectrovalenceDatas:function () {
  68. let datas = [];
  69. let pgljMap = {};
  70. let com_electrovalence = projectObj.project.projectGLJ.datas.com_electrovalence;
  71. for(let pg of projectObj.project.projectGLJ.datas.gljList){
  72. pgljMap[gljUtil.getIndex(pg)] = pg;
  73. }
  74. if(com_electrovalence && com_electrovalence.gljList){
  75. for (let g of com_electrovalence.gljList){
  76. let t = this.createNewElectrovalenceData(g);
  77. let tg = pgljMap[gljUtil.getIndex(g)];
  78. if(tg) gljOprObj.setGLJPrice(t,tg);
  79. datas.push(t);
  80. }
  81. }
  82. return datas;
  83. },
  84. createNewElectrovalenceData:function (g) {//只是拷贝一份
  85. let t = {
  86. ID:g.ID,
  87. GLJID:g.GLJID,
  88. projectGLJID:g.projectGLJID,
  89. name:g.name,
  90. displayName:g.displayName,
  91. code:g.code,
  92. specs:g.specs,
  93. unit:g.unit,
  94. type:g.type,
  95. coe: g.coe,
  96. from:g.from
  97. };
  98. return t;
  99. },
  100. calcPertElectrovalenceMarketPrice:function (datas) {
  101. let total = 0;
  102. for(let d of datas){
  103. if(d.name == "电网电"){
  104. d.electPrice = d.marketPrice;
  105. }else {
  106. let w = parseInt(d.name);
  107. if(!w) continue;
  108. let t = scMathUtil.roundForObj(d.marketPrice/w,getDecimal("process"));
  109. d.electPrice = scMathUtil.roundForObj(t * gljUtil.getElecCoe(),getDecimal("glj.unitPriceHasMix"));
  110. }
  111. let et = scMathUtil.roundForObj(d.electPrice * d.coe,getDecimal("process"));
  112. total = scMathUtil.roundForObj(et + total,getDecimal("process"));
  113. }
  114. this.total = scMathUtil.roundForObj(total,getDecimal("glj.unitPrice"));
  115. $("#electrovalenceLabel").text(`综合电价:${this.total}`);
  116. },
  117. getElectrovalenceOptions:function () {
  118. return _.map(this.options,"name")
  119. },
  120. onElectrovalenceSelectionChange:function (sender,args) {
  121. args.sheet.repaint();
  122. },
  123. onElectrovalenceEditStarting:function (sender,args) {
  124. let me = electrovalenceObj;
  125. let dataCode = me.setting.header[args.col].dataCode;
  126. if(dataCode == "electPrice" ){//除电网电外,不可修改
  127. let cancel = true;
  128. if(me.datas[args.row] && me.datas[args.row].name == "电网电") cancel = false;
  129. args.cancel = cancel;
  130. }
  131. },
  132. onElectrovalenceValueChange:function (sender,args) {
  133. let me = electrovalenceObj;
  134. let dataCode = me.setting.header[args.col].dataCode;
  135. let value = args.newValue;
  136. if(dataCode == "displayName" && args.row >= me.datas.length) {//新增
  137. me.addElectrovalence(value);
  138. }else { //修改
  139. let tem = me.datas[args.row];
  140. if (value&&!sheetCommonObj.checkData(args.col,me.setting,value)) {
  141. alert('输入的数据类型不对,请重新输入!');
  142. return me.showDatas(me.datas);
  143. }
  144. if(dataCode == 'coe' || dataCode == 'electPrice'){
  145. let dec = dataCode == 'coe' ?getDecimal("process"):getDecimal("glj.unitPrice");
  146. if(value){
  147. value = scMathUtil.roundForObj(value,dec);
  148. }
  149. tem[dataCode] = value;
  150. if(dataCode == 'electPrice') tem.marketPrice = value;
  151. }else if(dataCode == 'displayName'){//下拉替换
  152. me.editElectrovalence(value,args.row,"replace");
  153. }
  154. me.showDatas(me.datas);
  155. }
  156. },
  157. addElectrovalence:async function (name) {
  158. this.editElectrovalence(name);
  159. },
  160. editElectrovalence:async function (name,row,type="add") {
  161. //新建项目的时候,电已经默认生成了,所以不用考考虑电没有的情况
  162. try {
  163. let glj = _.find(this.options,{name:name});
  164. if(glj){
  165. let tem = {displayName:glj.name,code:glj.code,specs:glj.specs,unit:glj.unit,type:glj.type,projectID : projectObj.project.ID()};
  166. tem.ID = uuid.v1();
  167. $.bootstrapLoading.start();
  168. let result = await ajaxPost('/glj/insertElectrovalence',tem);
  169. //插入项目工料机列表
  170. let newProjectPGJ = projectObj.project.projectGLJ.loadNewProjectGLJToCache(result.projetcGLJData);
  171. //加入综合电价显示列表缓存
  172. tem.GLJID = result.projetcGLJData.glj_id;
  173. tem.projectGLJID = result.projetcGLJData.id;
  174. tem.name = result.projetcGLJData.name;
  175. tem.coe = 0;
  176. tem.from = "std";
  177. gljOprObj.setGLJPrice(tem,newProjectPGJ);
  178. if(type == "add"){
  179. this.datas.push(tem);
  180. }else { //除了添加的就是替换
  181. if(this.datas[row])this.datas[row]=tem;
  182. }
  183. this.showDatas(this.datas);
  184. }
  185. }catch (e){
  186. console.log(e)
  187. }finally {
  188. //materialCalcObj.showDatas();
  189. $.bootstrapLoading.end();
  190. }
  191. },
  192. getGljListFromDatas:function (datas) {
  193. let gljList = [];
  194. for(let d of datas){
  195. gljList.push(this.createNewElectrovalenceData(d));
  196. }
  197. return gljList;
  198. },
  199. updateElectrovalence:function () {
  200. let updateMap = {};
  201. let dwd = null;//电网电
  202. let com_electrovalence = projectObj.project.projectGLJ.datas.com_electrovalence;
  203. if(com_electrovalence){//存在则是更新
  204. updateMap['electrovalence'] = {
  205. actionType:'update',
  206. ID:com_electrovalence.ID,
  207. doc:{gljList:this.getGljListFromDatas(this.datas)}
  208. };
  209. }else { //不存在则是新增
  210. updateMap['electrovalence'] = {
  211. actionType:'add',
  212. doc:{
  213. unit_price_file_id:projectObj.project.property.unitPriceFile.id,
  214. gljList:this.getGljListFromDatas(this.datas)
  215. }
  216. };
  217. updateMap['electrovalence']['doc'].ID = uuid.v1();
  218. }
  219. for(let t of this.datas){
  220. if(t.name == '电网电'){
  221. dwd = t;
  222. }
  223. }
  224. let unitPrices = [];
  225. for(let g of projectObj.project.projectGLJ.datas.gljList){
  226. if(dwd && g.id == dwd.projectGLJID){
  227. if(g.unit_price.market_price != dwd.electPrice+''){
  228. let t_unitPrice = {projectGLJID:g.id,id:g.unit_price.id,'unit_price_file_id':g.unit_price.unit_price_file_id,doc:{'market_price':dwd.electPrice+""}};
  229. unitPrices.push(t_unitPrice);
  230. }
  231. }
  232. if(g.code == gljUtil.getElecCode() && g.name == "电" && g.unit == "kW·h"){//更新电价
  233. if(g.unit_price.market_price != this.total+''){
  234. let d_unitPrice = {projectGLJID:g.id,id:g.unit_price.id,'unit_price_file_id':g.unit_price.unit_price_file_id,doc:{'market_price':this.total+''}};
  235. unitPrices.push(d_unitPrice);
  236. }
  237. }
  238. }
  239. if(unitPrices.length > 0)updateMap["unitPrice"] = unitPrices;
  240. this.submitElectrovalenceChange(updateMap)
  241. },
  242. submitElectrovalenceChange:async function (updateMap) {
  243. try {
  244. if(!_.isEmpty(updateMap)){
  245. $.bootstrapLoading.start();
  246. let result = await ajaxPost('/glj/updateElectrovalence',updateMap);
  247. projectObj.project.projectGLJ.refreshEctrovalenceCache(updateMap);
  248. }
  249. }catch (e){
  250. console.log(e)
  251. }finally {
  252. $.bootstrapLoading.end();
  253. }
  254. }
  255. };
  256. $(function () {
  257. $("#electrovalenceDiv").on('shown.bs.modal', function () {
  258. electrovalenceObj.initSpread();
  259. electrovalenceObj.showDatas();
  260. });
  261. $("#removeElectrovalencec").click(function(){
  262. let record = sheetCommonObj.getSelectedRecode(electrovalenceObj.sheet,electrovalenceObj.datas);
  263. if(record){
  264. _.remove(electrovalenceObj.datas,{'ID':record.ID});
  265. electrovalenceObj.showDatas(electrovalenceObj.datas);
  266. }
  267. });
  268. $("#electrovalencecConfirm").click(function () {
  269. electrovalenceObj.updateElectrovalence();
  270. })
  271. });