electrovalence_view.js 13 KB

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