material_calc_view.js 42 KB

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