material_calc_view.js 49 KB

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