project_glj_view.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /**
  2. * Created by zhang on 2018/3/13.
  3. */
  4. projectGljObject={
  5. showTag:'ration',//mixRatio/machine
  6. mixRatioType: [gljType.CONCRETE, gljType.MORTAR, gljType.MIX_RATIO,gljType.MAIN_MATERIAL],
  7. machineType: [gljType.GENERAL_MACHINE],
  8. projectGljSetting:{
  9. header: [
  10. {headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String"},
  11. {headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String"},
  12. {headerName: "规格型号", headerWidth: 120, dataCode: "specs", hAlign: "left", dataType: "String"},
  13. {headerName: "单位", headerWidth: 45, dataCode: "unit", hAlign: "center", dataType: "String"},
  14. {headerName: "类型", headerWidth: 45, dataCode: "short_name", hAlign: "center", dataType: "String"},
  15. {headerName: "总消耗量", headerWidth: 100, dataCode: "quantity", hAlign: "right", dataType: "Number",decimalField:'glj.quantity'},
  16. {headerName: "定额价", headerWidth: 70, dataCode: "basePrice", hAlign: "right", dataType: "Number",decimalField:'glj.unitPrice',validator:"number"},
  17. {headerName: "调整价", headerWidth: 70, dataCode: "adjustPrice", hAlign: "right", dataType: "Number",decimalField:"glj.unitPrice"},
  18. {headerName: "市场价", headerWidth: 70, dataCode: "marketPrice", hAlign: "right", dataType: "Number",decimalField:"glj.unitPrice",validator:"number"},
  19. {headerName: "是否暂估", headerWidth: 60, dataCode: "is_evaluate", hAlign: "center", dataType: "String",cellType:'checkBox'},
  20. {headerName: "供货方式", headerWidth: 80, dataCode: "supply", hAlign: "center", dataType: "String",cellType:'comboBox',editorValueType:true,options:supplyComboMap},
  21. {headerName: "甲供数量", headerWidth: 100, dataCode: "supply_quantity", hAlign: "right", dataType: "Number",validator:"number"},
  22. {headerName: "三材类别", headerWidth: 80, dataCode: "materialType", hAlign: "center", dataType: "String",cellType:'comboBox',editorValueType:true,options:materialComboMap},
  23. {headerName: "三材系数", headerWidth: 100, dataCode: "materialCoe", hAlign: "right", dataType: "Number",decimalField:'material'},
  24. {headerName: "交货方式", headerWidth: 90, dataCode: "delivery", hAlign: "left", dataType: "String"},
  25. {headerName: "送达地点", headerWidth: 100, dataCode: "delivery_address", hAlign: "left", dataType: "String"},
  26. {headerName: "不调价", headerWidth: 55, dataCode: "is_adjust_price", dataType: "String",cellType: "checkBox"}
  27. ],
  28. view: {
  29. lockColumns: [0,1,2,3,4,5,7]
  30. }
  31. },
  32. projectGljSpread:null,
  33. projectGljSheet:null,
  34. projectGljSheetData:[],
  35. mixRatioSetting:{
  36. header:[
  37. {headerName: "编码", headerWidth: 120, dataCode: "code", dataType: "String"},
  38. {headerName: "名称", headerWidth: 120, dataCode: "name", dataType: "String"},
  39. {headerName: "单位", headerWidth: 120, dataCode: "unit", hAlign: "center", dataType: "String"},
  40. {headerName: "类型", headerWidth: 120, dataCode: "short_name", hAlign: "center", dataType: "String"},
  41. {headerName: "定额价", headerWidth: 120, dataCode: "basePrice", hAlign: "right", dataType: "Number",decimalField:'glj.unitPrice',validator:"number"},
  42. {headerName: "调整价", headerWidth: 120, dataCode: "adjustPrice", hAlign: "right", dataType: "Number",decimalField:"glj.unitPrice"},
  43. {headerName: "市场价", headerWidth: 120, dataCode: "marketPrice", hAlign: "right", dataType: "Number",decimalField:"glj.unitPrice",validator:"number"},
  44. {headerName: "用量", headerWidth: 120, dataCode: "consumption", hAlign: "right", dataType: "Number",decimalField:"glj.quantity",validator:"number"}
  45. ],
  46. view: {
  47. lockColumns: [0,1,2,3,4,5,6]
  48. }
  49. },
  50. mixRatioSpread:null,
  51. mixRatioSheet:null,
  52. mixRatioData:[],
  53. usedTenderList:[],
  54. usedUnitPriceInfo:null,
  55. initProjectGljSpread:function () {
  56. this.projectGljSpread = SheetDataHelper.createNewSpread($("#project_glj_sheet")[0]);
  57. this.projectGljSheet = this.projectGljSpread .getSheet(0);
  58. this.initSheet(this.projectGljSheet,this.projectGljSetting);
  59. this.projectGljSheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onProjectGljSelectionChange);
  60. this.projectGljSheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onProjectGljEditStarting);
  61. this.projectGljSpread.bind(GC.Spread.Sheets.Events.RangeChanged, this.onProjectGljRangeChange);
  62. this.projectGljSheet.name('projectGljSheet');
  63. },
  64. initMixRatio:function () {
  65. let me = projectGljObject;
  66. if(me.mixRatioSpread==null){
  67. me.initMixRatioSpread();
  68. me.initRightClick();
  69. }
  70. me.showMixRatioData();
  71. },
  72. initMixRatioSpread:function () {
  73. this.mixRatioSpread = SheetDataHelper.createNewSpread($("#mix_ratio_sheet")[0]);
  74. this.mixRatioSheet = this.mixRatioSpread .getSheet(0);
  75. this.initSheet(this.mixRatioSheet,this.mixRatioSetting);
  76. this.mixRatioSheet.name('mixRatioSheet');
  77. },
  78. unitPriceFileInit:function() {
  79. let me = this;
  80. let projectGLJ = projectObj.project.projectGLJ;
  81. let data = projectGLJ.datas;
  82. me.usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
  83. me.usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ?
  84. data.constData.usedUnitPriceInfo : {};
  85. $("#current-name").text(me.usedUnitPriceInfo.name);
  86. let usedCount = me.usedTenderList.length <= 0 ? 1 : me.usedTenderList.length;
  87. $("#used-project-count").text(usedCount);
  88. },
  89. getUsedTenderInfo:function() {
  90. return projectGljObject.usedTenderList.join("<br>");
  91. },
  92. showMixRatioData:function () {
  93. let me = this,gljId = null;
  94. let consumptionCol = _.findIndex(me.mixRatioSetting.header, { 'dataCode': 'consumption'});
  95. if(me.showTag == 'ration'){
  96. return;
  97. }else if(me.showTag == 'mixRatio'){
  98. me.mixRatioSheet.setValue(0, consumptionCol, '用量', GC.Spread.Sheets.SheetArea.colHeader);
  99. }else if(me.showTag == 'machine'){
  100. me.mixRatioSheet.setValue(0, consumptionCol, '消耗量', GC.Spread.Sheets.SheetArea.colHeader);
  101. }
  102. let sel = me.projectGljSheet.getSelections()[0];
  103. let srow = sel.row == -1?0:sel.row;
  104. if(me.projectGljSheetData.length>srow){
  105. gljId = me.projectGljSheetData[srow].id;
  106. }
  107. projectObj.project.projectGLJ.getRatioData(gljId,function (data) {
  108. let rationList =[];
  109. console.log(data);
  110. for(let glj of data){
  111. rationList.push(me.getMixRatioSheetData(glj)) ;
  112. }
  113. me.mixRatioData = rationList;
  114. me.mixRatioSheet.setRowCount(0);
  115. sheetCommonObj.showData(me.mixRatioSheet, me.mixRatioSetting,me.mixRatioData);
  116. me.mixRatioSheet.setRowCount(me.mixRatioData.length);
  117. })
  118. },
  119. getMixRatioSheetData:function (glj) {
  120. let data ={
  121. id:glj.id,
  122. mix_ratio_id:glj.ratio_data.id,
  123. code:glj.code,
  124. name:glj.name,
  125. specs:glj.specs,
  126. unit:glj.unit,
  127. type:glj.type,
  128. short_name:projectObj.project.projectGLJ.getShortNameByID(glj.type),
  129. consumption:glj.ratio_data.consumption,
  130. unit_price:glj.unit_price
  131. };
  132. gljOprObj.setGLJPrice(data,glj);
  133. return data;
  134. },
  135. onProjectGljEditStarting:function (sender, args) {
  136. let me = projectGljObject;
  137. let row = args.row;
  138. let col = args.col;
  139. if(me.projectGljEditChecking(row,col)==false){
  140. args.cancel = true;
  141. }
  142. },
  143. projectGljEditChecking:function (row,col) {//return false表示不能编辑
  144. let me = projectGljObject;
  145. let data = me.projectGljSheetData[row];
  146. let dataCode = me.projectGljSetting.header[col].dataCode;
  147. let lockColumns = me.projectGljSetting.view.lockColumns;
  148. if(lockColumns.indexOf(col)!= -1){
  149. return false;
  150. }
  151. if(dataCode=='is_adjust_price'||dataCode=='is_evaluate'){
  152. return false;
  153. }
  154. if(dataCode=='basePrice'||dataCode=='marketPrice'||dataCode=='supply'){//有组成物时,市场单价、定额价、供货方式不能修改
  155. if (data.ratio_data && data.ratio_data.length > 0){
  156. return false;
  157. }
  158. if(dataCode=='basePrice'&&data.is_add!=1){//如果不是新增,定额价不可修改。
  159. return false;
  160. }
  161. }
  162. if(dataCode == 'supply_quantity'){
  163. if (data.supply != 1) {// 如果为部分甲供则甲供数量需要可编辑,其它的都不能编辑
  164. return false;
  165. }
  166. }
  167. return true;
  168. },
  169. onProjectGljSelectionChange:function (sender, args) {
  170. let me = projectGljObject;
  171. me.showMixRatioData();
  172. me.projectGljSheet.repaint();
  173. },
  174. onProjectGljRangeChange:function (sender,info) {
  175. let me = projectGljObject;
  176. let changeInfo=[];
  177. let canChange = true;
  178. if(me.projectGljEditChecking(info.row,info.col) == false){
  179. canChange = false;
  180. }else if (info.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  181. info.newValue = null;
  182. me.onProjectGLJValueChange(sender,info);
  183. return ;
  184. }
  185. for(let c of info.changedCells){
  186. let value= info.sheet.getCell(c.row, c.col).text();
  187. changeInfo.push({row:c.row,col:c.col,value:value});
  188. if(me.projectGljEditChecking(c.row,c.col)==false){//如果不能编辑
  189. canChange = false;
  190. }
  191. if (canChange==true&&!me.checkData(c.col,me.projectGljSetting,value)) {
  192. alert('输入的数据类型不对,请重新输入!');
  193. canChange = false;
  194. }
  195. }
  196. if(canChange == false){//恢复原来的值
  197. me.showProjectGljData();
  198. }else {
  199. me.batchUpdatePrice(changeInfo);
  200. }
  201. },
  202. batchUpdatePrice(changeInfo){
  203. let projectGLJ = projectObj.project.projectGLJ;
  204. let me = projectGljObject;
  205. projectGLJ.batchUpdatePrice(changeInfo,function (impactList) {
  206. let selected = me.projectGljSheet.getSelections()[0];
  207. me.showProjectGljData();
  208. me.projectGljSheet.setSelection(selected.row,selected.col,selected.rowCount,selected.colCount);
  209. });
  210. },
  211. showProjectGljData:function () {
  212. let sel = this.projectGljSheet.getSelections()[0];
  213. let projectGljSheetData = [];
  214. let gljList = projectObj.project.projectGLJ.datas.gljList;
  215. gljList = this.filterProjectGLJ(gljList);
  216. gljList = sortProjectGLJ(gljList);
  217. for(let glj of gljList){
  218. projectGljSheetData.push(this.getSheetDataByGLJ(glj));
  219. }
  220. this.projectGljSheetData = projectGljSheetData;
  221. this.projectGljSheet.setRowCount(0);
  222. sheetCommonObj.showData(this.projectGljSheet, this.projectGljSetting,this.projectGljSheetData);
  223. this.projectGljSheet.setRowCount(this.projectGljSheetData.length);
  224. this.projectGljSheet.setSelection(sel.row,sel.col,sel.rowCount,sel.colCount);
  225. },
  226. filterProjectGLJ:function (gljList) {
  227. let me = projectGljObject;
  228. if(gljList.length>0){
  229. gljList = _.filter(gljList,function (item) {
  230. if(item.quantity !== 0 && item.quantity !== '0'){//过滤掉消耗量为0的工料机
  231. //showTag:'ration',//mixRatio/machine
  232. if(me.showTag == 'ration'){
  233. return true;
  234. }else if(me.showTag == 'mixRatio'){
  235. return _.includes(me.mixRatioType,item.type)
  236. }else if(me.showTag == 'machine'){
  237. return _.includes(me.machineType,item.type)
  238. }
  239. }
  240. return false;
  241. });
  242. }
  243. return gljList;
  244. },
  245. getSheetDataByGLJ:function (glj) {
  246. let projectGLJ = projectObj.project.projectGLJ;
  247. let materialIdList = projectGLJ.datas.constData.materialIdList;
  248. let data ={
  249. id:glj.id,
  250. code:glj.code,
  251. name:glj.name,
  252. specs:glj.specs,
  253. unit:glj.unit,
  254. type:glj.type,
  255. short_name:projectGLJ.getShortNameByID(glj.type),
  256. quantity:glj.quantity,
  257. supply:glj.supply,
  258. supply_quantity:glj.supply_quantity,
  259. materialType:glj.materialType,
  260. materialCoe:glj.materialCoe,
  261. delivery:glj.delivery,
  262. delivery_address:glj.delivery_address,
  263. is_adjust_price:glj.is_adjust_price,
  264. ratio_data:glj.ratio_data,
  265. is_add:glj.unit_price.is_add,
  266. bgColour:'white'
  267. };
  268. gljOprObj.setGLJPrice(data,glj);
  269. //供货方式为完全甲供时设置甲供数量为总消耗量
  270. if (data.supply == 2) {
  271. data.supply_quantity = glj.quantity;
  272. }
  273. // 只有材料才显示是否暂估
  274. if (materialIdList.indexOf(glj.type) >= 0) {
  275. data.is_evaluate = glj.is_evaluate;
  276. }
  277. //bgColour
  278. if(data.basePrice == data.marketPrice){//如果定额价等于市场价时,改底色。 优先度低于有组成物时的底色
  279. data.bgColour = "#C4CAFB";
  280. }
  281. if (notEditType.indexOf(glj.type) >= 0) {
  282. if (data.ratio_data && data.ratio_data.length > 0){//有组成物时
  283. //设置底色
  284. data.bgColour = "#E0E0E0";
  285. }
  286. }
  287. return data;
  288. },
  289. refreshProjectGljRow:function (row) {
  290. let me = projectGljObject;
  291. let rowData = me.projectGljSheetData[row];
  292. let glj = projectObj.project.projectGLJ.getByID(rowData.id);
  293. if(glj){
  294. me.projectGljSheetData[row] = me.getSheetDataByGLJ(glj);
  295. }
  296. sheetCommonObj.showRowData(this.projectGljSheet, this.projectGljSetting,row,this.projectGljSheetData);
  297. },
  298. initSheet: function (sheet,setting) {
  299. var me = this;
  300. sheetCommonObj.initSheet(sheet, setting, 30);
  301. sheet.bind(GC.Spread.Sheets.Events.ValueChanged, me.onSheetValueChange);
  302. },
  303. onSheetValueChange:function (e,info) {
  304. let me = projectGljObject;
  305. if(info.sheetName=='projectGljSheet'){
  306. me.onProjectGLJValueChange(e,info);
  307. }if(info.sheetName == 'mixRatioSheet'){
  308. me.onMixRatioValueChange(e,info);
  309. }
  310. },
  311. onMixRatioValueChange:function (e,info){
  312. let composition = projectObj.project.composition;
  313. let me = projectGljObject,row = info.row, col = info.col;
  314. let dataCode = me.mixRatioSetting.header[col].dataCode;
  315. let recode = me.mixRatioData[row];
  316. let value = info.newValue;
  317. if (!me.checkData(col,me.mixRatioSetting,value)) {
  318. alert('输入的数据类型不对,请重新输入!');
  319. me.mixRatioSheet.setValue(row, col, info.oldValue);
  320. return false;
  321. }
  322. value = scMathUtil.roundToString(value,getDecimal("glj.quantity"));
  323. let [parentMarketPrice, parentBasePrice] = me.getCompositionSumPrice('modify', row, value);
  324. let updateData ={id: recode.mix_ratio_id, field: 'mix_ratio.' + dataCode, value: value, market_price: parentMarketPrice, base_price: parentBasePrice};
  325. let prow= projectGljObject.projectGljSheet.getActiveRowIndex();//取父机械或组成物的下标
  326. let prowData = projectGljObject.projectGljSheetData[prow];
  327. composition.updateConsumption(updateData,recode,prowData.id,function (sid) {
  328. me.refreshParentData(prow,prowData.id,sid);
  329. });
  330. },
  331. refreshParentData:function (row,pid,sid) {
  332. let me = this;
  333. me.refreshProjectGljRow(row);
  334. // 更新组成物缓存
  335. projectObj.project.composition.loadData();
  336. //先查找使用了父项目工料机的定额工料机
  337. let updateNodes=[];
  338. let ration_gljs = _.filter(projectObj.project.ration_glj.datas,{'projectGLJID':pid});
  339. for(let rg of ration_gljs){
  340. let node = projectObj.project.mainTree.getNodeByID(rg.rationID);
  341. if(node){
  342. updateNodes.push(node);
  343. }
  344. }
  345. //或者是使用了父项目工料机的工料机类型的定额
  346. let rations = _.filter(projectObj.project.Ration.datas,{'type':3,'projectGLJID':pid});
  347. for(let r of rations){
  348. let r_node = projectObj.project.mainTree.getNodeByID(r.ID);
  349. if(r_node){
  350. r_node.data.marketUnitFee = projectGljObject.projectGljSheetData[row].marketPrice;//parentMarketPrice;//这里用显示的价格
  351. updateNodes.push(r_node);
  352. }
  353. }
  354. if(sid){
  355. let subRations = calcTools.getRationsByProjectGLJ(sid);
  356. updateNodes = updateNodes.concat(subRations);
  357. }
  358. if(updateNodes.length>0){
  359. projectObj.project.calcProgram.calcRationsAndSave(updateNodes,function () {
  360. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  361. });
  362. }
  363. gljOprObj.refreshView();
  364. },
  365. deleteMixRatio:function (row) {
  366. let me = this, deleteRecode = me.mixRatioData[row];
  367. let consumption = deleteRecode.consumption;
  368. let [parentMarketPrice, parentBasePrice] = me.getCompositionSumPrice('delete', row);
  369. let prow= projectGljObject.projectGljSheet.getActiveRowIndex();//取父机械或组成物的下标
  370. let prowData = projectGljObject.projectGljSheetData[prow];
  371. let updateData = {id: deleteRecode.mix_ratio_id, field: 'mix_ratio.consumption' , value: 0, market_price: parentMarketPrice, base_price: parentBasePrice};
  372. projectObj.project.composition.deleteComposition(updateData,deleteRecode,prowData.id,function () {
  373. me.refreshParentData(prow,prowData.id);
  374. me.mixRatioSheet.deleteRows(row,1);
  375. });
  376. },
  377. getCompositionSumPrice : function(scene, affectRow, newValue = 0) {
  378. let me = this;
  379. let parentMarketPrice = 0;
  380. let parentBasePrice = 0;
  381. for(let i = 0;i < me.mixRatioData.length;i++){
  382. let ratio = me.mixRatioData[i];
  383. let marketPrice = ratio.unit_price.marketPrice;
  384. let basePrice = ratio.unit_price.base_price;
  385. // 如果是删除则忽略即将被删除的行数据
  386. if (scene === 'delete' && affectRow === i) {
  387. continue;
  388. }
  389. let consumption = i === affectRow ? newValue : ratio.consumption;
  390. parentMarketPrice += operationWithRound(consumption,marketPrice,"glj.unitPrice","*");
  391. parentBasePrice += operationWithRound(consumption,basePrice,"glj.unitPrice","*");
  392. }
  393. parentMarketPrice = parentMarketPrice.toDecimal(getDecimal("glj.unitPrice"));
  394. parentBasePrice = parentBasePrice.toDecimal(getDecimal("glj.unitPrice"));
  395. return [parentMarketPrice, parentBasePrice];
  396. },
  397. onProjectGLJValueChange:function (e,info) {//me.projectGljSetting
  398. let projectGLJ = projectObj.project.projectGLJ;
  399. let me = projectGljObject,row = info.row, col = info.col;
  400. let dataCode = me.projectGljSetting.header[col].dataCode;
  401. let recode = me.projectGljSheetData[row];
  402. let value = info.newValue;
  403. if (!me.checkData(col,me.projectGljSetting,value)) {
  404. alert('输入的数据类型不对,请重新输入!');
  405. me.refreshProjectGljRow(row);
  406. return ;
  407. }
  408. let callback=function (impactList) {
  409. info.sheet.suspendPaint();
  410. info.sheet.suspendEvent();
  411. me.refreshProjectGljRow(row);
  412. for(let g of impactList){
  413. let index = _.findIndex(me.projectGljSheetData, { 'id': g.id });
  414. if(index>=0&&index != row){
  415. me.refreshProjectGljRow(index);
  416. }
  417. }
  418. info.sheet.resumeEvent();
  419. info.sheet.resumePaint();
  420. if (dataCode === 'supply' || dataCode === 'supply_quantity'){ // basePrice、marketPrice 有自己的计算代码,无需走这里重复计算
  421. let rations = calcTools.getRationsByProjectGLJ(recode.id);
  422. projectObj.project.calcProgram.calcNodesAndSave(rations, function () {
  423. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  424. });
  425. }
  426. };
  427. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  428. value= scMathUtil.roundForObj(value,getDecimal('glj.unitPrice'));//修改市场价和修改定额价时需要重新记算很多受影响的树节点,现在改成与定字额工料机那里调相同的方法。
  429. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  430. projectObj.project.projectGLJ.updatePrice(recode,editField,value,'pg',callback);
  431. }else {
  432. let extend = {};
  433. // 如果是供货方式则需要处理数据
  434. if (dataCode === 'supply') {
  435. extend.supply_quantity = me.getSupplyQuantity(value, recode.quantity);
  436. }
  437. if(dataCode === 'supply_quantity'){//修改数量需做4舍5入
  438. value= value.toDecimal(getDecimal('glj.quantity'));
  439. }
  440. if(dataCode === 'is_evaluate'||dataCode === 'is_adjust_price'){
  441. if(value == true){
  442. value = 1;
  443. }else if(value == false){
  444. value = 0;
  445. }
  446. }
  447. extend = Object.keys(extend).length > 0 ? JSON.stringify(extend) : '';
  448. let updateData = {id: recode.id, field: dataCode, value: value, extend: extend};
  449. projectGLJ.pGljUpdate(updateData,callback);
  450. };
  451. },
  452. getSupplyQuantity : function(supplyType, quantity) {
  453. // 自行采购和甲定乙供则把甲供数量设置为0,其余情况则设置为当前总消耗量
  454. let supplyQuantity = supplyType == 0 || supplyType == 3 ? 0 : quantity;
  455. supplyQuantity = parseFloat(supplyQuantity);
  456. return supplyQuantity;
  457. },
  458. checkData : function(col,setting, value) {
  459. let result = true;
  460. let validator = setting.header[col].validator !== undefined ? setting.header[col].validator : null;
  461. if (validator === null) {
  462. return result;
  463. }
  464. switch (validator) {
  465. case 'number':
  466. let regular = /^\d+(\.\d+)?$/;
  467. result = regular.test(value);
  468. break;
  469. case 'boolean':
  470. let booleanValue = [true, false];
  471. result = booleanValue.indexOf(value) >= 0;
  472. break;
  473. }
  474. return result;
  475. },
  476. initRightClick : function() {
  477. let activeSheet = this.mixRatioSheet;
  478. let me = this;
  479. $.contextMenu({
  480. selector: '#mix_ratio_sheet',
  481. build: function ($trigger, e) {
  482. me.rightClickTarget = SheetDataHelper.safeRightClickSelection($trigger, e, me.mixRatioSpread);
  483. return me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.viewport ||
  484. me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  485. },
  486. items: {
  487. "deleteMixRatio": {
  488. name: "删除",
  489. icon: 'fa-trash-o',
  490. disabled: function () {
  491. return me.rightClickTarget.row === undefined;
  492. },
  493. callback: function (key, opt) {
  494. let row = me.rightClickTarget.row;
  495. me.deleteMixRatio(row);
  496. }
  497. },
  498. }
  499. });
  500. },
  501. changeFileCallback:function(){
  502. projectGljObject.unitPriceFileInit();
  503. projectGljObject.showProjectGljData();
  504. gljOprObj.refreshView();
  505. projectObj.project.calcProgram.calcAllNodesAndSave();
  506. if(socketObject.roomInfo){
  507. let data ={
  508. projectID:projectObj.project.ID(),
  509. oldRoom:socketObject.roomInfo.unitFile,
  510. newRoom:socketObject.getUnitFileRoomID(),
  511. name:'unitFile'
  512. };
  513. socket.emit('changeNewRoom',data);
  514. socketObject.roomInfo.unitFile = socketObject.getUnitFileRoomID();
  515. }
  516. },
  517. calcPartASupplyFeeByProjectGLJs: function (projectGLJsArr) {
  518. for (let pGLJ of projectGLJsArr){
  519. if (pGLJ.supply == supplyType.BFJG){
  520. let rations = calcTools.getRationsByProjectGLJ(pGLJ.id);
  521. projectObj.project.calcProgram.calcNodesAndSave(rations, function () {
  522. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  523. });
  524. }
  525. };
  526. }
  527. };
  528. $(function () {
  529. let pojGljResizeEles = {};
  530. pojGljResizeEles.id = '#project-glj-main';
  531. pojGljResizeEles.resize = $('#project-glj-main').find('.resize');
  532. pojGljResizeEles.nearElement = $('#project-glj-main').find('.top-content');
  533. pojGljResizeEles.nearSpread = pojGljResizeEles.nearElement.children(".main-data-top");
  534. pojGljResizeEles.farElement = $('#project-glj-main').find('.bottom-content');
  535. pojGljResizeEles.farSpread = pojGljResizeEles.farElement.children().find(".main-data-bottom");
  536. pojGljResizeEles.nav = pojGljResizeEles.farElement.children('ul.nav');
  537. slideResize(pojGljResizeEles, {min: 170, max: 700}, 'height', function () {
  538. projectGljObject.projectGljSpread.refresh();
  539. projectGljObject.mixRatioSpread?projectGljObject.mixRatioSpread.refresh():'';
  540. });
  541. $('#tab_project_glj').on('shown.bs.tab', function (e) {
  542. sessionStorage.setItem('mainTab', '#tab_project_glj');
  543. let me = projectGljObject;
  544. $(e.relatedTarget.hash).removeClass('active');
  545. if(me.projectGljSpread==null){
  546. me.initProjectGljSpread();
  547. }
  548. me.unitPriceFileInit();
  549. //projectObj.project.projectGLJ.calcQuantity(); 在工程量有更新的地方调用
  550. me.showProjectGljData();
  551. loadSize(pojGljResizeEles, 'height', function () {
  552. me.projectGljSpread.refresh();
  553. me.mixRatioSpread?me.mixRatioSpread.refresh():'';
  554. });
  555. });
  556. $('#ration_link').on('shown.bs.tab', function (e) {
  557. let me = projectGljObject;
  558. me.showTag='ration';
  559. me.showProjectGljData();
  560. });
  561. $('#mix_ratio_link').on('shown.bs.tab', function (e) {
  562. let me = projectGljObject;
  563. me.showTag='mixRatio';
  564. me.showProjectGljData();
  565. me.initMixRatio();
  566. });
  567. $('#machine_ratio_link').on('shown.bs.tab', function (e) {
  568. let me = projectGljObject;
  569. me.showTag='machine';
  570. me.showProjectGljData();
  571. me.initMixRatio();
  572. });
  573. $('#pop-used-list').popover({
  574. placement: "bottom",
  575. html: true,
  576. trigger: "hover | focus",
  577. content: projectGljObject.getUsedTenderInfo
  578. }
  579. );
  580. // 单价文件切换弹框
  581. $('#change-unitFile').on('shown.bs.modal', function () {
  582. let rootProjectID = projectInfoObj.projectInfo.property.rootProjectID;
  583. // 获取切换单价文件相关数据
  584. $.ajax({
  585. url: '/glj/get-project-info',
  586. type: 'post',
  587. data: {project_id: scUrlUtil.GetQueryString('project'),rootProjectID:rootProjectID},
  588. dataType: 'json',
  589. success: function (response) {
  590. if (response.err === 1) {
  591. alert('数据传输错误!');
  592. return false;
  593. }
  594. let data = response.data;
  595. $("#current-project-name").text(data.currentProjectName);
  596. // 本项目中的单价文件
  597. if (data.self.length > 0) {
  598. let selfFileHtml = '';
  599. for (let tmp of data.self) {
  600. let select = usedUnitPriceInfo === tmp.id ? ' selected="selected"' : '';
  601. selfFileHtml += '<option' + select + ' value="' + tmp.id + '">' + tmp.name + '</option>';
  602. }
  603. $("#self-file").html(selfFileHtml);
  604. }
  605. // 其他建设项目数据
  606. if (data.other.length > 0) {
  607. let otherProjectHtml = '';
  608. let otherFileHtml = '';
  609. for (let tmp of data.other) {
  610. otherProjectHtml += '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  611. otherFileData[tmp.ID] = tmp.unitPriceList;
  612. if (otherFileHtml !== '') {
  613. continue;
  614. }
  615. for (let unitPrice of tmp.unitPriceList) {
  616. otherFileHtml += '<option value="' + unitPrice.id + '">' + unitPrice.name + '</option>';
  617. }
  618. }
  619. $("#other-project").html(otherProjectHtml);
  620. $("#other-file").html(otherFileHtml);
  621. }
  622. }
  623. });
  624. });
  625. // 单价文件切换确认
  626. $("#change-file-confirm").click(function () {
  627. let type = $("input[name='change-type']:checked").val();
  628. type = parseInt(type);
  629. let changeUnitPriceId = 0;
  630. if (type === 0) {
  631. // 从本项目中选择
  632. changeUnitPriceId = $("#self-file").val();
  633. } else {
  634. // 从其他项目中复制
  635. changeUnitPriceId = $("#other-file").val();
  636. }
  637. $('#change-unitFile').modal("hide");
  638. let data = {project_id: scUrlUtil.GetQueryString('project'), change_id: changeUnitPriceId, type: type};
  639. projectObj.project.projectGLJ.changeFile(data,function () {
  640. projectGljObject.changeFileCallback();
  641. })
  642. });
  643. // 单价文件选项切换
  644. $("input[name='change-type']").change(function () {
  645. let type = $(this).val();
  646. type = parseInt(type);
  647. $("#change-unitFile .option").hide();
  648. if (type === 0) {
  649. $(".option.select").show();
  650. } else {
  651. $(".option.copy").show();
  652. }
  653. });
  654. $("#unitFile-save-as").on('shown.bs.modal', function () {
  655. // 获取当前建设项数据
  656. $("#save-as-name").val(projectGljObject.usedUnitPriceInfo.name + '副本');
  657. });
  658. // 从其他建设项目中复制 选择建设项目
  659. $("#other-project").change(function () {
  660. let projectId = $(this).val();
  661. if (otherFileData[projectId] === undefined) {
  662. return false;
  663. }
  664. let otherFileHtml = '';
  665. for (let unitPrice of otherFileData[projectId]) {
  666. otherFileHtml += '<option value="' + unitPrice.id + '">' + unitPrice.name + '</option>';
  667. }
  668. $("#other-file").html(otherFileHtml);
  669. });
  670. // 单价文件另存为操作
  671. $("#save-as-confirm").click(function () {
  672. let name = $("#save-as-name").val();
  673. if (name === '') {
  674. $("#save-as-tips").text('请填写单价文件名称').show();
  675. return false;
  676. }
  677. let saveData = {name: name, project_id: scUrlUtil.GetQueryString('project')};
  678. projectObj.project.projectGLJ.saveAs(saveData,function () {
  679. projectGljObject.changeFileCallback();
  680. $("#unitFile-save-as").modal("hide");
  681. });
  682. });
  683. });