electrovalence_view.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. this.sheet.name('electrovalence_sheet');
  47. if(projectReadOnly){
  48. disableSpread(this.spread);
  49. }
  50. },
  51. showDatas:function (datas) {
  52. let sel = this.sheet.getSelections()[0];
  53. let oldData = sel.row<this.datas.length?this.datas[sel.row]:"";
  54. this.sheet.setRowCount(0);
  55. this.datas = datas?datas:this.getElectrovalenceDatas();
  56. this.calcPertElectrovalenceMarketPrice(this.datas);
  57. sheetCommonObj.showData(this.sheet, this.setting,this.datas);
  58. this.sheet.setRowCount(this.datas.length+1);
  59. let nameCol = _.findIndex(this.setting.header,{'dataCode':'displayName'});
  60. let nameOptions = this.getElectrovalenceOptions();
  61. sheetCommonObj.setComboBox(-1,nameCol,this.sheet,nameOptions,false,false,5);
  62. sel.row = oldData?_.findIndex(this.datas,{'ID':oldData.ID}):sel.row ;
  63. this.sheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
  64. },
  65. getElectrovalenceDatas:function (ext) {
  66. let datas = [];
  67. let pgljMap = {};
  68. let com_electrovalence = projectObj.project.projectGLJ.datas.com_electrovalence;
  69. for(let pg of projectObj.project.projectGLJ.datas.gljList){
  70. pgljMap[gljUtil.getIndex(pg)] = pg;
  71. }
  72. if(com_electrovalence && com_electrovalence.gljList){
  73. for (let g of com_electrovalence.gljList){
  74. let t = this.createNewElectrovalenceData(g);
  75. let tg = pgljMap[gljUtil.getIndex(g)];
  76. if(tg) gljOprObj.setGLJPrice(t,tg,false,ext);
  77. datas.push(t);
  78. }
  79. }
  80. return datas;
  81. },
  82. createNewElectrovalenceData:function (g) {//只是拷贝一份
  83. let t = {
  84. ID:g.ID,
  85. GLJID:g.GLJID,
  86. projectGLJID:g.projectGLJID,
  87. name:g.name,
  88. displayName:g.displayName,
  89. code:g.code,
  90. specs:g.specs,
  91. unit:g.unit,
  92. type:g.type,
  93. coe: g.coe,
  94. from:g.from
  95. };
  96. return t;
  97. },
  98. calcPertElectrovalenceMarketPrice:function (datas,ext) {
  99. let total = 0;
  100. for(let d of datas){
  101. if(ext && ext[d.projectGLJID] && gljUtil.isDef(ext[d.projectGLJID].marketPrice)) d.marketPrice = ext[d.projectGLJID].marketPrice;
  102. if(d.name == "电网电"){
  103. d.electPrice = d.marketPrice;
  104. }else {
  105. let w = parseInt(d.name);
  106. if(!w) continue;
  107. let t = scMathUtil.roundForObj(d.marketPrice/w,getDecimal("process"));
  108. d.electPrice = scMathUtil.roundForObj(t * gljUtil.getElecCoe(),getDecimal("glj.unitPriceHasMix"));
  109. }
  110. let et = scMathUtil.roundForObj(d.electPrice * d.coe,getDecimal("process"));
  111. total = scMathUtil.roundForObj(et + total,getDecimal("process"));
  112. }
  113. this.total = scMathUtil.roundForObj(total,getDecimal("glj.unitPriceHasMix"));
  114. $("#electrovalenceLabel").text(`综合电价:${this.total}`);
  115. return this.total;
  116. },
  117. clacNewElecPrice:function (ext) {
  118. for(let g of projectObj.project.projectGLJ.datas.gljList){
  119. if(g.code == gljUtil.getElecCode() && g.name == "电" && g.unit == "kW·h"){//更新电价
  120. let datas = this.getElectrovalenceDatas(ext);
  121. if(datas.length > 0){
  122. let marketPrice = this.calcPertElectrovalenceMarketPrice(datas,ext);
  123. if(marketPrice && g.unit_price.market_price != marketPrice+'') return {projectGLJID:g.id,id:g.unit_price.id,'unit_price_file_id':g.unit_price.unit_price_file_id,doc:{'market_price':marketPrice+''}}
  124. }
  125. }
  126. }
  127. return null;
  128. },
  129. getElectrovalenceOptions:function () {
  130. return _.map(this.options,"name")
  131. },
  132. onElectrovalenceSelectionChange:function (sender,args) {
  133. args.sheet.repaint();
  134. },
  135. onElectrovalenceEditStarting:function (sender,args) {
  136. let me = electrovalenceObj;
  137. let dataCode = me.setting.header[args.col].dataCode;
  138. if(dataCode == "electPrice" ){//除电网电外,不可修改
  139. let cancel = true;
  140. if(me.datas[args.row] && me.datas[args.row].name == "电网电") cancel = false;
  141. args.cancel = cancel;
  142. }
  143. },
  144. onElectrovalenceValueChange:function (sender,args) {
  145. let me = electrovalenceObj;
  146. let dataCode = me.setting.header[args.col].dataCode;
  147. let value = args.newValue;
  148. if(dataCode == "displayName" && args.row >= me.datas.length) {//新增
  149. me.addElectrovalence(value);
  150. }else { //修改
  151. let tem = me.datas[args.row];
  152. if (value&&!sheetCommonObj.checkData(args.col,me.setting,value)) {
  153. alert('输入的数据类型不对,请重新输入!');
  154. return me.showDatas(me.datas);
  155. }
  156. if(dataCode == 'coe' || dataCode == 'electPrice'){
  157. let dec = dataCode == 'coe' ?getDecimal("process"):getDecimal("glj.unitPrice");
  158. if(value){
  159. value = scMathUtil.roundForObj(value,dec);
  160. }
  161. tem[dataCode] = value;
  162. if(dataCode == 'electPrice') tem.marketPrice = value;
  163. }else if(dataCode == 'displayName'){//下拉替换
  164. me.editElectrovalence(value,args.row,"replace");
  165. }
  166. me.showDatas(me.datas);
  167. }
  168. },
  169. addElectrovalence:async function (name) {
  170. this.editElectrovalence(name);
  171. },
  172. editElectrovalence:async function (name,row,type="add") {
  173. //新建项目的时候,电已经默认生成了,所以不用考考虑电没有的情况
  174. try {
  175. let glj = _.find(this.options,{name:name});
  176. if(glj){
  177. let tem = {displayName:glj.name,code:glj.code,specs:glj.specs,unit:glj.unit,type:glj.type,projectID : projectObj.project.ID()};
  178. tem.ID = uuid.v1();
  179. $.bootstrapLoading.start();
  180. let result = await ajaxPost('/glj/insertElectrovalence',tem);
  181. //插入项目工料机列表
  182. if(type == "add" && (!result.projetcGLJData || result.projetcGLJData.length == 0)){
  183. alert("没有找到该工料机,请检查工料机库");
  184. return this.showDatas(this.datas);
  185. }
  186. let newProjectPGJ = projectObj.project.projectGLJ.loadNewProjectGLJToCache(result.projetcGLJData);
  187. //加入综合电价显示列表缓存
  188. tem.GLJID = result.projetcGLJData.glj_id;
  189. tem.projectGLJID = result.projetcGLJData.id;
  190. tem.name = result.projetcGLJData.name;
  191. tem.coe = 0;
  192. tem.from = "std";
  193. gljOprObj.setGLJPrice(tem,newProjectPGJ);
  194. if(type == "add"){
  195. this.datas.push(tem);
  196. }else { //除了添加的就是替换
  197. if(this.datas[row])this.datas[row]=tem;
  198. }
  199. this.showDatas(this.datas);
  200. }
  201. }catch (e){
  202. console.log(e)
  203. }finally {
  204. //materialCalcObj.showDatas();
  205. $.bootstrapLoading.end();
  206. }
  207. },
  208. getGljListFromDatas:function (datas) {
  209. let gljList = [];
  210. for(let d of datas){
  211. gljList.push(this.createNewElectrovalenceData(d));
  212. }
  213. return gljList;
  214. },
  215. updateElectrovalence:function () {
  216. let updateMap = {};
  217. let dwd = null;//电网电
  218. let com_electrovalence = projectObj.project.projectGLJ.datas.com_electrovalence;
  219. if(com_electrovalence){//存在则是更新
  220. updateMap['electrovalence'] = {
  221. actionType:'update',
  222. ID:com_electrovalence.ID,
  223. doc:{gljList:this.getGljListFromDatas(this.datas)}
  224. };
  225. }else { //不存在则是新增
  226. updateMap['electrovalence'] = {
  227. actionType:'add',
  228. doc:{
  229. unit_price_file_id:projectObj.project.property.unitPriceFile.id,
  230. gljList:this.getGljListFromDatas(this.datas)
  231. }
  232. };
  233. updateMap['electrovalence']['doc'].ID = uuid.v1();
  234. }
  235. for(let t of this.datas){
  236. if(t.name == '电网电'){
  237. dwd = t;
  238. }
  239. }
  240. let unitPrices = [];
  241. for(let g of projectObj.project.projectGLJ.datas.gljList){
  242. if(dwd && g.id == dwd.projectGLJID){
  243. if(g.unit_price.market_price != dwd.electPrice+''){
  244. 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+""}};
  245. unitPrices.push(t_unitPrice);
  246. }
  247. }
  248. if(g.code == gljUtil.getElecCode() && g.name == "电" && g.unit == "kW·h"){//更新电价
  249. if(g.unit_price.market_price != this.total+''){
  250. 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+''}};
  251. unitPrices.push(d_unitPrice);
  252. }
  253. }
  254. }
  255. if(unitPrices.length > 0)updateMap["unitPrice"] = unitPrices;
  256. this.submitElectrovalenceChange(updateMap)
  257. },
  258. submitElectrovalenceChange:async function (updateMap) {
  259. try {
  260. if(!_.isEmpty(updateMap)){
  261. $.bootstrapLoading.start();
  262. let result = await ajaxPost('/glj/updateElectrovalence',updateMap);
  263. projectObj.project.projectGLJ.refreshEctrovalenceCache(updateMap);
  264. }
  265. }catch (e){
  266. console.log(e)
  267. }finally {
  268. $.bootstrapLoading.end();
  269. }
  270. }
  271. };
  272. $(function () {
  273. $("#electrovalenceDiv").on('shown.bs.modal', function () {
  274. electrovalenceObj.initSpread();
  275. electrovalenceObj.showDatas();
  276. });
  277. $("#removeElectrovalencec").click(function(){
  278. let record = sheetCommonObj.getSelectedRecode(electrovalenceObj.sheet,electrovalenceObj.datas);
  279. if(record){
  280. _.remove(electrovalenceObj.datas,{'ID':record.ID});
  281. electrovalenceObj.showDatas(electrovalenceObj.datas);
  282. }
  283. });
  284. $("#electrovalencecConfirm").click(function () {
  285. electrovalenceObj.updateElectrovalence();
  286. })
  287. });