glj_view.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /**
  2. * Created by CSL on 2017-05-12.
  3. */
  4. var gljOprObj = {
  5. sheet: null,
  6. libID: null,
  7. ration: null,
  8. sheetData:[],
  9. coeSheetData:[],
  10. checkb:null,
  11. coeSheet:null,
  12. assSheet:null,
  13. assSheetData:[],
  14. setting: {
  15. header: [
  16. {headerName: "编码", headerWidth: 100, dataCode: "code", dataType: "String", formatter: "@"},
  17. {headerName: "名称", headerWidth: 120, dataCode: "name", dataType: "String"},
  18. {headerName: "规格型号", headerWidth: 80, dataCode: "specs", dataType: "String", hAlign: "center"},
  19. {headerName: "单位", headerWidth: 60, dataCode: "unit", dataType: "String", hAlign: "center"},
  20. {headerName: "类别", headerWidth: 50, dataCode: "gljDistType", dataType: "String", hAlign: "center"},
  21. {headerName: "定额消耗量", headerWidth: 80, dataCode: "rationItemQuantity", dataType: "Number", hAlign: "right"}, // dataType: "Number", formatter: "0.00"
  22. {headerName: "自定义消耗量", headerWidth: 80, dataCode: "customQuantity", dataType: "Number", hAlign: "right"},
  23. {headerName: "消耗量", headerWidth: 80, dataCode: "quantity", dataType: "Number", hAlign: "right"},
  24. {headerName: "基价单价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", hAlign: "right"},
  25. {headerName: "调整基价", headerWidth: 80, dataCode: "adjustPrice", dataType: "String", hAlign: "right"},
  26. {headerName: "市场单价", headerWidth: 80, dataCode: "marketPrice", dataType: "String", hAlign: "right"},
  27. {headerName: "市场单价调整", headerWidth: 80, dataCode: "marketPriceAdjust", dataType: "String", hAlign: "right"},
  28. {headerName: "是否暂估", headerWidth: 80, dataCode: "isEstimate", dataType: "String", hAlign: "center",vAlign:"center",cellType:"checkBox"}
  29. ],
  30. view: {
  31. comboBox: [{row: -1, col: 12, rowCount: -1, colCount: 1}],
  32. lockedCells: [{row: -1, col: 3, rowCount: -1, colCount: 1}],
  33. lockColumns:[0,1,2,3,4,5,7,8,9,10,12]
  34. },
  35. notEditedType: ['混凝土','砂浆','配合比','机械']
  36. },
  37. coeSetting:{
  38. header:[
  39. {headerName: "调整", headerWidth: 100, dataCode: "isAdjust", dataType: "String",cellType:"checkBox"},
  40. {headerName: "条件", headerWidth: 120, dataCode: "name", dataType: "String"},
  41. {headerName: "内容", headerWidth: 350, dataCode: "content", dataType: "String", hAlign: "center"}
  42. ],
  43. view:{
  44. lockColumns:[0,1,2]
  45. }
  46. },
  47. assSetting:{
  48. header:[
  49. {headerName: "调整名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  50. {headerName: "定额值", headerWidth: 120, dataCode: "stdValue", dataType: "Number"},
  51. {headerName: "实际值", headerWidth: 120, dataCode: "actualValue", dataType: "Number"}
  52. ],
  53. view:{
  54. lockColumns:[0,1]
  55. }
  56. },
  57. initSheet: function(sheet) {
  58. var me = this;
  59. me.sheet = sheet;
  60. sheetCommonObj.initSheet(me.sheet, me.setting, 30);
  61. me.bindSheetEvent(sheet);
  62. sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  63. this.loadGLJSpreadContextMenu();
  64. },
  65. initCoeSheet:function (sheet) {
  66. var me = this;
  67. me.coeSheet = sheet;
  68. sheetCommonObj.initSheet(me.coeSheet, me.coeSetting, 30);
  69. me.bindSheetEvent(sheet);
  70. me.addDropDownList();
  71. sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCoeCellClick);
  72. subSpread.bind(GC.Spread.Sheets.Events.ButtonClicked,me.onCheckBoxClick);
  73. },
  74. initAssSheet: function(sheet) {
  75. var me = this;
  76. me.assSheet = sheet;
  77. sheetCommonObj.initSheet(me.assSheet, me.assSetting, 30);
  78. me.bindSheetEvent(sheet);
  79. },
  80. bindSheetEvent:function (sheet) {
  81. var me = this;
  82. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  83. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  84. sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  85. sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
  86. // sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  87. },
  88. onClipboardPasting: function(sender, args) {
  89. var me = gljOprObj;
  90. if (!me.ration) {
  91. args.cancel = true;
  92. }
  93. },
  94. onClipboardPasted: function(e, info) {
  95. var me = gljOprObj;
  96. if (!me.ration) {return;};
  97. // your code...
  98. },
  99. onEditEnded: function(sender,args){
  100. var me = gljOprObj;
  101. if(subSpread.getActiveSheetIndex()==0){
  102. me.onEditGLJSheet(args)
  103. }
  104. if(subSpread.getActiveSheetIndex()==1){
  105. me.onEditAssSheet(args);
  106. }
  107. },
  108. onEditGLJSheet(args){
  109. var me = gljOprObj;
  110. if(args.row>=me.sheetData.length){
  111. me.sheet.getCell(args.row, args.col).value(null);
  112. return;
  113. }
  114. var ration_glj = projectObj.project.ration_glj;
  115. var updateFunction =null;
  116. if(me.setting.header[args.col].dataCode=='marketPriceAdjust'){//市场单价调整
  117. updateFunction = ration_glj.marketPriceAdjustUpdate;
  118. }
  119. if(me.setting.header[args.col].dataCode=='customQuantity'){//自定义消耗量
  120. updateFunction = ration_glj.customQuantityUpdate;
  121. }
  122. me.updateRationGLJ(args,updateFunction);
  123. },
  124. onEditAssSheet(args){
  125. var me = gljOprObj;
  126. if(args.row>=me.assSheetData.length){
  127. me.assSheet.getCell(args.row, args.col).value(null);
  128. return;
  129. }
  130. if(me.assSetting.header[args.col].dataCode=='actualValue'){//自定义消耗量
  131. me.updateRationAss(args);
  132. }
  133. },
  134. onCheckBoxClick:function (sender,args) {
  135. if(subSpread.getActiveSheetIndex()==2){
  136. var checkboxValue = gljOprObj.coeSheet.getCell(args.row, args.col).value();
  137. var newval = 0;
  138. if(checkboxValue){
  139. newval = 0;
  140. gljOprObj.coeSheet.getCell(args.row, args.col).value(newval);
  141. }else {
  142. newval=1
  143. gljOprObj.coeSheet.getCell(args.row, args.col).value(newval);
  144. }
  145. gljOprObj.updateRationCoe(args,newval)
  146. }
  147. //console.log(args);
  148. },
  149. onCellClick: function(sender,args){
  150. var me = gljOprObj;
  151. if(args.row>=me.sheetData.length){
  152. return;
  153. }
  154. if(me.setting.header[args.col].dataCode=='marketPriceAdjust'){//市场单价调整
  155. var type = me.sheetData[args.row].gljDistType;
  156. var index= _.indexOf(me.setting.notEditedType,type);
  157. if(index!=-1){
  158. me.sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(true);
  159. }
  160. }
  161. },
  162. onCoeCellClick:function (sender,args) {
  163. var me = gljOprObj;
  164. var floatingObject = me.coeSheet.floatingObjects.get('customerCoe');
  165. // var isVisable = floatingObject.isVisible();
  166. if($('#dropdown').css("display") == 'none'){
  167. if(args.col==1&&me.coeSheetData.length>args.row&&me.coeSheetData[args.row].coeID==-1){
  168. me.showFloationObject(floatingObject,me.coeSheetData[args.row]);
  169. }
  170. } else {
  171. var result = me.checkIfNeedUpdate();
  172. if(result.isNeed){
  173. projectObj.project.ration_coe.updateCustomerCoe(result);
  174. }
  175. floatingObject.isVisible(false);
  176. $('#dropdown').hide();
  177. }
  178. },
  179. showFloationObject(floatingObject,data){
  180. floatingObject.isVisible(true);
  181. var sheet = this.coeSheet;
  182. var startRow = this.coeSheetData.length;
  183. var endRow = startRow+1;
  184. floatingObject.startRow(startRow);
  185. floatingObject.startColumn(1);
  186. floatingObject.endColumn(2);
  187. floatingObject.endRow(endRow);
  188. this.bindFloadingObjectValue(data);
  189. sheet.repaint();
  190. sheet.getViewportTopRow(1);
  191. var editPosition = $("#edit").offset();
  192. $('#dropdown').show();
  193. var top =editPosition.top>=825?825:editPosition.top
  194. $('#dropdown').offset({left:editPosition.left,top:top});//top: 791px; left:70px;
  195. },
  196. bindFloadingObjectValue(data){
  197. $('#coe_ration').val(data.coes[0].amount);
  198. $('#manual').val(data.coes[1].amount);
  199. $('#material').val(data.coes[2].amount);
  200. $('#manchine').val(data.coes[3].amount);
  201. $('#main').val(data.coes[4].amount);
  202. $('#equipment').val(data.coes[5].amount);
  203. },
  204. onInputChange(id,name){
  205. var coe = _.find(gljOprObj.coeSheetData,function (c) {
  206. return c.coeID == -1;
  207. });
  208. var newValue = gljOprObj.numberValueChecking($('#'+id).val());
  209. if(newValue){
  210. newValue=_.round(newValue,2);
  211. if(newValue==coe.coes[name].amount) return;
  212. if(id=='coe_ration'){
  213. $('#coe_ration').val(newValue);
  214. $('#manual').val(newValue);
  215. $('#material').val(newValue);
  216. $('#manchine').val(newValue);
  217. $('#main').val(newValue);
  218. $('#equipment').val(newValue);
  219. }
  220. }else {
  221. $('#'+id).val(coe.coes[name].amount);
  222. }
  223. },
  224. checkIfNeedUpdate(){
  225. var data = _.find(gljOprObj.coeSheetData,function (c) {
  226. return c.coeID == -1;
  227. });
  228. var result = {
  229. isNeed:false
  230. }
  231. var coe_ration = $('#coe_ration').val();
  232. var manual=$('#manual').val();
  233. var material = $('#material').val();
  234. var manchine= $('#manchine').val();
  235. var main = $('#main').val();
  236. var equipment=$('#equipment').val();
  237. if(coe_ration!=data.coes[0].amount){
  238. result.isNeed =true;
  239. data.coes[0].amount =coe_ration;
  240. }
  241. if(manual!=data.coes[1].amount){
  242. result.isNeed =true;
  243. data.coes[1].amount =manual;
  244. }
  245. if(material!=data.coes[2].amount){
  246. result.isNeed =true;
  247. data.coes[2].amount =material;
  248. }
  249. if(manchine!=data.coes[3].amount){
  250. result.isNeed =true;
  251. data.coes[3].amount =manchine;
  252. }
  253. if(main!=data.coes[4].amount){
  254. result.isNeed =true;
  255. data.coes[4].amount =main;
  256. }
  257. if(equipment!=data.coes[5].amount){
  258. result.isNeed =true;
  259. data.coes[5].amount =equipment;
  260. }
  261. if(result.isNeed){
  262. result.doc = {
  263. coes:data.coes
  264. };
  265. result.query = {
  266. projectID:data.projectID,
  267. ID:data.ID,
  268. rationID:data.rationID
  269. };
  270. }
  271. return result;
  272. },
  273. addDropDownList:function () {
  274. var sheet = this.coeSheet;
  275. sheet.suspendPaint();
  276. var customFloatingObject = new GC.Spread.Sheets.FloatingObjects.FloatingObject("customerCoe");
  277. var div = document.createElement('div');
  278. div.innerHTML = this.generateHtmlString();
  279. customFloatingObject.startRow(1);
  280. customFloatingObject.startColumn(1);
  281. customFloatingObject.endColumn(2);
  282. customFloatingObject.endRow(2);
  283. $(div).css('background', 'white');
  284. customFloatingObject.content(div);
  285. sheet.floatingObjects.add(customFloatingObject);
  286. customFloatingObject.isVisible(false);
  287. sheet.resumePaint();
  288. },
  289. onRangeChanged: function(sender, args) {
  290. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  291. if (!confirm(`确定要删除选中的 ${args.rowCount} 条辅助定额吗?`)){return; }
  292. // your code...
  293. };
  294. },
  295. generateHtmlString:function () {
  296. return "<div id='edit'><div>";
  297. /* var newString = "<form ><table border='1px' bordercolor='#CCCCCC' cellspacing='0px' style='border-collapse:collapse;font-size: 10px;>";
  298. //newString +="<tr><td style='height:15px' colspan='2'>自定义系数</td></tr>"
  299. newString += this.getOneRow('定额',0,'coe_ration');
  300. newString += this.getOneRow('人工',1,'manual');
  301. newString += this.getOneRow('材料',2,'material');
  302. newString += this.getOneRow('机械',3,'manchine');
  303. newString += this.getOneRow('主材',4,'main');
  304. newString += this.getOneRow('设备',5,'equipment');
  305. newString +="</table></form>";
  306. return newString;*/
  307. //"<form id='edit'><table border='1px' bordercolor='#CCCCCC' cellspacing='0px' style='border-collapse:collapse;font-size: 10px;><tr style='height:10px'><td style='width: 50px'>定额:</td><td style='width: 70px' align='right'><input type='text'value='1' name='ration' style='width:30px;border:0;height:14px' align='right'></td></tr><tr><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr><tr><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr><tr ><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr><tr><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr></table></form>";
  308. },
  309. getOneRow:function (text,name,id) {
  310. var rowstr = "<tr style='height:10px'><td style='width: 50px'>"+text
  311. +":</td><td style='width: 70px' align='right'><input type='text'value='1' name="+name
  312. +" style='width:30px;border:0;height:14px' align='right' id="+id+" onchange='gljOprObj.onInputChange(this.id,this.name)'></td></tr>";
  313. return rowstr;
  314. },
  315. showDataIfRationSelect:function (node) {
  316. var isShow = false;
  317. if(node){
  318. if(this.selectedNodeId&&this.selectedNodeId==node.getID()){
  319. return;
  320. }else {
  321. this.selectedNodeId=node.getID();
  322. }
  323. if(node.sourceType=="ration"){
  324. this.showRationGLJData(node);
  325. this.showRationCoeData(node);
  326. this.showRationAssData(node);
  327. isShow=true;
  328. }
  329. }else {
  330. this.selectedNodeId=null;
  331. }
  332. if(!isShow){
  333. this.clearSheetData();
  334. }
  335. /* this.lockRationGLJCell();
  336. this.lockRationCoeCell();*/
  337. //hide floatingObject
  338. var floatingObject = this.coeSheet.floatingObjects.get('customerCoe');
  339. floatingObject.isVisible(false);
  340. $('#dropdown').hide();
  341. },
  342. showRationGLJData:function (node) {
  343. let gljList = [];
  344. let ration_glj = projectObj.project.ration_glj;
  345. let ration = node.data;
  346. if(ration_glj.datas&&ration_glj.datas.length>0){
  347. gljList = _.filter(ration_glj.datas,{'projectID':ration.projectID,'rationID':ration.ID})
  348. }
  349. sheetCommonObj.showData(this.sheet,this.setting,gljList);
  350. this.sheetData=gljList;
  351. },
  352. showRationCoeData:function (node) {
  353. let coeList = [];
  354. let ration_coe= projectObj.project.ration_coe;
  355. let ration = node.data;
  356. if(ration_coe.datas&&ration_coe.datas.length>0){
  357. coeList = _.filter(ration_coe.datas,{'projectID':ration.projectID,'rationID':ration.ID})
  358. }
  359. sheetCommonObj.showData(this.coeSheet,this.coeSetting,coeList);
  360. this.coeSheetData=coeList;
  361. },
  362. showRationAssData:function (node) {
  363. let assList = node.data.rationAssList;
  364. sheetCommonObj.showData(this.assSheet,this.assSetting,assList);
  365. this.assSheetData =assList;
  366. },
  367. clearSheetData:function () {
  368. sheetCommonObj.showData(this.sheet,this.setting,[]);
  369. sheetCommonObj.showData(this.coeSheet,this.coeSetting,[]);
  370. sheetCommonObj.showData(this.assSheet,this.assSetting,[]);
  371. this.sheetData = [];
  372. this.coeSheetData = [];
  373. this.assSheetData = [];
  374. },
  375. /* lockRationGLJCell:function(){
  376. sheetCommonObj.lockCells(this.sheet,this.setting);
  377. },
  378. lockRationCoeCell:function () {
  379. sheetCommonObj.lockCells(this.coeSheet,this.coeSetting);
  380. /!* if(this.coeSheetData){
  381. for(var i =0;i<this.coeSheetData.length;i++){
  382. if(this.coeSheetData[i].coeID==-1){
  383. this.coeSheet.getCell(i, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  384. }
  385. }
  386. }*!/
  387. },
  388. lockRationGLJCell:function(){
  389. sheetCommonObj.lockCells(this.sheet,this.setting);
  390. },*/
  391. loadGLJSpreadContextMenu: function () {
  392. var project =projectObj.project, spread =subSpread;
  393. var selectedRow =null;
  394. $.contextMenu({
  395. selector: '#subSpread',
  396. build: function ($trigger, e) {
  397. var target = SheetDataHelper.safeRightClickSelection($trigger, e, spread);
  398. selectedRow = target.row;
  399. //controller.setTreeSelected(controller.tree.items[target.row]);
  400. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  401. },
  402. items: {
  403. "delete_glj": {
  404. name: '删除工料机',
  405. icon: 'fa-remove',
  406. disabled: function () {
  407. //var selected = project.mainTree.selected;
  408. var disable = true;
  409. if(subSpread.getActiveSheetIndex()==0&&gljOprObj.sheetData!=null&&gljOprObj.sheetData.length>0&&selectedRow<gljOprObj.sheetData.length){
  410. disable=false
  411. }
  412. return disable;
  413. },
  414. callback: function () {
  415. var deleteRow = gljOprObj.sheetData[selectedRow];
  416. projectObj.project.ration_glj.updataOrdelete(deleteRow);
  417. }
  418. }
  419. }
  420. });
  421. },
  422. updateRationGLJ:function (args,updateFunction) {
  423. if(!updateFunction){
  424. return
  425. }
  426. var me = gljOprObj;
  427. var newval = this.numberValueChecking(args.editingText);
  428. var recode = me.sheetData[args.row];
  429. updateFunction.apply(projectObj.project.ration_glj,[recode,newval,args.editingText]);
  430. if(newval){
  431. newval = parseFloat(recode.customQuantity).toFixed(2);
  432. }
  433. if(args.editingText===null){
  434. newval=null;
  435. }
  436. me.sheet.getCell(args.row, args.col).value(newval);
  437. },
  438. updateRationAss:function (args) {
  439. var me = gljOprObj;
  440. var newval = me.numberValueChecking(args.editingText);
  441. var recode = me.assSheetData[args.row];
  442. var isValidate = false;
  443. if(newval){
  444. isValidate = me.checkingActualValue(recode,newval)
  445. }
  446. if(isValidate){
  447. projectObj.project.ration_ass.updateActualValue(me.assSheetData,args.row,newval)
  448. }else {
  449. newval = recode.actualValue;
  450. me.assSheet.getCell(args.row, args.col).value(newval);
  451. }
  452. },
  453. updateRationCoe:function (args,newval) {
  454. var me = gljOprObj;
  455. var recode = me.coeSheetData[args.row];
  456. projectObj.project.ration_coe.adjustCoeClick(recode,newval);
  457. },
  458. numberValueChecking:function (val) {
  459. var newval = Number(val);
  460. if(number_util.isNumber(newval)){
  461. newval = newval.toFixed(2);
  462. }else {
  463. if(val){
  464. alert('您输入的数据类型不正确,请重新输入。');
  465. }
  466. newval = null;
  467. }
  468. return newval;
  469. },
  470. checkingActualValue(record,newval){
  471. var minExist = record.minValue&&record.minValue!='0'?true:false;
  472. var maxExist = record.maxValue&&record.maxValue!='0'?true:false;
  473. var minValue = parseFloat(record.minValue);
  474. var maxValue = parseFloat(record.maxValue);
  475. var stdVale = parseFloat(record.stdValue);
  476. if(stdVale==newval){
  477. return false;
  478. }
  479. if(!maxExist&&minExist){
  480. if(newval<minValue){
  481. alert('实际值应≥'+minValue);
  482. return false;
  483. }
  484. }
  485. if(maxExist&&!minExist){
  486. if(newval>maxValue){
  487. alert('实际值应≤'+maxValue);
  488. return false;
  489. }
  490. }
  491. if(maxExist&&minExist){
  492. if(newval<minValue||newval>maxValue){
  493. alert('实际值应介于'+minValue+'~'+maxValue+'之间');
  494. return false;
  495. }
  496. }
  497. return true;
  498. }
  499. }