quantity_edit_view.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. if(me.editingCell && hitinfo.row==me.editingCell.row){
  92. var offset=hitinfo.cellRect.x+hitinfo.cellRect.width-6;
  93. var imageMagin=3;
  94. var imageHeight = hitinfo.cellRect.height-2*imageMagin;
  95. var imageWidth = hitinfo.cellRect.width*2/7;
  96. if(hitinfo.x<offset&&hitinfo.x>offset-imageWidth){
  97. if(!projectReadOnly){
  98. me.showSelectModal(hitinfo);
  99. }
  100. }else {//点击其它地方,按钮消失
  101. hideButton(hitinfo)
  102. }
  103. }
  104. };
  105. QuantityEditCellType.prototype.processMouseEnter = function (hitinfo) {
  106. var me=quantityEditObj;
  107. me.pmLeave = false;
  108. if(me.editingCell==null){
  109. me.editingCell={
  110. row:hitinfo.row,
  111. col:hitinfo.col
  112. }
  113. hitinfo.sheet.invalidateLayout();
  114. hitinfo.sheet.repaint();
  115. }
  116. //取消悬浮提示
  117. /* let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  118. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  119. let dataField = "quantity";
  120. if(hitinfo.sheet.getCell(hitinfo.row,hitinfo.col).wordWrap()==true){
  121. return;
  122. }
  123. if(dataField=="quantity"){
  124. text = tag;
  125. }else if(tag !== undefined && tag) {
  126. text = tag;
  127. }
  128. if (text && text !== '') {
  129. if (!this._toolTipElement) {
  130. let div = $('#autoTip')[0];
  131. if (!div) {
  132. div = document.createElement("div");
  133. $(div).css("position", "absolute")
  134. .css("border", "1px #C0C0C0 solid")
  135. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  136. .css("font", "9pt Arial")
  137. .css("background", "white")
  138. .css("padding", 5)
  139. .attr("id", 'autoTip');
  140. $(div).hide();
  141. document.body.insertBefore(div, null);
  142. }
  143. this._toolTipElement = div;
  144. $(this._toolTipElement).text(text);
  145. let cellRect = hitinfo.sheet.getCellRect(hitinfo.row,hitinfo.col);
  146. $(this._toolTipElement).css("top", cellRect.y+$('#main').offset().top+cellRect.height).css("left", hitinfo.x );//
  147. $(this._toolTipElement).show("fast");
  148. TREE_SHEET_HELPER.tipDiv = 'show';//做个标记
  149. }
  150. }*/
  151. };
  152. QuantityEditCellType.prototype.processMouseLeave = function (hitinfo) {
  153. hideButton(hitinfo);
  154. //延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  155. /*TREE_SHEET_HELPER.tipDiv = 'hide'; 取消悬浮提示
  156. if (TREE_SHEET_HELPER._toolTipElement) {
  157. $(TREE_SHEET_HELPER._toolTipElement).hide();
  158. TREE_SHEET_HELPER._toolTipElement = null;
  159. };
  160. TREE_SHEET_HELPER.tipDivCheck();*/
  161. };
  162. function hideButton(hitinfo) {
  163. if(!quantityEditObj.pmLeave){//鼠标进入显示三个点按钮
  164. quantityEditObj.editingCell=null;
  165. hitinfo.sheet.invalidateLayout();
  166. hitinfo.sheet.repaint();
  167. quantityEditObj.pmLeave = true;
  168. }
  169. }
  170. return new QuantityEditCellType();
  171. },
  172. showSelectModal:function (hitinfo) {
  173. //锁定的清单不显示
  174. let project = projectObj.project;
  175. if(project.mainTree.selected.sourceType == ModuleNames.bills && project.isBillsLocked() && project.withinBillsLocked(project.mainTree.selected)){
  176. return;
  177. }
  178. this.initModalContent(hitinfo);
  179. $("#quantityEXPEdit").modal({show:true});
  180. },
  181. initModalContent:function (hitinfo) {
  182. //现在改成有可能点击时,还没选中节点,所以要靠row来判断
  183. let selected = projectObj.project.mainTree.items[hitinfo.row];
  184. if(selected.sourceType == ModuleNames.ration){//暂时只有定额才有基数选择,所以其它的先隐藏表格
  185. $("#quantityEditSpread").show();//quantityEditSpread
  186. }else {
  187. $("#quantityEditSpread").hide();
  188. }
  189. $("#quantityEXPValue").val(selected.data.quantityEXP);
  190. },
  191. checkingAndUpdate(quantityEXP,node){
  192. let me = this;
  193. if(quantityEXP === node.data.quantityEXP){ //没有变化,不做任何操作
  194. projectObj.mainController.refreshTreeNode([node]);
  195. return true;
  196. }
  197. quantityEXP = quantityEXP?quantityEXP.toUpperCase():'';//非空判断
  198. quantityEXP =replaceAll('(','(',quantityEXP);//转换中文左右符号
  199. quantityEXP =replaceAll(')',')',quantityEXP);
  200. let value = me.evalQuantityExp(quantityEXP,node);
  201. if(value!=='evalError'){
  202. if(node.data.hasOwnProperty('isFromDetail')&&node.data.isFromDetail==1){
  203. hintBox.infoBox('操作确认', '已有工程量明细,是否清空明细表?', 2, function () {
  204. node.data.isFromDetail=0;
  205. me.updateQuantityEXP(value,quantityEXP,node);
  206. }, function () {
  207. projectObj.mainController.refreshTreeNode([node]);
  208. },['确定','取消'],false);
  209. return true;
  210. }
  211. me.updateQuantityEXP(value,quantityEXP,node);
  212. return true;
  213. }else {
  214. projectObj.mainController.refreshTreeNode([node]);
  215. }
  216. return false;
  217. },
  218. evalQuantityExp(quantityEXP,node){
  219. let evalString = quantityEXP;
  220. if( node.sourceType == ModuleNames.ration && quantityEXP.indexOf('QDL')!=-1){
  221. let billNode = node.parent;
  222. let bQuantity = billNode.data.quantity?scMathUtil.roundForObj(billNode.data.quantity,getDecimal("quantity",billNode)):0;
  223. evalString = replaceAll("QDL","("+bQuantity+")",evalString);
  224. }
  225. try {
  226. let value = eval(evalString);
  227. return value;
  228. }catch (error){
  229. alert("输入的表达式有误,请重新输入!");
  230. return "evalError";
  231. }
  232. },
  233. updateQuantityEXP:function (value,quantityEXP,node) {
  234. let quantity_detail = projectObj.project.quantity_detail;
  235. quantity_detail.cleanQuantityDetail(node,true);
  236. if(node.sourceType === ModuleNames.bills){
  237. quantity_detail.updateBillQuantity(value,node,quantityEXP,quantityEXP);
  238. }else {
  239. quantity_detail.updateRationQuantity(value,node,quantityEXP,quantityEXP);
  240. }
  241. }
  242. };
  243. $(function(){
  244. $('#quantityEXPEdit').on('shown.bs.modal', function (e) {
  245. quantityEditObj.initSpread();
  246. });
  247. $('#operation_p').children("button").bind('click',function (){
  248. let oldVal = $("#quantityEXPValue").val();
  249. $("#quantityEXPValue").val(oldVal+$(this).text());
  250. $("#quantityEXPValue").focus();
  251. })
  252. $("#quantityEditConf").bind('click',function () {
  253. let selected = projectObj.project.mainTree.selected;
  254. let result = quantityEditObj.checkingAndUpdate($("#quantityEXPValue").val(),selected);
  255. if(result == true){
  256. $("#quantityEXPEdit").modal('hide');
  257. }
  258. })
  259. });