scratch.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. flag:true,
  6. isGet:false,//是否已经刮过奖
  7. startX: 0,
  8. startY: 0,
  9. startT:0,
  10. totleT:0,
  11. judgeX:false,
  12. judgeY:false,
  13. prize:0,
  14. orderid:'',
  15. coinNum:0
  16. },
  17. onLoad(options) {
  18. let that = this;
  19. // that.ctx = wx.createCanvasContext('myCanvas');
  20. // wx.getSystemInfo({
  21. // success: function(res) {
  22. // let screenWidth = res.screenWidth,pixelRatio = res.pixelRatio;
  23. // let imgH = 366 / (750 / screenWidth);
  24. // that.ctx.drawImage('/images/3.png', 0, 0, screenWidth, imgH);
  25. // that.ctx.draw();
  26. // }
  27. // })
  28. this.setData({coinNum:options.coin,isGet:options.coin&&options.coin>0?true:false})
  29. // this.userPrize(options.orderid);
  30. let pages = getCurrentPages(), prevPage = pages[pages.length - 2];
  31. if (prevPage.route == "pages/order/detail/index") {
  32. prevPage.data.query.otype = 0;
  33. }
  34. },
  35. jumpPage(e){
  36. let url=e.currentTarget.dataset.url;
  37. wx.navigateTo({
  38. url: url,
  39. })
  40. },
  41. userPrize(orderid){
  42. let that = this;
  43. util.ajax({
  44. func:'userPrize/scrapePrize',
  45. data:{"orderid":orderid}
  46. },function(res){
  47. if(res.code == 0){
  48. that.setData({prize:res.data.prize,orderid:orderid,isGet:true})
  49. }else if(res.code == -1){
  50. that.setData({isGet:false});
  51. }else{
  52. util.showTips(res.reason);
  53. }
  54. })
  55. },
  56. touchStart(e){
  57. var startX1 = e.changedTouches[0].x;
  58. var startY1 = e.changedTouches[0].y;
  59. this.ctx.save();
  60. this.ctx.beginPath();
  61. this.ctx.clearRect(startX1, startY1, 20, 20);
  62. this.ctx.restore();
  63. this.setData({startT:e.timeStamp,startX:startX1,startY:startY1});
  64. },
  65. touchMove(e){
  66. var startX1 = e.changedTouches[0].x;
  67. var startY1 = e.changedTouches[0].y;
  68. this.ctx.save();
  69. this.ctx.moveTo(this.startX, this.startY);
  70. this.ctx.clearRect(startX1, startY1,20,20);
  71. this.ctx.restore();
  72. this.startX = startX1;
  73. this.startY = startY1;
  74. wx.drawCanvas({
  75. canvasId: 'myCanvas',
  76. reserve: true,
  77. actions:this.ctx.getActions()
  78. })
  79. let startY = this.data.startY,startX = this.data.startX;
  80. if(Math.abs(startX - startX1) > 100){
  81. this.setData({judgeX:true})
  82. }
  83. if(Math.abs(startY - startY1) > 30){
  84. this.setData({judgeY:true})
  85. }
  86. },
  87. touchEnd(e){
  88. let totleT = this.data.totleT + e.timeStamp - this.data.startT,judgeX = this.data.judgeX,judgeY = this.data.judgeY;
  89. if((totleT > 1500 && judgeX && judgeY) || totleT > 3000 ){
  90. this.setData({flag:false})
  91. this.upData()
  92. }else{
  93. this.setData({totleT});
  94. }
  95. },
  96. upData(){
  97. let that = this;
  98. util.ajax({
  99. func:'userPrize/update',
  100. data:{"orderid":that.data.orderid},
  101. load:false
  102. },function(res){
  103. wx.reportAnalytics('click_scratch', {
  104. orderid:that.data.orderid
  105. });
  106. })
  107. }
  108. })