material_calc_view.js 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  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:[]}
  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. }
  335. },
  336. onFreightEditStarting:function(sender,args){
  337. let me = materialCalcObj;
  338. if(!me.getMaterialSelected()){
  339. args.cancel = true;
  340. }else {
  341. let freigth = me.freightDatas[args.row];
  342. let dataCode = me.freightSetting.header[args.col].dataCode;
  343. if(dataCode=="materialType"){
  344. if(!freigth){
  345. args.cancel = true;
  346. }else if(freigth.conveyance !="汽车"){//只有在汽车的情况下,材料类型列才能编辑
  347. args.cancel = true;
  348. }
  349. }
  350. if(freigth){
  351. if(dataCode == "kmDistance" || dataCode=="unitLoadingFee" || dataCode =="loadingTimes" || dataCode == "freightIncreaseRate"){
  352. if(freigth.conveyance == "自办运输") args.cancel = true;
  353. }
  354. if(dataCode == "unitFreight"){
  355. if(freigth.rations && freigth.rations.length > 0) args.cancel = true;
  356. if(gljUtil.isDef(freigth.materialType) && freigth.materialType != "") args.cancel = true;//当材料类型有值时,说明是内蒙古计算,运费是能过运距算出来的,不能编辑
  357. }
  358. }
  359. }
  360. },
  361. onFreightRationEditStarting:function (sender,args) {
  362. materialCalcObj.onRationEditStarting(sender,args,"freight");
  363. },
  364. onPriceRationEditStarting:function (sender,args) {
  365. materialCalcObj.onRationEditStarting(sender,args,"price");
  366. },
  367. onRationEditStarting:function(sender,args,type){
  368. let me = materialCalcObj;
  369. let dataCode = me.rationSetting.header[args.col].dataCode;
  370. let datas = type == "freight"?me.freightRations:me.priceRations;
  371. if(args.row > datas.length){
  372. args.cancel = true;
  373. }else if(args.row == datas.length && dataCode != "code"){
  374. args.cancel = true;
  375. }
  376. },
  377. onMaterialEditStarting:function (sender,args) {
  378. let me = materialCalcObj;
  379. let dataCode = me.materialSetting.header[args.col].dataCode;
  380. if(dataCode == "supplyLocation" ||dataCode == "originalPrice"){//原价计算表有数据时只读,
  381. args.cancel = me.getPriceDatas().length > 0;
  382. }
  383. if(dataCode == "unitFreight"){//当运费计算表有数据时,则只读
  384. args.cancel = me.getFreightDatas().length > 0;
  385. }
  386. },
  387. onMaterialValueChange:function (sender,args) {
  388. let me = materialCalcObj;
  389. let dataCode = me.materialSetting.header[args.col].dataCode;
  390. let value = args.newValue;
  391. if (value&&!sheetCommonObj.checkData(args.col,me.materialSetting,value)) {
  392. alert('输入的数据类型不对,请重新输入!');
  393. me.showDatas();
  394. return;
  395. }
  396. if(dataCode != 'supplyLocation'){
  397. value = value?scMathUtil.roundForObj(value,getDecimal("glj.unitPrice"))+'':'0'//4舍五入加默认为0
  398. }
  399. let recode = me.materialDatas[args.row];
  400. if(recode[dataCode] == value) return;
  401. let doc = {};
  402. doc[dataCode] = value;
  403. projectObj.project.projectGLJ.updateMaterialCalc([{id:recode.id,doc:doc}]);
  404. },
  405. getDefualtCalcType:function () {
  406. return "全国";
  407. },
  408. getNewFreightData:function (material) {
  409. let newData = {
  410. ID: uuid.v1(),
  411. start:"",//起讫地点
  412. conveyance:"汽车",//运输工具
  413. unitFreight:'0',//单位运价
  414. kmDistance:'0',//km运距
  415. unitLoadingFee:'0',//装卸费单价
  416. loadingTimes:'0',//装卸次数
  417. otherFee:'0',//其它费用
  418. freightIncreaseRate:'0',//运价增加率
  419. weightCoe:'1',//加权系数
  420. connect_key:gljUtil.getIndex(material),
  421. materialType:"",
  422. unit_price_file_id:material.unit_price.unit_price_file_id
  423. };
  424. return newData;
  425. },
  426. getSavedFreight:function (start,material) {
  427. let t = null;
  428. for(let f of this.userFreightList){
  429. if(f.freight.start == start){
  430. t = newDatas(f.freight,material);
  431. break;
  432. }
  433. }
  434. return t;
  435. function newDatas(freight,material) {
  436. let doc = {};
  437. for(let key in freight){
  438. doc[key] = freight[key];
  439. if(key == "ID") doc[key] = uuid.v1();
  440. if(key == "connect_key") doc[key] = gljUtil.getIndex(material);
  441. if(key == "unit_price_file_id") doc[key] = material.unit_price.unit_price_file_id;
  442. }
  443. return doc;
  444. }
  445. },
  446. checkSavedFreight:function (start) {
  447. let t = null;
  448. for(let f of this.userFreightList){
  449. if(f.freight.start == start){
  450. t = f;
  451. break;
  452. }
  453. }
  454. return t;
  455. },
  456. onFreightValueChange:function (sender,args) {
  457. let me = materialCalcObj;
  458. let dataCode = me.freightSetting.header[args.col].dataCode;
  459. let value = args.newValue;
  460. let material = me.getMaterialSelected();
  461. if (value&&!sheetCommonObj.checkData(args.col,me.freightSetting,value)) {
  462. alert('输入的数据类型不对,请重新输入!');
  463. me.showDatas();
  464. return;
  465. }
  466. if(dataCode != 'start'&&dataCode != 'conveyance'&&dataCode != 'calcType'&&dataCode != 'materialType'){
  467. value = value?scMathUtil.roundForObj(value,getDecimal("glj.unitPrice"))+'':'0'//4舍五入加默认为0
  468. }
  469. if(args.row >= me.freightDatas.length){//新增
  470. let newData = {};
  471. let tempFreight = null;
  472. if(dataCode == "start"){
  473. tempFreight = me.getSavedFreight(value,material);
  474. }
  475. if(tempFreight){
  476. newData = tempFreight;
  477. }else {
  478. newData = me.getNewFreightData(material);
  479. newData[dataCode] = value;
  480. }
  481. projectObj.project.projectGLJ.addFreightCalc([newData],material.id);
  482. }else {//修改
  483. let recode = me.freightDatas[args.row];
  484. if(recode[dataCode] == value) return;
  485. let doc = {};
  486. doc[dataCode] = value;
  487. if(dataCode == "conveyance"){//如果运输方式从自办运输切换成其它的东西时,要把底下挂的定额和定额工料机都清空
  488. if(args.oldValue == "自办运输"){
  489. doc["rations"] = [];
  490. doc["ration_gljs"] = [];
  491. }
  492. if(value == "自办运输"){//当运输工具下拉选择“自办运输”时,“Km运距”、“装卸费单价”、“装卸次数”、“运价增加率(%)”列数据归0,且灰选不可编辑
  493. doc["kmDistance"] = '0';
  494. doc["unitLoadingFee"] ='0';
  495. doc["loadingTimes"] = '0';
  496. doc["freightIncreaseRate"] = '0';
  497. }
  498. if(args.oldValue =="汽车") doc["materialType"] = "";//当运输方式从汽车切换成其它方式时,清空材料类型
  499. }
  500. /* if(dataCode == "calcType"){
  501. if(value == "全国") doc["materialType"] = "";
  502. if(value == "内蒙古"){
  503. doc["materialType"] = "地方材料";
  504. doc["unitFreight"] = me.calcNeiMengUnitFreight(recode.kmDistance,"地方材料");
  505. }
  506. }*/
  507. if(dataCode == "materialType" && value!="") doc["unitFreight"] = me.calcNeiMengUnitFreight(recode.kmDistance,value);
  508. if(dataCode == "kmDistance" && gljUtil.isDef(recode.materialType)&&recode.materialType!="") doc["unitFreight"] = me.calcNeiMengUnitFreight(value,recode.materialType);
  509. if(dataCode == "start"){
  510. let t_f = me.getSavedFreight(value,material);
  511. if(t_f) doc = t_f;
  512. }
  513. projectObj.project.projectGLJ.updateFreightCalc([{ID:recode.ID,doc:doc}],material.id);
  514. }
  515. },
  516. calcNeiMengUnitFreight:function (tkmDistance,tmaterialType) {
  517. if(!tkmDistance||tkmDistance == '0') return "0";
  518. let decimal = getDecimal("glj.unitPrice");
  519. tkmDistance = scMathUtil.roundForObj(tkmDistance,decimal);
  520. return scMathUtil.roundForObj(this.calNeiMengTotalFreight(tkmDistance,tmaterialType)/tkmDistance,decimal);
  521. },
  522. calNeiMengTotalFreight:function (kmDistance,materialType) {
  523. if(!kmDistance||kmDistance == '0') return 0;
  524. let decimal = getDecimal("glj.unitPrice");
  525. let baseMap = {"地方材料":6,"外购材料":13,"沥青、燃料等":19};//"地方材料","外购材料","沥青、燃料等"
  526. let baseFreight = baseMap[materialType];
  527. kmDistance = scMathUtil.roundForObj(kmDistance,decimal);
  528. //用截取的方式,一段段取值
  529. let less = kmDistance - 5;//kmDistance <= 5 这段
  530. if(less <= 0) return baseFreight ; //kmDistance <= 5 的时候直接取baseFreight
  531. //5< kmDistance <= 15 每增运1km 则增加0.6
  532. less = less - 10;
  533. if(less <=0) return scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj((less + 10) * 0.6,6),decimal);//baseFreight + (less + 10) * 0.6;
  534. baseFreight = baseFreight + 10 * 0.6; //累加5到15这一段的运费;
  535. //15< kmDistance <= 100 每增运1km 则增加0.45
  536. less = less - 85;
  537. if(less <=0) return scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj((less + 85)*0.45,6),decimal);//baseFreight + (less + 85)*0.45;
  538. baseFreight = scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj(85*0.45,6),6) ; //累加15到100这一段的运费;
  539. return scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj(less * 0.35,6),decimal); // >100 的所有部分每增运1km 则增加0.35 baseFreight + less * 0.35
  540. },
  541. getNeiMengUnitFreightString:function (kmDistance,materialType) {
  542. if(!kmDistance||kmDistance == '0') return "0";
  543. let decimal = getDecimal("glj.unitPrice");
  544. let baseMap = {"地方材料":6,"外购材料":13,"沥青、燃料等":19};//"地方材料","外购材料","沥青、燃料等"
  545. let baseFreight = baseMap[materialType];
  546. kmDistance = scMathUtil.roundForObj(kmDistance,decimal);
  547. let resultString = baseFreight+"";
  548. //用截取的方式,一段段取值
  549. let less = kmDistance - 5;//kmDistance <= 5 这段
  550. if(less <= 0) return resultString ; //kmDistance <= 5 的时候直接取baseFreight
  551. //5< kmDistance <= 15 每增运1km 则增加0.6
  552. less = less - 10;
  553. if(less <=0) return `(${resultString}+0.6x${less + 10})`;//baseFreight + (less + 10) * 0.6;
  554. resultString = `${resultString}+0.6x10`;
  555. //15< kmDistance <= 100 每增运1km 则增加0.45
  556. less = less - 85;
  557. if(less <=0) return `(${resultString}+0.45x${less + 85})`; //baseFreight + (less + 85)*0.45;
  558. resultString = `${resultString}+0.45x85`;
  559. return `(${resultString}+0.35x${less})`;// >100 的所有部分每增运1km 则增加0.35 baseFreight + less * 0.35
  560. },
  561. onFreightRationValueChange:function (sender,args) {
  562. materialCalcObj.onRationValueChange(sender,args,"freight");
  563. },
  564. onPriceRationValueChange:function (sender,args) {
  565. materialCalcObj.onRationValueChange(sender,args,"price");
  566. },
  567. onRationValueChange:function (sender,args,type) {
  568. let me = materialCalcObj;
  569. let dataCode = me.rationSetting.header[args.col].dataCode;
  570. let value = args.newValue;
  571. let parent = type == "freight"? me.getSelectedFreight():me.getSelectedPrice();
  572. let dataList = type == "freight"?me.freightRations:me.priceRations;
  573. if(dataCode == "code" && args.row >= dataList.length) {//新增
  574. if(parent) projectObj.project.projectGLJ.addMaterialRation(value,type,parent.ID,parent.connect_key);
  575. }else { //修改
  576. let ration = dataList[args.row];
  577. if (value&&!sheetCommonObj.checkData(args.col,me.rationSetting,value)) {
  578. alert('输入的数据类型不对,请重新输入!');
  579. return type == "freight"?me.showFreightRationDatas(parent):me.showPriceRationDatas();
  580. }
  581. if(dataCode == 'quantity'){
  582. if(value){
  583. value = scMathUtil.roundForObj(parseFloat(value) / FilterNumberFromUnit(ration.unit),getDecimal("ration.quantity"))+"";
  584. }else {
  585. value = "0";
  586. }
  587. }
  588. let datas = {parentID:parent.ID,rationID:ration.ID,type:type,actionType:"update",field:dataCode,value:value};
  589. if(dataCode == "code"){ //这时是替换,替换比较麻烦
  590. datas.code = value;
  591. datas.row = args.row;
  592. let libIDs = rationLibObj.getStdRationLibIDs();
  593. let defaultLibID = rationLibObj.getDefaultStdRationLibID();
  594. let selectedLib = sessionStorage.getItem("stdRationLib");
  595. selectedLib&&selectedLib!='undefined'?libIDs.unshift(selectedLib):libIDs.unshift(defaultLibID);
  596. datas.userID = userID;
  597. datas.defaultLibID = defaultLibID;
  598. datas.rationRepIds = libIDs;
  599. datas.quantityDecimal = getDecimal("ration.quantity");
  600. datas.connect_key = parent.connect_key;
  601. datas.projectID = projectObj.project.ID();
  602. datas.rations = parent.rations;
  603. datas.ration_gljs = parent.ration_gljs;
  604. }
  605. projectObj.project.projectGLJ.updateMaterialRation(datas);
  606. }
  607. },
  608. onPriceValueChange:function(sender,args){
  609. let me = materialCalcObj;
  610. let dataCode = me.priceSetting.header[args.col].dataCode;
  611. let value = args.newValue;
  612. let material = me.getMaterialSelected();
  613. //输入有效性判断, to do
  614. if (value&&!sheetCommonObj.checkData(args.col,me.priceSetting,value)) {
  615. alert('输入的数据类型不对,请重新输入!');
  616. me.showDatas();
  617. return;
  618. }
  619. if(dataCode == 'coe'||dataCode == 'supplyPrice'){
  620. value = value?scMathUtil.roundForObj(value,getDecimal("glj.unitPrice"))+'':'0'//4舍五入加默认为0
  621. }
  622. if(args.row >= me.priceDatas.length){//新增
  623. let newData = {
  624. ID:uuid.v1(),
  625. supplyLocation:"",
  626. supplyPrice:'0',
  627. coe:'1',
  628. connect_key:gljUtil.getIndex(material),
  629. unit_price_file_id:material.unit_price.unit_price_file_id
  630. };
  631. newData[dataCode] = value;
  632. projectObj.project.projectGLJ.addPriceCalc([newData],material.id);
  633. }else {//修改
  634. let recode = me.priceDatas[args.row];
  635. if(recode[dataCode] == value) return;
  636. let doc = {};
  637. doc[dataCode] = value;
  638. projectObj.project.projectGLJ.updatePriceCalc([{ID:recode.ID,doc:doc}],material.id);
  639. }
  640. },
  641. deleteMaterialCal:function (row) {
  642. let record = this.materialDatas[row];//修改材料计算标记的同时还要删除原价计算,运费计算等
  643. if(record){
  644. projectObj.project.projectGLJ.updateCalcMaterial(record,'calcMaterial',0);
  645. }
  646. },
  647. deletePriceCalc:function (row) {
  648. let record = this.priceDatas[row];
  649. if(record){
  650. let material = this.getMaterialSelected();
  651. projectObj.project.projectGLJ.deletePriceCalc(record.ID,material.id);
  652. }
  653. },
  654. deleteFreightCalc:function (row) {
  655. let record = this.freightDatas[row];
  656. if(record){
  657. let material = this.getMaterialSelected();
  658. projectObj.project.projectGLJ.deleteFreightCalc(record.ID,material.id);
  659. }
  660. },
  661. deleteRation:function (row,type) {
  662. let me = this;
  663. let parent = type == "freight"?me.getSelectedFreight():me.getSelectedPrice();
  664. let ration = type == "freight"?me.freightRations[row]:me.priceRations[row];
  665. let datas = {parentID:parent.ID,rationID:ration.ID,type:type,actionType:"delete"};
  666. projectObj.project.projectGLJ.updateMaterialRation(datas);
  667. },
  668. saveFreight:function (row) {
  669. let me = this;
  670. let record = this.freightDatas[row];
  671. if(record){
  672. let exist = this.checkSavedFreight(record.start);
  673. if(exist){//已存在的情况,更新
  674. let info =`起讫地点“${record.start}”已存在,是否覆盖?`;
  675. //to do 检查是否已经存在,存在给出是否覆盖提示
  676. hintBox.infoBox('操作确认', info, 2, function () {
  677. me.updateUserFreight(record,exist)
  678. }, function () {
  679. //
  680. },['确定','取消'],false);
  681. return true;
  682. }
  683. let user_freight = {rootProjectID:projectObj.project.projectInfo.property.rootProjectID};
  684. let f = {};
  685. for(let key in record){
  686. f[key] = record[key];
  687. if(key =="ration" || key == "ration_gljs")f[key] = [];//下面的定额和工料机不用保存
  688. }
  689. user_freight.freight = f;
  690. projectObj.project.projectGLJ.updateUserFreight({freights:[user_freight],action:"add"});
  691. }
  692. },
  693. updateUserFreight:function (record,userFreight) {
  694. let t = {};
  695. for(let t_key in userFreight){
  696. if(t_key == "ID") continue;
  697. t[t_key] = userFreight[t_key];
  698. }
  699. t.rootProjectID = projectObj.project.projectInfo.property.rootProjectID;
  700. let f = {};
  701. for(let key in record){
  702. f[key] = record[key];
  703. if(key =="ration" || key == "ration_gljs")f[key] = [];//下面的定额和工料机不用保存
  704. }
  705. t.freight = f;
  706. projectObj.project.projectGLJ.updateUserFreight({ID:userFreight.ID,doc:t,action:"update"});
  707. },
  708. getSideResize: function () {
  709. let rg_sideResizeEles = {};
  710. rg_sideResizeEles.eleObj = {
  711. module: this.moduleName,
  712. resize: $('#mrResize'),
  713. parent: $('#projectGljBottom'),
  714. left: $('#materialCalcSheet'),
  715. right: $('#calcDiv')
  716. };
  717. rg_sideResizeEles.limit = {
  718. min: 100,
  719. max: `$('#projectGljBottom').width()-100`
  720. };
  721. return rg_sideResizeEles;
  722. },
  723. initRightClick:function (id,spread) {
  724. let me = this;
  725. $.contextMenu({
  726. selector: '#'+id,
  727. build: function ($trigger, e) {
  728. me.rightClickTarget = SheetDataHelper.safeRightClickSelection($trigger, e, spread);
  729. return me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.viewport ||
  730. me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  731. },
  732. items: {
  733. "insertFreight":{
  734. name: "内蒙古计算",
  735. icon: 'fa-sign-in',
  736. visible:function () {
  737. return false;//2019-11-17 改成不需要右键插入功能 id == "freightSheet";
  738. },
  739. disabled: function (){
  740. let material = me.getMaterialSelected();
  741. return !material;
  742. },
  743. callback:function () {
  744. $("#insertNeimengDiv").modal("show");
  745. }
  746. },
  747. "saveFreight":{
  748. name: "保存运输起讫地点",
  749. icon: 'fa-sign-in',
  750. visible:function () {
  751. return id == "freightSheet";
  752. },
  753. disabled: function (){
  754. if(id == "freightSheet") return me.rightClickTarget.row >= me.freightDatas.length;
  755. return me.rightClickTarget.row === undefined;
  756. },
  757. callback:function () {
  758. let row = me.rightClickTarget.row;
  759. me.saveFreight(row);
  760. }
  761. },
  762. "delete": {
  763. name: "删除",
  764. icon: 'fa-trash-o',
  765. disabled: function () {
  766. if(id == "priceSheet") return me.rightClickTarget.row >= me.priceDatas.length;
  767. if(id == "freightSheet") return me.rightClickTarget.row >= me.freightDatas.length;
  768. if(id == "freight_ration_sheet") return me.rightClickTarget.row >= me.freightRations.length;
  769. if(id == "price_ration_sheet") return me.rightClickTarget.row >= me.priceRations.length;
  770. return me.rightClickTarget.row === undefined;
  771. },
  772. callback: function (key, opt) {
  773. let row = me.rightClickTarget.row;
  774. if (id == "materialCalcSheet") me.deleteMaterialCal(row);
  775. if (id == "priceSheet") me.deletePriceCalc(row);
  776. if (id == "freightSheet") me.deleteFreightCalc(row);
  777. if (id == "freight_ration_sheet") me.deleteRation(row,"freight");
  778. if (id == "price_ration_sheet") me.deleteRation(row,"price");
  779. }
  780. }
  781. }
  782. });
  783. },
  784. initTabWidth:function () {
  785. if($("#mix_ratio_sheet").is(':visible')) return ;//如果是组成物计算界面,返回
  786. let mr_sideResizeEles = this.getSideResize();
  787. SlideResize.loadHorizonWidth(mr_sideResizeEles.eleObj.module,
  788. [mr_sideResizeEles.eleObj.resize], [mr_sideResizeEles.eleObj.left, mr_sideResizeEles.eleObj.right],null,2);
  789. $("#spreadTabDiv").width( $('#calcDiv').width() - mr_sideResizeEles.eleObj.resize.width() - 32)
  790. },
  791. refreshRationView:function () {
  792. let freight = this.getSelectedFreight();
  793. let hide = true;
  794. let stats = $("#freight_ration").is(':visible');
  795. if(freight && freight.conveyance == "自办运输"){
  796. this.showFreightRationDatas(freight);
  797. $("#freightSheet").css("height","50%");
  798. $("#freight_ration").show();
  799. hide = false;
  800. }
  801. if(hide){
  802. $("#freightSheet").css("height","100%");
  803. $("#freight_ration").hide();
  804. }
  805. if(stats != $("#freight_ration").is(':visible')){//状态改变了才刷新
  806. this.freightSpread.refresh();
  807. this.freightRationSpread.refresh();
  808. }
  809. },
  810. refreshAssView:function () {
  811. let me = materialCalcObj;
  812. let sheet = $('#freightSheet').is(':visible')?me.freightRationSheet:me.priceRationSheet;
  813. let preString = $('#freightSheet').is(':visible')?"freight":"price";
  814. let show = false;
  815. let ass = null;
  816. let ration = me.getSelectedRation();
  817. let stats = $(`#${preString}_ration_ass`).is(':visible');
  818. if(ration && ration.rationAssList){
  819. for(let r of ration.rationAssList){
  820. if(r.name == "运距m"){//辅助定额只处理运距的情况,其它的都忽略
  821. show = true;
  822. ass = r;
  823. }
  824. }
  825. }
  826. if(show){
  827. $(`#${preString}_ration_sheet`).addClass("material-ration-left");
  828. $(`#${preString}_ration_ass`).addClass("material-ass");
  829. $(`#${preString}_ass_value`).val(ass.actualValue);
  830. $(`#${preString}_ration_ass`).show();
  831. }else {
  832. $(`#${preString}_ration_sheet`).removeClass("material-ration-left");
  833. $(`#${preString}_ration_ass`).removeClass("material-ass");
  834. $(`#${preString}_ration_ass`).hide();
  835. }
  836. if(stats != $(`#${preString}_ration_ass`).is(':visible')) sheet.parent.refresh();//状态改变了才刷新
  837. },
  838. updateMaterialRationAss:function (value,ele) {//to do 同步修改定额工料机的消耗量
  839. let parent = this.getSelectedRationParent(),ration = this.getSelectedRation();
  840. let replaceList = [];
  841. if(value && !number_util.isNum(value)){
  842. alert("输入的数据类型不对,请重新输入!");
  843. let a = _.find(ration.rationAssList,{'name':"运距m"});
  844. if(a)ele.val(a.actualValue);
  845. }
  846. for(let ass of ration.rationAssList){
  847. if(ass.name == "运距m"){
  848. ass.actualValue = value?scMathUtil.roundForObj(value,2):ass.stdValue;
  849. }
  850. replaceList.push(value);
  851. }
  852. let name = ration.caption;
  853. for(let re of replaceList){
  854. name = name.replace('%s',re);
  855. }
  856. let type = $('#freightSheet').is(':visible')?"freight":"price";
  857. //let ration_glj =
  858. let datas = {parentID:parent.ID,rationID:ration.ID,type:type,actionType:"update",field:"name",value:name,ext:{rationAssList:ration.rationAssList}};
  859. let ration_gljs = projectObj.project.projectGLJ.calcMaterialAssQuantity(parent,ration,ration.rationAssList);
  860. if(ration_gljs.length > 0) datas.ration_gljs = ration_gljs;
  861. projectObj.project.projectGLJ.updateMaterialRation(datas);
  862. },
  863. getSelectedRation:function () {
  864. if($('#freightSheet').is(':visible')){
  865. return this.getSelectedRecode(this.freightRationSheet,this.freightRations);
  866. }else {
  867. return this.getSelectedRecode(this.priceRationSheet,this.priceRations);
  868. }
  869. },
  870. getSelectedRationParent:function () {
  871. if($('#freightSheet').is(':visible')){
  872. return this.getSelectedFreight();
  873. }else {
  874. return this.getSelectedRecode(this.priceSheet,this.priceDatas);
  875. }
  876. },
  877. getSelectedFreight:function(){
  878. return this.getSelectedRecode(this.freightSheet,this.freightDatas);
  879. },
  880. getSelectedPrice:function () {
  881. return this.getSelectedRecode(this.priceSheet,this.priceDatas)
  882. },
  883. getSelectedRecode:function (sheet,datas) {
  884. let sel = sheet.getSelections()[0];
  885. let srow = sel.row == -1||sel.row == ""?0:sel.row;
  886. if(gljUtil.isDef(srow) && datas.length>srow){
  887. return datas[srow];
  888. }
  889. return null;
  890. }
  891. };
  892. $(function () {
  893. $("#calc-nav").on('shown.bs.tab', function () {
  894. materialCalcObj.initTabWidth();
  895. projectGljObject.refreshSubViews();
  896. });
  897. $("#calTab ul li a").on('shown.bs.tab', function () {
  898. materialCalcObj.showFreightDatas();
  899. materialCalcObj.showPriceDatas();
  900. projectGljObject.refreshSubViews();
  901. });
  902. $(".ration_ass_value").change(function () {
  903. let me = materialCalcObj;
  904. me.updateMaterialRationAss($(this).val(),$(this));
  905. });
  906. $('#calcCoeDiv').on('show.bs.modal', function () {
  907. $("#assistProductionFeeRate").val(scMathUtil.roundForObj(projectObj.project.projectGLJ.datas.constData.assistProductionFeeRate,getDecimal("feeRate")));
  908. })
  909. $("#calcCoeConfirm").click(function () {
  910. let feeRate = $("#assistProductionFeeRate").val();
  911. if(!number_util.isNum(feeRate)){
  912. alert("输入的数据类型不对,请重新输入!");
  913. return $("#assistProductionFeeRate").val(scMathUtil.roundForObj(projectObj.project.projectGLJ.datas.constData.assistProductionFeeRate,getDecimal("feeRate")));
  914. }
  915. feeRate = scMathUtil.roundForObj(feeRate,getDecimal("feeRate"));
  916. $("#calcCoeDiv").modal("hide");
  917. projectObj.project.projectGLJ.changeAssistProductionFeeRate(feeRate);
  918. });
  919. $("#insertFreightconfirm").click(function () {
  920. let me = materialCalcObj;
  921. let material = me.getMaterialSelected();
  922. let newData = me.getNewFreightData(material);
  923. let start = $("#freight_start").val();
  924. let kmDistance = $("#freight_kmDistance").val();
  925. let materialType = $("#freight_materialType").val();
  926. if(!number_util.isNum(kmDistance)){
  927. alert("运输距离数据类型不对,请重新输入!");
  928. return ;
  929. }
  930. kmDistance = scMathUtil.roundForObj(kmDistance,getDecimal("glj.unitPrice"))+'';
  931. newData.start = start;
  932. newData.kmDistance = kmDistance;
  933. newData.materialType = materialType;
  934. newData.calcType = "内蒙古";
  935. newData.unitFreight = me.calcNeiMengUnitFreight(kmDistance,materialType);
  936. $("#insertNeimengDiv").modal("hide");
  937. projectObj.project.projectGLJ.addFreightCalc([newData],material.id);
  938. })
  939. });
  940. let mr_sideResizeEles = materialCalcObj.getSideResize();
  941. SlideResize.horizontalSlide(mr_sideResizeEles.eleObj, mr_sideResizeEles.limit, function(){
  942. $("#spreadTabDiv").width( $('#calcDiv').width() - mr_sideResizeEles.eleObj.resize.width() - 32);
  943. projectGljObject.refreshSubViews();
  944. },2);