material_calc_view.js 49 KB

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