material_calc_view.js 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. /**
  2. * Created by zhang on 2019/3/11.
  3. */
  4. materialCalcObj = {
  5. moduleName:'materalCal',
  6. materialSpread:null,
  7. materialSheet:null,
  8. materialDatas:[],
  9. materialSetting:{
  10. header:[
  11. {headerName: "编号", headerWidth: 70, dataCode: "code", dataType: "String"},
  12. {headerName: "名称", headerWidth: 105, dataCode: "name", dataType: "String"},
  13. {headerName: "预算价", headerWidth: 60, dataCode: "marketPrice", hAlign: "right", dataType: "Number",validator:"number"},
  14. {headerName: "供应地点", headerWidth: 75, dataCode: "supplyLocation", hAlign: "left", dataType: "String"},
  15. {headerName: "原价", headerWidth: 60, dataCode: "originalPrice", hAlign: "right", dataType: "String"},
  16. {headerName: "单位运费", headerWidth: 60, dataCode: "unitFreight", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:'glj.unitPrice'
  17. {headerName: "单位毛重(吨)", headerWidth: 65, dataCode: "grossWeightCoe_n", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:"glj.unitPrice"
  18. {headerName: "装卸总次数", headerWidth: 53, dataCode: "totalLoadingTimes", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:"glj.unitPrice"
  19. {headerName: "每增加一次装卸损耗率", headerWidth: 80, dataCode: "handlingLossRate_n", hAlign: "right", dataType: "Number",validator:"number"},
  20. {headerName: "场外运输损耗率", headerWidth: 60, dataCode: "offSiteTransportLossRate_n", hAlign: "right", dataType: "Number"},//,decimalField:"glj.unitPrice"
  21. {headerName: "场外运输损耗", headerWidth: 60, dataCode: "offSiteTransportLoss", hAlign: "right", dataType: "Number"},//,decimalField:"glj.unitPrice"
  22. {headerName: "采购及保管费率", headerWidth: 60, dataCode: "purchaseStorageRate_n", hAlign: "right", dataType: "Number"},//,decimalField:"glj.unitPrice"
  23. {headerName: "采购及保管费", headerWidth: 60, dataCode: "purchaseStorage", hAlign: "right", dataType: "Number"},//,decimalField:"glj.unitPrice"
  24. {headerName: "包装品回收价值", headerWidth: 60, dataCode: "packageRecoverValue", hAlign: "right", dataType: "Number"}//,decimalField:"glj.unitPrice"
  25. ],
  26. view: {
  27. lockColumns: ["code","name","marketPrice",'offSiteTransportLoss','purchaseStorage'],
  28. rowHeaderWidth:25,
  29. colHeaderHeight:36
  30. }
  31. },
  32. freightSpread:null,
  33. freightSheet:null,
  34. freightDatas:[],
  35. conveyanceOptions:["自办运输","汽车","火车","船舶","马车","手推车","拖拉机"],
  36. userFreightList:[],
  37. freightSetting:{
  38. header:[
  39. {headerName: "起讫地点", headerWidth: 85, dataCode: "start", dataType: "String"},
  40. {headerName: "运输工具", headerWidth: 65, dataCode: "conveyance", dataType: "String"},
  41. {headerName: "材料类型", headerWidth: 65, dataCode: "materialType", visible: false,dataType: "String",cellType:"comboBox",options:["","地方材料","外购材料","沥青、燃料等"]},
  42. {headerName: "单位运价", headerWidth: 65, dataCode: "unitFreight", hAlign: "right", dataType: "Number",validator:"number"},
  43. {headerName: "km运距", headerWidth: 55, dataCode: "kmDistance", hAlign: "right", dataType: "String",validator:"number"},
  44. {headerName: "装卸费\n单价", headerWidth: 53, dataCode: "unitLoadingFee", hAlign: "right", dataType: "String",validator:"number"},
  45. {headerName: "装卸\n次数", headerWidth: 41, dataCode: "loadingTimes", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:'glj.unitPrice'
  46. {headerName: "其它\n费用", headerWidth: 41, dataCode: "otherFee", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:"glj.unitPrice"
  47. {headerName: "运价增\n加率(%)", headerWidth: 55, dataCode: "freightIncreaseRate", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:"glj.unitPrice"
  48. {headerName: "加权\n系数", headerWidth: 41, dataCode: "weightCoe", hAlign: "right", dataType: "Number",validator:"number"},
  49. {headerName: "计算式", headerWidth: 170, dataCode: "exp", hAlign: "left", dataType: "String",getText:'forExp'},//,decimalField:"glj.unitPrice"
  50. {headerName: "计算方式", headerWidth: 80, dataCode: "calcType",visible: false, dataType: "String",cellType:"comboBox",options:["全国","内蒙古"]}
  51. ],
  52. view: {
  53. lockColumns: ["exp"],
  54. rowHeaderWidth:25,
  55. colHeaderHeight:36
  56. },
  57. getText:{
  58. forExp:function (item) {
  59. return gljUtil.isDef(item.exp)?item.exp:materialCalcObj.getFreightEXP(item);
  60. }
  61. }
  62. },
  63. priceSpread:null,
  64. priceSheet:null,
  65. priceDatas:[],
  66. priceSetting:{
  67. header:[
  68. {headerName: "供应地点", headerWidth: 80, dataCode: "supplyLocation", dataType: "String"},
  69. {headerName: "供应价", headerWidth: 70, dataCode: "supplyPrice", hAlign: "right", dataType: "Number",validator:"number"},
  70. {headerName: "加权系数", headerWidth: 80, dataCode: "coe", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:'glj.unitPrice'
  71. ],
  72. view: {
  73. lockColumns: [],
  74. rowHeaderWidth:25,
  75. colHeaderHeight:36
  76. }
  77. },
  78. freightRationSpread:null,
  79. freightRationSheet:null,
  80. freightRations:[],
  81. priceRations:[],
  82. priceRationSpread:null,
  83. priceRationSheet:null,
  84. rationSetting:{
  85. header:[
  86. {headerName: "编号", headerWidth: 80, dataCode: "code", dataType: "String",formatter: "@"},
  87. {headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String"},
  88. {headerName: "单位", headerWidth: 100, dataCode: "unit", dataType: "String"},
  89. {headerName: "数量", headerWidth: 100, dataCode: "quantity", dataType: "String",hAlign: "right",validator:"number"},
  90. {headerName: "高原取费类别", headerWidth: 100, dataCode: "feeType", dataType: "String",visible: false,cellType:"comboBox",options:[],maxDropDownItems:5}
  91. ],
  92. view: {
  93. lockColumns: ["unit"],
  94. rowHeaderWidth:25,
  95. colHeaderHeight:36
  96. }
  97. },
  98. initMaterialSpread:function () {
  99. this.materialSpread = SheetDataHelper.createNewSpread($("#materialCalcSheet")[0]);
  100. sheetCommonObj.spreadDefaultStyle(this.materialSpread);
  101. this.materialSheet = this.materialSpread.getSheet(0);
  102. sheetCommonObj.initSheet(this.materialSheet, this.materialSetting, 30);
  103. this.materialSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onMaterialValueChange);
  104. this.materialSheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onMaterialSelectionChange);
  105. this.materialSheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onMaterialEditStarting);
  106. this.materialSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onMaterialRangeChange);
  107. this.materialSheet.name('material_calc');
  108. if(projectReadOnly){
  109. sheetCommonObj.disableSpread(this.materialSpread);
  110. }else {
  111. this.initRightClick("materialCalcSheet",this.materialSpread)
  112. }
  113. },
  114. initFreightSpread:async function(){
  115. this.freightSpread = SheetDataHelper.createNewSpread($("#freightSheet")[0]);
  116. sheetCommonObj.spreadDefaultStyle(this.freightSpread);
  117. this.freightSheet = this.freightSpread.getSheet(0);
  118. sheetCommonObj.initSheet(this.freightSheet, this.freightSetting, 30);
  119. this.freightSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onFreightValueChange);
  120. this.freightSheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onFreightSelectionChange);
  121. this.freightSheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onFreightEditStarting);
  122. this.freightSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onFreightPriceRangeChange);
  123. this.freightSheet.name('freight_calc');
  124. if(projectReadOnly){
  125. sheetCommonObj.disableSpread(this.freightSpread);
  126. }else {
  127. this.initRightClick("freightSheet",this.freightSpread)
  128. }
  129. this.userFreightList = await projectObj.project.projectGLJ.getUserFreights();
  130. },
  131. initFreightRationSpread:function () {
  132. this.freightRationSpread = SheetDataHelper.createNewSpread($("#freight_ration_sheet")[0]);
  133. sheetCommonObj.spreadDefaultStyle(this.freightRationSpread);
  134. this.freightRationSheet = this.freightRationSpread.getSheet(0);
  135. sheetCommonObj.initSheet(this.freightRationSheet, this.rationSetting, 30);
  136. this.freightRationSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onFreightRationValueChange);
  137. this.freightRationSheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onRationSelectionChange);
  138. this.freightRationSheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onFreightRationEditStarting);
  139. this.freightRationSheet.name('freight_ration');
  140. if(projectReadOnly){
  141. sheetCommonObj.disableSpread(this.freightRationSpread);
  142. }else {
  143. this.initRightClick("freight_ration_sheet",this.freightRationSpread);
  144. }
  145. },
  146. initPriceRationSpread:function () {
  147. this.priceRationSpread = SheetDataHelper.createNewSpread($("#price_ration_sheet")[0]);
  148. sheetCommonObj.spreadDefaultStyle(this.priceRationSpread);
  149. this.priceRationSheet = this.priceRationSpread.getSheet(0);
  150. sheetCommonObj.initSheet(this.priceRationSheet, this.rationSetting, 30);
  151. this.priceRationSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onPriceRationValueChange);
  152. this.priceRationSheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onRationSelectionChange);
  153. this.priceRationSheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onPriceRationEditStarting);
  154. this.priceRationSheet.name('price_ration');
  155. if(projectReadOnly){
  156. sheetCommonObj.disableSpread(this.priceRationSpread);
  157. }else {
  158. this.initRightClick("price_ration_sheet",this.priceRationSpread);
  159. }
  160. },
  161. initPriceSpread:async function(){
  162. this.priceSpread = SheetDataHelper.createNewSpread($("#priceSheet")[0]);
  163. sheetCommonObj.spreadDefaultStyle(this.priceSpread);
  164. this.priceSheet = this.priceSpread.getSheet(0);
  165. sheetCommonObj.initSheet(this.priceSheet, this.priceSetting, 30);
  166. this.priceSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onFreightPriceRangeChange);
  167. this.priceSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onPriceValueChange);
  168. this.priceSheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onPriceSelectionChange);
  169. this.priceSheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onPriceEditStarting);
  170. this.priceSheet.name('price_calc');
  171. if(projectReadOnly){
  172. sheetCommonObj.disableSpread(this.priceSpread);
  173. }else {
  174. this.initRightClick("priceSheet",this.priceSpread)
  175. }
  176. },
  177. showFreightDatas:function () {
  178. if(!$('#freightSheet').is(':visible')) return;
  179. let sel = this.freightSheet.getSelections()[0];
  180. let oldData = sel.row<this.freightDatas.length?this.freightDatas[sel.row]:"";
  181. this.freightSheet.setRowCount(0);
  182. this.freightDatas = this.getFreightDatas();
  183. sheetCommonObj.showData(this.freightSheet, this.freightSetting,this.freightDatas);
  184. this.freightSheet.setRowCount(this.freightDatas.length+20);
  185. let convCol = _.findIndex(this.freightSetting.header,{'dataCode':'conveyance'});
  186. sheetCommonObj.setComboBox(-1,convCol,this.freightSheet,this.conveyanceOptions,false);
  187. let startCol = _.findIndex(this.freightSetting.header,{'dataCode':'start'});
  188. let startOptions = this.getUserFreightOptions();
  189. sheetCommonObj.setComboBox(-1,startCol,this.freightSheet,startOptions,false,true,5);
  190. sel.row = oldData?_.findIndex(this.freightDatas,{'ID':oldData.ID}):sel.row ;
  191. this.freightSheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
  192. this.refreshRationView();
  193. },
  194. getUserFreightOptions :function () {
  195. let options = [];
  196. for(let uf of this.userFreightList){
  197. options.push(uf.freight.start);
  198. }
  199. return options;
  200. },
  201. showFreightRationDatas:function (freight) {
  202. let sel = this.freightRationSheet.getSelections()[0];
  203. let oldData = sel.row<this.freightRations.length?this.freightRations[sel.row]:"";
  204. this.freightRationSheet.setRowCount(0);
  205. this.freightRations = freight.rations?freight.rations:[];
  206. sheetCommonObj.showData(this.freightRationSheet, this.rationSetting,this.freightRations);
  207. this.freightRationSheet.setRowCount(this.freightRations+20);
  208. sel.row = oldData?_.findIndex(this.freightRations,{'ID':oldData.ID}):sel.row ;
  209. this.freightRationSheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
  210. this.refreshAssView();
  211. },
  212. showPriceRationDatas:function () {
  213. let price = this.getSelectedPrice();
  214. let sel = this.priceRationSheet.getSelections()[0];
  215. let oldData = sel.row<this.priceRations.length?this.priceRations[sel.row]:"";
  216. this.priceRationSheet.setRowCount(0);
  217. this.priceRations = price&&price.rations?price.rations:[];
  218. sheetCommonObj.showData(this.priceRationSheet, this.rationSetting,this.priceRations);
  219. this.priceRationSheet.setRowCount(this.priceRations+20);
  220. sel.row = oldData?_.findIndex(this.priceRations,{'ID':oldData.ID}):sel.row ;
  221. this.priceRationSheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
  222. this.refreshAssView();
  223. },
  224. showMaterialCalcDatas:function(){
  225. let sel = this.materialSheet.getSelections()[0];
  226. let oldData = sel.row<this.materialDatas.length?this.materialDatas[sel.row]:"";
  227. this.materialSheet.setRowCount(0);
  228. this.materialDatas = this.getMaterialCalcDatas();
  229. sheetCommonObj.showData(this.materialSheet, this.materialSetting,this.materialDatas);
  230. this.materialSheet.setRowCount(this.materialDatas.length);
  231. let pglj = projectGljObject.getProjectGLJSelected()
  232. sel.row = pglj?_.findIndex(this.materialDatas,{'id':pglj.id}):-1;
  233. if(sel.row == -1) sel.row = oldData?_.findIndex(this.materialDatas,{'id':oldData.id}):-1;
  234. this.materialSheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
  235. this.materialSheet.showRow(sel.row==-1?0:sel.row, GC.Spread.Sheets.VerticalPosition.center);
  236. },
  237. showPriceDatas:function () {
  238. if(!$('#priceSheet').is(':visible')) return;
  239. let sel = this.priceSheet.getSelections()[0];
  240. let oldData = sel.row<this.priceDatas.length?this.priceDatas[sel.row]:"";
  241. this.priceSheet.setRowCount(0);
  242. this.priceDatas = this.getPriceDatas();
  243. sheetCommonObj.showData(this.priceSheet, this.priceSetting,this.priceDatas);
  244. this.priceSheet.setRowCount(this.priceDatas.length+20);
  245. sel.row = oldData?_.findIndex(this.priceDatas,{'ID':oldData.ID}):sel.row ;
  246. this.priceSheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
  247. this.showPriceRationDatas();
  248. },
  249. showDatas:async function(){
  250. if(!$('#materialCalcSheet').is(':visible')) return;
  251. if(!this.materialSpread) this.initMaterialSpread();
  252. if(!this.freightSpread)await this.initFreightSpread();
  253. if(!this.priceSpread) this.initPriceSpread();
  254. if(!this.freightRationSpread) this.initFreightRationSpread();
  255. if(!this.priceRationSpread) this.initPriceRationSpread();
  256. let h =_.find(this.rationSetting.header,{"dataCode":"feeType"});
  257. if(h) h.options = projectObj.project.calcProgram.compiledTemplateNames;
  258. this.showMaterialCalcDatas();
  259. this.showFreightDatas();
  260. this.showPriceDatas();
  261. // 先试试看注释有没有bug projectGljObject.refreshSubViews();
  262. },
  263. getMaterialSelected:function () {
  264. let sel = this.materialSheet.getSelections()[0];
  265. if(sel.row != -1 && this.materialDatas.length>sel.row){
  266. return this.materialDatas[sel.row]
  267. }
  268. return null;
  269. },
  270. getPriceDatas:function () {
  271. let list = projectObj.project.projectGLJ.datas.originalList;
  272. let material = this.getMaterialSelected();
  273. return material?_.filter(list,{"connect_key":gljUtil.getIndex(material)}):[];
  274. },
  275. getFreightDatas:function () {
  276. let list = projectObj.project.projectGLJ.datas.freightList;
  277. let material = this.getMaterialSelected();
  278. return material?_.filter(list,{"connect_key":gljUtil.getIndex(material)}):[];
  279. },
  280. getMaterialCalcDatas:function () {
  281. let gljList = projectObj.project.projectGLJ.datas.gljList;
  282. let datas = [];
  283. for(let g of gljList){
  284. if(g.quantity !== 0 && g.quantity !== '0' && g.unit_price.calcMaterial == 1){
  285. let data = {
  286. id:g.id,
  287. code:g.code,
  288. name:g.name,
  289. type:g.type,
  290. unit:g.unit,
  291. specs:g.specs,
  292. unit_price:{id:g.unit_price.id,type:g.type,unit_price_file_id:g.unit_price.unit_price_file_id},//type用来排序
  293. supplyLocation:g.unit_price.supplyLocation,
  294. originalPrice:g.unit_price.originalPrice?g.unit_price.originalPrice:0,
  295. unitFreight:g.unit_price.unitFreight?g.unit_price.unitFreight:0,
  296. // unitWeight:g.unit_price.unitWeight?g.unit_price.unitWeight:0,
  297. totalLoadingTimes:g.unit_price.totalLoadingTimes?g.unit_price.totalLoadingTimes:0,
  298. handlingLossRate_n:g.unit_price.handlingLossRate_n?g.unit_price.handlingLossRate_n:0,
  299. offSiteTransportLossRate_n:g.unit_price.offSiteTransportLossRate_n?g.unit_price.offSiteTransportLossRate_n:0,
  300. offSiteTransportLoss:g.unit_price.offSiteTransportLoss?g.unit_price.offSiteTransportLoss:0,
  301. purchaseStorageRate_n:g.unit_price.purchaseStorageRate_n?g.unit_price.purchaseStorageRate_n:0,
  302. purchaseStorage:g.unit_price.purchaseStorage?g.unit_price.purchaseStorage:0,
  303. grossWeightCoe_n:g.unit_price.grossWeightCoe_n?g.unit_price.grossWeightCoe_n:0,
  304. packageRecoverValue:g.unit_price.packageRecoverValue?g.unit_price.packageRecoverValue:0
  305. };
  306. gljOprObj.setGLJPrice(data,g);
  307. datas.push(data);
  308. }
  309. }
  310. return gljUtil.sortProjectGLJ(datas);
  311. },
  312. onMaterialSelectionChange:function(sender,args){
  313. let me = materialCalcObj;
  314. let newSel = args.newSelections[0];
  315. let oldSel = args.oldSelections?args.oldSelections[0]:{};
  316. if(newSel.row != oldSel.row){
  317. me.showPriceDatas();
  318. me.showFreightDatas();
  319. projectGljObject.setSelectionWhenMaterialChange(me.getMaterialSelected())
  320. }
  321. },
  322. onFreightSelectionChange:function (sender,args) {
  323. materialCalcObj.refreshRationView();
  324. args.sheet.repaint();
  325. },
  326. onRationSelectionChange:function(sender,args){
  327. materialCalcObj.refreshAssView(args);
  328. args.sheet.repaint();
  329. },
  330. onPriceSelectionChange:function (sender,args) {
  331. materialCalcObj.showPriceRationDatas();
  332. },
  333. onPriceEditStarting:function (sender,args) {
  334. let me = materialCalcObj;
  335. if(!me.getMaterialSelected()){
  336. args.cancel = true;
  337. }else {
  338. let price = me.priceDatas[args.row];
  339. let dataCode = me.priceSetting.header[args.col].dataCode;
  340. if(dataCode == "supplyPrice"){
  341. if(price.rations && price.rations.length > 0) args.cancel = true;
  342. }
  343. }
  344. },
  345. onFreightEditStarting:function(sender,args){
  346. let me = materialCalcObj;
  347. if(!me.getMaterialSelected()){
  348. args.cancel = true;
  349. }else {
  350. let freigth = me.freightDatas[args.row];
  351. let dataCode = me.freightSetting.header[args.col].dataCode;
  352. if(dataCode=="materialType"){
  353. if(!freigth){
  354. args.cancel = true;
  355. }else if(freigth.conveyance !="汽车"){//只有在汽车的情况下,材料类型列才能编辑
  356. args.cancel = true;
  357. }
  358. }
  359. if(freigth){
  360. if(dataCode == "kmDistance" || dataCode=="unitLoadingFee" || dataCode =="loadingTimes" || dataCode == "freightIncreaseRate"){
  361. if(freigth.conveyance == "自办运输") args.cancel = true;
  362. }
  363. if(dataCode == "unitFreight"){
  364. if(freigth.conveyance == "自办运输") args.cancel = true;
  365. if(freigth.rations && freigth.rations.length > 0) args.cancel = true;
  366. if(gljUtil.isDef(freigth.materialType) && freigth.materialType != "") args.cancel = true;//当材料类型有值时,说明是内蒙古计算,运费是通过运距算出来的,不能编辑
  367. }
  368. }
  369. }
  370. },
  371. onFreightRationEditStarting:function (sender,args) {
  372. materialCalcObj.onRationEditStarting(sender,args,"freight");
  373. },
  374. onPriceRationEditStarting:function (sender,args) {
  375. materialCalcObj.onRationEditStarting(sender,args,"price");
  376. },
  377. onRationEditStarting:function(sender,args,type){
  378. let me = materialCalcObj;
  379. let dataCode = me.rationSetting.header[args.col].dataCode;
  380. let datas = type == "freight"?me.freightRations:me.priceRations;
  381. if(type == 'price' && !gljUtil.isDef(me.getSelectedPrice())) args.cancel = true;//没有选中原价,不可编辑
  382. if(args.row > datas.length){
  383. args.cancel = true;
  384. }else if(args.row == datas.length && dataCode != "code"){
  385. args.cancel = true;
  386. }
  387. },
  388. onMaterialEditStarting:function (sender,args) {
  389. let me = materialCalcObj;
  390. let dataCode = me.materialSetting.header[args.col].dataCode;
  391. if(dataCode == "supplyLocation" ||dataCode == "originalPrice"){//原价计算表有数据时只读,
  392. args.cancel = me.getPriceDatas().length > 0;
  393. }
  394. if(dataCode == "unitFreight"){//当运费计算表有数据时,则只读
  395. args.cancel = me.getFreightDatas().length > 0;
  396. }
  397. },
  398. onMaterialValueChange:function (sender,args) {
  399. let me = materialCalcObj;
  400. let dataMap = {};
  401. dataMap[args.row]={};
  402. dataMap[args.row][args.col] = args.newValue;
  403. me.updateMaterialCalcs(dataMap);
  404. },
  405. updateMaterialCalcs:function(dataMap){
  406. let me = materialCalcObj;
  407. let updateDatas = [];
  408. for(let row in dataMap) {
  409. let t = dataMap[row];
  410. let doc = {};
  411. let recode = me.materialDatas[row];
  412. for (let col in t) {
  413. let value = t[col];
  414. let dataCode = me.materialSetting.header[col].dataCode;
  415. if (value&&!sheetCommonObj.checkData(col,me.materialSetting,value)) {
  416. alert('输入的数据类型不对,请重新输入!');
  417. return me.showDatas();
  418. }
  419. if(dataCode != 'supplyLocation'){
  420. let decimal = getDecimal("glj.unitPrice");
  421. if(dataCode == "grossWeightCoe_n") decimal = 6;
  422. value = value?scMathUtil.roundForObj(value,decimal)+'':'0'//4舍五入加默认为0
  423. }
  424. if(recode[dataCode] == value) continue;
  425. doc[dataCode] = value;
  426. }
  427. if (!_.isEmpty(doc)) updateDatas.push({id:recode.id,doc:doc});
  428. }
  429. if(updateDatas.length > 0) projectObj.project.projectGLJ.updateMaterialCalc(updateDatas);
  430. },
  431. getDefualtCalcType:function () {
  432. return "全国";
  433. },
  434. getNewFreightData:function (material) {
  435. let newData = {
  436. ID: uuid.v1(),
  437. start:"",//起讫地点
  438. conveyance:"汽车",//运输工具
  439. unitFreight:'0',//单位运价
  440. kmDistance:'0',//km运距
  441. unitLoadingFee:'0',//装卸费单价
  442. loadingTimes:'0',//装卸次数
  443. otherFee:'0',//其它费用
  444. freightIncreaseRate:'0',//运价增加率
  445. weightCoe:'1',//加权系数
  446. connect_key:gljUtil.getIndex(material),
  447. materialType:"",
  448. unit_price_file_id:material.unit_price.unit_price_file_id
  449. };
  450. return newData;
  451. },
  452. getFreightEXP:function(obj,doc,needUpdate){
  453. let item = _.clone(obj);
  454. if(doc) gljUtil.setProperty(item,doc);
  455. let material = materialCalcObj.getMaterialSelected();
  456. if(gljUtil.isDef(item.materialType)&&item.materialType != ""){
  457. let uString = materialCalcObj.getNeiMengUnitFreightString(item.kmDistance,item.materialType);
  458. return `((${uString}×(1+${item.freightIncreaseRate}%)+${item.unitLoadingFee}×${item.loadingTimes})/1.09+${item.otherFee})×${material.grossWeightCoe_n}×${item.weightCoe}`;
  459. }
  460. //(单位运价×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重×加权系数
  461. if(item.conveyance == "自办运输"){
  462. let t = projectObj.project.projectGLJ.calcEachFreightOrPrice(item,"freight",{},needUpdate);
  463. if(t) return t.doc.exp;
  464. }
  465. //(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重×加权系数
  466. return `(${item.unitFreight}×${item.kmDistance}×(1+${item.freightIncreaseRate}%)+${item.unitLoadingFee}×${item.loadingTimes}+${item.otherFee})×${material.grossWeightCoe_n}×${item.weightCoe}`;
  467. },
  468. getSavedFreight:function (start,material) {
  469. let t = null;
  470. for(let f of this.userFreightList){
  471. if(f.freight.start == start){
  472. t = newDatas(f.freight,material);
  473. break;
  474. }
  475. }
  476. return t;
  477. function newDatas(freight,material) {
  478. let doc = {};
  479. for(let key in freight){
  480. doc[key] = freight[key];
  481. if(key == "ID") doc[key] = uuid.v1();
  482. if(key == "connect_key") doc[key] = gljUtil.getIndex(material);
  483. if(key == "unit_price_file_id") doc[key] = material.unit_price.unit_price_file_id;
  484. }
  485. delete doc._id;
  486. return doc;
  487. }
  488. },
  489. checkSavedFreight:function (start) {
  490. let t = null;
  491. for(let f of this.userFreightList){
  492. if(f.freight.start == start){
  493. t = f;
  494. break;
  495. }
  496. }
  497. return t;
  498. },
  499. onMaterialRangeChange:function(sender,args){
  500. let me = materialCalcObj;
  501. let dataMap={};
  502. for(let c of args.changedCells){
  503. let info = {row:c.row,col:c.col,cancel:false};
  504. me.onMaterialEditStarting(sender,info);
  505. if(info.cancel) return me.showDatas();
  506. let value= args.sheet.getCell(c.row, c.col).text();
  507. if(dataMap[c.row]){
  508. dataMap[c.row][c.col]=value;
  509. }else{
  510. dataMap[c.row] ={};
  511. dataMap[c.row][c.col] = value;
  512. }
  513. }
  514. me.updateMaterialCalcs(dataMap);
  515. },
  516. onFreightPriceRangeChange:function (sender,args) {
  517. let me = materialCalcObj;
  518. let dataMap={};
  519. let sheetName = args.sheet.name();
  520. for(let c of args.changedCells){
  521. let info = {row:c.row,col:c.col,cancel:false};
  522. sheetName == 'price_calc'?me.onPriceEditStarting(sender,info): me.onFreightEditStarting(sender,info);
  523. if(info.cancel) return me.showDatas();
  524. let value= args.sheet.getCell(c.row, c.col).text();
  525. if(dataMap[c.row]){
  526. dataMap[c.row][c.col]=value;
  527. }else{
  528. dataMap[c.row] ={};
  529. dataMap[c.row][c.col] = value;
  530. }
  531. }
  532. sheetName == 'price_calc'?me.addOrUpdatePriceCalc(dataMap):me.addOrUpdateFreightCalc(dataMap);
  533. },
  534. onFreightValueChange:function (sender,args) {
  535. let me = materialCalcObj;
  536. let dataMap = {};
  537. dataMap[args.row]={};
  538. dataMap[args.row][args.col] = args.newValue;
  539. me.addOrUpdateFreightCalc(dataMap);
  540. },
  541. addOrUpdateFreightCalc:function (dataMap) {//{2:{col:value}}
  542. let me = materialCalcObj;
  543. let material = me.getMaterialSelected();
  544. let addDatas=[],updateDatas=[];
  545. for(let row in dataMap) {
  546. let t = dataMap[row];
  547. let newData = {};
  548. let doc = {};
  549. let recode = me.freightDatas[row];
  550. for (let col in t) {
  551. let value = t[col];
  552. let dataCode = me.freightSetting.header[col].dataCode;
  553. if (value && !sheetCommonObj.checkData(col, me.freightSetting, value)) {
  554. alert('输入的数据类型不对,请重新输入!');
  555. return me.showDatas();
  556. }
  557. if (dataCode != 'start' && dataCode != 'conveyance' && dataCode != 'calcType' && dataCode != 'materialType') {
  558. value = value ? scMathUtil.roundForObj(value, getDecimal("glj.unitPrice")) + '' : '0'//4舍五入加默认为0
  559. }
  560. if (parseInt(row) >= me.freightDatas.length) {//新增
  561. let tempFreight = null;
  562. if (dataCode == "start") {
  563. tempFreight = me.getSavedFreight(value, material);
  564. }
  565. if (tempFreight) {
  566. if (tempFreight.conveyance == "自办运输") tempFreight.exp = "";
  567. newData = tempFreight;
  568. } else {
  569. if(_.isEmpty(newData)) newData = me.getNewFreightData(material);
  570. newData[dataCode] = value;
  571. newData.exp = this.getFreightEXP(newData);
  572. }
  573. } else {//修改
  574. if (recode[dataCode] == value) continue;
  575. doc[dataCode] = value;
  576. if (dataCode == "conveyance") {//如果运输方式从自办运输切换成其它的东西时,要把底下挂的定额和定额工料机都清空
  577. if (recode[dataCode] == "自办运输") {//没改之前的值
  578. doc["rations"] = [];
  579. doc["ration_gljs"] = [];
  580. }
  581. if (value == "自办运输") {//当运输工具下拉选择“自办运输”时,“Km运距”、“装卸费单价”、“装卸次数”、“运价增加率(%)”列数据归0,且灰选不可编辑
  582. doc["kmDistance"] = '0';
  583. doc["unitLoadingFee"] = '0';
  584. doc["loadingTimes"] = '0';
  585. doc["freightIncreaseRate"] = '0';
  586. }
  587. if (recode[dataCode] == "汽车") doc["materialType"] = "";//当运输方式从汽车切换成其它方式时,清空材料类型
  588. }
  589. if (dataCode == "materialType" && value != "") doc["unitFreight"] = me.calcNeiMengUnitFreight(recode.kmDistance, value);
  590. if (dataCode == "kmDistance" && gljUtil.isDef(recode.materialType) && recode.materialType != "") doc["unitFreight"] = me.calcNeiMengUnitFreight(value, recode.materialType);
  591. if (dataCode == "start") {
  592. let t_f = me.getSavedFreight(value, material);
  593. if (t_f) doc = t_f;
  594. }
  595. doc.exp = this.getFreightEXP(recode,doc,true);
  596. }
  597. }
  598. if (!_.isEmpty(newData)) addDatas.push(newData);
  599. if (!_.isEmpty(doc)) updateDatas.push({ID:recode.ID,doc:doc});
  600. }
  601. if(addDatas.length > 0 && updateDatas.length > 0) {
  602. alert("不能同时增加和更新操作");
  603. return me.showDatas();
  604. }
  605. if(addDatas.length > 0) projectObj.project.projectGLJ.addFreightCalc(addDatas,material.id);
  606. if(updateDatas.length > 0) projectObj.project.projectGLJ.updateFreightCalc(updateDatas,material.id);
  607. },
  608. calcNeiMengUnitFreight:function (tkmDistance,tmaterialType) {
  609. if(!tkmDistance||tkmDistance == '0') return "0";
  610. let decimal = getDecimal("glj.unitPrice");
  611. tkmDistance = scMathUtil.roundForObj(tkmDistance,decimal);
  612. return scMathUtil.roundForObj(this.calNeiMengTotalFreight(tkmDistance,tmaterialType)/tkmDistance,decimal);
  613. },
  614. calNeiMengTotalFreight:function (kmDistance,materialType) {
  615. if(!kmDistance||kmDistance == '0') return 0;
  616. let decimal = getDecimal("glj.unitPrice");
  617. let baseMap = {"地方材料":6,"外购材料":13,"沥青、燃料等":19};//"地方材料","外购材料","沥青、燃料等"
  618. let baseFreight = baseMap[materialType];
  619. kmDistance = scMathUtil.roundForObj(kmDistance,decimal);
  620. //用截取的方式,一段段取值
  621. let less = kmDistance - 5;//kmDistance <= 5 这段
  622. let backLess = less;
  623. if(less <= 0) return baseFreight ; //kmDistance <= 5 的时候直接取baseFreight
  624. //5< kmDistance <= 15 每增运1km 则增加0.6
  625. less = scMathUtil.roundForObj(less - 10,decimal);
  626. backLess = scMathUtil.roundForObj(less + 10,decimal);
  627. if(less <=0) return scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj(backLess * 0.6,6),decimal);//baseFreight + (less + 10) * 0.6;
  628. baseFreight = scMathUtil.roundForObj(baseFreight + 10 * 0.6,6); //累加5到15这一段的运费;
  629. //15< kmDistance <= 100 每增运1km 则增加0.45
  630. less = scMathUtil.roundForObj(less - 85,decimal);
  631. backLess = scMathUtil.roundForObj(less + 85,decimal);
  632. if(less <=0) return scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj(backLess*0.45,6),decimal);//baseFreight + (less + 85)*0.45;
  633. baseFreight = scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj(85*0.45,6),6) ; //累加15到100这一段的运费;
  634. return scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj(less * 0.35,6),decimal); // >100 的所有部分每增运1km 则增加0.35 baseFreight + less * 0.35
  635. },
  636. getNeiMengUnitFreightString:function (kmDistance,materialType) {
  637. if(!kmDistance||kmDistance == '0') return "0";
  638. let decimal = getDecimal("glj.unitPrice");
  639. let baseMap = {"地方材料":6,"外购材料":13,"沥青、燃料等":19};//"地方材料","外购材料","沥青、燃料等"
  640. let baseFreight = baseMap[materialType];
  641. kmDistance = scMathUtil.roundForObj(kmDistance,decimal);
  642. let resultString = baseFreight+"";
  643. //用截取的方式,一段段取值
  644. let less = scMathUtil.roundForObj(kmDistance - 5,decimal);//kmDistance <= 5 这段
  645. if(less <= 0) return resultString ; //kmDistance <= 5 的时候直接取baseFreight
  646. //5< kmDistance <= 15 每增运1km 则增加0.6
  647. less = scMathUtil.roundForObj(less - 10,decimal);
  648. if(less <=0) return `(${resultString}+0.6×${scMathUtil.roundForObj(less + 10,decimal)})`;//baseFreight + (less + 10) * 0.6;
  649. resultString = `${resultString}+0.6×10`;
  650. //15< kmDistance <= 100 每增运1km 则增加0.45
  651. less = scMathUtil.roundForObj(less - 85,decimal);
  652. if(less <=0) return `(${resultString}+0.45×${scMathUtil.roundForObj(less + 85,decimal)})`; //baseFreight + (less + 85)*0.45;
  653. resultString = `${resultString}+0.45×85`;
  654. return `(${resultString}+0.35×${less})`;// >100 的所有部分每增运1km 则增加0.35 baseFreight + less * 0.35
  655. },
  656. onFreightRationValueChange:function (sender,args) {
  657. materialCalcObj.onRationValueChange(sender,args,"freight");
  658. },
  659. onPriceRationValueChange:function (sender,args) {
  660. materialCalcObj.onRationValueChange(sender,args,"price");
  661. },
  662. onRationValueChange:function (sender,args,type) {
  663. let me = materialCalcObj;
  664. let dataCode = me.rationSetting.header[args.col].dataCode;
  665. let value = args.newValue;
  666. let parent = type == "freight"? me.getSelectedFreight():me.getSelectedPrice();
  667. let dataList = type == "freight"?me.freightRations:me.priceRations;
  668. if(dataCode == "code" && args.row >= dataList.length) {//新增
  669. if(parent) projectObj.project.projectGLJ.addMaterialRation(value,type,parent.ID,parent.connect_key);
  670. }else { //修改
  671. let ration = dataList[args.row];
  672. if (value&&!sheetCommonObj.checkData(args.col,me.rationSetting,value)) {
  673. alert('输入的数据类型不对,请重新输入!');
  674. return type == "freight"?me.showFreightRationDatas(parent):me.showPriceRationDatas();
  675. }
  676. if(dataCode == 'quantity'){
  677. if(value){
  678. value = scMathUtil.roundForObj(parseFloat(value) / FilterNumberFromUnit(ration.unit),getDecimal("ration.quantity"))+"";
  679. }else {
  680. value = "0";
  681. }
  682. }
  683. let datas = {parentID:parent.ID,rationID:ration.ID,type:type,actionType:"update",field:dataCode,value:value};
  684. if(dataCode == "code"){ //这时是替换,替换比较麻烦
  685. datas.code = value;
  686. datas.row = args.row;
  687. let libIDs = rationLibObj.getStdRationLibIDs();
  688. let defaultLibID = rationLibObj.getDefaultStdRationLibID();
  689. let selectedLib = sessionStorage.getItem("stdRationLib");
  690. selectedLib&&selectedLib!='undefined'?libIDs.unshift(selectedLib):libIDs.unshift(defaultLibID);
  691. datas.userID = userID;
  692. datas.defaultLibID = defaultLibID;
  693. datas.rationRepIds = libIDs;
  694. datas.quantityDecimal = getDecimal("ration.quantity");
  695. datas.connect_key = parent.connect_key;
  696. datas.projectID = projectObj.project.ID();
  697. datas.rations = parent.rations;
  698. datas.ration_gljs = parent.ration_gljs;
  699. }
  700. projectObj.project.projectGLJ.updateMaterialRation(datas);
  701. }
  702. },
  703. addOrUpdatePriceCalc:function (dataMap) {
  704. let me = materialCalcObj;
  705. let material = me.getMaterialSelected();
  706. let addDatas=[],updateDatas=[];
  707. for(let row in dataMap) {
  708. let t = dataMap[row];
  709. let doc = {};
  710. let recode = me.priceDatas[row];
  711. let newData = {};
  712. for (let col in t) {
  713. let value = t[col];
  714. let dataCode = me.priceSetting.header[col].dataCode;;
  715. if (value && !sheetCommonObj.checkData(col, me.priceSetting, value)) {
  716. alert('输入的数据类型不对,请重新输入!');
  717. return me.showDatas();
  718. }
  719. if(dataCode == 'coe'||dataCode == 'supplyPrice'){
  720. let decimal = dataCode == 'supplyPrice'?getDecimal("glj.unitPriceHasMix"):getDecimal("glj.unitPrice");
  721. value = value?scMathUtil.roundForObj(value,decimal)+'':'0'//4舍五入加默认为0
  722. }
  723. if(parseInt(row) >= me.priceDatas.length){//新增
  724. if(_.isEmpty(newData)) newData = me.getNewPriceData(material);
  725. newData[dataCode] = value;
  726. }else {//修改
  727. if(recode[dataCode] == value) continue;
  728. doc[dataCode] = value;
  729. }
  730. }
  731. if (!_.isEmpty(newData)) addDatas.push(newData);
  732. if (!_.isEmpty(doc)) updateDatas.push({ID:recode.ID,doc:doc});
  733. }
  734. if(addDatas.length > 0 && updateDatas.length > 0) {
  735. alert("不能同时增加和更新操作");
  736. return me.showDatas();
  737. }
  738. if(addDatas.length > 0) projectObj.project.projectGLJ.addPriceCalc(addDatas,material.id);
  739. if(updateDatas.length > 0) projectObj.project.projectGLJ.updatePriceCalc(updateDatas,material.id);
  740. },
  741. getNewPriceData:function (material) {
  742. let newData = {
  743. ID:uuid.v1(),
  744. supplyLocation:"",
  745. supplyPrice:'0',
  746. coe:'1',
  747. connect_key:gljUtil.getIndex(material),
  748. unit_price_file_id:material.unit_price.unit_price_file_id
  749. };
  750. return newData;
  751. },
  752. onPriceValueChange:function(sender,args){
  753. let me = materialCalcObj;
  754. let dataMap = {};
  755. dataMap[args.row]={};
  756. dataMap[args.row][args.col] = args.newValue;
  757. me.addOrUpdatePriceCalc(dataMap);
  758. },
  759. deleteMaterialCal:function (row) {
  760. let record = this.materialDatas[row];//修改材料计算标记的同时还要删除原价计算,运费计算等
  761. if(record){
  762. projectObj.project.projectGLJ.updateCalcMaterial(record,0);
  763. }
  764. },
  765. deletePriceCalc:function (row) {
  766. let record = this.priceDatas[row];
  767. if(record){
  768. let material = this.getMaterialSelected();
  769. projectObj.project.projectGLJ.deletePriceCalc(record.ID,material.id);
  770. }
  771. },
  772. deleteFreightCalc:function (row) {
  773. let record = this.freightDatas[row];
  774. if(record){
  775. let material = this.getMaterialSelected();
  776. projectObj.project.projectGLJ.deleteFreightCalc(record.ID,material.id);
  777. }
  778. },
  779. deleteRation:function (row,type) {
  780. let me = this;
  781. let parent = type == "freight"?me.getSelectedFreight():me.getSelectedPrice();
  782. let ration = type == "freight"?me.freightRations[row]:me.priceRations[row];
  783. let datas = {parentID:parent.ID,rationID:ration.ID,type:type,actionType:"delete"};
  784. projectObj.project.projectGLJ.updateMaterialRation(datas);
  785. },
  786. saveFreight:function (row) {
  787. let me = this;
  788. let record = this.freightDatas[row];
  789. if(record){
  790. let exist = this.checkSavedFreight(record.start);
  791. if(exist){//已存在的情况,更新
  792. let info =`起讫地点“${record.start}”已存在,是否覆盖?`;
  793. //to do 检查是否已经存在,存在给出是否覆盖提示
  794. hintBox.infoBox('操作确认', info, 2, function () {
  795. me.updateUserFreight(record,exist)
  796. }, function () {
  797. //
  798. },['确定','取消'],false);
  799. return true;
  800. }
  801. let user_freight = {rootProjectID:projectObj.project.projectInfo.property.rootProjectID};
  802. let f = {};
  803. for(let key in record){
  804. if(key == "_id") continue;
  805. f[key] = record[key];
  806. if(key =="rations" || key == "ration_gljs")f[key] = [];//下面的定额和工料机不用保存
  807. }
  808. user_freight.freight = f;
  809. projectObj.project.projectGLJ.updateUserFreight({freights:[user_freight],action:"add"});
  810. }
  811. },
  812. updateUserFreight:function (record,userFreight) {
  813. let t = {};
  814. for (let t_key in userFreight) {
  815. if (t_key == "ID") continue;
  816. t[t_key] = userFreight[t_key];
  817. }
  818. t.rootProjectID = projectObj.project.projectInfo.property.rootProjectID;
  819. let f = {};
  820. for (let key in record) {
  821. if (key == "_id") continue;
  822. f[key] = record[key];
  823. if (key == "rations" || key == "ration_gljs") f[key] = []; //下面的定额和工料机不用保存
  824. }
  825. if (record.conveyance == "自办运输") f.exp = '';
  826. t.freight = f;
  827. projectObj.project.projectGLJ.updateUserFreight({
  828. ID: userFreight.ID,
  829. doc: t,
  830. action: "update"
  831. });
  832. },
  833. getSideResize: function () {
  834. let rg_sideResizeEles = {};
  835. rg_sideResizeEles.eleObj = {
  836. module: this.moduleName,
  837. resize: $('#mrResize'),
  838. parent: $('#projectGljBottom'),
  839. left: $('#materialCalcSheet'),
  840. right: $('#calcDiv')
  841. };
  842. rg_sideResizeEles.limit = {
  843. min: 100,
  844. max: `$('#projectGljBottom').width()-100`
  845. };
  846. return rg_sideResizeEles;
  847. },
  848. initRightClick:function (id,spread) {
  849. let me = this;
  850. $.contextMenu({
  851. selector: '#'+id,
  852. build: function ($trigger, e) {
  853. me.rightClickTarget = SheetDataHelper.safeRightClickSelection($trigger, e, spread);
  854. return me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.viewport ||
  855. me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  856. },
  857. items: {
  858. "insertFreight":{
  859. name: "内蒙古计算",
  860. icon: 'fa-sign-in',
  861. visible:function () {
  862. return false;//2019-11-17 改成不需要右键插入功能 id == "freightSheet";
  863. },
  864. disabled: function (){
  865. let material = me.getMaterialSelected();
  866. return !material;
  867. },
  868. callback:function () {
  869. $("#insertNeimengDiv").modal("show");
  870. }
  871. },
  872. "saveFreight":{
  873. name: "保存运输起讫地点",
  874. icon: 'fa-sign-in',
  875. visible:function () {
  876. return id == "freightSheet";
  877. },
  878. disabled: function (){
  879. if(id == "freightSheet") return me.rightClickTarget.row >= me.freightDatas.length;
  880. return me.rightClickTarget.row === undefined;
  881. },
  882. callback:function () {
  883. let row = me.rightClickTarget.row;
  884. me.saveFreight(row);
  885. }
  886. },
  887. "delete": {
  888. name: "删除",
  889. icon: 'fa-trash-o',
  890. disabled: function () {
  891. if(id == "priceSheet") return me.rightClickTarget.row >= me.priceDatas.length;
  892. if(id == "freightSheet") return me.rightClickTarget.row >= me.freightDatas.length;
  893. if(id == "freight_ration_sheet") return me.rightClickTarget.row >= me.freightRations.length;
  894. if(id == "price_ration_sheet") return me.rightClickTarget.row >= me.priceRations.length;
  895. return me.rightClickTarget.row === undefined;
  896. },
  897. callback: function (key, opt) {
  898. let row = me.rightClickTarget.row;
  899. if (id == "materialCalcSheet") me.deleteMaterialCal(row);
  900. if (id == "priceSheet") me.deletePriceCalc(row);
  901. if (id == "freightSheet") me.deleteFreightCalc(row);
  902. if (id == "freight_ration_sheet") me.deleteRation(row,"freight");
  903. if (id == "price_ration_sheet") me.deleteRation(row,"price");
  904. }
  905. }
  906. }
  907. });
  908. },
  909. initTabWidth:function () {
  910. if($("#mix_ratio_sheet").is(':visible')) return ;//如果是组成物计算界面,返回
  911. let mr_sideResizeEles = this.getSideResize();
  912. SlideResize.loadHorizonWidth(mr_sideResizeEles.eleObj.module,
  913. [mr_sideResizeEles.eleObj.resize], [mr_sideResizeEles.eleObj.left, mr_sideResizeEles.eleObj.right],null,2);
  914. $("#spreadTabDiv").width( $('#calcDiv').width() - mr_sideResizeEles.eleObj.resize.width() - 32)
  915. },
  916. refreshRationView:function () {
  917. let freight = this.getSelectedFreight();
  918. let hide = true;
  919. let stats = $("#freight_ration").is(':visible');
  920. if(freight && freight.conveyance == "自办运输"){
  921. this.showFreightRationDatas(freight);
  922. $("#freightSheet").css("height","50%");
  923. $("#freight_ration").show();
  924. hide = false;
  925. }
  926. if(hide){
  927. $("#freightSheet").css("height","100%");
  928. $("#freight_ration").hide();
  929. }
  930. if(stats != $("#freight_ration").is(':visible')){//状态改变了才刷新
  931. this.freightSpread.refresh();
  932. this.freightRationSpread.refresh();
  933. }
  934. },
  935. refreshAssView:function () {
  936. let me = materialCalcObj;
  937. let sheet = $('#freightSheet').is(':visible')?me.freightRationSheet:me.priceRationSheet;
  938. let preString = $('#freightSheet').is(':visible')?"freight":"price";
  939. let show = false;
  940. let ass = null;
  941. let ration = me.getSelectedRation();
  942. let stats = $(`#${preString}_ration_ass`).is(':visible');
  943. if(ration && ration.rationAssList){
  944. for(let r of ration.rationAssList){
  945. if(r.name.indexOf("运距")!= -1){//辅助定额只处理运距的情况,其它的都忽略 模糊匹配
  946. show = true;
  947. ass = r;
  948. }
  949. }
  950. }
  951. if(show){
  952. $(`#${preString}_ration_sheet`).addClass("material-ration-left");
  953. $(`#${preString}_ration_ass`).addClass("material-ass");
  954. $(`#${preString}_ass_value`).val(ass.actualValue);
  955. $(`#${preString}_ass_label`).text(ass.name);
  956. $(`#${preString}_ration_ass`).show();
  957. }else {
  958. $(`#${preString}_ration_sheet`).removeClass("material-ration-left");
  959. $(`#${preString}_ration_ass`).removeClass("material-ass");
  960. $(`#${preString}_ration_ass`).hide();
  961. }
  962. if(stats != $(`#${preString}_ration_ass`).is(':visible')) sheet.parent.refresh();//状态改变了才刷新
  963. },
  964. updateMaterialRationAss:function (value,ele) {//to do 同步修改定额工料机的消耗量
  965. let parent = this.getSelectedRationParent(),ration = this.getSelectedRation();
  966. let replaceList = [];
  967. if(value && !number_util.isNum(value)){
  968. alert("输入的数据类型不对,请重新输入!");
  969. let a = _.find(ration.rationAssList,function (item) {
  970. return item.name.indexOf("运距") != -1;
  971. });
  972. if(a)ele.val(a.actualValue);
  973. return;
  974. }
  975. for(let ass of ration.rationAssList){
  976. if(ass.name.indexOf("运距")!= -1){
  977. ass.actualValue = value?scMathUtil.roundForObj(value,2):ass.stdValue;
  978. }
  979. replaceList.push(value);
  980. }
  981. let name = ration.caption;
  982. for(let re of replaceList){
  983. name = name.replace('%s',re);
  984. }
  985. let type = $('#freightSheet').is(':visible')?"freight":"price";
  986. //let ration_glj =
  987. let datas = {parentID:parent.ID,rationID:ration.ID,type:type,actionType:"update",field:"name",value:name,ext:{rationAssList:ration.rationAssList}};
  988. let ration_gljs = projectObj.project.projectGLJ.calcMaterialAssQuantity(parent,ration,ration.rationAssList);
  989. if(ration_gljs.length > 0) datas.ration_gljs = ration_gljs;
  990. projectObj.project.projectGLJ.updateMaterialRation(datas);
  991. },
  992. getSelectedRation:function () {
  993. if($('#freightSheet').is(':visible')){
  994. return this.getSelectedRecode(this.freightRationSheet,this.freightRations);
  995. }else {
  996. return this.getSelectedRecode(this.priceRationSheet,this.priceRations);
  997. }
  998. },
  999. getSelectedRationParent:function () {
  1000. if($('#freightSheet').is(':visible')){
  1001. return this.getSelectedFreight();
  1002. }else {
  1003. return this.getSelectedRecode(this.priceSheet,this.priceDatas);
  1004. }
  1005. },
  1006. getSelectedFreight:function(){
  1007. return this.getSelectedRecode(this.freightSheet,this.freightDatas);
  1008. },
  1009. getSelectedPrice:function () {
  1010. return this.getSelectedRecode(this.priceSheet,this.priceDatas)
  1011. },
  1012. getSelectedRecode:function (sheet,datas) {
  1013. return sheetCommonObj.getSelectedRecode(sheet,datas);
  1014. }
  1015. };
  1016. $(function () {
  1017. $("#calc-nav").on('shown.bs.tab', function () {
  1018. materialCalcObj.initTabWidth();
  1019. materialCalcObj.showDatas();
  1020. projectGljObject.refreshSubViews();
  1021. });
  1022. $("#calTab ul li a").on('shown.bs.tab', function () {
  1023. materialCalcObj.showFreightDatas();
  1024. materialCalcObj.showPriceDatas();
  1025. projectGljObject.refreshSubViews();
  1026. });
  1027. $(".ration_ass_value").change(function () {
  1028. let me = materialCalcObj;
  1029. me.updateMaterialRationAss($(this).val(),$(this));
  1030. });
  1031. $('#calcCoeDiv').on('show.bs.modal', function () {
  1032. if(materialCalcObj.getAssistProductionLabel) $("#assistProductionLabel").text(materialCalcObj.getAssistProductionLabel);
  1033. $("#assistProductionFeeRate").val(scMathUtil.roundForObj(projectObj.project.projectGLJ.datas.constData.assistProductionFeeRate,getDecimal("feeRate")));
  1034. $("#machineConstCoe").val(scMathUtil.roundForObj(projectObj.project.projectGLJ.datas.constData.machineConstCoe,getDecimal("feeRate")));
  1035. })
  1036. $("#calcCoeConfirm").click(function () {
  1037. let feeRate = $("#assistProductionFeeRate").val();
  1038. let constCoe = $("#machineConstCoe").val();
  1039. let rawFeeRate = scMathUtil.roundForObj(projectObj.project.projectGLJ.datas.constData.assistProductionFeeRate,getDecimal("feeRate"));
  1040. let rawConstCoe = scMathUtil.roundForObj(projectObj.project.projectGLJ.datas.constData.machineConstCoe,getDecimal("feeRate"));
  1041. if(!number_util.isNum(rawFeeRate)){
  1042. alert("输入的数据类型不对,请重新输入!");
  1043. return $("#assistProductionFeeRate").val(rawFeeRate);
  1044. }
  1045. if(!number_util.isNum(constCoe)){
  1046. alert("输入的数据类型不对,请重新输入!");
  1047. return $("#machineConstCoe").val(rawConstCoe);
  1048. }
  1049. let updateData = {};
  1050. feeRate = scMathUtil.roundForObj(feeRate,getDecimal("feeRate"));
  1051. constCoe = scMathUtil.roundForObj(constCoe,getDecimal("feeRate"));
  1052. if(feeRate != rawFeeRate) updateData.assistProductionFeeRate = feeRate;
  1053. if(constCoe != rawConstCoe) updateData.machineConstCoe = constCoe;
  1054. $("#calcCoeDiv").modal("hide");
  1055. if(!_.isEmpty(updateData))projectObj.project.projectGLJ.changeAssistProductionFeeRate(updateData);
  1056. });
  1057. $("#insertFreightconfirm").click(function () {
  1058. let me = materialCalcObj;
  1059. let material = me.getMaterialSelected();
  1060. let newData = me.getNewFreightData(material);
  1061. let start = $("#freight_start").val();
  1062. let kmDistance = $("#freight_kmDistance").val();
  1063. let materialType = $("#freight_materialType").val();
  1064. if(!number_util.isNum(kmDistance)){
  1065. alert("运输距离数据类型不对,请重新输入!");
  1066. return ;
  1067. }
  1068. kmDistance = scMathUtil.roundForObj(kmDistance,getDecimal("glj.unitPrice"))+'';
  1069. newData.start = start;
  1070. newData.kmDistance = kmDistance;
  1071. newData.materialType = materialType;
  1072. newData.calcType = "内蒙古";
  1073. newData.unitFreight = me.calcNeiMengUnitFreight(kmDistance,materialType);
  1074. $("#insertNeimengDiv").modal("hide");
  1075. projectObj.project.projectGLJ.addFreightCalc([newData],material.id);
  1076. })
  1077. });
  1078. let mr_sideResizeEles = materialCalcObj.getSideResize();
  1079. SlideResize.horizontalSlide(mr_sideResizeEles.eleObj, mr_sideResizeEles.limit, function(){
  1080. $("#spreadTabDiv").width( $('#calcDiv').width() - mr_sideResizeEles.eleObj.resize.width() - 32);
  1081. projectGljObject.refreshSubViews();
  1082. },2);