project_glj_view.js 27 KB

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