quantity_edit_view.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /**
  2. * Created by zhang on 2018/7/20.
  3. */
  4. let quantityEditObj = {
  5. spread:null,
  6. datas:[],
  7. setting:{
  8. header:[
  9. {headerName: "基数名称", headerWidth: 250, dataCode: "name", dataType: "String"},
  10. {headerName: "代码", headerWidth: 150, dataCode: "code", dataType: "String"},
  11. ],
  12. view: {
  13. lockColumns: [0,1]
  14. }
  15. },
  16. initSpread:function () {
  17. if(!this.spread){
  18. this.spread = SheetDataHelper.createNewSpread($("#quantityEditSpread")[0]);
  19. this.initSheet();
  20. }
  21. this.showData();
  22. },
  23. initSheet:function () {
  24. this.sheet = this.spread .getSheet(0);
  25. sheetCommonObj.initSheet( this.sheet, this.setting, 30);
  26. this.sheet.bind(GC.Spread.Sheets.Events.CellDoubleClick,this.onCellDoubleClick);
  27. this.sheet.name('quantityEdit');
  28. // console.log(cell.value());
  29. },
  30. showData:function () {
  31. this.datas = [];//{name:'工程量明细合计',code:'GCLMXHJ'}这里暂时只有清单量一个选项
  32. let selected = projectObj.project.mainTree.selected;
  33. if(selected.sourceType == ModuleNames.ration){
  34. this.datas.push({name:'清单量',code:'QDL'});
  35. }
  36. sheetCommonObj.showData(this.sheet, this.setting,this.datas);
  37. this.sheet.setRowCount(this.datas.length);
  38. },
  39. onCellDoubleClick:function (e,info) {
  40. if(quantityEditObj.datas[info.row]){
  41. let oldVal = $("#quantityEXPValue").val();
  42. $("#quantityEXPValue").val(oldVal+quantityEditObj.datas[info.row].code);
  43. $("#quantityEXPValue").focus();
  44. }
  45. },
  46. getQuantityEditCellType:function () {
  47. var ns = GC.Spread.Sheets;
  48. function QuantityEditCellType() {
  49. var init=false;
  50. }
  51. QuantityEditCellType.prototype = new ns.CellTypes.Text();
  52. QuantityEditCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  53. // if(value!=null){
  54. // ctx.fillText(value,x+3+ctx.measureText(value).width,y+h-3);
  55. // }
  56. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  57. if(quantityEditObj.editingCell && !projectReadOnly){
  58. if(quantityEditObj.editingCell.row==options.row&&quantityEditObj.editingCell.col==options.col){
  59. var image = document.getElementById('f_btn'),imageMagin = 3;
  60. var imageHeight = h-2*imageMagin;
  61. var imageWidth = w*2/7;
  62. var imageX = x + w - imageWidth- imageMagin, imageY = y + h / 2 - imageHeight / 2;
  63. ctx.save();
  64. ctx.drawImage(image, imageX, imageY,imageWidth,imageHeight);
  65. ctx.beginPath();
  66. ctx.arc(imageX+imageWidth/2,imageY+imageHeight/2,1,0,360,false);
  67. ctx.arc(imageX+imageWidth/2-4,imageY+imageHeight/2,1,0,360,false);
  68. ctx.arc(imageX+imageWidth/2+4,imageY+imageHeight/2,1,0,360,false);
  69. ctx.fillStyle="black";//填充颜色,默认是黑色
  70. ctx.fill();//画实心圆
  71. ctx.closePath();
  72. ctx.restore();
  73. }
  74. }
  75. };
  76. QuantityEditCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  77. return {
  78. x: x,
  79. y: y,
  80. row: context.row,
  81. col: context.col,
  82. cellStyle: cellStyle,
  83. cellRect: cellRect,
  84. sheetArea: context.sheetArea
  85. };
  86. };
  87. QuantityEditCellType.prototype.processMouseDown = function (hitinfo) {
  88. var me=quantityEditObj;
  89. me.pmLeave = false;
  90. if(me.editingCell==null){
  91. var showSelectBtn = true;
  92. if(showSelectBtn){
  93. me.editingCell={
  94. row:hitinfo.row,
  95. col:hitinfo.col
  96. }
  97. hitinfo.sheet.invalidateLayout();
  98. hitinfo.sheet.repaint();
  99. }
  100. }else if(hitinfo.row==me.editingCell.row){
  101. var offset=hitinfo.cellRect.x+hitinfo.cellRect.width-6;
  102. var imageMagin=3;
  103. var imageHeight = hitinfo.cellRect.height-2*imageMagin;
  104. var imageWidth = hitinfo.cellRect.width*2/7;
  105. if(hitinfo.x<offset&&hitinfo.x>offset-imageWidth){
  106. if(!projectReadOnly){
  107. me.showSelectModal(hitinfo);
  108. }
  109. }
  110. }
  111. };
  112. QuantityEditCellType.prototype.processMouseEnter = function (hitinfo) {
  113. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  114. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  115. let dataField = "quantity";
  116. if(hitinfo.sheet.getCell(hitinfo.row,hitinfo.col).wordWrap()==true){
  117. return;
  118. }
  119. if(dataField=="quantity"){
  120. text = tag;
  121. }else if(tag !== undefined && tag) {
  122. text = tag;
  123. }
  124. if (text && text !== '') {
  125. if (!this._toolTipElement) {
  126. let div = $('#autoTip')[0];
  127. if (!div) {
  128. div = document.createElement("div");
  129. $(div).css("position", "absolute")
  130. .css("border", "1px #C0C0C0 solid")
  131. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  132. .css("font", "9pt Arial")
  133. .css("background", "white")
  134. .css("padding", 5)
  135. .attr("id", 'autoTip');
  136. $(div).hide();
  137. document.body.insertBefore(div, null);
  138. }
  139. this._toolTipElement = div;
  140. $(this._toolTipElement).text(text);
  141. let cellRect = hitinfo.sheet.getCellRect(hitinfo.row,hitinfo.col);
  142. $(this._toolTipElement).css("top", cellRect.y+$('#main').offset().top+cellRect.height).css("left", hitinfo.x );//
  143. $(this._toolTipElement).show("fast");
  144. TREE_SHEET_HELPER.tipDiv = 'show';//做个标记
  145. }
  146. }
  147. };
  148. QuantityEditCellType.prototype.processMouseLeave = function (hitinfo) {
  149. if(!quantityEditObj.pmLeave){
  150. quantityEditObj.editingCell=null;
  151. hitinfo.sheet.invalidateLayout();
  152. hitinfo.sheet.repaint();
  153. quantityEditObj.pmLeave = true;
  154. }
  155. let me = this;
  156. TREE_SHEET_HELPER.tipDiv = 'hide';
  157. if (me._toolTipElement) {
  158. $(me._toolTipElement).hide();
  159. me._toolTipElement = null;
  160. };
  161. TREE_SHEET_HELPER.tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  162. };
  163. return new QuantityEditCellType();
  164. },
  165. showSelectModal:function (hitinfo) {
  166. //锁定的清单不显示
  167. let project = projectObj.project;
  168. if(project.isBillsLocked() && project.withinBillsLocked(project.mainTree.selected)){
  169. return;
  170. }
  171. $("#quantityEXPEdit").modal({show:true});
  172. },
  173. checkingAndUpdate(quantityEXP,node){
  174. let me = this;
  175. quantityEXP = quantityEXP.toUpperCase();
  176. if(quantityEXP === node.data.quantityEXP){ //没有变化,不做任何操作
  177. projectObj.mainController.refreshTreeNode([node]);
  178. return;
  179. }
  180. let value = me.evalQuantityExp(quantityEXP,node);
  181. if(value!=='evalError'){
  182. if(node.data.hasOwnProperty('isFromDetail')&&node.data.isFromDetail==1){
  183. hintBox.infoBox('操作确认', '已有工程量明细,是否清空明细表,采用手工输入的表达式?', 2, function () {
  184. node.data.isFromDetail=0;
  185. me.updateQuantityEXP(value,quantityEXP,node);
  186. }, function () {
  187. projectObj.mainController.refreshTreeNode([node]);
  188. },['确定','取消'],false);
  189. return;
  190. }
  191. me.updateQuantityEXP(value,quantityEXP,node);
  192. }else {
  193. projectObj.mainController.refreshTreeNode([node]);
  194. }
  195. },
  196. evalQuantityExp(quantityEXP,node){
  197. let evalString = quantityEXP;
  198. if( node.sourceType == ModuleNames.ration && quantityEXP.indexOf('QDL')!=-1){
  199. let billNode = node.parent;
  200. let bQuantity = billNode.data.quantity?scMathUtil.roundForObj(billNode.data.quantity,getDecimal("quantity",billNode)):0;
  201. evalString = replaceAll("QDL","("+bQuantity+")",evalString);
  202. }
  203. try {
  204. let value = eval(evalString);
  205. return value;
  206. }catch (error){
  207. alert("输入的表达式有误,请重新输入!");
  208. return "evalError"
  209. }
  210. },
  211. updateQuantityEXP:function (value,quantityEXP,node) {
  212. let quantity_detail = projectObj.project.quantity_detail;
  213. quantity_detail.cleanQuantityDetail(node,true);
  214. if(node.sourceType === ModuleNames.bills){
  215. quantity_detail.updateBillQuantity(value,node,quantityEXP,quantityEXP);
  216. //me.updateBillQuantity(value,node,null,editingText);
  217. }else {
  218. quantity_detail.updateRationQuantity(value,node,quantityEXP,quantityEXP);
  219. }
  220. }
  221. };
  222. $(function(){
  223. $('#quantityEXPEdit').on('shown.bs.modal', function (e) {
  224. let selected = projectObj.project.mainTree.selected;
  225. $("#quantityEXPValue").val(selected.data.quantityEXP);
  226. quantityEditObj.initSpread();
  227. });
  228. $('#operation_p').children("button").bind('click',function (){
  229. let oldVal = $("#quantityEXPValue").val();
  230. $("#quantityEXPValue").val(oldVal+$(this).text());
  231. $("#quantityEXPValue").focus();
  232. })
  233. $("#quantityEditConf").bind('click',function () {
  234. let selected = projectObj.project.mainTree.selected;
  235. quantityEditObj.checkingAndUpdate($("#quantityEXPValue").val(),selected);
  236. $("#quantityEXPEdit").modal('hide');
  237. })
  238. });