quantity_edit_view.js 11 KB

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