glj_view.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. setting: {
  13. header: [
  14. {headerName: "编码", headerWidth: 100, dataCode: "code", dataType: "String", formatter: "@"},
  15. {headerName: "名称", headerWidth: 120, dataCode: "name", dataType: "String"},
  16. {headerName: "规格型号", headerWidth: 80, dataCode: "specs", dataType: "String", hAlign: "center"},
  17. {headerName: "单位", headerWidth: 60, dataCode: "unit", dataType: "String", hAlign: "center"},
  18. {headerName: "类别", headerWidth: 50, dataCode: "gljDistType", dataType: "String", hAlign: "center"},
  19. {headerName: "定额消耗量", headerWidth: 80, dataCode: "rationItemQuantity", dataType: "Number", hAlign: "right"}, // dataType: "Number", formatter: "0.00"
  20. {headerName: "自定义消耗量", headerWidth: 80, dataCode: "customQuantity", dataType: "Number", hAlign: "right"},
  21. {headerName: "消耗量", headerWidth: 80, dataCode: "quantity", dataType: "Number", hAlign: "right"},
  22. {headerName: "基价单价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", hAlign: "right"},
  23. {headerName: "调整基价", headerWidth: 80, dataCode: "adjustPrice", dataType: "String", hAlign: "right"},
  24. {headerName: "市场单价", headerWidth: 80, dataCode: "marketPrice", dataType: "String", hAlign: "right"},
  25. {headerName: "市场单价调整", headerWidth: 80, dataCode: "marketPriceAdjust", dataType: "String", hAlign: "right"},
  26. {headerName: "是否暂估", headerWidth: 80, dataCode: "isEstimate", dataType: "String", hAlign: "center",vAlign:"center",cellType:"checkBox"}
  27. ],
  28. view: {
  29. comboBox: [{row: -1, col: 12, rowCount: -1, colCount: 1}],
  30. lockedCells: [{row: -1, col: 3, rowCount: -1, colCount: 1}],
  31. lockColumns:[0,1,2,3,4,5,7,8,9,10,12]
  32. }
  33. },
  34. coeSetting:{
  35. header:[
  36. {headerName: "调整", headerWidth: 100, dataCode: "isAdjust", dataType: "String",cellType:"checkBox"},
  37. {headerName: "条件", headerWidth: 120, dataCode: "name", dataType: "String"},
  38. {headerName: "内容", headerWidth: 260, dataCode: "content", dataType: "String", hAlign: "center"}
  39. ]
  40. },
  41. initSheet: function(sheet) {
  42. var me = this;
  43. me.sheet = sheet;
  44. sheetCommonObj.initSheet(me.sheet, me.setting, 30);
  45. // var unit = new GC.Spread.Sheets.CellTypes.ComboBox();
  46. //unit.items(["米","千克"]);
  47. // me.sheet.getRange(-1, 3, -1, 1).cellType(unit);
  48. me.bindSheetEvent(sheet);
  49. this.loadGLJSpreadContextMenu();
  50. },
  51. initCoeSheet:function (sheet) {
  52. var me = this;
  53. me.coeSheet = sheet;
  54. sheetCommonObj.initSheet(me.coeSheet, me.coeSetting, 30);
  55. me.bindSheetEvent(sheet);
  56. },
  57. bindSheetEvent:function (sheet) {
  58. var me = this;
  59. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  60. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  61. sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  62. sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
  63. },
  64. onClipboardPasting: function(sender, args) {
  65. var me = gljOprObj;
  66. if (!me.ration) {
  67. args.cancel = true;
  68. }
  69. },
  70. onClipboardPasted: function(e, info) {
  71. var me = gljOprObj;
  72. if (!me.ration) {return;};
  73. // your code...
  74. },
  75. onEditEnded: function(sender,args){
  76. var me = gljOprObj;
  77. if(args.row>=me.sheetData.length){
  78. return;
  79. }
  80. var ration_glj = projectObj.project.ration_glj;
  81. var updateFunction =null;
  82. if(me.setting.header[args.col].dataCode=='marketPriceAdjust'){//市场单价调整
  83. updateFunction = ration_glj.marketPriceAdjustUpdate;
  84. }
  85. if(me.setting.header[args.col].dataCode=='customQuantity'){//自定义消耗量
  86. updateFunction = ration_glj.customQuantityUpdate;
  87. }
  88. me.updateRationGLJ(args,updateFunction);
  89. },
  90. onRangeChanged: function(sender, args) {
  91. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  92. if (!confirm(`确定要删除选中的 ${args.rowCount} 条辅助定额吗?`)){return; }
  93. // your code...
  94. };
  95. },
  96. showDataIfRationSelect:function (node) {
  97. var isShow = false;
  98. if(node){
  99. if(this.selectedNodeId&&this.selectedNodeId==node.getID()){
  100. return;
  101. }else {
  102. this.selectedNodeId=node.getID();
  103. }
  104. if(node.sourceType=="ration"){
  105. this.showRationGLJData(node);
  106. this.showRationCoeData(node);
  107. isShow=true;
  108. }
  109. }else {
  110. this.selectedNodeId=null;
  111. }
  112. if(!isShow){
  113. this.clearSheetData();
  114. }
  115. // var activitySheet = subSpread.getActiveSheet();
  116. //activitySheet.clear(0, 0, activitySheet.getRowCount(), activitySheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  117. // ------sheetCommonObj.showData(this.sheet,this.setting,gljList);
  118. // sheetCommonObj.lockCells(this.sheet,this.setting);
  119. },
  120. showRationGLJData:function (node) {
  121. let gljList = [];
  122. let ration_glj = projectObj.project.ration_glj;
  123. let ration = node.data;
  124. if(ration_glj.datas&&ration_glj.datas.length>0){
  125. gljList = _.filter(ration_glj.datas,{'projectID':ration.projectID,'rationID':ration.ID})
  126. }
  127. sheetCommonObj.showData(this.sheet,this.setting,gljList);
  128. this.sheetData=gljList;
  129. },
  130. showRationCoeData:function (node) {
  131. let coeList = [];
  132. let ration_coe= projectObj.project.ration_coe;
  133. let ration = node.data;
  134. if(ration_coe.datas&&ration_coe.datas.length>0){
  135. coeList = _.filter(ration_coe.datas,{'projectID':ration.projectID,'rationID':ration.ID})
  136. }
  137. sheetCommonObj.showData(this.coeSheet,this.coeSetting,coeList);
  138. this.coeSheetData=coeList;
  139. },
  140. clearSheetData:function () {
  141. sheetCommonObj.showData(this.sheet,this.setting,[]);
  142. sheetCommonObj.showData(this.coeSheet,this.coeSetting,[]);
  143. this.sheetData = [];
  144. this.coeSheetData = [];
  145. },
  146. loadGLJSpreadContextMenu: function () {
  147. var project =projectObj.project, spread =subSpread;
  148. var selectedRow =null;
  149. $.contextMenu({
  150. selector: '#subSpread',
  151. build: function ($trigger, e) {
  152. var target = SheetDataHelper.safeRightClickSelection($trigger, e, spread);
  153. selectedRow = target.row;
  154. //controller.setTreeSelected(controller.tree.items[target.row]);
  155. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  156. },
  157. items: {
  158. "delete_glj": {
  159. name: '删除工料机',
  160. icon: 'fa-remove',
  161. disabled: function () {
  162. //var selected = project.mainTree.selected;
  163. var disable = true;
  164. if(subSpread.getActiveSheetIndex()==0&&gljOprObj.sheetData!=null&&gljOprObj.sheetData.length>0&&selectedRow<gljOprObj.sheetData.length){
  165. disable=false
  166. }
  167. return disable;
  168. },
  169. callback: function () {
  170. var deleteRow = gljOprObj.sheetData[selectedRow];
  171. projectObj.project.ration_glj.updataOrdelete(deleteRow);
  172. }
  173. }
  174. }
  175. });
  176. },
  177. updateRationGLJ:function (args,updateFunction) {
  178. var me = gljOprObj;
  179. var newval = this.numberValueChecking(args.editingText);
  180. var recode = me.sheetData[args.row];
  181. if(newval){
  182. updateFunction.apply(projectObj.project.ration_glj,[recode,newval]);
  183. }else {
  184. newval = parseFloat(recode.customQuantity).toFixed(2);
  185. me.sheet.getCell(args.row, args.col).value(newval);
  186. }
  187. },
  188. numberValueChecking:function (val) {
  189. var newval = Number(val);
  190. if(number_util.isNumber(newval)){
  191. newval = newval.toFixed(2);
  192. }else {
  193. if(val){
  194. alert('您输入的数据类型不正确,请重新输入。');
  195. }
  196. newval = null;
  197. }
  198. return newval;
  199. }
  200. }