material_calc_view.js 49 KB

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